After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 436796 - Wrong return type for RadioAction create_tool_item and create_menu_item
Wrong return type for RadioAction create_tool_item and create_menu_item
Status: RESOLVED WONTFIX
Product: pygtk
Classification: Bindings
Component: documentation
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
gnome[unmaintained]
Depends on:
Blocks:
 
 
Reported: 2007-05-08 07:21 UTC by Don Hopkins
Modified: 2018-08-17 13:37 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Don Hopkins 2007-05-08 07:21:35 UTC
Please describe the problem:
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



Steps to reproduce:
########################################################################
# gtk_action_bug.py
# Don Hopkins (dhopkins@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!!!


"""




Actual results:


# 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!!!


"""



Expected results:
It should make the documented classes, instead of the weird ones. 

Does this happen every time?
Yes.

Other information:
This took a long time to diagnose. 
It made it very difficult to create my own custom actions. 
Now that I know what the bug is, I can work around it, but it's a gross hack. 
There are other bugs in the buttons that cause them to draw (when the cursor is over them, and when they are redrawn in response to user input), which I will file separately, that I would like to be able to work around by creating my own classes.
Comment 1 Johan (not receiving bugmail) Dahlin 2007-05-08 13:22:18 UTC
What's wrong about this bug is that the documentation does not properly reflect what the methods return.

PyGTK is not doing anything special wrt to create_menu_item/create_tool_item, it just returns a wrapper for the object created by GTK+ itself.

Confirming bug and moving to documentation.
Comment 2 Don Hopkins 2007-05-09 02:09:27 UTC
Agreed that it would be good to fix the documentation to describe the actual behavior (both correcting the pygtk doc and elaborating the gtk doc to specify the right classes and relationships between actions and items). 

But there still exist some confusing classes like RadioToolButton, ToggleMenuItem and RadioMenuItem that don't seem to be used (and don't work when I subclass them and use them instead of the ones that are actually used: the RadioToolButtons are all selected and won't deselect). Would it be a good idea to fix or remove them? Does anything else use them? 
Comment 3 Johan (not receiving bugmail) Dahlin 2007-05-09 02:29:37 UTC
(In reply to comment #2)
> Agreed that it would be good to fix the documentation to describe the actual
> behavior (both correcting the pygtk doc and elaborating the gtk doc to specify
> the right classes and relationships between actions and items). 
> 
> But there still exist some confusing classes like RadioToolButton,
> ToggleMenuItem and RadioMenuItem that don't seem to be used (and don't work
> when I subclass them and use them instead of the ones that are actually used:
> the RadioToolButtons are all selected and won't deselect). Would it be a good
> idea to fix or remove them? Does anything else use them? 
> 

Perhaps, but file another bug against gtk+ and not pygtk then.
Just remember that you can't remove or change any API anyway, neither gtk+ nor pygtk is allowed to break the API.

Please leave this bug in the documentation component.
Comment 4 André Klapper 2018-08-17 13:37:42 UTC
pygtk is not under active development anymore and had its last code changes
in 2013. Its codebase has been archived:
https://gitlab.gnome.org/Archive/pygtk/commits/master

PyGObject at https://gitlab.gnome.org/GNOME/pygobject is its successor. See https://pygobject.readthedocs.io/en/latest/guide/porting.html for porting info.

Closing this report as WONTFIX as part of Bugzilla Housekeeping to reflect
reality. Feel free to open a task in GNOME Gitlab if the issue described in this task still applies to a recent version of PyGObject. Thanks!