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