1edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""Wrapper functions for Tcl/Tk.
2edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepTkinter provides classes which allow the display, positioning and
4edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepcontrol of widgets. Toplevel widgets are Tk and Toplevel. Other
5edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepwidgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
6edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepCheckbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
7edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepLabelFrame and PanedWindow.
8edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
9edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepProperties of the widgets are specified with keyword arguments.
10edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepKeyword arguments have the same name as the corresponding resource
11edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepunder Tk.
12edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
13edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepWidgets are positioned with one of the geometry managers Place, Pack
14edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepor Grid. These managers can be called with methods place, pack, grid
15edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepavailable in every Widget.
16edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
17edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepActions are bound to events by resources (e.g. keyword argument
18edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepcommand) or with the method bind.
19edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
20edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepExample (Hello, World):
21edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport Tkinter
22edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom Tkconstants import *
23edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptk = Tkinter.Tk()
24edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepframe = Tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
25edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepframe.pack(fill=BOTH,expand=1)
26edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeplabel = Tkinter.Label(frame, text="Hello, World")
27edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeplabel.pack(fill=X, expand=1)
28edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepbutton = Tkinter.Button(frame,text="Exit",command=tk.destroy)
29edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepbutton.pack(side=BOTTOM)
30edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptk.mainloop()
31edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep"""
32edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
33edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep__version__ = "$Revision: 81008 $"
34edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
35edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport sys
36edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif sys.platform == "win32":
37edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Attempt to configure Tcl/Tk without requiring PATH
38edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    import FixTk
39edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport _tkinter # If this fails your Python may not be configured for Tk
40edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptkinter = _tkinter # b/w compat for export
41edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepTclError = _tkinter.TclError
42edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom types import *
43edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom Tkconstants import *
44edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport re
45edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
46edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepwantobjects = 1
47edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
48edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepTkVersion = float(_tkinter.TK_VERSION)
49edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepTclVersion = float(_tkinter.TCL_VERSION)
50edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
51edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepREADABLE = _tkinter.READABLE
52edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepWRITABLE = _tkinter.WRITABLE
53edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander StoepEXCEPTION = _tkinter.EXCEPTION
54edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
55edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# These are not always defined, e.g. not on Win32 with Tk 8.0 :-(
56edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptry: _tkinter.createfilehandler
57edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepexcept AttributeError: _tkinter.createfilehandler = None
58edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptry: _tkinter.deletefilehandler
59edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepexcept AttributeError: _tkinter.deletefilehandler = None
60edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
61edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
62edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep_magic_re = re.compile(r'([\\{}])')
63edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep_space_re = re.compile(r'([\s])')
64edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
65edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _join(value):
66edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal function."""
67edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return ' '.join(map(_stringify, value))
68edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
69edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _stringify(value):
70edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal function."""
71edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    if isinstance(value, (list, tuple)):
72edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if len(value) == 1:
73edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = _stringify(value[0])
74edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if value[0] == '{':
75edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                value = '{%s}' % value
76edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
77edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = '{%s}' % _join(value)
78edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    else:
79edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if isinstance(value, basestring):
80edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = unicode(value)
81edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
82edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = str(value)
83edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not value:
84edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = '{}'
85edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif _magic_re.search(value):
86edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # add '\' before special characters and spaces
87edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = _magic_re.sub(r'\\\1', value)
88edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = _space_re.sub(r'\\\1', value)
89edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif value[0] == '"' or _space_re.search(value):
90edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = '{%s}' % value
91edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return value
92edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
93edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _flatten(tuple):
94edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal function."""
95edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    res = ()
96edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    for item in tuple:
97edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(item) in (TupleType, ListType):
98edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            res = res + _flatten(item)
99edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif item is not None:
100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            res = res + (item,)
101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return res
102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptry: _flatten = _tkinter._flatten
104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepexcept AttributeError: pass
105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _cnfmerge(cnfs):
107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal function."""
108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    if type(cnfs) is DictionaryType:
109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return cnfs
110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    elif type(cnfs) in (NoneType, StringType):
111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return cnfs
112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    else:
113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cnf = {}
114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for c in _flatten(cnfs):
115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                cnf.update(c)
117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except (AttributeError, TypeError), msg:
118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                print "_cnfmerge: fallback due to:", msg
119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                for k, v in c.items():
120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    cnf[k] = v
121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return cnf
122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoeptry: _cnfmerge = _tkinter._cnfmerge
124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepexcept AttributeError: pass
125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Event:
127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Container for the properties of an event.
128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Instances of this type are generated if one of the following events occurs:
130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    KeyPress, KeyRelease - for keyboard events
132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ButtonPress, ButtonRelease, Motion, Enter, Leave, MouseWheel - for mouse events
133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Visibility, Unmap, Map, Expose, FocusIn, FocusOut, Circulate,
134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Colormap, Gravity, Reparent, Property, Destroy, Activate,
135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Deactivate - for window events.
136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    If a callback function for one of these events is registered
138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    using bind, bind_all, bind_class, or tag_bind, the callback is
139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    called with an Event as first argument. It will have the
140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    following attributes (in braces are the event types for which
141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    the attribute is valid):
142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        serial - serial number of event
144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    num - mouse button pressed (ButtonPress, ButtonRelease)
145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    focus - whether the window has the focus (Enter, Leave)
146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    height - height of the exposed window (Configure, Expose)
147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    width - width of the exposed window (Configure, Expose)
148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    keycode - keycode of the pressed key (KeyPress, KeyRelease)
149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    state - state of the event as a number (ButtonPress, ButtonRelease,
150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            Enter, KeyPress, KeyRelease,
151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            Leave, Motion)
152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    state - state as a string (Visibility)
153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    time - when the event occurred
154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    x - x-position of the mouse
155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    y - y-position of the mouse
156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    x_root - x-position of the mouse on the screen
157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep             (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    y_root - y-position of the mouse on the screen
159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep             (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion)
160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    char - pressed character (KeyPress, KeyRelease)
161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    send_event - see X/Windows documentation
162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    keysym - keysym of the event as a string (KeyPress, KeyRelease)
163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    keysym_num - keysym of the event as a number (KeyPress, KeyRelease)
164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    type - type of the event as a number
165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    widget - widget in which the event occurred
166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    delta - delta of wheel movement (MouseWheel)
167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """
168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    pass
169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep_support_default_root = 1
171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep_default_root = None
172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef NoDefaultRoot():
174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Inhibit setting of default root window.
175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Call this function to inhibit that the first instance of
177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Tk is used for windows without an explicit parent window.
178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """
179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    global _support_default_root
180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _support_default_root = 0
181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    global _default_root
182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default_root = None
183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    del _default_root
184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _tkerror(err):
186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal function."""
187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    pass
188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _exit(code=0):
190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal function. Calling it will raise the exception SystemExit."""
191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    try:
192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        code = int(code)
193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    except ValueError:
194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pass
195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    raise SystemExit, code
196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep_varnum = 0
198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Variable:
199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Class to define value holders for e.g. buttons.
200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations
202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    that constrain the type of the value returned from get()."""
203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default = ""
204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, value=None, name=None):
205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a variable
206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MASTER can be given as master widget.
208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        VALUE is an optional value (defaults to "")
209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        NAME is an optional Tcl name (defaults to PY_VARnum).
210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If NAME matches an existing variable and VALUE is omitted
212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        then the existing value is retained.
213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        global _varnum
215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not master:
216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            master = _default_root
217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._master = master
218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tk = master.tk
219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if name:
220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._name = name
221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._name = 'PY_VAR' + repr(_varnum)
223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            _varnum += 1
224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if value is not None:
225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.set(value)
226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif not self._tk.call("info", "exists", self._name):
227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.set(self._default)
228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __del__(self):
229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unset the variable in Tcl."""
230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tk.globalunsetvar(self._name)
231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __str__(self):
232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the name of the variable in Tcl."""
233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._name
234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def set(self, value):
235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the variable to VALUE."""
236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._tk.globalsetvar(self._name, value)
237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return value of variable."""
239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._tk.globalgetvar(self._name)
240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def trace_variable(self, mode, callback):
241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Define a trace callback for the variable.
242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MODE is one of "r", "w", "u" for read, write, undefine.
244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        CALLBACK must be a function which is called when
245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the variable is read, written or undefined.
246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return the name of the callback.
248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cbname = self._master._register(callback)
250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tk.call("trace", "variable", self._name, mode, cbname)
251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return cbname
252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    trace = trace_variable
253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def trace_vdelete(self, mode, cbname):
254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete the trace callback for a variable.
255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MODE is one of "r", "w", "u" for read, write, undefine.
257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        CBNAME is the name of the callback returned from trace_variable or trace.
258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tk.call("trace", "vdelete", self._name, mode, cbname)
260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._master.deletecommand(cbname)
261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def trace_vinfo(self):
262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all trace callback information."""
263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(self._tk.split, self._tk.splitlist(
264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._tk.call("trace", "vinfo", self._name)))
265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __eq__(self, other):
266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Comparison for equality (==).
267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Note: if the Variable's master matters to behavior
269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        also compare self._master == other._master
270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.__class__.__name__ == other.__class__.__name__ \
272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            and self._name == other._name
273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass StringVar(Variable):
275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Value holder for strings variables."""
276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default = ""
277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, value=None, name=None):
278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a string variable.
279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MASTER can be given as master widget.
281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        VALUE is an optional value (defaults to "")
282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        NAME is an optional Tcl name (defaults to PY_VARnum).
283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If NAME matches an existing variable and VALUE is omitted
285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        then the existing value is retained.
286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Variable.__init__(self, master, value, name)
288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return value of variable as string."""
291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        value = self._tk.globalgetvar(self._name)
292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if isinstance(value, basestring):
293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return value
294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return str(value)
295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass IntVar(Variable):
297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Value holder for integer variables."""
298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default = 0
299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, value=None, name=None):
300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct an integer variable.
301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MASTER can be given as master widget.
303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        VALUE is an optional value (defaults to 0)
304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        NAME is an optional Tcl name (defaults to PY_VARnum).
305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If NAME matches an existing variable and VALUE is omitted
307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        then the existing value is retained.
308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Variable.__init__(self, master, value, name)
310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def set(self, value):
312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the variable to value, converting booleans to integers."""
313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if isinstance(value, bool):
314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = int(value)
315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return Variable.set(self, value)
316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of the variable as an integer."""
319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self._tk.globalgetvar(self._name))
320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass DoubleVar(Variable):
322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Value holder for float variables."""
323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default = 0.0
324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, value=None, name=None):
325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a float variable.
326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MASTER can be given as master widget.
328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        VALUE is an optional value (defaults to 0.0)
329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        NAME is an optional Tcl name (defaults to PY_VARnum).
330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If NAME matches an existing variable and VALUE is omitted
332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        then the existing value is retained.
333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Variable.__init__(self, master, value, name)
335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of the variable as a float."""
338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getdouble(self._tk.globalgetvar(self._name))
339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass BooleanVar(Variable):
341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Value holder for boolean variables."""
342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default = False
343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, value=None, name=None):
344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a boolean variable.
345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MASTER can be given as master widget.
347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        VALUE is an optional value (defaults to False)
348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        NAME is an optional Tcl name (defaults to PY_VARnum).
349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If NAME matches an existing variable and VALUE is omitted
351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        then the existing value is retained.
352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Variable.__init__(self, master, value, name)
354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of the variable as a bool."""
357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._tk.getboolean(self._tk.globalgetvar(self._name))
358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef mainloop(n=0):
360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Run the main loop of Tcl."""
361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _default_root.tk.mainloop(n)
362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepgetint = int
364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepgetdouble = float
366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef getboolean(s):
368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Convert true and false to integer values 1 and 0."""
369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return _default_root.tk.getboolean(s)
370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Methods defined on both toplevel and interior widgets
372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Misc:
373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal class.
374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Base class which defines methods common for interior widgets."""
376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX font command?
378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _tclCommands = None
379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def destroy(self):
380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function.
381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Delete all Tcl commands created for
383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        this widget in the Tcl interpreter."""
384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self._tclCommands is not None:
385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for name in self._tclCommands:
386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                #print '- Tkinter: deleted command', name
387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.tk.deletecommand(name)
388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._tclCommands = None
389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def deletecommand(self, name):
390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function.
391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Delete the Tcl command provided in NAME."""
393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        #print '- Tkinter: deleted command', name
394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.deletecommand(name)
395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._tclCommands.remove(name)
397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except ValueError:
398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_strictMotif(self, boolean=None):
400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set Tcl internal variable, whether the look and feel
401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        should adhere to Motif.
402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A parameter of 1 means adhere to Motif (e.g. no color
404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        change if mouse passes over slider).
405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Returns the set value."""
406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(self.tk.call(
407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'set', 'tk_strictMotif', boolean))
408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_bisque(self):
409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Change the color scheme to light brown as used in Tk 3.6 and before."""
410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_bisque')
411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_setPalette(self, *args, **kw):
412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set a new color scheme for all widget elements.
413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A single color as argument will cause that all colors of Tk
415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget elements are derived from this.
416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Alternatively several keyword parameters and its associated
417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        colors can be given. The following keywords are valid:
418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        activeBackground, foreground, selectColor,
419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        activeForeground, highlightBackground, selectBackground,
420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        background, highlightColor, selectForeground,
421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        disabledForeground, insertBackground, troughColor."""
422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('tk_setPalette',)
423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + _flatten(args) + _flatten(kw.items()))
424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_menuBar(self, *args):
425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Do not use. Needed in Tk 3.6 and earlier."""
426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pass # obsolete since Tk 4.0
427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wait_variable(self, name='PY_VAR'):
428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Wait until the variable is modified.
429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A parameter of type IntVar, StringVar, DoubleVar or
431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        BooleanVar must be given."""
432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkwait', 'variable', name)
433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    waitvar = wait_variable # XXX b/w compat
434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wait_window(self, window=None):
435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Wait until a WIDGET is destroyed.
436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If no parameter is given self is used."""
438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if window is None:
439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            window = self
440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkwait', 'window', window._w)
441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wait_visibility(self, window=None):
442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Wait until the visibility of a WIDGET changes
443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (e.g. it appears).
444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If no parameter is given self is used."""
446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if window is None:
447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            window = self
448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkwait', 'visibility', window._w)
449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def setvar(self, name='PY_VAR', value='1'):
450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set Tcl variable NAME to VALUE."""
451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.setvar(name, value)
452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def getvar(self, name='PY_VAR'):
453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return value of Tcl variable NAME."""
454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getvar(name)
455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    getint = int
456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    getdouble = float
457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def getboolean(self, s):
458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a boolean value for Tcl boolean values true and false given as parameter."""
459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(s)
460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def focus_set(self):
461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Direct input focus to this widget.
462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If the application currently does not have the focus
464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        this widget will get the focus if the application gets
465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the focus through the window manager."""
466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('focus', self._w)
467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    focus = focus_set # XXX b/w compat?
468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def focus_force(self):
469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Direct input focus to this widget even if the
470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        application does not have the focus. Use with
471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        caution!"""
472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('focus', '-force', self._w)
473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def focus_get(self):
474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the widget which has currently the focus in the
475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        application.
476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Use focus_displayof to allow working with several
478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        displays. Return None if application does not have
479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the focus."""
480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call('focus')
481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if name == 'none' or not name: return None
482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def focus_displayof(self):
484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the widget which has currently the focus on the
485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        display where this widget is located.
486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return None if the application does not have the focus."""
488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call('focus', '-displayof', self._w)
489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if name == 'none' or not name: return None
490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def focus_lastfor(self):
492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the widget which would have the focus if top level
493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for this widget gets the focus from the window manager."""
494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call('focus', '-lastfor', self._w)
495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if name == 'none' or not name: return None
496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_focusFollowsMouse(self):
498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """The widget under mouse will get automatically focus. Can not
499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be disabled easily."""
500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_focusFollowsMouse')
501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_focusNext(self):
502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the next widget in the focus order which follows
503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget which has currently the focus.
504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The focus order first goes to the next child, then to
506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the children of the child recursively and then to the
507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        next sibling which is higher in the stacking order.  A
508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget is omitted if it has the takefocus resource set
509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to 0."""
510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call('tk_focusNext', self._w)
511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name: return None
512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_focusPrev(self):
514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return previous widget in the focus order. See tk_focusNext for details."""
515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call('tk_focusPrev', self._w)
516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name: return None
517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def after(self, ms, func=None, *args):
519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Call function once after given time.
520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        MS specifies the time in milliseconds. FUNC gives the
522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        function which shall be called. Additional parameters
523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        are given as parameters to the function call.  Return
524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        identifier to cancel scheduling with after_cancel."""
525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not func:
526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # I'd rather use time.sleep(ms*0.001)
527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('after', ms)
528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def callit():
530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                try:
531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    func(*args)
532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                finally:
533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    try:
534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        self.deletecommand(name)
535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    except TclError:
536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        pass
537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            name = self._register(callit)
538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.call('after', ms, name)
539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def after_idle(self, func, *args):
540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Call FUNC once if the Tcl main loop has no event to
541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        process.
542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return an identifier to cancel the scheduling with
544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        after_cancel."""
545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.after('idle', func, *args)
546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def after_cancel(self, id):
547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Cancel scheduling of function identified with ID.
548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Identifier returned by after or after_idle must be
550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        given as first parameter."""
551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            data = self.tk.call('after', 'info', id)
553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # In Tk 8.3, splitlist returns: (script, type)
554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # In Tk 8.4, splitlist may return (script, type) or (script,)
555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            script = self.tk.splitlist(data)[0]
556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.deletecommand(script)
557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except TclError:
558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('after', 'cancel', id)
560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bell(self, displayof=0):
561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Ring a display's bell."""
562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('bell',) + self._displayof(displayof))
563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Clipboard handling:
565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def clipboard_get(self, **kw):
566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Retrieve data from the clipboard on window's display.
567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The window keyword defaults to the root window of the Tkinter
569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        application.
570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The type keyword specifies the form in which the data is
572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to be returned and should be an atom name such as STRING
573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        or FILE_NAME.  Type defaults to STRING, except on X11, where the default
574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is to try UTF8_STRING and fall back to STRING.
575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        This command is equivalent to:
577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selection_get(CLIPBOARD)
579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'type' not in kw and self._windowingsystem == 'x11':
581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                kw['type'] = 'UTF8_STRING'
583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return self.tk.call(('clipboard', 'get') + self._options(kw))
584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TclError:
585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                del kw['type']
586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(('clipboard', 'get') + self._options(kw))
587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def clipboard_clear(self, **kw):
589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the data in the Tk clipboard.
590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A widget specified for the optional displayof keyword
592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        argument specifies the target display."""
593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'displayof' not in kw: kw['displayof'] = self._w
594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('clipboard', 'clear') + self._options(kw))
595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def clipboard_append(self, string, **kw):
596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Append STRING to the Tk clipboard.
597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A widget specified at the optional displayof keyword
599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        argument specifies the target display. The clipboard
600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        can be retrieved with selection_get."""
601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'displayof' not in kw: kw['displayof'] = self._w
602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('clipboard', 'append') + self._options(kw)
603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + ('--', string))
604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX grab current w/o window argument
605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grab_current(self):
606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return widget which has currently the grab in this application
607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        or None."""
608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call('grab', 'current', self._w)
609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name: return None
610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grab_release(self):
612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Release grab for this widget if currently set."""
613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('grab', 'release', self._w)
614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grab_set(self):
615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set grab for this widget.
616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A grab directs all events to this and descendant
618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widgets in the application."""
619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('grab', 'set', self._w)
620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grab_set_global(self):
621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set global grab for this widget.
622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A global grab directs all events to this and
624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        descendant widgets on the display. Use with caution -
625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        other applications do not get events anymore."""
626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('grab', 'set', '-global', self._w)
627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grab_status(self):
628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return None, "local" or "global" if this widget has
629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        no, a local or a global grab."""
630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        status = self.tk.call('grab', 'status', self._w)
631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if status == 'none': status = None
632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return status
633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def option_add(self, pattern, value, priority = None):
634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set a VALUE (second parameter) for an option
635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        PATTERN (first parameter).
636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An optional third parameter gives the numeric priority
638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (defaults to 80)."""
639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('option', 'add', pattern, value, priority)
640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def option_clear(self):
641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the option database.
642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        It will be reloaded if option_add is called."""
644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('option', 'clear')
645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def option_get(self, name, className):
646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value for an option NAME for this widget
647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with CLASSNAME.
648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Values with higher priority override lower values."""
650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('option', 'get', self._w, name, className)
651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def option_readfile(self, fileName, priority = None):
652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Read file FILENAME into the option database.
653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An optional second parameter gives the numeric
655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        priority."""
656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('option', 'readfile', fileName, priority)
657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_clear(self, **kw):
658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the current X selection."""
659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'displayof' not in kw: kw['displayof'] = self._w
660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('selection', 'clear') + self._options(kw))
661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_get(self, **kw):
662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the contents of the current X selection.
663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A keyword parameter selection specifies the name of
665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the selection and defaults to PRIMARY.  A keyword
666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        parameter displayof specifies a widget on the display
667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to use. A keyword parameter type specifies the form of data to be
668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        fetched, defaulting to STRING except on X11, where UTF8_STRING is tried
669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        before STRING."""
670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'displayof' not in kw: kw['displayof'] = self._w
671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'type' not in kw and self._windowingsystem == 'x11':
672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                kw['type'] = 'UTF8_STRING'
674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return self.tk.call(('selection', 'get') + self._options(kw))
675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TclError:
676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                del kw['type']
677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(('selection', 'get') + self._options(kw))
678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_handle(self, command, **kw):
679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Specify a function COMMAND to call if the X
680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selection owned by this widget is queried by another
681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        application.
682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        This function must return the contents of the
684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selection. The function will be called with the
685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        arguments OFFSET and LENGTH which allows the chunking
686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of very long selections. The following keyword
687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        parameters can be provided:
688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selection - name of the selection (default PRIMARY),
689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        type - type of the selection (e.g. STRING, FILE_NAME)."""
690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self._register(command)
691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('selection', 'handle') + self._options(kw)
692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + (self._w, name))
693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_own(self, **kw):
694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Become owner of X selection.
695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A keyword parameter selection specifies the name of
697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the selection (default PRIMARY)."""
698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('selection', 'own') +
699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 self._options(kw) + (self._w,))
700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_own_get(self, **kw):
701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return owner of X selection.
702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The following keyword parameter can
704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be provided:
705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selection - name of the selection (default PRIMARY),
706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        type - type of the selection (e.g. STRING, FILE_NAME)."""
707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'displayof' not in kw: kw['displayof'] = self._w
708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call(('selection', 'own') + self._options(kw))
709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name: return None
710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def send(self, interp, cmd, *args):
712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Send Tcl command CMD to different interpreter INTERP to be executed."""
713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(('send', interp, cmd) + args)
714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def lower(self, belowThis=None):
715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Lower this widget in the stacking order."""
716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('lower', self._w, belowThis)
717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tkraise(self, aboveThis=None):
718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Raise this widget in the stacking order."""
719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('raise', self._w, aboveThis)
720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    lift = tkraise
721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def colormodel(self, value=None):
722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Useless. Not implemented in Tk."""
723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('tk', 'colormodel', self._w, value)
724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_atom(self, name, displayof=0):
725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return integer which represents atom NAME."""
726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('winfo', 'atom') + self._displayof(displayof) + (name,)
727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call(args))
728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_atomname(self, id, displayof=0):
729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return name of atom with identifier ID."""
730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('winfo', 'atomname') \
731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               + self._displayof(displayof) + (id,)
732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(args)
733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_cells(self):
734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return number of cells in the colormap for this widget."""
735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'cells', self._w))
737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_children(self):
738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all widgets which are children of this widget."""
739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        result = []
740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for child in self.tk.splitlist(
741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'children', self._w)):
742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # Tcl sometimes returns extra windows, e.g. for
744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # menus; those need to be skipped
745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                result.append(self._nametowidget(child))
746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except KeyError:
747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return result
749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_class(self):
751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return window class name of this widget."""
752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'class', self._w)
753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_colormapfull(self):
754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return true if at the last color request the colormap was full."""
755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(
756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'colormapfull', self._w))
757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_containing(self, rootX, rootY, displayof=0):
758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the widget which is at the root coordinates ROOTX, ROOTY."""
759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('winfo', 'containing') \
760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               + self._displayof(displayof) + (rootX, rootY)
761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = self.tk.call(args)
762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name: return None
763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(name)
764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_depth(self):
765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of bits per pixel."""
766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call('winfo', 'depth', self._w))
767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_exists(self):
768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return true if this widget exists."""
769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'exists', self._w))
771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_fpixels(self, number):
772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of pixels for the given distance NUMBER
773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (e.g. "3c") as float."""
774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getdouble(self.tk.call(
775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'winfo', 'fpixels', self._w, number))
776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_geometry(self):
777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return geometry string for this widget in the form "widthxheight+X+Y"."""
778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'geometry', self._w)
779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_height(self):
780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return height of this widget."""
781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'height', self._w))
783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_id(self):
784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return identifier ID for this widget."""
785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getint(
786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'id', self._w))
787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_interps(self, displayof=0):
788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the name of all Tcl interpreters for this display."""
789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('winfo', 'interps') + self._displayof(displayof)
790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(self.tk.call(args))
791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_ismapped(self):
792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return true if this widget is mapped."""
793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'ismapped', self._w))
795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_manager(self):
796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the window mananger name for this widget."""
797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'manager', self._w)
798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_name(self):
799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the name of this widget."""
800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'name', self._w)
801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_parent(self):
802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the name of the parent of this widget."""
803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'parent', self._w)
804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_pathname(self, id, displayof=0):
805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the pathname of the widget given by ID."""
806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('winfo', 'pathname') \
807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               + self._displayof(displayof) + (id,)
808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(args)
809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_pixels(self, number):
810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Rounded integer value of winfo_fpixels."""
811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'pixels', self._w, number))
813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_pointerx(self):
814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the x coordinate of the pointer on the root window."""
815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'pointerx', self._w))
817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_pointerxy(self):
818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of x and y coordinates of the pointer on the root window."""
819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'pointerxy', self._w))
821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_pointery(self):
822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the y coordinate of the pointer on the root window."""
823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'pointery', self._w))
825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_reqheight(self):
826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return requested height of this widget."""
827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'reqheight', self._w))
829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_reqwidth(self):
830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return requested width of this widget."""
831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'reqwidth', self._w))
833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_rgb(self, color):
834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return tuple of decimal values for red, green, blue for
835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        COLOR in this widget."""
836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'rgb', self._w, color))
838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_rootx(self):
839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return x coordinate of upper left corner of this widget on the
840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        root window."""
841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'rootx', self._w))
843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_rooty(self):
844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return y coordinate of upper left corner of this widget on the
845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        root window."""
846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'rooty', self._w))
848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screen(self):
849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the screen name of this widget."""
850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'screen', self._w)
851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screencells(self):
852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of the cells in the colormap of the screen
853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of this widget."""
854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'screencells', self._w))
856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screendepth(self):
857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of bits per pixel of the root window of the
858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        screen of this widget."""
859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'screendepth', self._w))
861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screenheight(self):
862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of pixels of the height of the screen of this widget
863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in pixel."""
864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'screenheight', self._w))
866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screenmmheight(self):
867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of pixels of the height of the screen of
868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        this widget in mm."""
869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'screenmmheight', self._w))
871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screenmmwidth(self):
872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of pixels of the width of the screen of
873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        this widget in mm."""
874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'screenmmwidth', self._w))
876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screenvisual(self):
877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return one of the strings directcolor, grayscale, pseudocolor,
878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        staticcolor, staticgray, or truecolor for the default
879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        colormodel of this screen."""
880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'screenvisual', self._w)
881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_screenwidth(self):
882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of pixels of the width of the screen of
883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        this widget in pixel."""
884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'screenwidth', self._w))
886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_server(self):
887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return information of the X-Server of the screen of this widget in
888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the form "XmajorRminor vendor vendorVersion"."""
889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'server', self._w)
890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_toplevel(self):
891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the toplevel widget of this widget."""
892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._nametowidget(self.tk.call(
893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'winfo', 'toplevel', self._w))
894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_viewable(self):
895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return true if the widget and all its higher ancestors are mapped."""
896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'viewable', self._w))
898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_visual(self):
899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return one of the strings directcolor, grayscale, pseudocolor,
900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        staticcolor, staticgray, or truecolor for the
901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        colormodel of this widget."""
902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'visual', self._w)
903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_visualid(self):
904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the X identifier for the visual for this widget."""
905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('winfo', 'visualid', self._w)
906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_visualsavailable(self, includeids=0):
907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all visuals available for the screen
908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of this widget.
909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Each item in the list consists of a visual name (see winfo_visual), a
911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        depth and if INCLUDEIDS=1 is given also the X identifier."""
912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        data = self.tk.split(
913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'visualsavailable', self._w,
914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                     includeids and 'includeids' or None))
915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(data) is StringType:
916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            data = [self.tk.split(data)]
917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(self.__winfo_parseitem, data)
918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __winfo_parseitem(self, t):
919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return t[:1] + tuple(map(self.__winfo_getint, t[1:]))
921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __winfo_getint(self, x):
922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return int(x, 0)
924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_vrootheight(self):
925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the height of the virtual root window associated with this
926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget in pixels. If there is no virtual root window return the
927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        height of the screen."""
928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'vrootheight', self._w))
930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_vrootwidth(self):
931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the width of the virtual root window associated with this
932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget in pixel. If there is no virtual root window return the
933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width of the screen."""
934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'vrootwidth', self._w))
936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_vrootx(self):
937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the x offset of the virtual root relative to the root
938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        window of the screen of this widget."""
939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'vrootx', self._w))
941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_vrooty(self):
942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the y offset of the virtual root relative to the root
943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        window of the screen of this widget."""
944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'vrooty', self._w))
946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_width(self):
947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the width of this widget."""
948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'width', self._w))
950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_x(self):
951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the x coordinate of the upper left corner of this widget
952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in the parent."""
953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'x', self._w))
955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def winfo_y(self):
956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the y coordinate of the upper left corner of this widget
957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in the parent."""
958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('winfo', 'y', self._w))
960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def update(self):
961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Enter event loop until all pending events have been processed by Tcl."""
962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('update')
963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def update_idletasks(self):
964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Enter event loop until all idle callbacks have been called. This
965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        will update the display of windows but not process events caused by
966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the user."""
967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('update', 'idletasks')
968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bindtags(self, tagList=None):
969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set or get the list of bindtags for this widget.
970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        With no argument return the list of all bindtags associated with
972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        this widget. With a list of strings as argument the bindtags are
973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        set to this list. The bindtags determine in which order events are
974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        processed (see bind)."""
975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if tagList is None:
976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.splitlist(
977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.tk.call('bindtags', self._w))
978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('bindtags', self._w, tagList)
980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _bind(self, what, sequence, func, add, needcleanup=1):
981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(func) is StringType:
983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(what + (sequence, func))
984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif func:
985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            funcid = self._register(func, self._substitute,
986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        needcleanup)
987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cmd = ('%sif {"[%s %s]" == "break"} break\n'
988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   %
989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   (add and '+' or '',
990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                funcid, self._subst_format_str))
991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(what + (sequence, cmd))
992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return funcid
993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif sequence:
994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.call(what + (sequence,))
995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.splitlist(self.tk.call(what))
997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bind(self, sequence=None, func=None, add=None):
998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind to this widget at event SEQUENCE a call to function FUNC.
999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        SEQUENCE is a string of concatenated event
1001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        patterns. An event pattern is of the form
1002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        <MODIFIER-MODIFIER-TYPE-DETAIL> where MODIFIER is one
1003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of Control, Mod2, M2, Shift, Mod3, M3, Lock, Mod4, M4,
1004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Button1, B1, Mod5, M5 Button2, B2, Meta, M, Button3,
1005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        B3, Alt, Button4, B4, Double, Button5, B5 Triple,
1006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Mod1, M1. TYPE is one of Activate, Enter, Map,
1007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ButtonPress, Button, Expose, Motion, ButtonRelease
1008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        FocusIn, MouseWheel, Circulate, FocusOut, Property,
1009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Colormap, Gravity Reparent, Configure, KeyPress, Key,
1010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Unmap, Deactivate, KeyRelease Visibility, Destroy,
1011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Leave and DETAIL is the button number for ButtonPress,
1012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ButtonRelease and DETAIL is the Keysym for KeyPress and
1013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        KeyRelease. Examples are
1014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        <Control-Button-1> for pressing Control and mouse button 1 or
1015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        <Alt-A> for pressing A and the Alt key (KeyPress can be omitted).
1016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An event pattern can also be a virtual event of the form
1017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        <<AString>> where AString can be arbitrary. This
1018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        event can be generated by event_generate.
1019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If events are concatenated they must appear shortly
1020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        after each other.
1021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        FUNC will be called if the event sequence occurs with an
1023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        instance of Event as argument. If the return value of FUNC is
1024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "break" no further bound function is invoked.
1025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An additional boolean parameter ADD specifies whether FUNC will
1027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be called additionally to the other bound function or whether
1028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        it will replace the previous function.
1029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Bind will return an identifier to allow deletion of the bound function with
1031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        unbind without memory leak.
1032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If FUNC or SEQUENCE is omitted the bound function or list
1034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of bound events are returned."""
1035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._bind(('bind', self._w), sequence, func, add)
1037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def unbind(self, sequence, funcid=None):
1038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unbind for this widget for event SEQUENCE  the
1039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        function identified with FUNCID."""
1040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('bind', self._w, sequence, '')
1041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if funcid:
1042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.deletecommand(funcid)
1043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bind_all(self, sequence=None, func=None, add=None):
1044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind to all widgets at an event SEQUENCE a call to function FUNC.
1045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An additional boolean parameter ADD specifies whether FUNC will
1046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be called additionally to the other bound function or whether
1047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        it will replace the previous function. See bind for the return value."""
1048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._bind(('bind', 'all'), sequence, func, add, 0)
1049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def unbind_all(self, sequence):
1050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unbind for all widgets for event SEQUENCE all functions."""
1051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('bind', 'all' , sequence, '')
1052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bind_class(self, className, sequence=None, func=None, add=None):
1053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind to widgets with bindtag CLASSNAME at event
1055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        SEQUENCE a call of function FUNC. An additional
1056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        boolean parameter ADD specifies whether FUNC will be
1057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        called additionally to the other bound function or
1058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        whether it will replace the previous function. See bind for
1059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the return value."""
1060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._bind(('bind', className), sequence, func, add, 0)
1062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def unbind_class(self, className, sequence):
1063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unbind for a all widgets with bindtag CLASSNAME for event SEQUENCE
1064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        all functions."""
1065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('bind', className , sequence, '')
1066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mainloop(self, n=0):
1067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Call the mainloop of Tk."""
1068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.mainloop(n)
1069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def quit(self):
1070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Quit the Tcl interpreter. All widgets will be destroyed."""
1071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.quit()
1072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _getints(self, string):
1073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if string:
1075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return tuple(map(getint, self.tk.splitlist(string)))
1076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _getdoubles(self, string):
1077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if string:
1079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return tuple(map(getdouble, self.tk.splitlist(string)))
1080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _getboolean(self, string):
1081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if string:
1083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.getboolean(string)
1084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _displayof(self, displayof):
1085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if displayof:
1087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return ('-displayof', displayof)
1088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if displayof is None:
1089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return ('-displayof', self._w)
1090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return ()
1091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    @property
1092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _windowingsystem(self):
1093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
1095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self._root()._windowingsystem_cached
1096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AttributeError:
1097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            ws = self._root()._windowingsystem_cached = \
1098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        self.tk.call('tk', 'windowingsystem')
1099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return ws
1100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _options(self, cnf, kw = None):
1101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if kw:
1103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = _cnfmerge((cnf, kw))
1104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
1105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = _cnfmerge(cnf)
1106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        res = ()
1107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for k, v in cnf.items():
1108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if v is not None:
1109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if k[-1] == '_': k = k[:-1]
1110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if hasattr(v, '__call__'):
1111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    v = self._register(v)
1112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                elif isinstance(v, (tuple, list)):
1113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    nv = []
1114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    for item in v:
1115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        if not isinstance(item, (basestring, int)):
1116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            break
1117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        elif isinstance(item, int):
1118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            nv.append('%d' % item)
1119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        else:
1120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            # format it to proper Tcl code if it contains space
1121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                            nv.append(_stringify(item))
1122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    else:
1123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                        v = ' '.join(nv)
1124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                res = res + ('-'+k, v)
1125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return res
1126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def nametowidget(self, name):
1127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the Tkinter instance of a widget identified by
1128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        its Tcl name NAME."""
1129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = str(name).split('.')
1130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        w = self
1131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name[0]:
1133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w = w._root()
1134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            name = name[1:]
1135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for n in name:
1137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if not n:
1138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                break
1139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            w = w.children[n]
1140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return w
1142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _nametowidget = nametowidget
1143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _register(self, func, subst=None, needcleanup=1):
1144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a newly created Tcl function. If this
1145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        function is called, the Python function FUNC will
1146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be executed. An optional function SUBST can
1147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be given which will be executed before FUNC."""
1148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        f = CallWrapper(func, subst, self).__call__
1149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = repr(id(f))
1150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
1151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            func = func.im_func
1152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AttributeError:
1153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
1154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
1155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            name = name + func.__name__
1156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except AttributeError:
1157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass
1158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.createcommand(name, f)
1159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if needcleanup:
1160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if self._tclCommands is None:
1161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self._tclCommands = []
1162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._tclCommands.append(name)
1163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return name
1164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    register = _register
1165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _root(self):
1166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        w = self
1168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        while w.master: w = w.master
1169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return w
1170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _subst_format = ('%#', '%b', '%f', '%h', '%k',
1171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep             '%s', '%t', '%w', '%x', '%y',
1172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep             '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y', '%D')
1173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _subst_format_str = " ".join(_subst_format)
1174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _substitute(self, *args):
1175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if len(args) != len(self._subst_format): return args
1177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        getboolean = self.tk.getboolean
1178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        getint = int
1180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        def getint_event(s):
1181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            """Tk changed behavior in 8.4.2, returning "??" rather more often."""
1182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
1183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return int(s)
1184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except ValueError:
1185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                return s
1186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y, D = args
1188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Missing: (a, c, d, m, o, v, B, R)
1189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e = Event()
1190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # serial field: valid vor all events
1191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # number of button: ButtonPress and ButtonRelease events only
1192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # height field: Configure, ConfigureRequest, Create,
1193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # ResizeRequest, and Expose events only
1194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # keycode field: KeyPress and KeyRelease events only
1195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # time field: "valid for events that contain a time field"
1196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # width field: Configure, ConfigureRequest, Create, ResizeRequest,
1197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # and Expose events only
1198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # x field: "valid for events that contain a x field"
1199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # y field: "valid for events that contain a y field"
1200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # keysym as decimal: KeyPress and KeyRelease events only
1201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # x_root, y_root fields: ButtonPress, ButtonRelease, KeyPress,
1202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # KeyRelease,and Motion events
1203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.serial = getint(nsign)
1204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.num = getint_event(b)
1205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: e.focus = getboolean(f)
1206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except TclError: pass
1207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.height = getint_event(h)
1208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.keycode = getint_event(k)
1209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.state = getint_event(s)
1210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.time = getint_event(t)
1211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.width = getint_event(w)
1212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.x = getint_event(x)
1213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.y = getint_event(y)
1214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.char = A
1215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try: e.send_event = getboolean(E)
1216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except TclError: pass
1217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.keysym = K
1218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.keysym_num = getint_event(N)
1219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.type = T
1220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
1221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            e.widget = self._nametowidget(W)
1222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except KeyError:
1223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            e.widget = W
1224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.x_root = getint_event(X)
1225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.y_root = getint_event(Y)
1226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
1227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            e.delta = getint(D)
1228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except ValueError:
1229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            e.delta = 0
1230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return (e,)
1231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _report_exception(self):
1232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import sys
1234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
1235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        root = self._root()
1236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        root.report_callback_exception(exc, val, tb)
1237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _configure(self, cmd, cnf, kw):
1238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if kw:
1240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = _cnfmerge((cnf, kw))
1241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif cnf:
1242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = _cnfmerge(cnf)
1243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if cnf is None:
1244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = {}
1245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for x in self.tk.split(
1246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.tk.call(_flatten((self._w, cmd)))):
1247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                cnf[x[0][1:]] = (x[0][1:],) + x[1:]
1248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return cnf
1249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(cnf) is StringType:
1250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x = self.tk.split(
1251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.tk.call(_flatten((self._w, cmd, '-'+cnf))))
1252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return (x[0][1:],) + x[1:]
1253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
1254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # These used to be defined in Widget:
1255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def configure(self, cnf=None, **kw):
1256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure resources of a widget.
1257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The values for resources are specified as keyword
1259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        arguments. To get an overview about
1260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the allowed keyword arguments call the method keys.
1261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure('configure', cnf, kw)
1263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    config = configure
1264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def cget(self, key):
1265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the resource value for a KEY given as string."""
1266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'cget', '-' + key)
1267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    __getitem__ = cget
1268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __setitem__(self, key, value):
1269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.configure({key: value})
1270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __contains__(self, key):
1271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        raise TypeError("Tkinter objects don't support 'in' tests.")
1272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def keys(self):
1273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all resource names of this widget."""
1274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(lambda x: x[0][1:],
1275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               self.tk.split(self.tk.call(self._w, 'configure')))
1276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __str__(self):
1277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the window path name of this widget."""
1278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._w
1279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Pack methods that apply to the master
1280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _noarg_ = ['_noarg_']
1281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def pack_propagate(self, flag=_noarg_):
1282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set or get the status for propagation of geometry information.
1283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A boolean argument specifies whether the geometry information
1285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the slaves will determine the size of this widget. If no argument
1286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is given the current setting will be returned.
1287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if flag is Misc._noarg_:
1289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self._getboolean(self.tk.call(
1290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                'pack', 'propagate', self._w))
1291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
1292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('pack', 'propagate', self._w, flag)
1293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    propagate = pack_propagate
1294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def pack_slaves(self):
1295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all slaves of this widget
1296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in its packing order."""
1297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(self._nametowidget,
1298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               self.tk.splitlist(
1299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   self.tk.call('pack', 'slaves', self._w)))
1300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    slaves = pack_slaves
1301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Place method that applies to the master
1302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def place_slaves(self):
1303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all slaves of this widget
1304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in its packing order."""
1305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(self._nametowidget,
1306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               self.tk.splitlist(
1307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   self.tk.call(
1308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                       'place', 'slaves', self._w)))
1309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Grid methods that apply to the master
1310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_bbox(self, column=None, row=None, col2=None, row2=None):
1311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of integer coordinates for the bounding
1312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        box of this widget controlled by the geometry manager grid.
1313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If COLUMN, ROW is given the bounding box applies from
1315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the cell with row and column 0 to the specified
1316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cell. If COL2 and ROW2 are given the bounding box
1317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        starts at that cell.
1318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The returned integers specify the offset of the upper left
1320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        corner in the master widget and the width and height.
1321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('grid', 'bbox', self._w)
1323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if column is not None and row is not None:
1324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + (column, row)
1325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if col2 is not None and row2 is not None:
1326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + (col2, row2)
1327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(*args)) or None
1328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    bbox = grid_bbox
1330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _grid_configure(self, command, index, cnf, kw):
1331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
1332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(cnf) is StringType and not kw:
1333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if cnf[-1:] == '_':
1334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                cnf = cnf[:-1]
1335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if cnf[:1] != '-':
1336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                cnf = '-'+cnf
1337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            options = (cnf,)
1338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
1339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            options = self._options(cnf, kw)
1340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not options:
1341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            res = self.tk.call('grid',
1342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                       command, self._w, index)
1343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            words = self.tk.splitlist(res)
1344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            dict = {}
1345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for i in range(0, len(words), 2):
1346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                key = words[i][1:]
1347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                value = words[i+1]
1348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if not value:
1349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    value = None
1350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                elif '.' in value:
1351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    value = getdouble(value)
1352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                else:
1353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    value = getint(value)
1354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                dict[key] = value
1355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return dict
1356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        res = self.tk.call(
1357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  ('grid', command, self._w, index)
1358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  + options)
1359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if len(options) == 1:
1360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if not res: return None
1361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # In Tk 7.5, -width can be a float
1362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if '.' in res: return getdouble(res)
1363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return getint(res)
1364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_columnconfigure(self, index, cnf={}, **kw):
1365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure column INDEX of a grid.
1366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resources are minsize (minimum size of the column),
1368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        weight (how much does additional space propagate to this column)
1369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and pad (how much space to let additionally)."""
1370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._grid_configure('columnconfigure', index, cnf, kw)
1371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    columnconfigure = grid_columnconfigure
1372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_location(self, x, y):
1373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of column and row which identify the cell
1374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        at which the pixel at position X and Y inside the master
1375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget is located."""
1376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
1377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(
1378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                'grid', 'location', self._w, x, y)) or None
1379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_propagate(self, flag=_noarg_):
1380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set or get the status for propagation of geometry information.
1381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        A boolean argument specifies whether the geometry information
1383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the slaves will determine the size of this widget. If no argument
1384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is given, the current setting will be returned.
1385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if flag is Misc._noarg_:
1387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self._getboolean(self.tk.call(
1388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                'grid', 'propagate', self._w))
1389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
1390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('grid', 'propagate', self._w, flag)
1391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_rowconfigure(self, index, cnf={}, **kw):
1392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure row INDEX of a grid.
1393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resources are minsize (minimum size of the row),
1395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        weight (how much does additional space propagate to this row)
1396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and pad (how much space to let additionally)."""
1397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._grid_configure('rowconfigure', index, cnf, kw)
1398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    rowconfigure = grid_rowconfigure
1399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_size(self):
1400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of the number of column and rows in the grid."""
1401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
1402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('grid', 'size', self._w)) or None
1403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    size = grid_size
1404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_slaves(self, row=None, column=None):
1405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all slaves of this widget
1406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in its packing order."""
1407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ()
1408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if row is not None:
1409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + ('-row', row)
1410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if column is not None:
1411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + ('-column', column)
1412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(self._nametowidget,
1413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep               self.tk.splitlist(self.tk.call(
1414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   ('grid', 'slaves', self._w) + args)))
1415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Support for the "event" command, new in Tk 4.2.
1417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # By Case Roole.
1418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def event_add(self, virtual, *sequences):
1420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind a virtual event VIRTUAL (of the form <<Name>>)
1421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to an event SEQUENCE such that the virtual event is triggered
1422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        whenever SEQUENCE occurs."""
1423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('event', 'add', virtual) + sequences
1424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(args)
1425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def event_delete(self, virtual, *sequences):
1427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unbind a virtual event VIRTUAL from SEQUENCE."""
1428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('event', 'delete', virtual) + sequences
1429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(args)
1430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def event_generate(self, sequence, **kw):
1432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Generate an event SEQUENCE. Additional
1433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        keyword arguments specify parameter of the event
1434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (e.g. x, y, rootx, rooty)."""
1435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('event', 'generate', self._w, sequence)
1436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for k, v in kw.items():
1437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + ('-%s' % k, str(v))
1438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(args)
1439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def event_info(self, virtual=None):
1441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all virtual events or the information
1442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        about the SEQUENCE bound to the virtual event VIRTUAL."""
1443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(
1444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('event', 'info', virtual))
1445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Image related commands
1447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def image_names(self):
1449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all existing image names."""
1450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('image', 'names')
1451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def image_types(self):
1453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all available image types (e.g. phote bitmap)."""
1454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('image', 'types')
1455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass CallWrapper:
1458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal class. Stores function to call when some user
1459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    defined Tcl function is called e.g. after an event occurred."""
1460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, func, subst, widget):
1461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Store FUNC, SUBST and WIDGET as members."""
1462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.func = func
1463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.subst = subst
1464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.widget = widget
1465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __call__(self, *args):
1466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Apply first function SUBST to arguments, than FUNC."""
1467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
1468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if self.subst:
1469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                args = self.subst(*args)
1470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.func(*args)
1471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except SystemExit, msg:
1472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            raise SystemExit, msg
1473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except:
1474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.widget._report_exception()
1475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass XView:
1478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Mix-in class for querying and changing the horizontal position
1479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    of a widget's window."""
1480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def xview(self, *args):
1482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Query and change the horizontal position of the view."""
1483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        res = self.tk.call(self._w, 'xview', *args)
1484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not args:
1485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self._getdoubles(res)
1486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def xview_moveto(self, fraction):
1488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjusts the view in the window so that FRACTION of the
1489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        total width of the canvas is off-screen to the left."""
1490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'xview', 'moveto', fraction)
1491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def xview_scroll(self, number, what):
1493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Shift the x-view according to NUMBER which is measured in "units"
1494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        or "pages" (WHAT)."""
1495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'xview', 'scroll', number, what)
1496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass YView:
1499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Mix-in class for querying and changing the vertical position
1500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    of a widget's window."""
1501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def yview(self, *args):
1503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Query and change the vertical position of the view."""
1504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        res = self.tk.call(self._w, 'yview', *args)
1505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not args:
1506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self._getdoubles(res)
1507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def yview_moveto(self, fraction):
1509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjusts the view in the window so that FRACTION of the
1510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        total height of the canvas is off-screen to the top."""
1511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'yview', 'moveto', fraction)
1512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def yview_scroll(self, number, what):
1514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Shift the y-view according to NUMBER which is measured in
1515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "units" or "pages" (WHAT)."""
1516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'yview', 'scroll', number, what)
1517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Wm:
1520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Provides functions for the communication with the window manager."""
1521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_aspect(self,
1523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              minNumer=None, minDenom=None,
1524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              maxNumer=None, maxDenom=None):
1525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager to set the aspect ratio (width/height)
1526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple
1527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the actual values if no argument is given."""
1528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
1529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('wm', 'aspect', self._w,
1530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                     minNumer, minDenom,
1531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                     maxNumer, maxDenom))
1532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    aspect = wm_aspect
1533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_attributes(self, *args):
1535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """This subcommand returns or sets platform specific attributes
1536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The first form returns a list of the platform specific flags and
1538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        their values. The second form returns the value for the specific
1539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        option. The third form sets one or more of the values. The values
1540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        are as follows:
1541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        On Windows, -disabled gets or sets whether the window is in a
1543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        disabled state. -toolwindow gets or sets the style of the window
1544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to toolwindow (as defined in the MSDN). -topmost gets or sets
1545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        whether this is a topmost window (displays above all other
1546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        windows).
1547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        On Macintosh, XXXXX
1549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        On Unix, there are currently no special attribute values.
1551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('wm', 'attributes', self._w) + args
1553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(args)
1554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    attributes=wm_attributes
1555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_client(self, name=None):
1557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Store NAME in WM_CLIENT_MACHINE property of this widget. Return
1558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        current value."""
1559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'client', self._w, name)
1560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    client = wm_client
1561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_colormapwindows(self, *wlist):
1562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Store list of window names (WLIST) into WM_COLORMAPWINDOWS property
1563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of this widget. This list contains windows whose colormaps differ from their
1564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        parents. Return current list of widgets if WLIST is empty."""
1565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if len(wlist) > 1:
1566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            wlist = (wlist,) # Tk needs a list of windows here
1567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = ('wm', 'colormapwindows', self._w) + wlist
1568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(self._nametowidget, self.tk.call(args))
1569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    colormapwindows = wm_colormapwindows
1570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_command(self, value=None):
1571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Store VALUE in WM_COMMAND property. It is the command
1572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        which shall be used to invoke the application. Return current
1573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        command if VALUE is None."""
1574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'command', self._w, value)
1575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    command = wm_command
1576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_deiconify(self):
1577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Deiconify this widget. If it was never mapped it will not be mapped.
1578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        On Windows it will raise this widget and give it the focus."""
1579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'deiconify', self._w)
1580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    deiconify = wm_deiconify
1581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_focusmodel(self, model=None):
1582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set focus model to MODEL. "active" means that this widget will claim
1583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the focus itself, "passive" means that the window manager shall give
1584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the focus. Return current focus model if MODEL is None."""
1585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'focusmodel', self._w, model)
1586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    focusmodel = wm_focusmodel
1587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_frame(self):
1588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return identifier for decorative frame of this widget if present."""
1589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'frame', self._w)
1590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    frame = wm_frame
1591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_geometry(self, newGeometry=None):
1592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set geometry to NEWGEOMETRY of the form =widthxheight+x+y. Return
1593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        current value if None is given."""
1594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'geometry', self._w, newGeometry)
1595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    geometry = wm_geometry
1596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_grid(self,
1597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep         baseWidth=None, baseHeight=None,
1598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep         widthInc=None, heightInc=None):
1599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager that this widget shall only be
1600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        resized on grid boundaries. WIDTHINC and HEIGHTINC are the width and
1601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        height of a grid unit in pixels. BASEWIDTH and BASEHEIGHT are the
1602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        number of grid units requested in Tk_GeometryRequest."""
1603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(
1604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'wm', 'grid', self._w,
1605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            baseWidth, baseHeight, widthInc, heightInc))
1606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    grid = wm_grid
1607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_group(self, pathName=None):
1608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the group leader widgets for related widgets to PATHNAME. Return
1609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the group leader of this widget if None is given."""
1610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'group', self._w, pathName)
1611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    group = wm_group
1612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_iconbitmap(self, bitmap=None, default=None):
1613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set bitmap for the iconified widget to BITMAP. Return
1614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the bitmap if None is given.
1615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Under Windows, the DEFAULT parameter can be used to set the icon
1617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for the widget and any descendents that don't have an icon set
1618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        explicitly.  DEFAULT can be the relative path to a .ico file
1619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (example: root.iconbitmap(default='myicon.ico') ).  See Tk
1620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        documentation for more information."""
1621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if default:
1622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
1623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
1624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
1625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    iconbitmap = wm_iconbitmap
1626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_iconify(self):
1627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Display widget as icon."""
1628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'iconify', self._w)
1629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    iconify = wm_iconify
1630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_iconmask(self, bitmap=None):
1631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set mask for the icon bitmap of this widget. Return the
1632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        mask if None is given."""
1633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'iconmask', self._w, bitmap)
1634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    iconmask = wm_iconmask
1635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_iconname(self, newName=None):
1636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the name of the icon for this widget. Return the name if
1637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        None is given."""
1638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'iconname', self._w, newName)
1639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    iconname = wm_iconname
1640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_iconposition(self, x=None, y=None):
1641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the position of the icon of this widget to X and Y. Return
1642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        a tuple of the current values of X and X if None is given."""
1643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(
1644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'wm', 'iconposition', self._w, x, y))
1645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    iconposition = wm_iconposition
1646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_iconwindow(self, pathName=None):
1647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set widget PATHNAME to be displayed instead of icon. Return the current
1648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        value if None is given."""
1649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'iconwindow', self._w, pathName)
1650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    iconwindow = wm_iconwindow
1651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_maxsize(self, width=None, height=None):
1652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set max WIDTH and HEIGHT for this widget. If the window is gridded
1653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the values are given in grid units. Return the current values if None
1654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is given."""
1655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(
1656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'wm', 'maxsize', self._w, width, height))
1657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    maxsize = wm_maxsize
1658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_minsize(self, width=None, height=None):
1659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set min WIDTH and HEIGHT for this widget. If the window is gridded
1660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the values are given in grid units. Return the current values if None
1661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is given."""
1662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(
1663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'wm', 'minsize', self._w, width, height))
1664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    minsize = wm_minsize
1665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_overrideredirect(self, boolean=None):
1666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager to ignore this widget
1667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if BOOLEAN is given with 1. Return the current value if None
1668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is given."""
1669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getboolean(self.tk.call(
1670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'wm', 'overrideredirect', self._w, boolean))
1671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    overrideredirect = wm_overrideredirect
1672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_positionfrom(self, who=None):
1673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager that the position of this widget shall
1674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be defined by the user if WHO is "user", and by its own policy if WHO is
1675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "program"."""
1676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'positionfrom', self._w, who)
1677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    positionfrom = wm_positionfrom
1678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_protocol(self, name=None, func=None):
1679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind function FUNC to command NAME for this widget.
1680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return the function bound to NAME if None is given. NAME could be
1681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        e.g. "WM_SAVE_YOURSELF" or "WM_DELETE_WINDOW"."""
1682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if hasattr(func, '__call__'):
1683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            command = self._register(func)
1684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
1685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            command = func
1686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(
1687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            'wm', 'protocol', self._w, name, command)
1688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    protocol = wm_protocol
1689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_resizable(self, width=None, height=None):
1690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager whether this width can be resized
1691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in WIDTH or HEIGHT. Both values are boolean values."""
1692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'resizable', self._w, width, height)
1693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    resizable = wm_resizable
1694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_sizefrom(self, who=None):
1695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager that the size of this widget shall
1696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be defined by the user if WHO is "user", and by its own policy if WHO is
1697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "program"."""
1698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'sizefrom', self._w, who)
1699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    sizefrom = wm_sizefrom
1700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_state(self, newstate=None):
1701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Query or set the state of this widget as one of normal, icon,
1702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        iconic (see wm_iconwindow), withdrawn, or zoomed (Windows only)."""
1703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'state', self._w, newstate)
1704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    state = wm_state
1705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_title(self, string=None):
1706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the title of this widget."""
1707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'title', self._w, string)
1708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    title = wm_title
1709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_transient(self, master=None):
1710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Instruct the window manager that this widget is transient
1711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        with regard to widget MASTER."""
1712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'transient', self._w, master)
1713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    transient = wm_transient
1714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def wm_withdraw(self):
1715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Withdraw this widget from the screen such that it is unmapped
1716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and forgotten by the window manager. Re-draw it with wm_deiconify."""
1717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('wm', 'withdraw', self._w)
1718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    withdraw = wm_withdraw
1719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Tk(Misc, Wm):
1722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Toplevel widget of Tk which represents mostly the main window
1723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    of an application. It has an associated Tcl interpreter."""
1724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _w = '.'
1725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, screenName=None, baseName=None, className='Tk',
1726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 useTk=1, sync=0, use=None):
1727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
1728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be created. BASENAME will be used for the identification of the profile file (see
1729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        readprofile).
1730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
1731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is the name of the widget class."""
1732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.master = None
1733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.children = {}
1734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tkloaded = 0
1735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # to avoid recursions in the getattr code in case of failure, we
1736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # ensure that self.tk is always _something_.
1737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk = None
1738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if baseName is None:
1739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            import sys, os
1740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            baseName = os.path.basename(sys.argv[0])
1741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            baseName, ext = os.path.splitext(baseName)
1742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if ext not in ('.py', '.pyc', '.pyo'):
1743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                baseName = baseName + ext
1744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        interactive = 0
1745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if useTk:
1747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._loadtk()
1748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not sys.flags.ignore_environment:
1749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Issue #16248: Honor the -E flag to avoid code injection.
1750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.readprofile(baseName, className)
1751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def loadtk(self):
1752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not self._tkloaded:
1753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.loadtk()
1754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._loadtk()
1755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _loadtk(self):
1756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tkloaded = 1
1757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        global _default_root
1758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Version sanity checks
1759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tk_version = self.tk.getvar('tk_version')
1760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if tk_version != _tkinter.TK_VERSION:
1761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            raise RuntimeError, \
1762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            "tk.h version (%s) doesn't match libtk.a version (%s)" \
1763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            % (_tkinter.TK_VERSION, tk_version)
1764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Under unknown circumstances, tcl_version gets coerced to float
1765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tcl_version = str(self.tk.getvar('tcl_version'))
1766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if tcl_version != _tkinter.TCL_VERSION:
1767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            raise RuntimeError, \
1768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            "tcl.h version (%s) doesn't match libtcl.a version (%s)" \
1769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            % (_tkinter.TCL_VERSION, tcl_version)
1770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if TkVersion < 4.0:
1771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            raise RuntimeError, \
1772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            "Tk 4.0 or higher is required; found Tk %s" \
1773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            % str(TkVersion)
1774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # Create and register the tkerror and exit commands
1775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # We need to inline parts of _register here, _ register
1776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # would register differently-named commands.
1777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self._tclCommands is None:
1778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._tclCommands = []
1779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.createcommand('tkerror', _tkerror)
1780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.createcommand('exit', _exit)
1781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tclCommands.append('tkerror')
1782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._tclCommands.append('exit')
1783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if _support_default_root and not _default_root:
1784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            _default_root = self
1785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.protocol("WM_DELETE_WINDOW", self.destroy)
1786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def destroy(self):
1787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Destroy this and all descendants widgets. This will
1788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        end the application of this Tcl interpreter."""
1789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for c in self.children.values(): c.destroy()
1790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('destroy', self._w)
1791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Misc.destroy(self)
1792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        global _default_root
1793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if _support_default_root and _default_root is self:
1794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            _default_root = None
1795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def readprofile(self, baseName, className):
1796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
1797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if
1798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        such a file exists in the home directory."""
1799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import os
1800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'HOME' in os.environ: home = os.environ['HOME']
1801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else: home = os.curdir
1802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class_tcl = os.path.join(home, '.%s.tcl' % className)
1803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        class_py = os.path.join(home, '.%s.py' % className)
1804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        base_tcl = os.path.join(home, '.%s.tcl' % baseName)
1805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        base_py = os.path.join(home, '.%s.py' % baseName)
1806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        dir = {'self': self}
1807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exec 'from Tkinter import *' in dir
1808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if os.path.isfile(class_tcl):
1809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('source', class_tcl)
1810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if os.path.isfile(class_py):
1811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            execfile(class_py, dir)
1812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if os.path.isfile(base_tcl):
1813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('source', base_tcl)
1814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if os.path.isfile(base_py):
1815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            execfile(base_py, dir)
1816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def report_callback_exception(self, exc, val, tb):
1817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function. It reports exception on sys.stderr."""
1818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        import traceback, sys
1819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sys.stderr.write("Exception in Tkinter callback\n")
1820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sys.last_type = exc
1821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sys.last_value = val
1822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sys.last_traceback = tb
1823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        traceback.print_exception(exc, val, tb)
1824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __getattr__(self, attr):
1825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "Delegate attribute access to the interpreter object"
1826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getattr(self.tk, attr)
1827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Ideally, the classes Pack, Place and Grid disappear, the
1829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# pack/place/grid methods are defined on the Widget class, and
1830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# everybody uses w.pack_whatever(...) instead of Pack.whatever(w,
1831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# ...), with pack(), place() and grid() being short for
1832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# pack_configure(), place_configure() and grid_columnconfigure(), and
1833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# forget() being short for pack_forget().  As a practical matter, I'm
1834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# afraid that there is too much code out there that may be using the
1835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Pack, Place or Grid class, so I leave them intact -- but only as
1836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# backwards compatibility features.  Also note that those methods that
1837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# take a master as argument (e.g. pack_propagate) have been moved to
1838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# the Misc class (which now incorporates all methods common between
1839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# toplevel and interior widgets).  Again, for compatibility, these are
1840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# copied into the Pack, Place or Grid class.
1841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef Tcl(screenName=None, baseName=None, className='Tk', useTk=0):
1844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return Tk(screenName, baseName, className, useTk)
1845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Pack:
1847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Geometry manager Pack.
1848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Base class to use the methods pack_* in every widget."""
1850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def pack_configure(self, cnf={}, **kw):
1851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Pack a widget in the parent widget. Use as options:
1852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        after=widget - pack it after you have packed widget
1853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        anchor=NSEW (or subset) - position widget according to
1854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                  given direction
1855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        before=widget - pack it before you will pack widget
1856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        expand=bool - expand widget if parent size grows
1857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        fill=NONE or X or Y or BOTH - fill widget if widget grows
1858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in=master - use master to contain this widget
1859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in_=master - see 'in' option description
1860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ipadx=amount - add internal padding in x direction
1861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ipady=amount - add internal padding in y direction
1862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        padx=amount - add padding in x direction
1863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pady=amount - add padding in y direction
1864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        side=TOP or BOTTOM or LEFT or RIGHT -  where to add this widget.
1865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
1867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              ('pack', 'configure', self._w)
1868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + self._options(cnf, kw))
1869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    pack = configure = config = pack_configure
1870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def pack_forget(self):
1871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unmap this widget and do not use it for the packing order."""
1872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('pack', 'forget', self._w)
1873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    forget = pack_forget
1874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def pack_info(self):
1875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return information about the packing options
1876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for this widget."""
1877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        words = self.tk.splitlist(
1878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('pack', 'info', self._w))
1879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        dict = {}
1880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i in range(0, len(words), 2):
1881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            key = words[i][1:]
1882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = words[i+1]
1883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if value[:1] == '.':
1884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                value = self._nametowidget(value)
1885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            dict[key] = value
1886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return dict
1887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    info = pack_info
1888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    propagate = pack_propagate = Misc.pack_propagate
1889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    slaves = pack_slaves = Misc.pack_slaves
1890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Place:
1892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Geometry manager Place.
1893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Base class to use the methods place_* in every widget."""
1895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def place_configure(self, cnf={}, **kw):
1896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Place a widget in the parent widget. Use as options:
1897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in=master - master relative to which the widget is placed
1898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in_=master - see 'in' option description
1899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        x=amount - locate anchor of this widget at position x of master
1900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        y=amount - locate anchor of this widget at position y of master
1901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        relx=amount - locate anchor of this widget between 0.0 and 1.0
1902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                      relative to width of master (1.0 is right edge)
1903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        rely=amount - locate anchor of this widget between 0.0 and 1.0
1904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                      relative to height of master (1.0 is bottom edge)
1905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        anchor=NSEW (or subset) - position anchor according to given direction
1906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width=amount - width of this widget in pixel
1907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        height=amount - height of this widget in pixel
1908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        relwidth=amount - width of this widget between 0.0 and 1.0
1909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          relative to width of master (1.0 is the same width
1910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                          as the master)
1911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        relheight=amount - height of this widget between 0.0 and 1.0
1912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                           relative to height of master (1.0 is the same
1913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                           height as the master)
1914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        bordermode="inside" or "outside" - whether to take border width of
1915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                           master widget into account
1916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
1918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              ('place', 'configure', self._w)
1919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + self._options(cnf, kw))
1920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    place = configure = config = place_configure
1921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def place_forget(self):
1922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unmap this widget."""
1923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('place', 'forget', self._w)
1924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    forget = place_forget
1925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def place_info(self):
1926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return information about the placing options
1927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for this widget."""
1928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        words = self.tk.splitlist(
1929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('place', 'info', self._w))
1930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        dict = {}
1931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i in range(0, len(words), 2):
1932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            key = words[i][1:]
1933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = words[i+1]
1934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if value[:1] == '.':
1935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                value = self._nametowidget(value)
1936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            dict[key] = value
1937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return dict
1938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    info = place_info
1939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    slaves = place_slaves = Misc.place_slaves
1940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Grid:
1942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Geometry manager Grid.
1943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Base class to use the methods grid_* in every widget."""
1945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # Thanks to Masazumi Yoshikawa (yosikawa@isi.edu)
1946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_configure(self, cnf={}, **kw):
1947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Position a widget in the parent widget in a grid. Use as options:
1948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        column=number - use cell identified with given column (starting with 0)
1949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        columnspan=number - this widget will span several columns
1950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in=master - use master to contain this widget
1951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in_=master - see 'in' option description
1952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ipadx=amount - add internal padding in x direction
1953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        ipady=amount - add internal padding in y direction
1954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        padx=amount - add padding in x direction
1955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pady=amount - add padding in y direction
1956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        row=number - use cell identified with given row (starting with 0)
1957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        rowspan=number - this widget will span several rows
1958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sticky=NSEW - if cell is larger on which sides will this
1959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                      widget stick to the cell boundary
1960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
1961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
1962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              ('grid', 'configure', self._w)
1963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + self._options(cnf, kw))
1964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    grid = configure = config = grid_configure
1965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    bbox = grid_bbox = Misc.grid_bbox
1966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    columnconfigure = grid_columnconfigure = Misc.grid_columnconfigure
1967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_forget(self):
1968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unmap this widget."""
1969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('grid', 'forget', self._w)
1970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    forget = grid_forget
1971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_remove(self):
1972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unmap this widget but remember the grid options."""
1973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('grid', 'remove', self._w)
1974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def grid_info(self):
1975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return information about the options
1976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for positioning this widget in a grid."""
1977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        words = self.tk.splitlist(
1978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('grid', 'info', self._w))
1979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        dict = {}
1980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i in range(0, len(words), 2):
1981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            key = words[i][1:]
1982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            value = words[i+1]
1983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if value[:1] == '.':
1984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                value = self._nametowidget(value)
1985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            dict[key] = value
1986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return dict
1987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    info = grid_info
1988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    location = grid_location = Misc.grid_location
1989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    propagate = grid_propagate = Misc.grid_propagate
1990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    rowconfigure = grid_rowconfigure = Misc.grid_rowconfigure
1991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    size = grid_size = Misc.grid_size
1992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    slaves = grid_slaves = Misc.grid_slaves
1993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
1994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass BaseWidget(Misc):
1995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal class."""
1996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _setup(self, master, cnf):
1997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function. Sets up information about children."""
1998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if _support_default_root:
1999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            global _default_root
2000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if not master:
2001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if not _default_root:
2002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    _default_root = Tk()
2003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                master = _default_root
2004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.master = master
2005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk = master.tk
2006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        name = None
2007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'name' in cnf:
2008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            name = cnf['name']
2009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            del cnf['name']
2010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name:
2011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            name = repr(id(self))
2012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self._name = name
2013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if master._w=='.':
2014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w = '.' + name
2015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
2016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w = master._w + '.' + name
2017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.children = {}
2018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self._name in self.master.children:
2019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.master.children[self._name].destroy()
2020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.master.children[self._name] = self
2021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master, widgetName, cnf={}, kw={}, extra=()):
2022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a widget with the parent widget MASTER, a name WIDGETNAME
2023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and appropriate options."""
2024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if kw:
2025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = _cnfmerge((cnf, kw))
2026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.widgetName = widgetName
2027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        BaseWidget._setup(self, master, cnf)
2028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self._tclCommands is None:
2029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._tclCommands = []
2030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        classes = []
2031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for k in cnf.keys():
2032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if type(k) is ClassType:
2033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                classes.append((k, cnf[k]))
2034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                del cnf[k]
2035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
2036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (widgetName, self._w) + extra + self._options(cnf))
2037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for k, v in classes:
2038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            k.configure(self, v)
2039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def destroy(self):
2040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Destroy this and all descendants widgets."""
2041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for c in self.children.values(): c.destroy()
2042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('destroy', self._w)
2043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self._name in self.master.children:
2044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            del self.master.children[self._name]
2045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Misc.destroy(self)
2046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _do(self, name, args=()):
2047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # XXX Obsolete -- better use self.tk.call directly!
2048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call((self._w, name) + args)
2049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Widget(BaseWidget, Pack, Place, Grid):
2051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal class.
2052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Base class for a widget which can be positioned with the geometry managers
2054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    Pack, Place or Grid."""
2055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    pass
2056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Toplevel(BaseWidget, Wm):
2058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Toplevel widget, e.g. for dialogs."""
2059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a toplevel widget with the parent MASTER.
2061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, bd, bg, borderwidth, class,
2063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        colormap, container, cursor, height, highlightbackground,
2064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightcolor, highlightthickness, menu, relief, screen, takefocus,
2065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        use, visual, width."""
2066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if kw:
2067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = _cnfmerge((cnf, kw))
2068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        extra = ()
2069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for wmkey in ['screen', 'class_', 'class', 'visual',
2070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  'colormap']:
2071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if wmkey in cnf:
2072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                val = cnf[wmkey]
2073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # TBD: a hack needed because some keys
2074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # are not valid as keyword arguments
2075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if wmkey[-1] == '_': opt = '-'+wmkey[:-1]
2076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                else: opt = '-'+wmkey
2077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                extra = extra + (opt, val)
2078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                del cnf[wmkey]
2079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        BaseWidget.__init__(self, master, 'toplevel', cnf, {}, extra)
2080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        root = self._root()
2081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.iconname(root.iconname())
2082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.title(root.title())
2083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.protocol("WM_DELETE_WINDOW", self.destroy)
2084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Button(Widget):
2086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Button widget."""
2087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a button widget with the parent MASTER.
2089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        STANDARD OPTIONS
2091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            activebackground, activeforeground, anchor,
2093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            background, bitmap, borderwidth, cursor,
2094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            disabledforeground, font, foreground
2095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightbackground, highlightcolor,
2096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightthickness, image, justify,
2097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            padx, pady, relief, repeatdelay,
2098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            repeatinterval, takefocus, text,
2099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            textvariable, underline, wraplength
2100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        WIDGET-SPECIFIC OPTIONS
2102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            command, compound, default, height,
2104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            overrelief, state, width
2105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'button', cnf, kw)
2107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tkButtonEnter(self, *dummy):
2109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkButtonEnter', self._w)
2110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tkButtonLeave(self, *dummy):
2112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkButtonLeave', self._w)
2113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tkButtonDown(self, *dummy):
2115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkButtonDown', self._w)
2116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tkButtonUp(self, *dummy):
2118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkButtonUp', self._w)
2119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tkButtonInvoke(self, *dummy):
2121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tkButtonInvoke', self._w)
2122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def flash(self):
2124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Flash the button.
2125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        This is accomplished by redisplaying
2127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the button several times, alternating between active and
2128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        normal colors. At the end of the flash the button is left
2129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        in the same normal/active state as when the command was
2130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        invoked. This command is ignored if the button's state is
2131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        disabled.
2132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'flash')
2134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def invoke(self):
2136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Invoke the command associated with the button.
2137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The return value is the return value from the command,
2139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        or an empty string if there is no command associated with
2140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the button. This command is ignored if the button's state
2141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is disabled.
2142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'invoke')
2144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Indices:
2146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# XXX I don't like these -- take them away
2147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef AtEnd():
2148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return 'end'
2149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef AtInsert(*args):
2150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    s = 'insert'
2151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    for a in args:
2152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if a: s = s + (' ' + a)
2153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return s
2154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef AtSelFirst():
2155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return 'sel.first'
2156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef AtSelLast():
2157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    return 'sel.last'
2158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef At(x, y=None):
2159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    if y is None:
2160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return '@%r' % (x,)
2161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    else:
2162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return '@%r,%r' % (x, y)
2163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Canvas(Widget, XView, YView):
2165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Canvas widget to display graphical elements like lines or text."""
2166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a canvas widget with the parent MASTER.
2168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, bd, bg, borderwidth, closeenough,
2170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        confine, cursor, height, highlightbackground, highlightcolor,
2171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightthickness, insertbackground, insertborderwidth,
2172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        insertofftime, insertontime, insertwidth, offset, relief,
2173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        scrollregion, selectbackground, selectborderwidth, selectforeground,
2174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        state, takefocus, width, xscrollcommand, xscrollincrement,
2175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        yscrollcommand, yscrollincrement."""
2176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'canvas', cnf, kw)
2177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag(self, *args):
2178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
2179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'addtag') + args)
2180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_above(self, newtag, tagOrId):
2181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to all items above TAGORID."""
2182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'above', tagOrId)
2183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_all(self, newtag):
2184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to all items."""
2185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'all')
2186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_below(self, newtag, tagOrId):
2187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to all items below TAGORID."""
2188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'below', tagOrId)
2189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_closest(self, newtag, x, y, halo=None, start=None):
2190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to item which is closest to pixel at X, Y.
2191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If several match take the top-most.
2192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        All items closer than HALO are considered overlapping (all are
2193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        closests). If START is specified the next below this tag is taken."""
2194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'closest', x, y, halo, start)
2195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_enclosed(self, newtag, x1, y1, x2, y2):
2196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to all items in the rectangle defined
2197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        by X1,Y1,X2,Y2."""
2198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'enclosed', x1, y1, x2, y2)
2199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_overlapping(self, newtag, x1, y1, x2, y2):
2200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to all items which overlap the rectangle
2201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        defined by X1,Y1,X2,Y2."""
2202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'overlapping', x1, y1, x2, y2)
2203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def addtag_withtag(self, newtag, tagOrId):
2204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag NEWTAG to all items with TAGORID."""
2205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.addtag(newtag, 'withtag', tagOrId)
2206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bbox(self, *args):
2207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
2208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        which encloses all items with tags specified as arguments."""
2209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
2210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'bbox') + args)) or None
2211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_unbind(self, tagOrId, sequence, funcid=None):
2212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unbind for all items with TAGORID for event SEQUENCE  the
2213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        function identified with FUNCID."""
2214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'bind', tagOrId, sequence, '')
2215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if funcid:
2216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.deletecommand(funcid)
2217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_bind(self, tagOrId, sequence=None, func=None, add=None):
2218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind to all items with TAGORID at event SEQUENCE a call to function FUNC.
2219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An additional boolean parameter ADD specifies whether FUNC will be
2221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        called additionally to the other bound function or whether it will
2222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        replace the previous function. See bind for the return value."""
2223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._bind((self._w, 'bind', tagOrId),
2224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  sequence, func, add)
2225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def canvasx(self, screenx, gridspacing=None):
2226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the canvas x coordinate of pixel position SCREENX rounded
2227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to nearest multiple of GRIDSPACING units."""
2228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getdouble(self.tk.call(
2229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'canvasx', screenx, gridspacing))
2230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def canvasy(self, screeny, gridspacing=None):
2231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the canvas y coordinate of pixel position SCREENY rounded
2232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to nearest multiple of GRIDSPACING units."""
2233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getdouble(self.tk.call(
2234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'canvasy', screeny, gridspacing))
2235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def coords(self, *args):
2236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of coordinates for the item given in ARGS."""
2237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # XXX Should use _flatten on args
2238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return map(getdouble,
2239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                           self.tk.splitlist(
2240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                   self.tk.call((self._w, 'coords') + args)))
2241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={})
2242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
2243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = _flatten(args)
2244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cnf = args[-1]
2245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(cnf) in (DictionaryType, TupleType):
2246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args[:-1]
2247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
2248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = {}
2249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call(
2250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'create', itemType,
2251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            *(args + self._options(cnf, kw))))
2252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_arc(self, *args, **kw):
2253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create arc shaped region with coordinates x1,y1,x2,y2."""
2254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('arc', args, kw)
2255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_bitmap(self, *args, **kw):
2256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create bitmap with coordinates x1,y1."""
2257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('bitmap', args, kw)
2258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_image(self, *args, **kw):
2259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create image item with coordinates x1,y1."""
2260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('image', args, kw)
2261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_line(self, *args, **kw):
2262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create line with coordinates x1,y1,...,xn,yn."""
2263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('line', args, kw)
2264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_oval(self, *args, **kw):
2265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create oval with coordinates x1,y1,x2,y2."""
2266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('oval', args, kw)
2267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_polygon(self, *args, **kw):
2268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create polygon with coordinates x1,y1,...,xn,yn."""
2269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('polygon', args, kw)
2270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_rectangle(self, *args, **kw):
2271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create rectangle with coordinates x1,y1,x2,y2."""
2272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('rectangle', args, kw)
2273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_text(self, *args, **kw):
2274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create text with coordinates x1,y1."""
2275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('text', args, kw)
2276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def create_window(self, *args, **kw):
2277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create window with coordinates x1,y1,x2,y2."""
2278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._create('window', args, kw)
2279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def dchars(self, *args):
2280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete characters of text items identified by tag or id in ARGS (possibly
2281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        several times) from FIRST to LAST character (including)."""
2282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'dchars') + args)
2283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delete(self, *args):
2284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete items identified by all tag or ids contained in ARGS."""
2285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'delete') + args)
2286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def dtag(self, *args):
2287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete tag or id given as last arguments in ARGS from items
2288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        identified by first argument in ARGS."""
2289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'dtag') + args)
2290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find(self, *args):
2291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
2292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
2293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'find') + args)) or ()
2294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_above(self, tagOrId):
2295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return items above TAGORID."""
2296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('above', tagOrId)
2297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_all(self):
2298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all items."""
2299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('all')
2300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_below(self, tagOrId):
2301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all items below TAGORID."""
2302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('below', tagOrId)
2303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_closest(self, x, y, halo=None, start=None):
2304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return item which is closest to pixel at X, Y.
2305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If several match take the top-most.
2306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        All items closer than HALO are considered overlapping (all are
2307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        closests). If START is specified the next below this tag is taken."""
2308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('closest', x, y, halo, start)
2309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_enclosed(self, x1, y1, x2, y2):
2310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all items in rectangle defined
2311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        by X1,Y1,X2,Y2."""
2312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('enclosed', x1, y1, x2, y2)
2313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_overlapping(self, x1, y1, x2, y2):
2314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all items which overlap the rectangle
2315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        defined by X1,Y1,X2,Y2."""
2316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('overlapping', x1, y1, x2, y2)
2317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def find_withtag(self, tagOrId):
2318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all items with TAGORID."""
2319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.find('withtag', tagOrId)
2320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def focus(self, *args):
2321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set focus to the first item specified in ARGS."""
2322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call((self._w, 'focus') + args)
2323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def gettags(self, *args):
2324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return tags associated with the first item specified in ARGS."""
2325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(
2326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'gettags') + args))
2327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def icursor(self, *args):
2328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set cursor at position POS in the item identified by TAGORID.
2329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        In ARGS TAGORID must be first."""
2330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'icursor') + args)
2331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def index(self, *args):
2332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return position of cursor as integer in item specified in ARGS."""
2333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call((self._w, 'index') + args))
2334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert(self, *args):
2335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Insert TEXT in item TAGORID at position POS. ARGS must
2336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        be TAGORID POS TEXT."""
2337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'insert') + args)
2338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def itemcget(self, tagOrId, option):
2339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the resource value for an OPTION for item TAGORID."""
2340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(
2341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (self._w, 'itemcget') + (tagOrId, '-'+option))
2342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def itemconfigure(self, tagOrId, cnf=None, **kw):
2343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure resources of an item TAGORID.
2344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The values for resources are specified as keyword
2346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        arguments. To get an overview about
2347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the allowed keyword arguments call the method without arguments.
2348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure(('itemconfigure', tagOrId), cnf, kw)
2350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    itemconfig = itemconfigure
2351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # lower, tkraise/lift hide Misc.lower, Misc.tkraise/lift,
2352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # so the preferred name for them is tag_lower, tag_raise
2353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # (similar to tag_bind, and similar to the Text widget);
2354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # unfortunately can't delete the old ones yet (maybe in 1.6)
2355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_lower(self, *args):
2356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Lower an item TAGORID given in ARGS
2357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (optional below another item)."""
2358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'lower') + args)
2359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    lower = tag_lower
2360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def move(self, *args):
2361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Move an item TAGORID given in ARGS."""
2362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'move') + args)
2363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def postscript(self, cnf={}, **kw):
2364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Print the contents of the canvas to a postscript
2365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        file. Valid options: colormap, colormode, file, fontmap,
2366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        height, pageanchor, pageheight, pagewidth, pagex, pagey,
2367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        rotate, witdh, x, y."""
2368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call((self._w, 'postscript') +
2369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self._options(cnf, kw))
2370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_raise(self, *args):
2371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Raise an item TAGORID given in ARGS
2372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (optional above another item)."""
2373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'raise') + args)
2374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    lift = tkraise = tag_raise
2375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scale(self, *args):
2376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Scale item TAGORID with XORIGIN, YORIGIN, XSCALE, YSCALE."""
2377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'scale') + args)
2378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_mark(self, x, y):
2379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remember the current X, Y coordinates."""
2380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'mark', x, y)
2381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_dragto(self, x, y, gain=10):
2382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjust the view of the canvas to GAIN times the
2383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        difference between X and Y and the coordinates given in
2384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        scan_mark."""
2385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'dragto', x, y, gain)
2386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select_adjust(self, tagOrId, index):
2387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjust the end of the selection near the cursor of an item TAGORID to index."""
2388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
2389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select_clear(self):
2390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the selection if it is in this widget."""
2391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'select', 'clear')
2392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select_from(self, tagOrId, index):
2393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the fixed end of a selection in item TAGORID to INDEX."""
2394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'select', 'from', tagOrId, index)
2395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select_item(self):
2396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the item which has the selection."""
2397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'select', 'item') or None
2398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select_to(self, tagOrId, index):
2399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the variable end of a selection in item TAGORID to INDEX."""
2400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'select', 'to', tagOrId, index)
2401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def type(self, tagOrId):
2402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the type of the item TAGORID."""
2403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'type', tagOrId) or None
2404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Checkbutton(Widget):
2406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Checkbutton widget which is either in on- or off-state."""
2407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a checkbutton widget with the parent MASTER.
2409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: activebackground, activeforeground, anchor,
2411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        background, bd, bg, bitmap, borderwidth, command, cursor,
2412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        disabledforeground, fg, font, foreground, height,
2413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightbackground, highlightcolor, highlightthickness, image,
2414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        indicatoron, justify, offvalue, onvalue, padx, pady, relief,
2415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selectcolor, selectimage, state, takefocus, text, textvariable,
2416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        underline, variable, width, wraplength."""
2417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'checkbutton', cnf, kw)
2418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def deselect(self):
2419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Put the button in off-state."""
2420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'deselect')
2421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def flash(self):
2422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Flash the button."""
2423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'flash')
2424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def invoke(self):
2425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Toggle the button and invoke a command if given as resource."""
2426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'invoke')
2427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select(self):
2428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Put the button in on-state."""
2429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'select')
2430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def toggle(self):
2431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Toggle the button."""
2432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'toggle')
2433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Entry(Widget, XView):
2435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Entry widget which allows to display simple text."""
2436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct an entry widget with the parent MASTER.
2438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, bd, bg, borderwidth, cursor,
2440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exportselection, fg, font, foreground, highlightbackground,
2441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightcolor, highlightthickness, insertbackground,
2442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        insertborderwidth, insertofftime, insertontime, insertwidth,
2443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        invalidcommand, invcmd, justify, relief, selectbackground,
2444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selectborderwidth, selectforeground, show, state, takefocus,
2445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        textvariable, validate, validatecommand, vcmd, width,
2446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        xscrollcommand."""
2447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'entry', cnf, kw)
2448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delete(self, first, last=None):
2449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete text from FIRST to LAST (not included)."""
2450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'delete', first, last)
2451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
2452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the text."""
2453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'get')
2454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def icursor(self, index):
2455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Insert cursor at INDEX."""
2456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'icursor', index)
2457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def index(self, index):
2458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return position of cursor."""
2459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call(
2460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'index', index))
2461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert(self, index, string):
2462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Insert STRING at INDEX."""
2463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'insert', index, string)
2464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_mark(self, x):
2465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remember the current X, Y coordinates."""
2466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'mark', x)
2467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_dragto(self, x):
2468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjust the view of the canvas to 10 times the
2469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        difference between X and Y and the coordinates given in
2470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        scan_mark."""
2471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'dragto', x)
2472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_adjust(self, index):
2473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjust the end of the selection near the cursor to INDEX."""
2474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'adjust', index)
2475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_adjust = selection_adjust
2476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_clear(self):
2477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the selection if it is in this widget."""
2478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'clear')
2479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_clear = selection_clear
2480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_from(self, index):
2481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the fixed end of a selection to INDEX."""
2482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'from', index)
2483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_from = selection_from
2484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_present(self):
2485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return True if there are characters selected in the entry, False
2486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        otherwise."""
2487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(
2488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(self._w, 'selection', 'present'))
2489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_present = selection_present
2490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_range(self, start, end):
2491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the selection from START to END (not included)."""
2492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'range', start, end)
2493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_range = selection_range
2494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_to(self, index):
2495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the variable end of a selection to INDEX."""
2496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'to', index)
2497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_to = selection_to
2498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Frame(Widget):
2500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Frame widget which may contain other widgets and can have a 3D border."""
2501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a frame widget with the parent MASTER.
2503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, bd, bg, borderwidth, class,
2505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        colormap, container, cursor, height, highlightbackground,
2506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightcolor, highlightthickness, relief, takefocus, visual, width."""
2507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        cnf = _cnfmerge((cnf, kw))
2508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        extra = ()
2509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'class_' in cnf:
2510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            extra = ('-class', cnf['class_'])
2511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            del cnf['class_']
2512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif 'class' in cnf:
2513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            extra = ('-class', cnf['class'])
2514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            del cnf['class']
2515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'frame', cnf, {}, extra)
2516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Label(Widget):
2518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Label widget which can display text and bitmaps."""
2519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a label widget with the parent MASTER.
2521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        STANDARD OPTIONS
2523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            activebackground, activeforeground, anchor,
2525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            background, bitmap, borderwidth, cursor,
2526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            disabledforeground, font, foreground,
2527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightbackground, highlightcolor,
2528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightthickness, image, justify,
2529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            padx, pady, relief, takefocus, text,
2530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            textvariable, underline, wraplength
2531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        WIDGET-SPECIFIC OPTIONS
2533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            height, state, width
2535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'label', cnf, kw)
2538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Listbox(Widget, XView, YView):
2540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Listbox widget which can display a list of strings."""
2541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a listbox widget with the parent MASTER.
2543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, bd, bg, borderwidth, cursor,
2545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        exportselection, fg, font, foreground, height, highlightbackground,
2546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightcolor, highlightthickness, relief, selectbackground,
2547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selectborderwidth, selectforeground, selectmode, setgrid, takefocus,
2548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width, xscrollcommand, yscrollcommand, listvariable."""
2549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'listbox', cnf, kw)
2550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def activate(self, index):
2551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Activate item identified by INDEX."""
2552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'activate', index)
2553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bbox(self, *args):
2554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of X1,Y1,X2,Y2 coordinates for a rectangle
2555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        which encloses the item identified by index in ARGS."""
2556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
2557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'bbox') + args)) or None
2558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def curselection(self):
2559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return list of indices of currently selected item."""
2560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # XXX Ought to apply self._getints()...
2561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(self.tk.call(
2562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'curselection'))
2563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delete(self, first, last=None):
2564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete items from FIRST to LAST (not included)."""
2565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'delete', first, last)
2566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self, first, last=None):
2567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Get list of items from FIRST to LAST (not included)."""
2568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if last:
2569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.splitlist(self.tk.call(
2570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self._w, 'get', first, last))
2571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        else:
2572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.tk.call(self._w, 'get', first)
2573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def index(self, index):
2574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return index of item identified with INDEX."""
2575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        i = self.tk.call(self._w, 'index', index)
2576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if i == 'none': return None
2577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(i)
2578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert(self, index, *elements):
2579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Insert ELEMENTS at INDEX."""
2580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'insert', index) + elements)
2581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def nearest(self, y):
2582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Get index of item which is nearest to y coordinate Y."""
2583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call(
2584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'nearest', y))
2585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_mark(self, x, y):
2586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remember the current X, Y coordinates."""
2587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'mark', x, y)
2588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_dragto(self, x, y):
2589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjust the view of the listbox to 10 times the
2590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        difference between X and Y and the coordinates given in
2591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        scan_mark."""
2592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'dragto', x, y)
2593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def see(self, index):
2594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Scroll such that INDEX is visible."""
2595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'see', index)
2596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_anchor(self, index):
2597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the fixed end oft the selection to INDEX."""
2598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'anchor', index)
2599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_anchor = selection_anchor
2600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_clear(self, first, last=None):
2601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the selection from FIRST to LAST (not included)."""
2602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w,
2603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 'selection', 'clear', first, last)
2604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_clear = selection_clear
2605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_includes(self, index):
2606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return 1 if INDEX is part of the selection."""
2607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(self.tk.call(
2608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'selection', 'includes', index))
2609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_includes = selection_includes
2610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_set(self, first, last=None):
2611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the selection from FIRST to LAST (not included) without
2612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        changing the currently selected elements."""
2613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'selection', 'set', first, last)
2614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    select_set = selection_set
2615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def size(self):
2616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the number of elements in the listbox."""
2617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call(self._w, 'size'))
2618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def itemcget(self, index, option):
2619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the resource value for an ITEM and an OPTION."""
2620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(
2621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (self._w, 'itemcget') + (index, '-'+option))
2622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def itemconfigure(self, index, cnf=None, **kw):
2623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure resources of an ITEM.
2624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The values for resources are specified as keyword arguments.
2626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        To get an overview about the allowed keyword arguments
2627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        call the method without arguments.
2628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, bg, foreground, fg,
2629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selectbackground, selectforeground."""
2630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure(('itemconfigure', index), cnf, kw)
2631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    itemconfig = itemconfigure
2632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Menu(Widget):
2634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Menu widget which allows to display menu bars, pull-down menus and pop-up menus."""
2635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct menu widget with the parent MASTER.
2637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: activebackground, activeborderwidth,
2639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        activeforeground, background, bd, bg, borderwidth, cursor,
2640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        disabledforeground, fg, font, foreground, postcommand, relief,
2641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        selectcolor, takefocus, tearoff, tearoffcommand, title, type."""
2642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'menu', cnf, kw)
2643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_bindForTraversal(self):
2644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pass # obsolete since Tk 4.0
2645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_mbPost(self):
2646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_mbPost', self._w)
2647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_mbUnpost(self):
2648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_mbUnpost')
2649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_traverseToMenu(self, char):
2650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_traverseToMenu', self._w, char)
2651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_traverseWithinMenu(self, char):
2652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_traverseWithinMenu', self._w, char)
2653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_getMenuButtons(self):
2654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('tk_getMenuButtons', self._w)
2655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_nextMenu(self, count):
2656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_nextMenu', count)
2657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_nextMenuEntry(self, count):
2658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_nextMenuEntry', count)
2659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_invokeMenu(self):
2660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_invokeMenu', self._w)
2661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_firstMenu(self):
2662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_firstMenu', self._w)
2663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_mbButtonDown(self):
2664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_mbButtonDown', self._w)
2665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_popup(self, x, y, entry=""):
2666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Post the menu at position X,Y with entry ENTRY."""
2667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_popup', self._w, x, y, entry)
2668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def activate(self, index):
2669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Activate entry at INDEX."""
2670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'activate', index)
2671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add(self, itemType, cnf={}, **kw):
2672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
2673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'add', itemType) +
2674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 self._options(cnf, kw))
2675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add_cascade(self, cnf={}, **kw):
2676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add hierarchical menu item."""
2677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.add('cascade', cnf or kw)
2678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add_checkbutton(self, cnf={}, **kw):
2679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add checkbutton menu item."""
2680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.add('checkbutton', cnf or kw)
2681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add_command(self, cnf={}, **kw):
2682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add command menu item."""
2683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.add('command', cnf or kw)
2684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add_radiobutton(self, cnf={}, **kw):
2685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Addd radio menu item."""
2686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.add('radiobutton', cnf or kw)
2687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add_separator(self, cnf={}, **kw):
2688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add separator."""
2689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.add('separator', cnf or kw)
2690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert(self, index, itemType, cnf={}, **kw):
2691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
2692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'insert', index, itemType) +
2693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 self._options(cnf, kw))
2694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert_cascade(self, index, cnf={}, **kw):
2695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add hierarchical menu item at INDEX."""
2696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.insert(index, 'cascade', cnf or kw)
2697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert_checkbutton(self, index, cnf={}, **kw):
2698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add checkbutton menu item at INDEX."""
2699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.insert(index, 'checkbutton', cnf or kw)
2700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert_command(self, index, cnf={}, **kw):
2701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add command menu item at INDEX."""
2702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.insert(index, 'command', cnf or kw)
2703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert_radiobutton(self, index, cnf={}, **kw):
2704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Addd radio menu item at INDEX."""
2705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.insert(index, 'radiobutton', cnf or kw)
2706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert_separator(self, index, cnf={}, **kw):
2707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add separator at INDEX."""
2708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.insert(index, 'separator', cnf or kw)
2709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delete(self, index1, index2=None):
2710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete menu items between INDEX1 and INDEX2 (included)."""
2711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if index2 is None:
2712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            index2 = index1
2713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        num_index1, num_index2 = self.index(index1), self.index(index2)
2715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if (num_index1 is None) or (num_index2 is None):
2716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            num_index1, num_index2 = 0, -1
2717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for i in range(num_index1, num_index2 + 1):
2719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if 'command' in self.entryconfig(i):
2720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                c = str(self.entrycget(i, 'command'))
2721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if c:
2722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    self.deletecommand(c)
2723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'delete', index1, index2)
2724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def entrycget(self, index, option):
2725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the resource value of an menu item for OPTION at INDEX."""
2726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'entrycget', index, '-' + option)
2727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def entryconfigure(self, index, cnf=None, **kw):
2728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure a menu item at INDEX."""
2729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure(('entryconfigure', index), cnf, kw)
2730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    entryconfig = entryconfigure
2731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def index(self, index):
2732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the index of a menu item identified by INDEX."""
2733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        i = self.tk.call(self._w, 'index', index)
2734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if i == 'none': return None
2735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(i)
2736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def invoke(self, index):
2737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Invoke a menu item identified by INDEX and execute
2738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the associated command."""
2739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'invoke', index)
2740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def post(self, x, y):
2741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Display a menu at position X,Y."""
2742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'post', x, y)
2743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def type(self, index):
2744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the type of the menu item at INDEX."""
2745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'type', index)
2746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def unpost(self):
2747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unmap a menu."""
2748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'unpost')
2749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def yposition(self, index):
2750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the y-position of the topmost pixel of the menu item at INDEX."""
2751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(self.tk.call(
2752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'yposition', index))
2753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Menubutton(Widget):
2755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Menubutton widget, obsolete since Tk8.0."""
2756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'menubutton', cnf, kw)
2758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Message(Widget):
2760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Message widget to display multiline text. Obsolete since Label does it too."""
2761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'message', cnf, kw)
2763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Radiobutton(Widget):
2765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Radiobutton widget which shows only one of several buttons in on-state."""
2766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a radiobutton widget with the parent MASTER.
2768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: activebackground, activeforeground, anchor,
2770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        background, bd, bg, bitmap, borderwidth, command, cursor,
2771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        disabledforeground, fg, font, foreground, height,
2772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightbackground, highlightcolor, highlightthickness, image,
2773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        indicatoron, justify, padx, pady, relief, selectcolor, selectimage,
2774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        state, takefocus, text, textvariable, underline, value, variable,
2775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width, wraplength."""
2776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'radiobutton', cnf, kw)
2777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def deselect(self):
2778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Put the button in off-state."""
2779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'deselect')
2781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def flash(self):
2782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Flash the button."""
2783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'flash')
2784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def invoke(self):
2785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Toggle the button and invoke a command if given as resource."""
2786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'invoke')
2787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def select(self):
2788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Put the button in on-state."""
2789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'select')
2790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Scale(Widget):
2792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Scale widget which can display a numerical scale."""
2793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a scale widget with the parent MASTER.
2795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2796edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: activebackground, background, bigincrement, bd,
2797edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
2798edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightbackground, highlightcolor, highlightthickness, label,
2799edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        length, orient, relief, repeatdelay, repeatinterval, resolution,
2800edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        showvalue, sliderlength, sliderrelief, state, takefocus,
2801edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tickinterval, to, troughcolor, variable, width."""
2802edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'scale', cnf, kw)
2803edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
2804edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Get the current value as integer or float."""
2805edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        value = self.tk.call(self._w, 'get')
2806edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
2807edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return getint(value)
2808edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except ValueError:
2809edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return getdouble(value)
2810edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def set(self, value):
2811edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the value to VALUE."""
2812edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'set', value)
2813edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def coords(self, value=None):
2814edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple (X,Y) of the point along the centerline of the
2815edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        trough that corresponds to VALUE or the current value if None is
2816edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        given."""
2817edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2818edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(self._w, 'coords', value))
2819edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def identify(self, x, y):
2820edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return where the point X,Y lies. Valid return values are "slider",
2821edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "though1" and "though2"."""
2822edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'identify', x, y)
2823edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2824edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Scrollbar(Widget):
2825edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Scrollbar widget which displays a slider at a certain position."""
2826edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2827edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a scrollbar widget with the parent MASTER.
2828edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2829edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: activebackground, activerelief,
2830edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        background, bd, bg, borderwidth, command, cursor,
2831edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elementborderwidth, highlightbackground,
2832edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        highlightcolor, highlightthickness, jump, orient,
2833edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        relief, repeatdelay, repeatinterval, takefocus,
2834edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        troughcolor, width."""
2835edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'scrollbar', cnf, kw)
2836edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def activate(self, index):
2837edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Display the element at INDEX with activebackground and activerelief.
2838edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        INDEX can be "arrow1","slider" or "arrow2"."""
2839edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'activate', index)
2840edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delta(self, deltax, deltay):
2841edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the fractional change of the scrollbar setting if it
2842edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        would be moved by DELTAX or DELTAY pixels."""
2843edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getdouble(
2844edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(self._w, 'delta', deltax, deltay))
2845edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def fraction(self, x, y):
2846edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the fractional value which corresponds to a slider
2847edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        position of X,Y."""
2848edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getdouble(self.tk.call(self._w, 'fraction', x, y))
2849edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def identify(self, x, y):
2850edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the element under position X,Y as one of
2851edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        "arrow1","slider","arrow2" or ""."""
2852edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'identify', x, y)
2853edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
2854edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the current fractional values (upper and lower end)
2855edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the slider position."""
2856edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getdoubles(self.tk.call(self._w, 'get'))
2857edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def set(self, *args):
2858edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set the fractional values of the slider position (upper and
2859edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        lower ends as value between 0 and 1)."""
2860edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'set') + args)
2861edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2862edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2863edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2864edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Text(Widget, XView, YView):
2865edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Text widget which can display text in various forms."""
2866edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
2867edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a text widget with the parent MASTER.
2868edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2869edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        STANDARD OPTIONS
2870edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2871edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            background, borderwidth, cursor,
2872edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            exportselection, font, foreground,
2873edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightbackground, highlightcolor,
2874edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightthickness, insertbackground,
2875edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            insertborderwidth, insertofftime,
2876edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            insertontime, insertwidth, padx, pady,
2877edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            relief, selectbackground,
2878edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            selectborderwidth, selectforeground,
2879edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            setgrid, takefocus,
2880edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            xscrollcommand, yscrollcommand,
2881edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2882edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        WIDGET-SPECIFIC OPTIONS
2883edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2884edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            autoseparators, height, maxundo,
2885edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            spacing1, spacing2, spacing3,
2886edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            state, tabs, undo, width, wrap,
2887edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2888edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2889edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'text', cnf, kw)
2890edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bbox(self, *args):
2891edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of (x,y,width,height) which gives the bounding
2892edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        box of the visible part of the character at the index in ARGS."""
2893edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
2894edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'bbox') + args)) or None
2895edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_textSelectTo(self, index):
2896edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_textSelectTo', self._w, index)
2897edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_textBackspace(self):
2898edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_textBackspace', self._w)
2899edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_textIndexCloser(self, a, b, c):
2900edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_textIndexCloser', self._w, a, b, c)
2901edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tk_textResetAnchor(self, index):
2902edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call('tk_textResetAnchor', self._w, index)
2903edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def compare(self, index1, op, index2):
2904edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return whether between index INDEX1 and index INDEX2 the
2905edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=."""
2906edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(self.tk.call(
2907edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'compare', index1, op, index2))
2908edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def debug(self, boolean=None):
2909edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Turn on the internal consistency checks of the B-Tree inside the text
2910edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        widget according to BOOLEAN."""
2911edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.getboolean(self.tk.call(
2912edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'debug', boolean))
2913edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delete(self, index1, index2=None):
2914edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete the characters between INDEX1 and INDEX2 (not included)."""
2915edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'delete', index1, index2)
2916edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def dlineinfo(self, index):
2917edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return tuple (x,y,width,height,baseline) giving the bounding box
2918edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and baseline position of the visible part of the line containing
2919edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the character at INDEX."""
2920edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(self.tk.call(self._w, 'dlineinfo', index))
2921edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def dump(self, index1, index2=None, command=None, **kw):
2922edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the contents of the widget between index1 and index2.
2923edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2924edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The type of contents returned in filtered based on the keyword
2925edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        parameters; if 'all', 'image', 'mark', 'tag', 'text', or 'window' are
2926edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        given and true, then the corresponding items are returned. The result
2927edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is a list of triples of the form (key, value, index). If none of the
2928edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        keywords are true then 'all' is used by default.
2929edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2930edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If the 'command' argument is given, it is called once for each element
2931edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the list of triples, with the values of each triple serving as the
2932edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        arguments to the function. In this case the list is not returned."""
2933edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = []
2934edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        func_name = None
2935edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        result = None
2936edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not command:
2937edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # Never call the dump command without the -command flag, since the
2938edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # output could involve Tcl quoting and would be a pain to parse
2939edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # right. Instead just set the command to build a list of triples
2940edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # as if we had done the parsing.
2941edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            result = []
2942edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            def append_triple(key, value, index, result=result):
2943edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                result.append((key, value, index))
2944edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            command = append_triple
2945edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
2946edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if not isinstance(command, str):
2947edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                func_name = command = self._register(command)
2948edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args += ["-command", command]
2949edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for key in kw:
2950edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if kw[key]: args.append("-" + key)
2951edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args.append(index1)
2952edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if index2:
2953edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                args.append(index2)
2954edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(self._w, "dump", *args)
2955edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return result
2956edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        finally:
2957edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if func_name:
2958edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.deletecommand(func_name)
2959edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2960edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    ## new in tk8.4
2961edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def edit(self, *args):
2962edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal method
2963edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2964edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        This method controls the undo mechanism and
2965edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the modified flag. The exact behavior of the
2966edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        command depends on the option argument that
2967edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        follows the edit argument. The following forms
2968edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the command are currently supported:
2969edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2970edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        edit_modified, edit_redo, edit_reset, edit_separator
2971edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and edit_undo
2972edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2973edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2974edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'edit', *args)
2975edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2976edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def edit_modified(self, arg=None):
2977edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Get or Set the modified flag
2978edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2979edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If arg is not specified, returns the modified
2980edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        flag of the widget. The insert, delete, edit undo and
2981edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        edit redo commands or the user can set or clear the
2982edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        modified flag. If boolean is specified, sets the
2983edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        modified flag of the widget to arg.
2984edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2985edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.edit("modified", arg)
2986edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2987edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def edit_redo(self):
2988edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Redo the last undone edit
2989edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2990edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        When the undo option is true, reapplies the last
2991edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        undone edits provided no other edits were done since
2992edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        then. Generates an error when the redo stack is empty.
2993edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Does nothing when the undo option is false.
2994edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
2995edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.edit("redo")
2996edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
2997edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def edit_reset(self):
2998edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clears the undo and redo stacks
2999edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3000edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.edit("reset")
3001edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3002edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def edit_separator(self):
3003edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Inserts a separator (boundary) on the undo stack.
3004edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3005edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Does nothing when the undo option is false
3006edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3007edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.edit("separator")
3008edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3009edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def edit_undo(self):
3010edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Undoes the last edit action
3011edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3012edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If the undo option is true. An edit action is defined
3013edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        as all the insert and delete commands that are recorded
3014edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        on the undo stack in between two separators. Generates
3015edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        an error when the undo stack is empty. Does nothing
3016edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        when the undo option is false
3017edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3018edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.edit("undo")
3019edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3020edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self, index1, index2=None):
3021edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the text from INDEX1 to INDEX2 (not included)."""
3022edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'get', index1, index2)
3023edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # (Image commands are new in 8.0)
3024edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def image_cget(self, index, option):
3025edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of OPTION of an embedded image at INDEX."""
3026edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if option[:1] != "-":
3027edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            option = "-" + option
3028edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if option[-1:] == "_":
3029edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            option = option[:-1]
3030edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, "image", "cget", index, option)
3031edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def image_configure(self, index, cnf=None, **kw):
3032edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure an embedded image at INDEX."""
3033edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure(('image', 'configure', index), cnf, kw)
3034edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def image_create(self, index, cnf={}, **kw):
3035edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create an embedded image at INDEX."""
3036edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(
3037edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 self._w, "image", "create", index,
3038edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 *self._options(cnf, kw))
3039edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def image_names(self):
3040edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all names of embedded images in this widget."""
3041edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, "image", "names")
3042edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def index(self, index):
3043edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the index in the form line.char for INDEX."""
3044edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return str(self.tk.call(self._w, 'index', index))
3045edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert(self, index, chars, *args):
3046edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Insert CHARS before the characters at INDEX. An additional
3047edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        tag can be given in ARGS. Additional CHARS and tags can follow in ARGS."""
3048edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'insert', index, chars) + args)
3049edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mark_gravity(self, markName, direction=None):
3050edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Change the gravity of a mark MARKNAME to DIRECTION (LEFT or RIGHT).
3051edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return the current value if None is given for DIRECTION."""
3052edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(
3053edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (self._w, 'mark', 'gravity', markName, direction))
3054edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mark_names(self):
3055edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all mark names."""
3056edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(self.tk.call(
3057edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'mark', 'names'))
3058edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mark_set(self, markName, index):
3059edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Set mark MARKNAME before the character at INDEX."""
3060edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'mark', 'set', markName, index)
3061edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mark_unset(self, *markNames):
3062edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete all marks in MARKNAMES."""
3063edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'mark', 'unset') + markNames)
3064edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mark_next(self, index):
3065edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the name of the next mark after INDEX."""
3066edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'mark', 'next', index) or None
3067edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def mark_previous(self, index):
3068edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the name of the previous mark before INDEX."""
3069edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'mark', 'previous', index) or None
3070edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_mark(self, x, y):
3071edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remember the current X, Y coordinates."""
3072edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'mark', x, y)
3073edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_dragto(self, x, y):
3074edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Adjust the view of the text to 10 times the
3075edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        difference between X and Y and the coordinates given in
3076edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        scan_mark."""
3077edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'scan', 'dragto', x, y)
3078edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def search(self, pattern, index, stopindex=None,
3079edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep           forwards=None, backwards=None, exact=None,
3080edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep           regexp=None, nocase=None, count=None, elide=None):
3081edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Search PATTERN beginning from INDEX until STOPINDEX.
3082edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return the index of the first character of a match or an
3083edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        empty string."""
3084edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = [self._w, 'search']
3085edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if forwards: args.append('-forwards')
3086edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if backwards: args.append('-backwards')
3087edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if exact: args.append('-exact')
3088edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if regexp: args.append('-regexp')
3089edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if nocase: args.append('-nocase')
3090edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if elide: args.append('-elide')
3091edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if count: args.append('-count'); args.append(count)
3092edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if pattern and pattern[0] == '-': args.append('--')
3093edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args.append(pattern)
3094edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args.append(index)
3095edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if stopindex: args.append(stopindex)
3096edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return str(self.tk.call(tuple(args)))
3097edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def see(self, index):
3098edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Scroll such that the character at INDEX is visible."""
3099edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'see', index)
3100edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_add(self, tagName, index1, *args):
3101edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add tag TAGNAME to all characters between INDEX1 and index2 in ARGS.
3102edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Additional pairs of indices may follow in ARGS."""
3103edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
3104edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (self._w, 'tag', 'add', tagName, index1) + args)
3105edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_unbind(self, tagName, sequence, funcid=None):
3106edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Unbind for all characters with TAGNAME for event SEQUENCE  the
3107edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        function identified with FUNCID."""
3108edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
3109edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if funcid:
3110edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.deletecommand(funcid)
3111edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_bind(self, tagName, sequence, func, add=None):
3112edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.
3113edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3114edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        An additional boolean parameter ADD specifies whether FUNC will be
3115edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        called additionally to the other bound function or whether it will
3116edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        replace the previous function. See bind for the return value."""
3117edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._bind((self._w, 'tag', 'bind', tagName),
3118edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  sequence, func, add)
3119edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_cget(self, tagName, option):
3120edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of OPTION for tag TAGNAME."""
3121edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if option[:1] != '-':
3122edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            option = '-' + option
3123edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if option[-1:] == '_':
3124edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            option = option[:-1]
3125edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'tag', 'cget', tagName, option)
3126edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_configure(self, tagName, cnf=None, **kw):
3127edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure a tag TAGNAME."""
3128edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure(('tag', 'configure', tagName), cnf, kw)
3129edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    tag_config = tag_configure
3130edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_delete(self, *tagNames):
3131edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete all tags in TAGNAMES."""
3132edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'tag', 'delete') + tagNames)
3133edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_lower(self, tagName, belowThis=None):
3134edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Change the priority of tag TAGNAME such that it is lower
3135edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        than the priority of BELOWTHIS."""
3136edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
3137edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_names(self, index=None):
3138edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of all tag names."""
3139edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(
3140edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(self._w, 'tag', 'names', index))
3141edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_nextrange(self, tagName, index1, index2=None):
3142edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of start and end index for the first sequence of
3143edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        characters between INDEX1 and INDEX2 which all have tag TAGNAME.
3144edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The text is searched forward from INDEX1."""
3145edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(self.tk.call(
3146edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'tag', 'nextrange', tagName, index1, index2))
3147edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_prevrange(self, tagName, index1, index2=None):
3148edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of start and end index for the first sequence of
3149edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        characters between INDEX1 and INDEX2 which all have tag TAGNAME.
3150edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The text is searched backwards from INDEX1."""
3151edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(self.tk.call(
3152edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'tag', 'prevrange', tagName, index1, index2))
3153edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_raise(self, tagName, aboveThis=None):
3154edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Change the priority of tag TAGNAME such that it is higher
3155edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        than the priority of ABOVETHIS."""
3156edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
3157edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'tag', 'raise', tagName, aboveThis)
3158edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_ranges(self, tagName):
3159edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a list of ranges of text which have tag TAGNAME."""
3160edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(self.tk.call(
3161edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'tag', 'ranges', tagName))
3162edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def tag_remove(self, tagName, index1, index2=None):
3163edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remove tag TAGNAME from all characters between INDEX1 and INDEX2."""
3164edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
3165edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self._w, 'tag', 'remove', tagName, index1, index2)
3166edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def window_cget(self, index, option):
3167edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of OPTION of an embedded window at INDEX."""
3168edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if option[:1] != '-':
3169edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            option = '-' + option
3170edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if option[-1:] == '_':
3171edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            option = option[:-1]
3172edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'window', 'cget', index, option)
3173edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def window_configure(self, index, cnf=None, **kw):
3174edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure an embedded window at INDEX."""
3175edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._configure(('window', 'configure', index), cnf, kw)
3176edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    window_config = window_configure
3177edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def window_create(self, index, cnf={}, **kw):
3178edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create a window at INDEX."""
3179edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(
3180edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              (self._w, 'window', 'create', index)
3181edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              + self._options(cnf, kw))
3182edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def window_names(self):
3183edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return all names of embedded windows in this widget."""
3184edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.splitlist(
3185edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call(self._w, 'window', 'names'))
3186edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def yview_pickplace(self, *what):
3187edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Obsolete function, use see."""
3188edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'yview', '-pickplace') + what)
3189edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3190edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3191edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass _setit:
3192edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Internal class. It wraps the command in the widget OptionMenu."""
3193edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, var, value, callback=None):
3194edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.__value = value
3195edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.__var = var
3196edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.__callback = callback
3197edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __call__(self, *args):
3198edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.__var.set(self.__value)
3199edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self.__callback:
3200edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.__callback(self.__value, *args)
3201edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3202edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass OptionMenu(Menubutton):
3203edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """OptionMenu which allows the user to select a value from a menu."""
3204edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master, variable, value, *values, **kwargs):
3205edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct an optionmenu widget with the parent MASTER, with
3206edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the resource textvariable set to VARIABLE, the initially selected
3207edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        value VALUE, the other menu values VALUES and an additional
3208edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        keyword argument command."""
3209edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        kw = {"borderwidth": 2, "textvariable": variable,
3210edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              "indicatoron": 1, "relief": RAISED, "anchor": "c",
3211edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              "highlightthickness": 2}
3212edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, "menubutton", kw)
3213edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.widgetName = 'tk_optionMenu'
3214edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        menu = self.__menu = Menu(self, name="menu", tearoff=0)
3215edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.menuname = menu._w
3216edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        # 'command' is the only supported keyword
3217edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        callback = kwargs.get('command')
3218edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if 'command' in kwargs:
3219edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            del kwargs['command']
3220edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if kwargs:
3221edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            raise TclError, 'unknown option -'+kwargs.keys()[0]
3222edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        menu.add_command(label=value,
3223edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 command=_setit(variable, value, callback))
3224edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for v in values:
3225edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            menu.add_command(label=v,
3226edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                     command=_setit(variable, v, callback))
3227edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self["menu"] = menu
3228edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3229edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __getitem__(self, name):
3230edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if name == 'menu':
3231edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return self.__menu
3232edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return Widget.__getitem__(self, name)
3233edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3234edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def destroy(self):
3235edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Destroy this widget and the associated menu."""
3236edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Menubutton.destroy(self)
3237edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.__menu = None
3238edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3239edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Image:
3240edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Base class for images."""
3241edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _last_id = 0
3242edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, imgtype, name=None, cnf={}, master=None, **kw):
3243edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.name = None
3244edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not master:
3245edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            master = _default_root
3246edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if not master:
3247edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                raise RuntimeError, 'Too early to create image'
3248edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk = master.tk
3249edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if not name:
3250edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Image._last_id += 1
3251edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            name = "pyimage%r" % (Image._last_id,) # tk itself would use image<x>
3252edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # The following is needed for systems where id(x)
3253edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            # can return a negative number, such as Linux/m68k:
3254edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if name[0] == '-': name = '_' + name[1:]
3255edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if kw and cnf: cnf = _cnfmerge((cnf, kw))
3256edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        elif kw: cnf = kw
3257edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        options = ()
3258edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for k, v in cnf.items():
3259edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if hasattr(v, '__call__'):
3260edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                v = self._register(v)
3261edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            options = options + ('-'+k, v)
3262edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(('image', 'create', imgtype, name,) + options)
3263edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.name = name
3264edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __str__(self): return self.name
3265edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __del__(self):
3266edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if self.name:
3267edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            try:
3268edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.tk.call('image', 'delete', self.name)
3269edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            except TclError:
3270edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                # May happen if the root was destroyed
3271edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                pass
3272edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __setitem__(self, key, value):
3273edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self.name, 'configure', '-'+key, value)
3274edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __getitem__(self, key):
3275edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self.name, 'configure', '-'+key)
3276edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def configure(self, **kw):
3277edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Configure the image."""
3278edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        res = ()
3279edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        for k, v in _cnfmerge(kw).items():
3280edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if v is not None:
3281edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if k[-1] == '_': k = k[:-1]
3282edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                if hasattr(v, '__call__'):
3283edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                    v = self._register(v)
3284edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                res = res + ('-'+k, v)
3285edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self.name, 'config') + res)
3286edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    config = configure
3287edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def height(self):
3288edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the height of the image."""
3289edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
3290edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('image', 'height', self.name))
3291edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def type(self):
3292edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the type of the imgage, e.g. "photo" or "bitmap"."""
3293edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call('image', 'type', self.name)
3294edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def width(self):
3295edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the width of the image."""
3296edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return getint(
3297edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call('image', 'width', self.name))
3298edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3299edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass PhotoImage(Image):
3300edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Widget which can display colored images in GIF, PPM/PGM format."""
3301edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, name=None, cnf={}, master=None, **kw):
3302edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create an image with NAME.
3303edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3304edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: data, format, file, gamma, height, palette,
3305edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width."""
3306edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Image.__init__(self, 'photo', name, cnf, master, **kw)
3307edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def blank(self):
3308edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Display a transparent image."""
3309edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self.name, 'blank')
3310edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def cget(self, option):
3311edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the value of OPTION."""
3312edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self.name, 'cget', '-' + option)
3313edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX config
3314edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __getitem__(self, key):
3315edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self.name, 'cget', '-' + key)
3316edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX copy -from, -to, ...?
3317edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def copy(self):
3318edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a new PhotoImage with the same image as this widget."""
3319edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        destImage = PhotoImage()
3320edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(destImage, 'copy', self.name)
3321edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return destImage
3322edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def zoom(self,x,y=''):
3323edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a new PhotoImage with the same image as this widget
3324edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        but zoom it with X and Y."""
3325edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        destImage = PhotoImage()
3326edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if y=='': y=x
3327edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(destImage, 'copy', self.name, '-zoom',x,y)
3328edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return destImage
3329edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def subsample(self,x,y=''):
3330edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a new PhotoImage based on the same image as this widget
3331edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        but use only every Xth or Yth pixel."""
3332edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        destImage = PhotoImage()
3333edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if y=='': y=x
3334edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(destImage, 'copy', self.name, '-subsample',x,y)
3335edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return destImage
3336edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self, x, y):
3337edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the color (red, green, blue) of the pixel at X,Y."""
3338edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self.name, 'get', x, y)
3339edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def put(self, data, to=None):
3340edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Put row formatted colors to image starting from
3341edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        position TO, e.g. image.put("{red green} {blue yellow}", to=(4,6))"""
3342edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = (self.name, 'put', data)
3343edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if to:
3344edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if to[0] == '-to':
3345edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                to = to[1:]
3346edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + ('-to',) + tuple(to)
3347edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(args)
3348edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # XXX read
3349edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def write(self, filename, format=None, from_coords=None):
3350edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Write image to file FILENAME in FORMAT starting from
3351edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        position FROM_COORDS."""
3352edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        args = (self.name, 'write', filename)
3353edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if format:
3354edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + ('-format', format)
3355edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if from_coords:
3356edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            args = args + ('-from',) + tuple(from_coords)
3357edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(args)
3358edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3359edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass BitmapImage(Image):
3360edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """Widget which can display a bitmap."""
3361edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, name=None, cnf={}, master=None, **kw):
3362edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Create a bitmap with NAME.
3363edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3364edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Valid resource names: background, data, file, foreground, maskdata, maskfile."""
3365edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Image.__init__(self, 'bitmap', name, cnf, master, **kw)
3366edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3367edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef image_names(): return _default_root.tk.call('image', 'names')
3368edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef image_types(): return _default_root.tk.call('image', 'types')
3369edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3370edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3371edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Spinbox(Widget, XView):
3372edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """spinbox widget."""
3373edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
3374edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a spinbox widget with the parent MASTER.
3375edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3376edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        STANDARD OPTIONS
3377edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3378edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            activebackground, background, borderwidth,
3379edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cursor, exportselection, font, foreground,
3380edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightbackground, highlightcolor,
3381edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightthickness, insertbackground,
3382edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            insertborderwidth, insertofftime,
3383edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            insertontime, insertwidth, justify, relief,
3384edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            repeatdelay, repeatinterval,
3385edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            selectbackground, selectborderwidth
3386edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            selectforeground, takefocus, textvariable
3387edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            xscrollcommand.
3388edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3389edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        WIDGET-SPECIFIC OPTIONS
3390edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3391edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            buttonbackground, buttoncursor,
3392edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            buttondownrelief, buttonuprelief,
3393edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            command, disabledbackground,
3394edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            disabledforeground, format, from,
3395edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            invalidcommand, increment,
3396edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            readonlybackground, state, to,
3397edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            validate, validatecommand values,
3398edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            width, wrap,
3399edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3400edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'spinbox', cnf, kw)
3401edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3402edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def bbox(self, index):
3403edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return a tuple of X1,Y1,X2,Y2 coordinates for a
3404edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        rectangle which encloses the character given by index.
3405edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3406edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The first two elements of the list give the x and y
3407edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        coordinates of the upper-left corner of the screen
3408edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        area covered by the character (in pixels relative
3409edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to the widget) and the last two elements give the
3410edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width and height of the character, in pixels. The
3411edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        bounding box may refer to a region outside the
3412edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        visible area of the window.
3413edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3414edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'bbox', index)
3415edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3416edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def delete(self, first, last=None):
3417edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Delete one or more elements of the spinbox.
3418edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3419edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        First is the index of the first character to delete,
3420edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and last is the index of the character just after
3421edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the last one to delete. If last isn't specified it
3422edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        defaults to first+1, i.e. a single character is
3423edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        deleted.  This command returns an empty string.
3424edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3425edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'delete', first, last)
3426edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3427edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def get(self):
3428edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Returns the spinbox's string"""
3429edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'get')
3430edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3431edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def icursor(self, index):
3432edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Alter the position of the insertion cursor.
3433edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3434edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The insertion cursor will be displayed just before
3435edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the character given by index. Returns an empty string
3436edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3437edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'icursor', index)
3438edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3439edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def identify(self, x, y):
3440edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Returns the name of the widget at position x, y
3441edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3442edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Return value is one of: none, buttondown, buttonup, entry
3443edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3444edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'identify', x, y)
3445edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3446edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def index(self, index):
3447edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Returns the numerical index corresponding to index
3448edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3449edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'index', index)
3450edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3451edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def insert(self, index, s):
3452edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Insert string s at index
3453edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3454edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep         Returns an empty string.
3455edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3456edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'insert', index, s)
3457edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3458edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def invoke(self, element):
3459edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Causes the specified element to be invoked
3460edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3461edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The element could be buttondown or buttonup
3462edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        triggering the action associated with it.
3463edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3464edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'invoke', element)
3465edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3466edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan(self, *args):
3467edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
3468edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
3469edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'scan') + args)) or ()
3470edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3471edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_mark(self, x):
3472edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Records x and the current view in the spinbox window;
3473edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3474edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        used in conjunction with later scan dragto commands.
3475edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Typically this command is associated with a mouse button
3476edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        press in the widget. It returns an empty string.
3477edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3478edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.scan("mark", x)
3479edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3480edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def scan_dragto(self, x):
3481edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Compute the difference between the given x argument
3482edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        and the x argument to the last scan mark command
3483edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3484edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        It then adjusts the view left or right by 10 times the
3485edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        difference in x-coordinates. This command is typically
3486edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        associated with mouse motion events in the widget, to
3487edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        produce the effect of dragging the spinbox at high speed
3488edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        through the window. The return value is an empty string.
3489edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3490edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.scan("dragto", x)
3491edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3492edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection(self, *args):
3493edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
3494edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
3495edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'selection') + args)) or ()
3496edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3497edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_adjust(self, index):
3498edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Locate the end of the selection nearest to the character
3499edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        given by index,
3500edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3501edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Then adjust that end of the selection to be at index
3502edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        (i.e including but not going beyond index). The other
3503edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        end of the selection is made the anchor point for future
3504edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        select to commands. If the selection isn't currently in
3505edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the spinbox, then a new selection is created to include
3506edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        the characters between index and the most recent selection
3507edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        anchor point, inclusive. Returns an empty string.
3508edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3509edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.selection("adjust", index)
3510edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3511edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_clear(self):
3512edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Clear the selection
3513edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3514edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If the selection isn't in this widget then the
3515edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        command has no effect. Returns an empty string.
3516edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3517edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.selection("clear")
3518edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3519edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def selection_element(self, element=None):
3520edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Sets or gets the currently selected element.
3521edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3522edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If a spinbutton element is specified, it will be
3523edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        displayed depressed
3524edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3525edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.selection("element", element)
3526edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3527edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep###########################################################################
3528edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3529edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass LabelFrame(Widget):
3530edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """labelframe widget."""
3531edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
3532edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a labelframe widget with the parent MASTER.
3533edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3534edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        STANDARD OPTIONS
3535edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3536edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            borderwidth, cursor, font, foreground,
3537edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightbackground, highlightcolor,
3538edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            highlightthickness, padx, pady, relief,
3539edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            takefocus, text
3540edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3541edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        WIDGET-SPECIFIC OPTIONS
3542edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3543edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            background, class, colormap, container,
3544edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            height, labelanchor, labelwidget,
3545edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            visual, width
3546edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3547edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'labelframe', cnf, kw)
3548edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3549edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep########################################################################
3550edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3551edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass PanedWindow(Widget):
3552edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    """panedwindow widget."""
3553edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
3554edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Construct a panedwindow widget with the parent MASTER.
3555edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3556edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        STANDARD OPTIONS
3557edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3558edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            background, borderwidth, cursor, height,
3559edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            orient, relief, width
3560edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3561edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        WIDGET-SPECIFIC OPTIONS
3562edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3563edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            handlepad, handlesize, opaqueresize,
3564edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sashcursor, sashpad, sashrelief,
3565edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            sashwidth, showhandle,
3566edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3567edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'panedwindow', cnf, kw)
3568edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3569edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def add(self, child, **kw):
3570edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Add a child widget to the panedwindow in a new pane.
3571edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3572edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        The child argument is the name of the child widget
3573edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        followed by pairs of arguments that specify how to
3574edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        manage the windows. The possible options and values
3575edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        are the ones accepted by the paneconfigure method.
3576edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3577edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'add', child) + self._options(kw))
3578edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3579edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def remove(self, child):
3580edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remove the pane containing child from the panedwindow
3581edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3582edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        All geometry management options for child will be forgotten.
3583edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3584edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call(self._w, 'forget', child)
3585edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    forget=remove
3586edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3587edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def identify(self, x, y):
3588edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Identify the panedwindow component at point x, y
3589edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3590edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If the point is over a sash or a sash handle, the result
3591edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is a two element list containing the index of the sash or
3592edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        handle, and a word indicating whether it is over a sash
3593edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        or a handle, such as {0 sash} or {2 handle}. If the point
3594edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        is over any other part of the panedwindow, the result is
3595edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        an empty list.
3596edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3597edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'identify', x, y)
3598edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3599edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def proxy(self, *args):
3600edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
3601edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
3602edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'proxy') + args)) or ()
3603edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3604edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def proxy_coord(self):
3605edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the x and y pair of the most recent proxy location
3606edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3607edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.proxy("coord")
3608edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3609edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def proxy_forget(self):
3610edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Remove the proxy from the display.
3611edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3612edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.proxy("forget")
3613edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3614edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def proxy_place(self, x, y):
3615edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Place the proxy at the given x and y coordinates.
3616edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3617edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.proxy("place", x, y)
3618edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3619edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def sash(self, *args):
3620edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Internal function."""
3621edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self._getints(
3622edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            self.tk.call((self._w, 'sash') + args)) or ()
3623edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3624edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def sash_coord(self, index):
3625edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Return the current x and y pair for the sash given by index.
3626edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3627edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Index must be an integer between 0 and 1 less than the
3628edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        number of panes in the panedwindow. The coordinates given are
3629edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        those of the top left corner of the region containing the sash.
3630edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pathName sash dragto index x y This command computes the
3631edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        difference between the given coordinates and the coordinates
3632edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        given to the last sash coord command for the given sash. It then
3633edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        moves that sash the computed difference. The return value is the
3634edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        empty string.
3635edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3636edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.sash("coord", index)
3637edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3638edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def sash_mark(self, index):
3639edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Records x and y for the sash given by index;
3640edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3641edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Used in conjunction with later dragto commands to move the sash.
3642edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3643edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.sash("mark", index)
3644edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3645edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def sash_place(self, index, x, y):
3646edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Place the sash given by index at the given coordinates
3647edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3648edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.sash("place", index, x, y)
3649edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3650edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def panecget(self, child, option):
3651edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Query a management option for window.
3652edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3653edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Option may be any value allowed by the paneconfigure subcommand
3654edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3655edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(
3656edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (self._w, 'panecget') + (child, '-'+option))
3657edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3658edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def paneconfigure(self, tagOrId, cnf=None, **kw):
3659edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Query or modify the management options for window.
3660edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3661edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        If no option is specified, returns a list describing all
3662edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        of the available options for pathName.  If option is
3663edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        specified with no value, then the command returns a list
3664edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        describing the one named option (this list will be identical
3665edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        to the corresponding sublist of the value returned if no
3666edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        option is specified). If one or more option-value pairs are
3667edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        specified, then the command modifies the given widget
3668edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        option(s) to have the given value(s); in this case the
3669edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        command returns an empty string. The following options
3670edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        are supported:
3671edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3672edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        after window
3673edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Insert the window after the window specified. window
3674edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            should be the name of a window already managed by pathName.
3675edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        before window
3676edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Insert the window before the window specified. window
3677edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            should be the name of a window already managed by pathName.
3678edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        height size
3679edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Specify a height for the window. The height will be the
3680edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            outer dimension of the window including its border, if
3681edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            any. If size is an empty string, or if -height is not
3682edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            specified, then the height requested internally by the
3683edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            window will be used initially; the height may later be
3684edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            adjusted by the movement of sashes in the panedwindow.
3685edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Size may be any value accepted by Tk_GetPixels.
3686edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        minsize n
3687edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Specifies that the size of the window cannot be made
3688edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            less than n. This constraint only affects the size of
3689edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            the widget in the paned dimension -- the x dimension
3690edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for horizontal panedwindows, the y dimension for
3691edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            vertical panedwindows. May be any value accepted by
3692edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Tk_GetPixels.
3693edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        padx n
3694edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Specifies a non-negative value indicating how much
3695edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            extra space to leave on each side of the window in
3696edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            the X-direction. The value may have any of the forms
3697edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            accepted by Tk_GetPixels.
3698edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        pady n
3699edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Specifies a non-negative value indicating how much
3700edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            extra space to leave on each side of the window in
3701edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            the Y-direction. The value may have any of the forms
3702edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            accepted by Tk_GetPixels.
3703edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        sticky style
3704edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            If a window's pane is larger than the requested
3705edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            dimensions of the window, this option may be used
3706edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            to position (or stretch) the window within its pane.
3707edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Style is a string that contains zero or more of the
3708edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            characters n, s, e or w. The string can optionally
3709edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            contains spaces or commas, but they are ignored. Each
3710edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            letter refers to a side (north, south, east, or west)
3711edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            that the window will "stick" to. If both n and s
3712edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            (or e and w) are specified, the window will be
3713edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            stretched to fill the entire height (or width) of
3714edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            its cavity.
3715edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        width size
3716edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Specify a width for the window. The width will be
3717edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            the outer dimension of the window including its
3718edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            border, if any. If size is an empty string, or
3719edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            if -width is not specified, then the width requested
3720edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            internally by the window will be used initially; the
3721edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            width may later be adjusted by the movement of sashes
3722edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            in the panedwindow. Size may be any value accepted by
3723edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            Tk_GetPixels.
3724edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3725edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """
3726edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if cnf is None and not kw:
3727edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            cnf = {}
3728edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            for x in self.tk.split(
3729edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self.tk.call(self._w,
3730edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                         'paneconfigure', tagOrId)):
3731edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                cnf[x[0][1:]] = (x[0][1:],) + x[1:]
3732edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return cnf
3733edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        if type(cnf) == StringType and not kw:
3734edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            x = self.tk.split(self.tk.call(
3735edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                self._w, 'paneconfigure', tagOrId, '-'+cnf))
3736edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            return (x[0][1:],) + x[1:]
3737edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.tk.call((self._w, 'paneconfigure', tagOrId) +
3738edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                 self._options(cnf, kw))
3739edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    paneconfig = paneconfigure
3740edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3741edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def panes(self):
3742edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        """Returns an ordered list of the child panes."""
3743edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        return self.tk.call(self._w, 'panes')
3744edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3745edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep######################################################################
3746edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Extensions:
3747edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3748edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Studbutton(Button):
3749edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
3750edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'studbutton', cnf, kw)
3751edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<Any-Enter>',       self.tkButtonEnter)
3752edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<Any-Leave>',       self.tkButtonLeave)
3753edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<1>',               self.tkButtonDown)
3754edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<ButtonRelease-1>', self.tkButtonUp)
3755edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3756edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass Tributton(Button):
3757edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    def __init__(self, master=None, cnf={}, **kw):
3758edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        Widget.__init__(self, master, 'tributton', cnf, kw)
3759edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<Any-Enter>',       self.tkButtonEnter)
3760edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<Any-Leave>',       self.tkButtonLeave)
3761edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<1>',               self.tkButtonDown)
3762edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self.bind('<ButtonRelease-1>', self.tkButtonUp)
3763edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self['fg']               = self['bg']
3764edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        self['activebackground'] = self['bg']
3765edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3766edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep######################################################################
3767edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Test:
3768edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3769edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef _test():
3770edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    root = Tk()
3771edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    text = "This is Tcl/Tk version %s" % TclVersion
3772edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    if TclVersion >= 8.1:
3773edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        try:
3774edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            text = text + unicode("\nThis should be a cedilla: \347",
3775edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                                  "iso-8859-1")
3776edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep        except NameError:
3777edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep            pass # no unicode support
3778edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    label = Label(root, text=text)
3779edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    label.pack()
3780edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    test = Button(root, text="Click me!",
3781edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep              command=lambda root=root: root.test.configure(
3782edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep                  text="[%s]" % root.test['text']))
3783edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    test.pack()
3784edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    root.test = test
3785edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    quit = Button(root, text="QUIT", command=root.destroy)
3786edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    quit.pack()
3787edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # The following three commands are needed so the window pops
3788edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    # up on top on Windows...
3789edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    root.iconify()
3790edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    root.update()
3791edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    root.deiconify()
3792edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    root.mainloop()
3793edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep
3794edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif __name__ == '__main__':
3795edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep    _test()
3796