Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: dynOptionMenuWidget.py
"""
[0] Fix | Delete
OptionMenu widget modified to allow dynamic menu reconfiguration
[1] Fix | Delete
and setting of highlightthickness
[2] Fix | Delete
"""
[3] Fix | Delete
import copy
[4] Fix | Delete
from Tkinter import OptionMenu, _setit, StringVar, Button
[5] Fix | Delete
[6] Fix | Delete
class DynOptionMenu(OptionMenu):
[7] Fix | Delete
"""
[8] Fix | Delete
unlike OptionMenu, our kwargs can include highlightthickness
[9] Fix | Delete
"""
[10] Fix | Delete
def __init__(self, master, variable, value, *values, **kwargs):
[11] Fix | Delete
# TODO copy value instead of whole dict
[12] Fix | Delete
kwargsCopy=copy.copy(kwargs)
[13] Fix | Delete
if 'highlightthickness' in kwargs.keys():
[14] Fix | Delete
del(kwargs['highlightthickness'])
[15] Fix | Delete
OptionMenu.__init__(self, master, variable, value, *values, **kwargs)
[16] Fix | Delete
self.config(highlightthickness=kwargsCopy.get('highlightthickness'))
[17] Fix | Delete
#self.menu=self['menu']
[18] Fix | Delete
self.variable=variable
[19] Fix | Delete
self.command=kwargs.get('command')
[20] Fix | Delete
[21] Fix | Delete
def SetMenu(self,valueList,value=None):
[22] Fix | Delete
"""
[23] Fix | Delete
clear and reload the menu with a new set of options.
[24] Fix | Delete
valueList - list of new options
[25] Fix | Delete
value - initial value to set the optionmenu's menubutton to
[26] Fix | Delete
"""
[27] Fix | Delete
self['menu'].delete(0,'end')
[28] Fix | Delete
for item in valueList:
[29] Fix | Delete
self['menu'].add_command(label=item,
[30] Fix | Delete
command=_setit(self.variable,item,self.command))
[31] Fix | Delete
if value:
[32] Fix | Delete
self.variable.set(value)
[33] Fix | Delete
[34] Fix | Delete
def _dyn_option_menu(parent): # htest #
[35] Fix | Delete
from Tkinter import Toplevel
[36] Fix | Delete
[37] Fix | Delete
top = Toplevel()
[38] Fix | Delete
top.title("Tets dynamic option menu")
[39] Fix | Delete
top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
[40] Fix | Delete
parent.winfo_rooty() + 150))
[41] Fix | Delete
top.focus_set()
[42] Fix | Delete
[43] Fix | Delete
var = StringVar(top)
[44] Fix | Delete
var.set("Old option set") #Set the default value
[45] Fix | Delete
dyn = DynOptionMenu(top,var, "old1","old2","old3","old4")
[46] Fix | Delete
dyn.pack()
[47] Fix | Delete
[48] Fix | Delete
def update():
[49] Fix | Delete
dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
[50] Fix | Delete
button = Button(top, text="Change option set", command=update)
[51] Fix | Delete
button.pack()
[52] Fix | Delete
[53] Fix | Delete
if __name__ == '__main__':
[54] Fix | Delete
from idlelib.idle_test.htest import run
[55] Fix | Delete
run(_dyn_option_menu)
[56] Fix | Delete
[57] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function