[sugar] Bug in pygtk RadioAction

Don Hopkins dhopkins
Tue May 8 03:23:13 EDT 2007


(I've filed the following bugs against gtk/pygtk):

http://bugzilla.gnome.org/show_bug.cgi?id=436796

Apparently a RadioAction does not create the documented classes 
RadioMenuItem when you call create_menu_item(), and RadioToolButton when 
you call create_tool_item(). Instead of a RadioMenuItem it creates a 
RadioToggleItem, and instead of RadioToolItem it creates a CheckMenuItem.

I discovered this issue when I tried to create my own subclass of 
RadioAction called SugarRadioAction and went 
SugarRadioAction.set_tool_item_type(SugarRadioToolButton) so it would 
make my own subclass of gtk.RadioToolButton. Unfortunately it did not 
work when my SugarRadioToolButton was a subclass of gtk.RadioToolButton 
-- it selected all the buttons at once and never let me deselect them, 
instead of only having one selected at once like a good radio button 
set. But I noticed that normal RadioActions were actually creating 
gtk.ToggleToolButton's instead of gtk.RadioToolButton's, so I changed 
SugarRadioButton to subclass gtk.ToggleToolButton instead of 
gtk.RadioToolButton, and suddenly it started working correctly!

Here is the documentation for pygtk's Radio Actions, which incorrectly 
states the corresponding proxy widgets are RadioMenuItem and 
RadioToolButton. The gtk+ documentation itself is more vague, just 
muttering something about how RadioAction is similar to RadioMenuItem, 
but not specifying which proxy classes RadioAction actually makes.

http://www.pygtk.org/pygtk2tutorial/ch-NewInPyGTK2.4.html

    16.1.1.7. Radio Actions

    A RadioAction is a subclass of ToggleAction that can be grouped so 
that only one RadioAction is active at a time. The corresponding proxy 
widgets are the RadioMenuItem and RadioToolButton.

http://www.pygtk.org/docs/pygtk/class-gtkradioaction.html

    A gtk.RadioAction is a subclass of gtk.ToggleAction and similar to 
gtk.RadioMenuItem. A number of radio actions can be linked together so 
that only one may be active at any one time.

Here is a minimal test program that demonstrates the problem, followed 
by its output.

    -Don

########################################################################
# gtk_action_bug.py
# Don Hopkins (dhopkins at DonHopkins.com)


import gtk

# Test ToggleAction, which works as documented.

toggle_action = gtk.ToggleAction('a', 'label', None, None)
print "Made toggle_action", toggle_action

toggle_tool_item = toggle_action.create_tool_item()
print "toggle_action.create_tool_item() RETURNED", toggle_tool_item, "SHOULD BE", gtk.ToggleToolButton, "AND IT IS!"

toggle_menu_item = toggle_action.create_menu_item()
print "toggle_action.create_menu_item RETURNED", toggle_menu_item, "SHOULD BE", gtk.CheckMenuItem, "AND IT IS!"

# Test RadioAction, which does not work as documented.

radio_action = gtk.RadioAction('a', 'label', None, None, 1)
print "Made radio_action", radio_action

radio_tool_item = radio_action.create_tool_item()
print "radio_action.create_tool_item() RETURNED", radio_tool_item, "SHOULD BE", gtk.RadioToolButton, "BUT IT IS NOT!!!"

radio_menu_item = radio_action.create_menu_item()
print "radio_action.create_menu_item() RETURNED", radio_menu_item, "SHOULD BE", gtk.RadioMenuItem, "BUT IT IS NOT!!!"



# Output:
"""
Made toggle_action <gtk.ToggleAction object at 0xb7ec8be4 (GtkToggleAction at 0xa020d10)>
toggle_action.create_tool_item() RETURNED <gtk.ToggleToolButton object at 0xb7ec85cc (GtkToggleToolButton at 0xa030810)> SHOULD BE <type 'gtk.ToggleToolButton'> AND IT IS!
toggle_action.create_menu_item RETURNED <gtk.CheckMenuItem object at 0xb7ec8824 (GtkCheckMenuItem at 0xa021570)> SHOULD BE <type 'gtk.CheckMenuItem'> AND IT IS!
Made radio_action <gtk.RadioAction object at 0xb7ec884c (GtkRadioAction at 0xa03d808)>
radio_action.create_tool_item() RETURNED <gtk.ToggleToolButton object at 0xb7ec8dc4 (GtkToggleToolButton at 0xa030940)> SHOULD BE <type 'gtk.RadioToolButton'> BUT IT IS NOT!!!
radio_action.create_menu_item() RETURNED <gtk.CheckMenuItem object at 0xb7ec8dec (GtkCheckMenuItem at 0xa0215d8)> SHOULD BE <type 'gtk.RadioMenuItem'> BUT IT IS NOT!!!


"""





More information about the Sugar-devel mailing list