bug with "enum" initalization

Bug #418654 reported by Paulo Zanoni
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gDesklets
Fix Released
Medium
Bjoern Koch

Bug Description

I'm talking about config/ConfigEnum.py:

When the enum is being initialized, the code does this:

   self.__optmenu.set_active(-1)
   self.__optmenu.set_active(index)

From what I understood, this code is meant to force a "change event", which will trigger the script callbacks.

According to gtk's manual [0], the "-1" position means "inactive".

But here is the problem:

If you look at the __on_change function (inside the same file), it has something like this:
   value = self.__items_values[src.get_active()]

BUT: get_active() returns "-1", so the last element on that list is returned (because in Python, the last element of a list has index "-1"). This is wrong, because the enum is inactive! The way it is now, when the enum is being initialized, its last option will always be "selected" before the correct option is set. And this behavior causes bugs in the applet I'm debugging.

The solution:

The __on_change function needs to check if the "enum" is active or inactive before doing anything, so, replace this line (inside __on_change function, same file):

   if (self.__items_values):

with this line:
   if (self.__items_values) and (src.get_active() != -1):

This way, when the item is changed to "inactive" (index -1), we won't act as if it was changed to the "last item".

[0]: http://www.pygtk.org/docs/pygtk/class-gtkcombobox.html#method-gtkcombobox--get-active

Revision history for this message
Paulo Zanoni (pzanoni) wrote :
Revision history for this message
Bjoern Koch (h.humpel) wrote :

Thanks for the patch! Fix committed in revision 123.
Is there the same problem in ConfigList and ConfigToggle ?

Changed in gdesklets:
assignee: nobody → Bjoern Koch (h.humpel)
importance: Undecided → Medium
milestone: none → release-of-0.36.2
status: New → Fix Committed
Revision history for this message
Bjoern Koch (h.humpel) wrote :

Released with gDesklets 0.36.2.

Changed in gdesklets:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.