If you create an option menu using GtkExtra.MenuFactory, the resulting
menu is "squashed", and initially appears with no default setting.

The reason turns out to be simple, and typical of Gtk+. If you
associate a GtkMenu with a GtkOptionMenu before adding items to the
GtkMenu, the GtkOptionMenu behaves as above.  If you wait until the
GtkMenu is fully populated, the GtkOptionMenu displays a default
selection and has a reasonable size.

I tried a couple of different mods to GtkExtra.MenuFactory, hoping to
apply the above workaround without breaking any existing behavior. 
And failed.  (I haven't tried refactoring MenuFactory into a set of
related classes.  Maybe tomorrow...)

Instead, here's a hacky workaround: a subclass which re-attaches the
GtkMenu to its GtkOptionMenu every time a new menu item is created.

import GtkExtra

class OptionMenuFactory(GtkExtra.MenuFactory):
    def create(self, path, accelerator=None, callback=None, *args):
        """Work around a Gtk+ bug:  if you set_menu on a GtkOptionMenu
        before the corresponding GtkMenu has been fully populated, the  
        result is a 'squished', initially blank option menu.

        A better workaround might be to refactor GtkExtra.MenuFactory
        into a hierarchy of classes."""
        result = apply(GtkExtra.MenuFactory.create,
                       (self, path, accelerator, callback) + args)
        self._MenuFactory__ret.remove_menu()
        self._MenuFactory__ret.set_menu(self._MenuFactory__w)
        return result

--
Mitch Chapman
[EMAIL PROTECTED]
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to