diff options
author | JosephSBoyle <48555120+JosephSBoyle@users.noreply.github.com> | 2023-02-28 06:11:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-28 06:11:52 (GMT) |
commit | c41af812c948ec3cb07b2ef7a46a238f5cab3dc2 (patch) | |
tree | 6e8944b309fd7d9e824711ca71cca345f529ac90 | |
parent | 0f89acf6cc4d4790f7b7a82165d0a6e7e84e4b72 (diff) | |
download | cpython-c41af812c948ec3cb07b2ef7a46a238f5cab3dc2.zip cpython-c41af812c948ec3cb07b2ef7a46a238f5cab3dc2.tar.gz cpython-c41af812c948ec3cb07b2ef7a46a238f5cab3dc2.tar.bz2 |
IDLE: Simplify DynOptionsMenu __init__code (#101371)
Refactor DynOptionMenu's initializer to not copy kwargs dict and use subscripting;
improve its htest.
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
-rw-r--r-- | Lib/idlelib/dynoption.py | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/Lib/idlelib/dynoption.py b/Lib/idlelib/dynoption.py index 9c6ffa4..d5dfc3e 100644 --- a/Lib/idlelib/dynoption.py +++ b/Lib/idlelib/dynoption.py @@ -2,24 +2,19 @@ OptionMenu widget modified to allow dynamic menu reconfiguration and setting of highlightthickness """ -import copy - from tkinter import OptionMenu, _setit, StringVar, Button class DynOptionMenu(OptionMenu): - """ - unlike OptionMenu, our kwargs can include highlightthickness + """Add SetMenu and highlightthickness to OptionMenu. + + Highlightthickness adds space around menu button. """ def __init__(self, master, variable, value, *values, **kwargs): - # TODO copy value instead of whole dict - kwargsCopy=copy.copy(kwargs) - if 'highlightthickness' in list(kwargs.keys()): - del(kwargs['highlightthickness']) + highlightthickness = kwargs.pop('highlightthickness', None) OptionMenu.__init__(self, master, variable, value, *values, **kwargs) - self.config(highlightthickness=kwargsCopy.get('highlightthickness')) - #self.menu=self['menu'] - self.variable=variable - self.command=kwargs.get('command') + self['highlightthickness'] = highlightthickness + self.variable = variable + self.command = kwargs.get('command') def SetMenu(self,valueList,value=None): """ @@ -38,14 +33,15 @@ def _dyn_option_menu(parent): # htest # from tkinter import Toplevel # + StringVar, Button top = Toplevel(parent) - top.title("Tets dynamic option menu") + top.title("Test dynamic option menu") x, y = map(int, parent.geometry().split('+')[1:]) top.geometry("200x100+%d+%d" % (x + 250, y + 175)) top.focus_set() var = StringVar(top) var.set("Old option set") #Set the default value - dyn = DynOptionMenu(top,var, "old1","old2","old3","old4") + dyn = DynOptionMenu(top, var, "old1","old2","old3","old4", + highlightthickness=5) dyn.pack() def update(): @@ -54,5 +50,6 @@ def _dyn_option_menu(parent): # htest # button.pack() if __name__ == '__main__': + # Only module without unittests because of intention to replace. from idlelib.idle_test.htest import run run(_dyn_option_menu) |