#36 setitems in OptionMenu: previous list not removed

closed-fixed
Adrian
None
5
2013-02-04
2013-01-07
No

In the method setitems in PmwOptionMenu, there is two bugs (at least from my point of view)

1) line 69, self._menu.delete(0,'end') should be out of the "if sys.version_info" block and therefore should be aligned with self._itemList=list(items)
The consequence is that the previous list of items is not removed
2) line 94, self.setvalue(text) should be out of the "if index is None:" block and therefore should be aligned with "if index is None:" and with "else:"
The consequence is that if index is None, the textvariable is not set to the first element of the list of items as required by line 89: text = items[0].
Indeed, line 89 set the variable text to be the first items but this variable is never used if line 94 "self.setvalue(text)" is not aligned correctly.

These 2 bugs are found in Pmw 1.3.3 as well as in Pmw 2.0.0.

Best regards
Vincent LIEGEOIS

PS

The patch is therefore:
##########################################
69c69
< self._menu.delete(0, 'end')
---
> self._menu.delete(0, 'end')
94c94
< self.setvalue(text)
---
> self.setvalue(text)
#####################

PS2:

Here is an example to illustrate the two bugs:
########################
#!/usr/bin/env python

import Pmw
import Tkinter

category=["Sport","Music"]
sport = ["Tennis","Soccer","Baseball"]
music = ["Piano","Guitar"]

def printcategories(var):
print om1.getvalue(),var

def setsubcategory(var):
if var not in category:
return
if var == "Sport":
om2.setitems(sport)
elif var == "Music":
om2.setitems(music)

root = Tkinter.Tk()
Pmw.initialise(root)
om1 = Pmw.OptionMenu(root,labelpos='w',label_text="Choose a category:",
items= category,command=setsubcategory)
om1.pack()

om2 = Pmw.OptionMenu(root,labelpos="w",label_text="Choose a subcategory:",command=printcategories)
om2.pack()

root.mainloop()
########################

At the start of the program, both optionmenu field are empty (see screenshot1).
After selecting the category "Sport", the subcategory field is still empty.
Then, i select a subcategory.
Now, let's choose another category, the category "Music".
In the list of items in subcategory, i have the choice between "Piano", "Guitar", but also "Tennis", "Soccer", "Baseball' which is wrong (see screenshot2)

The good behavior would be:
At the start of the program, the optionmenu field for the category display "Sport' (see screenshot3) because it is the first items.
After selecting the category "Sport", the subcategory field display "Tennis" as it is the first items in the sport list
If I now select the category "Music', the possible values for the subcategory are "Piano" and "Guitar" alone.

Discussion

  • Adrian

    Adrian - 2013-02-04

    Thanks for the catch. The problem's been fixed and will soon be available in the CVS tree for both Pmw 1.3.3 and Pmw 2.

     
  • Adrian

    Adrian - 2013-02-04
    • assigned_to: nobody --> adyh
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks