On Thu, 2007-03-08 at 11:00 +0100, Geoff Bache wrote:
Hello,

I'm wondering about defining a menu structure using gtk.UIManager and an XML file. What confuses me a bit is that it seems to be necessary to define which menus and submenus I have in the Python code, even if I can then control their contents from XML. The reason seems to be that everything has to have
an "action".

I define a menu like this:

<menu action="actionsmenu">
      <menuitem action="Select"/>
      <menuitem action="Run"/>
</menu>

But for this to work I have to write (somewhere in my Python code)

menuAction = gtk.Action("actionsmenu", "_Actions", None, None)
...

just in order to translate the identifier "actionsmenu" into the label "_Actions".

I'd like to be able to write something like

<menu label="_Actions>

so that I can define the whole menu structure in one format in one place. Is this possible in some way?

I don't believe it's possible and for good reason. A major
benefit/feature of UIManger is making actions independent of any given
widget, e.g. a menu item. When the notion of separated actions and
widgets introduced you can then combine them at will without having to
keep multiple widgets in sync. One reason I switched to UIManager was
the all too common scenario where an icon or label was modified in one
part of the UI but other parts of the UI (e.g. the same item in a popup
menu or a toolbar button) was forgotten about in the update leading to
inconsistencies in the UI. I really like the fact I change the
definition in exactly one place and every part of the UI is consistently
updated. That flexibility and consistency occurs because actions and
widgets are independent.

I agree, but I think you've missed the point. All my actions and widgets are independent and that's great. My point is that the menus and submenus themselves are just display details, they don't really correspond to any action. My code does not react when somebody just clicks a menu without actually selecting a menu item.
I have no problem with how it works for the menu items themselves.

It therefore seems odd to me that I can put most of the display details in an XML file but have to hardcode the "allowed names" of all the menus and submenus in my Python code, when all this code does is translate
one string identifier to another.

Regards,
Geoff

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to