2001-10-26 06:49:14 +00:00
|
|
|
"""
|
|
|
|
OptionMenu widget modified to allow dynamic menu reconfiguration
|
2001-11-03 14:55:47 +00:00
|
|
|
and setting of highlightthickness
|
2001-10-26 06:49:14 +00:00
|
|
|
"""
|
|
|
|
from Tkinter import OptionMenu
|
|
|
|
from Tkinter import _setit
|
2001-11-03 14:55:47 +00:00
|
|
|
import copy
|
2001-10-26 06:49:14 +00:00
|
|
|
|
|
|
|
class DynOptionMenu(OptionMenu):
|
|
|
|
"""
|
2001-11-03 14:55:47 +00:00
|
|
|
unlike OptionMenu, our kwargs can include highlightthickness
|
2001-10-26 06:49:14 +00:00
|
|
|
"""
|
|
|
|
def __init__(self, master, variable, value, *values, **kwargs):
|
2001-11-03 14:55:47 +00:00
|
|
|
#get a copy of kwargs before OptionMenu.__init__ munges them
|
|
|
|
kwargsCopy=copy.copy(kwargs)
|
|
|
|
if 'highlightthickness' in kwargs.keys():
|
|
|
|
del(kwargs['highlightthickness'])
|
2001-10-26 06:49:14 +00:00
|
|
|
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
|
2001-11-03 14:55:47 +00:00
|
|
|
self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
|
2001-10-26 06:49:14 +00:00
|
|
|
#self.menu=self['menu']
|
|
|
|
self.variable=variable
|
|
|
|
self.command=kwargs.get('command')
|
|
|
|
|
2001-10-29 08:05:34 +00:00
|
|
|
def SetMenu(self,valueList,value=None):
|
2001-10-26 06:49:14 +00:00
|
|
|
"""
|
|
|
|
clear and reload the menu with a new set of options.
|
|
|
|
valueList - list of new options
|
|
|
|
value - initial value to set the optionmenu's menubutton to
|
|
|
|
"""
|
|
|
|
self['menu'].delete(0,'end')
|
|
|
|
for item in valueList:
|
|
|
|
self['menu'].add_command(label=item,
|
|
|
|
command=_setit(self.variable,item,self.command))
|
2001-10-29 08:05:34 +00:00
|
|
|
if value:
|
|
|
|
self.variable.set(value)
|