How to use ToolBarData_t

I am trying to create a toolbar in PyRoot. However, I need to fill a structrue ToolBarData_t, that contains const char * fPixmap. When I declare the structure object a, and try a.fPixmap = “path”, then I get an error:

TypeError: assignment to const data not allowed

So how should I initialize thee structure? And then, how should I pass it to TGToolBar::AddButton, which requires an address of the structure?


the array semantics (done for data buffers used in TTree, see e.g. tutorials/pyroot/ are that the values are copied over from a buffer in python to the one in C++, as it is assumed that the array in C++ is pointing somewhere.

Given that the pointer is to const data, it can’t write into it …

Not sure how to tackle this one then, given that the pointers point into nowhere (the ToolBarData_t does not have a ctor that sets them to NULL or any other recognizable value). It would be possible to allocate memory and copy from the python string into it. Tough call on memory management after that, though, and not sure what to do if you were to set the value a second time. Extracting the pointer out of the python string is also possible, but then you’d have a life-time management problem of the same order as the earlier memory problem.

So, unless you can give me a consistent set of rules to implement the expected behavior on this one, I would suggest following this approach:[code]>>> import ROOT

ROOT.gROOT.ProcessLine(‘ToolBarData_t myTBData = { “aap”, “noot”, false, 0, 0 };’)
print ROOT.myTBData.fPixmap



Perhaps the easiest solution would be to add a class for the ToolBarData_t and new method for ToolBarData to be initialized with that class. It should’nt break any backward compatibility, should be very simple and somehow go with ROOT objectivity.


yes, a constructor with proper default values would go a long way. However, then one can no longer use the {} initializer list to initialize ToolBarData_t objects and arrays. There are quite a few of those in the ROOT code, and presumably then also in the wider world. So, that’d all break. :frowning:

This only changes with C++11, which introduces the concept of “uniform initializers”, allowing both the default constructor and initializer list to co-exist.

So, revisit when we have the language upgrade (i.e. post Cling/ROOT6 becoming the default) …