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