1"""
2OptionMenu widget modified to allow dynamic menu reconfiguration
3and setting of highlightthickness
4"""
5from Tkinter import OptionMenu
6from Tkinter import _setit
7import copy
8
9class DynOptionMenu(OptionMenu):
10    """
11    unlike OptionMenu, our kwargs can include highlightthickness
12    """
13    def __init__(self, master, variable, value, *values, **kwargs):
14        #get a copy of kwargs before OptionMenu.__init__ munges them
15        kwargsCopy=copy.copy(kwargs)
16        if 'highlightthickness' in kwargs.keys():
17            del(kwargs['highlightthickness'])
18        OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
19        self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
20        #self.menu=self['menu']
21        self.variable=variable
22        self.command=kwargs.get('command')
23
24    def SetMenu(self,valueList,value=None):
25        """
26        clear and reload the menu with a new set of options.
27        valueList - list of new options
28        value - initial value to set the optionmenu's menubutton to
29        """
30        self['menu'].delete(0,'end')
31        for item in valueList:
32            self['menu'].add_command(label=item,
33                    command=_setit(self.variable,item,self.command))
34        if value:
35            self.variable.set(value)
36