XRC: using the same status bar text for menus and toolbar

Is there a way to connect a menu item and a toolbar button in XRC so that they use the same status bar help text? I see that in order for them to have the same functionality, you just give them the same ID, but is there a similar thing for the help text?

Thanks.

John Salerno wrote:

Is there a way to connect a menu item and a toolbar button in XRC so that they use the same status bar help text? I see that in order for them to have the same functionality, you just give them the same ID, but is there a similar thing for the help text?

No, there isn't a way to do that. (It's a good idea though.)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

John Salerno wrote:

Is there a way to connect a menu item and a toolbar button in XRC so that they use the same status bar help text? I see that in order for them to have the same functionality, you just give them the same ID, but is there a similar thing for the help text?

No, there isn't a way to do that. (It's a good idea though.)

Hmm. How is this normally done when hand-writing the GUI code? I would imagine one way is to just define the text as a variable, then pass that variable as the help text argument when creating the widget.

Something similar in XRC could be that instead of a value in the XRC file (e.g. "Click here to destroy computer"), you can insert a variable, and then as long as that variable is defined in your Python program before the xrc file is loaded, it will receive that value wherever it appears in the xml file. Or is that not even possible?

E.g.:

longhelp = "Click here to destroy computer"
self.res = xrc.XmlResource('gui.xrc')

And inside the XRC file:

<object class="tool" name="newRecord">
   <bitmap>image.png</bitmap>
   <tooltip>Something here</tooltip>
   <longhelp>$longhelp</longhelp> #'$' for a variable?
</object>

Eh, maybe this is too messy. Just a thought. Probably the real answer is more inline with how you can give menu items and toolbar buttons the same functionality, i.e. create a new attribute that ties them together, like the ID.

John Salerno wrote:

Robin Dunn wrote:

John Salerno wrote:

Is there a way to connect a menu item and a toolbar button in XRC so that they use the same status bar help text? I see that in order for them to have the same functionality, you just give them the same ID, but is there a similar thing for the help text?

No, there isn't a way to do that. (It's a good idea though.)

Hmm. How is this normally done when hand-writing the GUI code? I would imagine one way is to just define the text as a variable, then pass that variable as the help text argument when creating the widget.

Something similar in XRC could be that instead of a value in the XRC file (e.g. "Click here to destroy computer"), you can insert a variable, and then as long as that variable is defined in your Python program before the xrc file is loaded, it will receive that value wherever it appears in the xml file. Or is that not even possible?

No, the C++ code that loads the XRC is not aware of the python namespace it is being called from, or even that Python is there at all.

E.g.:

longhelp = "Click here to destroy computer"
self.res = xrc.XmlResource('gui.xrc')

One approach you could take is to substitute the values into the xml before loading it into the XmlResource. For example, you can define your strings in the XRC with "%(longhelp)s" syntax, and then use Python's string substitution to insert the values into the string from your local variables:

longhelp = "Click here to destroy computer"
xmltext = file('gui.xrc').read()
xmltext = xmltext % locals()
self.res = xrc.EmptyXmlRsource()
self.res.LoadFromString(xmltext)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

One approach you could take is to substitute the values into the xml before loading it into the XmlResource. For example, you can define your strings in the XRC with "%(longhelp)s" syntax, and then use Python's string substitution to insert the values into the string from your local variables:

longhelp = "Click here to destroy computer"
xmltext = file('gui.xrc').read()
xmltext = xmltext % locals()
self.res = xrc.EmptyXmlRsource()
self.res.LoadFromString(xmltext)

Very interesting! This could be useful for a lot of things (although I can't think of anything else right now!).