Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1 | # Tkinter.py -- Tk/Tcl widget wrappers |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 3 | __version__ = "$Revision$" |
| 4 | |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 5 | import _tkinter # If this fails your Python is not configured for Tk |
| 6 | tkinter = _tkinter # b/w compat for export |
| 7 | TclError = _tkinter.TclError |
Guido van Rossum | 7e9394a | 1995-03-17 16:21:33 +0000 | [diff] [blame] | 8 | from types import * |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 9 | from Tkconstants import * |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 10 | import string; _string = string; del string |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 11 | try: |
| 12 | import MacOS; _MacOS = MacOS; del MacOS |
| 13 | except ImportError: |
| 14 | _MacOS = None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 15 | |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 16 | TkVersion = _string.atof(_tkinter.TK_VERSION) |
| 17 | TclVersion = _string.atof(_tkinter.TCL_VERSION) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 18 | |
Guido van Rossum | d6615ab | 1997-08-05 02:35:01 +0000 | [diff] [blame] | 19 | READABLE = _tkinter.READABLE |
| 20 | WRITABLE = _tkinter.WRITABLE |
| 21 | EXCEPTION = _tkinter.EXCEPTION |
Guido van Rossum | f53c86c | 1997-08-14 14:15:54 +0000 | [diff] [blame] | 22 | |
| 23 | # These are not always defined, e.g. not on Win32 with Tk 8.0 :-( |
| 24 | try: _tkinter.createfilehandler |
| 25 | except AttributeError: _tkinter.createfilehandler = None |
| 26 | try: _tkinter.deletefilehandler |
| 27 | except AttributeError: _tkinter.deletefilehandler = None |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 28 | |
| 29 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 30 | def _flatten(tuple): |
| 31 | res = () |
| 32 | for item in tuple: |
| 33 | if type(item) in (TupleType, ListType): |
| 34 | res = res + _flatten(item) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 35 | elif item is not None: |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 36 | res = res + (item,) |
| 37 | return res |
| 38 | |
| 39 | def _cnfmerge(cnfs): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 40 | if type(cnfs) is DictionaryType: |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 41 | return cnfs |
| 42 | elif type(cnfs) in (NoneType, StringType): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 43 | return cnfs |
| 44 | else: |
| 45 | cnf = {} |
| 46 | for c in _flatten(cnfs): |
Guido van Rossum | 65c78e1 | 1997-07-19 20:02:04 +0000 | [diff] [blame] | 47 | try: |
| 48 | cnf.update(c) |
| 49 | except (AttributeError, TypeError), msg: |
| 50 | print "_cnfmerge: fallback due to:", msg |
| 51 | for k, v in c.items(): |
| 52 | cnf[k] = v |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 53 | return cnf |
| 54 | |
| 55 | class Event: |
| 56 | pass |
| 57 | |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 58 | _support_default_root = 1 |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 59 | _default_root = None |
| 60 | |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 61 | def NoDefaultRoot(): |
| 62 | global _support_default_root |
| 63 | _support_default_root = 0 |
| 64 | del _default_root |
| 65 | |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 66 | def _tkerror(err): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 67 | pass |
| 68 | |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 69 | def _exit(code='0'): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 70 | raise SystemExit, code |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 72 | _varnum = 0 |
| 73 | class Variable: |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 74 | _default = "" |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 75 | def __init__(self, master=None): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 76 | global _varnum |
Guido van Rossum | e2c6e20 | 1998-01-14 16:44:34 +0000 | [diff] [blame] | 77 | if not master: |
| 78 | master = _default_root |
| 79 | self._master = master |
| 80 | self._tk = master.tk |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 81 | self._name = 'PY_VAR' + `_varnum` |
| 82 | _varnum = _varnum + 1 |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 83 | self.set(self._default) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 84 | def __del__(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 85 | self._tk.globalunsetvar(self._name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 86 | def __str__(self): |
| 87 | return self._name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 88 | def set(self, value): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 89 | return self._tk.globalsetvar(self._name, value) |
Guido van Rossum | e2c6e20 | 1998-01-14 16:44:34 +0000 | [diff] [blame] | 90 | def trace_variable(self, mode, callback): |
| 91 | cbname = self._master._register(callback) |
| 92 | self._tk.call("trace", "variable", self._name, mode, cbname) |
| 93 | return cbname |
| 94 | trace = trace_variable |
| 95 | def trace_vdelete(self, mode, cbname): |
| 96 | self._tk.call("trace", "vdelete", self._name, mode, cbname) |
Guido van Rossum | 0001a11 | 1998-02-19 21:20:30 +0000 | [diff] [blame] | 97 | self._master.deletecommand(cbname) |
Guido van Rossum | e2c6e20 | 1998-01-14 16:44:34 +0000 | [diff] [blame] | 98 | def trace_vinfo(self): |
| 99 | return map(self._tk.split, self._tk.splitlist( |
| 100 | self._tk.call("trace", "vinfo", self._name))) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 101 | |
| 102 | class StringVar(Variable): |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 103 | _default = "" |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 104 | def __init__(self, master=None): |
| 105 | Variable.__init__(self, master) |
| 106 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 107 | return self._tk.globalgetvar(self._name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 108 | |
| 109 | class IntVar(Variable): |
Guido van Rossum | 0b96b94 | 1996-12-27 15:30:20 +0000 | [diff] [blame] | 110 | _default = 0 |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 111 | def __init__(self, master=None): |
| 112 | Variable.__init__(self, master) |
| 113 | def get(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 114 | return getint(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 115 | |
| 116 | class DoubleVar(Variable): |
Guido van Rossum | 0b96b94 | 1996-12-27 15:30:20 +0000 | [diff] [blame] | 117 | _default = 0.0 |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 118 | def __init__(self, master=None): |
| 119 | Variable.__init__(self, master) |
| 120 | def get(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 121 | return getdouble(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 122 | |
| 123 | class BooleanVar(Variable): |
Guido van Rossum | e1a7a3b | 1996-09-05 16:45:49 +0000 | [diff] [blame] | 124 | _default = "false" |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 125 | def __init__(self, master=None): |
| 126 | Variable.__init__(self, master) |
| 127 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 128 | return self._tk.getboolean(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 129 | |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 130 | def mainloop(n=0): |
| 131 | _default_root.tk.mainloop(n) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 132 | |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 133 | getint = int |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 134 | |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 135 | getdouble = float |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 136 | |
| 137 | def getboolean(s): |
| 138 | return _default_root.tk.getboolean(s) |
| 139 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 140 | # Methods defined on both toplevel and interior widgets |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 141 | class Misc: |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 142 | # XXX font command? |
Fred Drake | 526749b | 1997-05-03 04:16:23 +0000 | [diff] [blame] | 143 | _tclCommands = None |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 144 | def destroy(self): |
| 145 | if self._tclCommands is not None: |
| 146 | for name in self._tclCommands: |
| 147 | #print '- Tkinter: deleted command', name |
| 148 | self.tk.deletecommand(name) |
| 149 | self._tclCommands = None |
| 150 | def deletecommand(self, name): |
| 151 | #print '- Tkinter: deleted command', name |
| 152 | self.tk.deletecommand(name) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 153 | try: |
| 154 | self._tclCommands.remove(name) |
| 155 | except ValueError: |
| 156 | pass |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 157 | def tk_strictMotif(self, boolean=None): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 158 | return self.tk.getboolean(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 159 | 'set', 'tk_strictMotif', boolean)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 160 | def tk_bisque(self): |
| 161 | self.tk.call('tk_bisque') |
| 162 | def tk_setPalette(self, *args, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 163 | self.tk.call(('tk_setPalette',) |
Fred Drake | 3faf9b4 | 1996-10-04 19:23:04 +0000 | [diff] [blame] | 164 | + _flatten(args) + _flatten(kw.items())) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 165 | def tk_menuBar(self, *args): |
Guido van Rossum | 688bbfc | 1996-09-10 12:39:26 +0000 | [diff] [blame] | 166 | pass # obsolete since Tk 4.0 |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 167 | def wait_variable(self, name='PY_VAR'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 168 | self.tk.call('tkwait', 'variable', name) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 169 | waitvar = wait_variable # XXX b/w compat |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 170 | def wait_window(self, window=None): |
| 171 | if window == None: |
| 172 | window = self |
| 173 | self.tk.call('tkwait', 'window', window._w) |
| 174 | def wait_visibility(self, window=None): |
| 175 | if window == None: |
| 176 | window = self |
| 177 | self.tk.call('tkwait', 'visibility', window._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 178 | def setvar(self, name='PY_VAR', value='1'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 179 | self.tk.setvar(name, value) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 180 | def getvar(self, name='PY_VAR'): |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 181 | return self.tk.getvar(name) |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 182 | getint = int |
| 183 | getdouble = float |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 184 | def getboolean(self, s): |
| 185 | return self.tk.getboolean(s) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 186 | def focus_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 187 | self.tk.call('focus', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 188 | focus = focus_set # XXX b/w compat? |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 189 | def focus_force(self): |
| 190 | self.tk.call('focus', '-force', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 191 | def focus_get(self): |
| 192 | name = self.tk.call('focus') |
Guido van Rossum | 5468a7b | 1996-08-08 18:31:42 +0000 | [diff] [blame] | 193 | if name == 'none' or not name: return None |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 194 | return self._nametowidget(name) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 195 | def focus_displayof(self): |
| 196 | name = self.tk.call('focus', '-displayof', self._w) |
| 197 | if name == 'none' or not name: return None |
| 198 | return self._nametowidget(name) |
| 199 | def focus_lastfor(self): |
| 200 | name = self.tk.call('focus', '-lastfor', self._w) |
| 201 | if name == 'none' or not name: return None |
| 202 | return self._nametowidget(name) |
| 203 | def tk_focusFollowsMouse(self): |
| 204 | self.tk.call('tk_focusFollowsMouse') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 205 | def tk_focusNext(self): |
| 206 | name = self.tk.call('tk_focusNext', self._w) |
| 207 | if not name: return None |
| 208 | return self._nametowidget(name) |
| 209 | def tk_focusPrev(self): |
| 210 | name = self.tk.call('tk_focusPrev', self._w) |
| 211 | if not name: return None |
| 212 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 213 | def after(self, ms, func=None, *args): |
| 214 | if not func: |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 215 | # I'd rather use time.sleep(ms*0.001) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 216 | self.tk.call('after', ms) |
| 217 | else: |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 218 | # XXX Disgusting hack to clean up after calling func |
| 219 | tmp = [] |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 220 | def callit(func=func, args=args, self=self, tmp=tmp): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 221 | try: |
| 222 | apply(func, args) |
| 223 | finally: |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 224 | self.deletecommand(tmp[0]) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 225 | name = self._register(callit) |
| 226 | tmp.append(name) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 227 | return self.tk.call('after', ms, name) |
| 228 | def after_idle(self, func, *args): |
| 229 | return apply(self.after, ('idle', func) + args) |
| 230 | def after_cancel(self, id): |
| 231 | self.tk.call('after', 'cancel', id) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 232 | def bell(self, displayof=0): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 233 | self.tk.call(('bell',) + self._displayof(displayof)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 234 | # Clipboard handling: |
| 235 | def clipboard_clear(self, **kw): |
| 236 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 237 | self.tk.call(('clipboard', 'clear') + self._options(kw)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 238 | def clipboard_append(self, string, **kw): |
| 239 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 240 | self.tk.call(('clipboard', 'append') + self._options(kw) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 241 | + ('--', string)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 242 | # XXX grab current w/o window argument |
| 243 | def grab_current(self): |
| 244 | name = self.tk.call('grab', 'current', self._w) |
| 245 | if not name: return None |
| 246 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 247 | def grab_release(self): |
| 248 | self.tk.call('grab', 'release', self._w) |
| 249 | def grab_set(self): |
| 250 | self.tk.call('grab', 'set', self._w) |
| 251 | def grab_set_global(self): |
| 252 | self.tk.call('grab', 'set', '-global', self._w) |
| 253 | def grab_status(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 254 | status = self.tk.call('grab', 'status', self._w) |
| 255 | if status == 'none': status = None |
| 256 | return status |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 257 | def lower(self, belowThis=None): |
| 258 | self.tk.call('lower', self._w, belowThis) |
Guido van Rossum | 780044f | 1994-10-20 22:02:27 +0000 | [diff] [blame] | 259 | def option_add(self, pattern, value, priority = None): |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 260 | self.tk.call('option', 'add', pattern, value, priority) |
Guido van Rossum | 780044f | 1994-10-20 22:02:27 +0000 | [diff] [blame] | 261 | def option_clear(self): |
| 262 | self.tk.call('option', 'clear') |
| 263 | def option_get(self, name, className): |
| 264 | return self.tk.call('option', 'get', self._w, name, className) |
| 265 | def option_readfile(self, fileName, priority = None): |
| 266 | self.tk.call('option', 'readfile', fileName, priority) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 267 | def selection_clear(self, **kw): |
| 268 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 269 | self.tk.call(('selection', 'clear') + self._options(kw)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 270 | def selection_get(self, **kw): |
| 271 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 272 | return self.tk.call(('selection', 'get') + self._options(kw)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 273 | def selection_handle(self, command, **kw): |
| 274 | name = self._register(command) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 275 | self.tk.call(('selection', 'handle') + self._options(kw) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 276 | + (self._w, name)) |
| 277 | def selection_own(self, **kw): |
| 278 | "Become owner of X selection." |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 279 | self.tk.call(('selection', 'own') + |
| 280 | self._options(kw) + (self._w,)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 281 | def selection_own_get(self, **kw): |
| 282 | "Find owner of X selection." |
| 283 | if not kw.has_key('displayof'): kw['displayof'] = self._w |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 284 | name = self.tk.call(('selection', 'own') + self._options(kw)) |
Guido van Rossum | 76f587b | 1997-01-21 23:22:03 +0000 | [diff] [blame] | 285 | if not name: return None |
| 286 | return self._nametowidget(name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 287 | def send(self, interp, cmd, *args): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 288 | return self.tk.call(('send', interp, cmd) + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 289 | def lower(self, belowThis=None): |
Guido van Rossum | 6e8ec59 | 1996-09-11 14:25:41 +0000 | [diff] [blame] | 290 | self.tk.call('lower', self._w, belowThis) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 291 | def tkraise(self, aboveThis=None): |
| 292 | self.tk.call('raise', self._w, aboveThis) |
| 293 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 294 | def colormodel(self, value=None): |
| 295 | return self.tk.call('tk', 'colormodel', self._w, value) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 296 | def winfo_atom(self, name, displayof=0): |
| 297 | args = ('winfo', 'atom') + self._displayof(displayof) + (name,) |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 298 | return getint(self.tk.call(args)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 299 | def winfo_atomname(self, id, displayof=0): |
| 300 | args = ('winfo', 'atomname') \ |
| 301 | + self._displayof(displayof) + (id,) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 302 | return self.tk.call(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 303 | def winfo_cells(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 304 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 305 | self.tk.call('winfo', 'cells', self._w)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 306 | def winfo_children(self): |
| 307 | return map(self._nametowidget, |
| 308 | self.tk.splitlist(self.tk.call( |
| 309 | 'winfo', 'children', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 310 | def winfo_class(self): |
| 311 | return self.tk.call('winfo', 'class', self._w) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 312 | def winfo_colormapfull(self): |
| 313 | return self.tk.getboolean( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 314 | self.tk.call('winfo', 'colormapfull', self._w)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 315 | def winfo_containing(self, rootX, rootY, displayof=0): |
| 316 | args = ('winfo', 'containing') \ |
| 317 | + self._displayof(displayof) + (rootX, rootY) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 318 | name = self.tk.call(args) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 319 | if not name: return None |
| 320 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 321 | def winfo_depth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 322 | return getint(self.tk.call('winfo', 'depth', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 323 | def winfo_exists(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 324 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 325 | self.tk.call('winfo', 'exists', self._w)) |
| 326 | def winfo_fpixels(self, number): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 327 | return getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 328 | 'winfo', 'fpixels', self._w, number)) |
| 329 | def winfo_geometry(self): |
| 330 | return self.tk.call('winfo', 'geometry', self._w) |
| 331 | def winfo_height(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 332 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 333 | self.tk.call('winfo', 'height', self._w)) |
| 334 | def winfo_id(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 335 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 336 | self.tk.call('winfo', 'id', self._w)) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 337 | def winfo_interps(self, displayof=0): |
| 338 | args = ('winfo', 'interps') + self._displayof(displayof) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 339 | return self.tk.splitlist(self.tk.call(args)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 340 | def winfo_ismapped(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 341 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 342 | self.tk.call('winfo', 'ismapped', self._w)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 343 | def winfo_manager(self): |
| 344 | return self.tk.call('winfo', 'manager', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 345 | def winfo_name(self): |
| 346 | return self.tk.call('winfo', 'name', self._w) |
| 347 | def winfo_parent(self): |
| 348 | return self.tk.call('winfo', 'parent', self._w) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 349 | def winfo_pathname(self, id, displayof=0): |
| 350 | args = ('winfo', 'pathname') \ |
| 351 | + self._displayof(displayof) + (id,) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 352 | return self.tk.call(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 353 | def winfo_pixels(self, number): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 354 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 355 | self.tk.call('winfo', 'pixels', self._w, number)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 356 | def winfo_pointerx(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 357 | return getint( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 358 | self.tk.call('winfo', 'pointerx', self._w)) |
| 359 | def winfo_pointerxy(self): |
| 360 | return self._getints( |
| 361 | self.tk.call('winfo', 'pointerxy', self._w)) |
| 362 | def winfo_pointery(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 363 | return getint( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 364 | self.tk.call('winfo', 'pointery', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 365 | def winfo_reqheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 366 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 367 | self.tk.call('winfo', 'reqheight', self._w)) |
| 368 | def winfo_reqwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 369 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 370 | self.tk.call('winfo', 'reqwidth', self._w)) |
| 371 | def winfo_rgb(self, color): |
| 372 | return self._getints( |
| 373 | self.tk.call('winfo', 'rgb', self._w, color)) |
| 374 | def winfo_rootx(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 375 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 376 | self.tk.call('winfo', 'rootx', self._w)) |
| 377 | def winfo_rooty(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 378 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 379 | self.tk.call('winfo', 'rooty', self._w)) |
| 380 | def winfo_screen(self): |
| 381 | return self.tk.call('winfo', 'screen', self._w) |
| 382 | def winfo_screencells(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 383 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 384 | self.tk.call('winfo', 'screencells', self._w)) |
| 385 | def winfo_screendepth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 386 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 387 | self.tk.call('winfo', 'screendepth', self._w)) |
| 388 | def winfo_screenheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 389 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 390 | self.tk.call('winfo', 'screenheight', self._w)) |
| 391 | def winfo_screenmmheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 392 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 393 | self.tk.call('winfo', 'screenmmheight', self._w)) |
| 394 | def winfo_screenmmwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 395 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 396 | self.tk.call('winfo', 'screenmmwidth', self._w)) |
| 397 | def winfo_screenvisual(self): |
| 398 | return self.tk.call('winfo', 'screenvisual', self._w) |
| 399 | def winfo_screenwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 400 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 401 | self.tk.call('winfo', 'screenwidth', self._w)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 402 | def winfo_server(self): |
| 403 | return self.tk.call('winfo', 'server', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 404 | def winfo_toplevel(self): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 405 | return self._nametowidget(self.tk.call( |
| 406 | 'winfo', 'toplevel', self._w)) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 407 | def winfo_viewable(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 408 | return getint( |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 409 | self.tk.call('winfo', 'viewable', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 410 | def winfo_visual(self): |
| 411 | return self.tk.call('winfo', 'visual', self._w) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 412 | def winfo_visualid(self): |
| 413 | return self.tk.call('winfo', 'visualid', self._w) |
| 414 | def winfo_visualsavailable(self, includeids=0): |
| 415 | data = self.tk.split( |
| 416 | self.tk.call('winfo', 'visualsavailable', self._w, |
| 417 | includeids and 'includeids' or None)) |
| 418 | def parseitem(x, self=self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 419 | return x[:1] + tuple(map(getint, x[1:])) |
Guido van Rossum | c0967cd | 1996-12-12 16:43:05 +0000 | [diff] [blame] | 420 | return map(parseitem, data) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 421 | def winfo_vrootheight(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 422 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 423 | self.tk.call('winfo', 'vrootheight', self._w)) |
| 424 | def winfo_vrootwidth(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 425 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 426 | self.tk.call('winfo', 'vrootwidth', self._w)) |
| 427 | def winfo_vrootx(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 428 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 429 | self.tk.call('winfo', 'vrootx', self._w)) |
| 430 | def winfo_vrooty(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 431 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 432 | self.tk.call('winfo', 'vrooty', self._w)) |
| 433 | def winfo_width(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 434 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 435 | self.tk.call('winfo', 'width', self._w)) |
| 436 | def winfo_x(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 437 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 438 | self.tk.call('winfo', 'x', self._w)) |
| 439 | def winfo_y(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 440 | return getint( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 441 | self.tk.call('winfo', 'y', self._w)) |
| 442 | def update(self): |
| 443 | self.tk.call('update') |
| 444 | def update_idletasks(self): |
| 445 | self.tk.call('update', 'idletasks') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 446 | def bindtags(self, tagList=None): |
| 447 | if tagList is None: |
| 448 | return self.tk.splitlist( |
| 449 | self.tk.call('bindtags', self._w)) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 450 | else: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 451 | self.tk.call('bindtags', self._w, tagList) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 452 | def _bind(self, what, sequence, func, add, needcleanup=1): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 453 | if func: |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 454 | funcid = self._register(func, self._substitute, |
| 455 | needcleanup) |
Guido van Rossum | dc59340 | 1998-04-29 22:16:57 +0000 | [diff] [blame] | 456 | cmd = ('%sif {"[%s %s]" == "break"} break\n' |
| 457 | % |
| 458 | (add and '+' or '', |
| 459 | funcid, |
| 460 | _string.join(self._subst_format))) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 461 | self.tk.call(what + (sequence, cmd)) |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 462 | return funcid |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 463 | elif func == '': |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 464 | self.tk.call(what + (sequence, func)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 465 | else: |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 466 | return self.tk.call(what + (sequence,)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 467 | def bind(self, sequence=None, func=None, add=None): |
| 468 | return self._bind(('bind', self._w), sequence, func, add) |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 469 | def unbind(self, sequence, funcid=None): |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 470 | self.tk.call('bind', self._w, sequence, '') |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 471 | if funcid: |
| 472 | self.deletecommand(funcid) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 473 | def bind_all(self, sequence=None, func=None, add=None): |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 474 | return self._bind(('bind', 'all'), sequence, func, add, 0) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 475 | def unbind_all(self, sequence): |
| 476 | self.tk.call('bind', 'all' , sequence, '') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 477 | def bind_class(self, className, sequence=None, func=None, add=None): |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 478 | return self._bind(('bind', className), sequence, func, add, 0) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 479 | def unbind_class(self, className, sequence): |
| 480 | self.tk.call('bind', className , sequence, '') |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 481 | def mainloop(self, n=0): |
| 482 | self.tk.mainloop(n) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 483 | def quit(self): |
| 484 | self.tk.quit() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 485 | def _getints(self, string): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 486 | if string: |
| 487 | return tuple(map(getint, self.tk.splitlist(string))) |
Guido van Rossum | 7e9394a | 1995-03-17 16:21:33 +0000 | [diff] [blame] | 488 | def _getdoubles(self, string): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 489 | if string: |
| 490 | return tuple(map(getdouble, self.tk.splitlist(string))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 491 | def _getboolean(self, string): |
| 492 | if string: |
| 493 | return self.tk.getboolean(string) |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 494 | def _displayof(self, displayof): |
| 495 | if displayof: |
| 496 | return ('-displayof', displayof) |
| 497 | if displayof is None: |
| 498 | return ('-displayof', self._w) |
| 499 | return () |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 500 | def _options(self, cnf, kw = None): |
| 501 | if kw: |
| 502 | cnf = _cnfmerge((cnf, kw)) |
| 503 | else: |
| 504 | cnf = _cnfmerge(cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 505 | res = () |
| 506 | for k, v in cnf.items(): |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 507 | if v is not None: |
| 508 | if k[-1] == '_': k = k[:-1] |
| 509 | if callable(v): |
| 510 | v = self._register(v) |
| 511 | res = res + ('-'+k, v) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 512 | return res |
Guido van Rossum | 98b9d77 | 1997-12-12 00:09:34 +0000 | [diff] [blame] | 513 | def nametowidget(self, name): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 514 | w = self |
| 515 | if name[0] == '.': |
| 516 | w = w._root() |
| 517 | name = name[1:] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 518 | find = _string.find |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 519 | while name: |
| 520 | i = find(name, '.') |
| 521 | if i >= 0: |
| 522 | name, tail = name[:i], name[i+1:] |
| 523 | else: |
| 524 | tail = '' |
| 525 | w = w.children[name] |
| 526 | name = tail |
| 527 | return w |
Guido van Rossum | 98b9d77 | 1997-12-12 00:09:34 +0000 | [diff] [blame] | 528 | _nametowidget = nametowidget |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 529 | def _register(self, func, subst=None, needcleanup=1): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 530 | f = CallWrapper(func, subst, self).__call__ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 531 | name = `id(f)` |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 532 | try: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 533 | func = func.im_func |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 534 | except AttributeError: |
| 535 | pass |
| 536 | try: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 537 | name = name + func.__name__ |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 538 | except AttributeError: |
| 539 | pass |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 540 | self.tk.createcommand(name, f) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 541 | if needcleanup: |
| 542 | if self._tclCommands is None: |
| 543 | self._tclCommands = [] |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 544 | self._tclCommands.append(name) |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 545 | #print '+ Tkinter created command', name |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 546 | return name |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 547 | register = _register |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 548 | def _root(self): |
| 549 | w = self |
| 550 | while w.master: w = w.master |
| 551 | return w |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 552 | _subst_format = ('%#', '%b', '%f', '%h', '%k', |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 553 | '%s', '%t', '%w', '%x', '%y', |
| 554 | '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y') |
| 555 | def _substitute(self, *args): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 556 | if len(args) != len(self._subst_format): return args |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 557 | getboolean = self.tk.getboolean |
| 558 | getint = int |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 559 | nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args |
| 560 | # Missing: (a, c, d, m, o, v, B, R) |
| 561 | e = Event() |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 562 | e.serial = getint(nsign) |
| 563 | e.num = getint(b) |
| 564 | try: e.focus = getboolean(f) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 565 | except TclError: pass |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 566 | e.height = getint(h) |
| 567 | e.keycode = getint(k) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 568 | # For Visibility events, event state is a string and |
| 569 | # not an integer: |
| 570 | try: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 571 | e.state = getint(s) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 572 | except TclError: |
| 573 | e.state = s |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 574 | e.time = getint(t) |
| 575 | e.width = getint(w) |
| 576 | e.x = getint(x) |
| 577 | e.y = getint(y) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 578 | e.char = A |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 579 | try: e.send_event = getboolean(E) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 580 | except TclError: pass |
| 581 | e.keysym = K |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 582 | e.keysym_num = getint(N) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 583 | e.type = T |
Guido van Rossum | e86271a | 1998-04-27 19:32:59 +0000 | [diff] [blame] | 584 | try: |
| 585 | e.widget = self._nametowidget(W) |
| 586 | except KeyError: |
| 587 | e.widget = W |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 588 | e.x_root = getint(X) |
| 589 | e.y_root = getint(Y) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 590 | return (e,) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 591 | def _report_exception(self): |
| 592 | import sys |
| 593 | exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback |
| 594 | root = self._root() |
| 595 | root.report_callback_exception(exc, val, tb) |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 596 | # These used to be defined in Widget: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 597 | def configure(self, cnf=None, **kw): |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 598 | # XXX ought to generalize this so tag_config etc. can use it |
| 599 | if kw: |
| 600 | cnf = _cnfmerge((cnf, kw)) |
| 601 | elif cnf: |
| 602 | cnf = _cnfmerge(cnf) |
| 603 | if cnf is None: |
| 604 | cnf = {} |
| 605 | for x in self.tk.split( |
| 606 | self.tk.call(self._w, 'configure')): |
| 607 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 608 | return cnf |
| 609 | if type(cnf) is StringType: |
| 610 | x = self.tk.split(self.tk.call( |
| 611 | self._w, 'configure', '-'+cnf)) |
| 612 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 613 | self.tk.call((self._w, 'configure') |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 614 | + self._options(cnf)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 615 | config = configure |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 616 | def cget(self, key): |
| 617 | return self.tk.call(self._w, 'cget', '-' + key) |
| 618 | __getitem__ = cget |
| 619 | def __setitem__(self, key, value): |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 620 | self.configure({key: value}) |
Guido van Rossum | 83bd9a9 | 1997-09-29 23:24:52 +0000 | [diff] [blame] | 621 | def keys(self): |
| 622 | return map(lambda x: x[0][1:], |
| 623 | self.tk.split(self.tk.call(self._w, 'configure'))) |
| 624 | def __str__(self): |
| 625 | return self._w |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 626 | # Pack methods that apply to the master |
| 627 | _noarg_ = ['_noarg_'] |
| 628 | def pack_propagate(self, flag=_noarg_): |
| 629 | if flag is Misc._noarg_: |
| 630 | return self._getboolean(self.tk.call( |
| 631 | 'pack', 'propagate', self._w)) |
| 632 | else: |
| 633 | self.tk.call('pack', 'propagate', self._w, flag) |
| 634 | propagate = pack_propagate |
| 635 | def pack_slaves(self): |
| 636 | return map(self._nametowidget, |
| 637 | self.tk.splitlist( |
| 638 | self.tk.call('pack', 'slaves', self._w))) |
| 639 | slaves = pack_slaves |
| 640 | # Place method that applies to the master |
| 641 | def place_slaves(self): |
| 642 | return map(self._nametowidget, |
| 643 | self.tk.splitlist( |
| 644 | self.tk.call( |
| 645 | 'place', 'slaves', self._w))) |
| 646 | # Grid methods that apply to the master |
| 647 | def grid_bbox(self, column, row): |
| 648 | return self._getints( |
| 649 | self.tk.call( |
| 650 | 'grid', 'bbox', self._w, column, row)) or None |
| 651 | bbox = grid_bbox |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 652 | def _grid_configure(self, command, index, cnf, kw): |
| 653 | if type(cnf) is StringType and not kw: |
| 654 | if cnf[-1:] == '_': |
| 655 | cnf = cnf[:-1] |
| 656 | if cnf[:1] != '-': |
| 657 | cnf = '-'+cnf |
| 658 | options = (cnf,) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 659 | else: |
| 660 | options = self._options(cnf, kw) |
| 661 | if not options: |
| 662 | res = self.tk.call('grid', |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 663 | command, self._w, index) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 664 | words = self.tk.splitlist(res) |
| 665 | dict = {} |
| 666 | for i in range(0, len(words), 2): |
| 667 | key = words[i][1:] |
| 668 | value = words[i+1] |
| 669 | if not value: |
| 670 | value = None |
| 671 | elif '.' in value: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 672 | value = getdouble(value) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 673 | else: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 674 | value = getint(value) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 675 | dict[key] = value |
| 676 | return dict |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 677 | res = self.tk.call( |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 678 | ('grid', command, self._w, index) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 679 | + options) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 680 | if len(options) == 1: |
| 681 | if not res: return None |
| 682 | # In Tk 7.5, -width can be a float |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 683 | if '.' in res: return getdouble(res) |
| 684 | return getint(res) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 685 | def grid_columnconfigure(self, index, cnf={}, **kw): |
| 686 | return self._grid_configure('columnconfigure', index, cnf, kw) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 687 | columnconfigure = grid_columnconfigure |
| 688 | def grid_propagate(self, flag=_noarg_): |
| 689 | if flag is Misc._noarg_: |
| 690 | return self._getboolean(self.tk.call( |
| 691 | 'grid', 'propagate', self._w)) |
| 692 | else: |
| 693 | self.tk.call('grid', 'propagate', self._w, flag) |
| 694 | def grid_rowconfigure(self, index, cnf={}, **kw): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 695 | return self._grid_configure('rowconfigure', index, cnf, kw) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 696 | rowconfigure = grid_rowconfigure |
| 697 | def grid_size(self): |
| 698 | return self._getints( |
| 699 | self.tk.call('grid', 'size', self._w)) or None |
| 700 | size = grid_size |
Guido van Rossum | 1cd6a45 | 1997-12-30 04:07:19 +0000 | [diff] [blame] | 701 | def grid_slaves(self, row=None, column=None): |
| 702 | args = () |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 703 | if row: |
| 704 | args = args + ('-row', row) |
| 705 | if column: |
| 706 | args = args + ('-column', column) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 707 | return map(self._nametowidget, |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 708 | self.tk.splitlist(self.tk.call( |
| 709 | ('grid', 'slaves', self._w) + args))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 710 | |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 711 | # Support for the "event" command, new in Tk 4.2. |
| 712 | # By Case Roole. |
| 713 | |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 714 | def event_add(self, virtual, *sequences): |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 715 | args = ('event', 'add', virtual) + sequences |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 716 | self.tk.call(args) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 717 | |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 718 | def event_delete(self, virtual, *sequences): |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 719 | args = ('event', 'delete', virtual) + sequences |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 720 | self.tk.call(args) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 721 | |
| 722 | def event_generate(self, sequence, **kw): |
| 723 | args = ('event', 'generate', self._w, sequence) |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 724 | for k, v in kw.items(): |
| 725 | args = args + ('-%s' % k, str(v)) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 726 | self.tk.call(args) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 727 | |
Guido van Rossum | 56c04b8 | 1998-04-06 03:10:03 +0000 | [diff] [blame] | 728 | def event_info(self, virtual=None): |
| 729 | return self.tk.splitlist( |
| 730 | self.tk.call('event', 'info', virtual)) |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 731 | |
Guido van Rossum | c296651 | 1998-04-10 19:16:10 +0000 | [diff] [blame] | 732 | # Image related commands |
| 733 | |
| 734 | def image_names(self): |
| 735 | return self.tk.call('image', 'names') |
| 736 | |
| 737 | def image_types(self): |
| 738 | return self.tk.call('image', 'types') |
| 739 | |
Guido van Rossum | 80f8be8 | 1997-12-02 19:51:39 +0000 | [diff] [blame] | 740 | |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 741 | class CallWrapper: |
| 742 | def __init__(self, func, subst, widget): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 743 | self.func = func |
| 744 | self.subst = subst |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 745 | self.widget = widget |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 746 | def __call__(self, *args): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 747 | try: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 748 | if self.subst: |
| 749 | args = apply(self.subst, args) |
| 750 | return apply(self.func, args) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 751 | except SystemExit, msg: |
| 752 | raise SystemExit, msg |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 753 | except: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 754 | self.widget._report_exception() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 755 | |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 756 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 757 | class Wm: |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 758 | def wm_aspect(self, |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 759 | minNumer=None, minDenom=None, |
| 760 | maxNumer=None, maxDenom=None): |
| 761 | return self._getints( |
| 762 | self.tk.call('wm', 'aspect', self._w, |
| 763 | minNumer, minDenom, |
| 764 | maxNumer, maxDenom)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 765 | aspect = wm_aspect |
| 766 | def wm_client(self, name=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 767 | return self.tk.call('wm', 'client', self._w, name) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 768 | client = wm_client |
| 769 | def wm_colormapwindows(self, *wlist): |
Fred Drake | 3c602d7 | 1996-09-27 14:06:54 +0000 | [diff] [blame] | 770 | args = ('wm', 'colormapwindows', self._w) + _flatten(wlist) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 771 | return map(self._nametowidget, self.tk.call(args)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 772 | colormapwindows = wm_colormapwindows |
| 773 | def wm_command(self, value=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 774 | return self.tk.call('wm', 'command', self._w, value) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 775 | command = wm_command |
| 776 | def wm_deiconify(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 777 | return self.tk.call('wm', 'deiconify', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 778 | deiconify = wm_deiconify |
| 779 | def wm_focusmodel(self, model=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 780 | return self.tk.call('wm', 'focusmodel', self._w, model) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 781 | focusmodel = wm_focusmodel |
| 782 | def wm_frame(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 783 | return self.tk.call('wm', 'frame', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 784 | frame = wm_frame |
| 785 | def wm_geometry(self, newGeometry=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 786 | return self.tk.call('wm', 'geometry', self._w, newGeometry) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 787 | geometry = wm_geometry |
| 788 | def wm_grid(self, |
Guido van Rossum | 21df8f5 | 1998-02-24 23:26:18 +0000 | [diff] [blame] | 789 | baseWidth=None, baseHeight=None, |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 790 | widthInc=None, heightInc=None): |
| 791 | return self._getints(self.tk.call( |
| 792 | 'wm', 'grid', self._w, |
Guido van Rossum | 4d9d3f1 | 1997-12-27 15:14:43 +0000 | [diff] [blame] | 793 | baseWidth, baseHeight, widthInc, heightInc)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 794 | grid = wm_grid |
| 795 | def wm_group(self, pathName=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 796 | return self.tk.call('wm', 'group', self._w, pathName) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 797 | group = wm_group |
| 798 | def wm_iconbitmap(self, bitmap=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 799 | return self.tk.call('wm', 'iconbitmap', self._w, bitmap) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 800 | iconbitmap = wm_iconbitmap |
| 801 | def wm_iconify(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 802 | return self.tk.call('wm', 'iconify', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 803 | iconify = wm_iconify |
| 804 | def wm_iconmask(self, bitmap=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 805 | return self.tk.call('wm', 'iconmask', self._w, bitmap) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 806 | iconmask = wm_iconmask |
| 807 | def wm_iconname(self, newName=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 808 | return self.tk.call('wm', 'iconname', self._w, newName) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 809 | iconname = wm_iconname |
| 810 | def wm_iconposition(self, x=None, y=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 811 | return self._getints(self.tk.call( |
| 812 | 'wm', 'iconposition', self._w, x, y)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 813 | iconposition = wm_iconposition |
| 814 | def wm_iconwindow(self, pathName=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 815 | return self.tk.call('wm', 'iconwindow', self._w, pathName) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 816 | iconwindow = wm_iconwindow |
| 817 | def wm_maxsize(self, width=None, height=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 818 | return self._getints(self.tk.call( |
| 819 | 'wm', 'maxsize', self._w, width, height)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 820 | maxsize = wm_maxsize |
| 821 | def wm_minsize(self, width=None, height=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 822 | return self._getints(self.tk.call( |
| 823 | 'wm', 'minsize', self._w, width, height)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 824 | minsize = wm_minsize |
| 825 | def wm_overrideredirect(self, boolean=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 826 | return self._getboolean(self.tk.call( |
| 827 | 'wm', 'overrideredirect', self._w, boolean)) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 828 | overrideredirect = wm_overrideredirect |
| 829 | def wm_positionfrom(self, who=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 830 | return self.tk.call('wm', 'positionfrom', self._w, who) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 831 | positionfrom = wm_positionfrom |
| 832 | def wm_protocol(self, name=None, func=None): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 833 | if callable(func): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 834 | command = self._register(func) |
| 835 | else: |
| 836 | command = func |
| 837 | return self.tk.call( |
| 838 | 'wm', 'protocol', self._w, name, command) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 839 | protocol = wm_protocol |
| 840 | def wm_resizable(self, width=None, height=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 841 | return self.tk.call('wm', 'resizable', self._w, width, height) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 842 | resizable = wm_resizable |
| 843 | def wm_sizefrom(self, who=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 844 | return self.tk.call('wm', 'sizefrom', self._w, who) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 845 | sizefrom = wm_sizefrom |
| 846 | def wm_state(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 847 | return self.tk.call('wm', 'state', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 848 | state = wm_state |
| 849 | def wm_title(self, string=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 850 | return self.tk.call('wm', 'title', self._w, string) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 851 | title = wm_title |
| 852 | def wm_transient(self, master=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 853 | return self.tk.call('wm', 'transient', self._w, master) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 854 | transient = wm_transient |
| 855 | def wm_withdraw(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 856 | return self.tk.call('wm', 'withdraw', self._w) |
Guido van Rossum | e365a59 | 1998-05-01 19:48:20 +0000 | [diff] [blame] | 857 | withdraw = wm_withdraw |
| 858 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 859 | |
| 860 | class Tk(Misc, Wm): |
| 861 | _w = '.' |
| 862 | def __init__(self, screenName=None, baseName=None, className='Tk'): |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 863 | global _default_root |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 864 | self.master = None |
| 865 | self.children = {} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 866 | if baseName is None: |
| 867 | import sys, os |
| 868 | baseName = os.path.basename(sys.argv[0]) |
Fred Drake | cab3c3b | 1996-10-06 17:55:20 +0000 | [diff] [blame] | 869 | baseName, ext = os.path.splitext(baseName) |
| 870 | if ext not in ('.py', 'pyc'): baseName = baseName + ext |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 871 | self.tk = _tkinter.create(screenName, baseName, className) |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 872 | if _MacOS: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 873 | # Disable event scanning except for Command-Period |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 874 | _MacOS.SchedParams(1, 0) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 875 | # Work around nasty MacTk bug |
Guido van Rossum | f0c891a | 1998-04-29 21:43:36 +0000 | [diff] [blame] | 876 | # XXX Is this one still needed? |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 877 | self.update() |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 878 | # Version sanity checks |
| 879 | tk_version = self.tk.getvar('tk_version') |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 880 | if tk_version != _tkinter.TK_VERSION: |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 881 | raise RuntimeError, \ |
| 882 | "tk.h version (%s) doesn't match libtk.a version (%s)" \ |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 883 | % (_tkinter.TK_VERSION, tk_version) |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 884 | tcl_version = self.tk.getvar('tcl_version') |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 885 | if tcl_version != _tkinter.TCL_VERSION: |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 886 | raise RuntimeError, \ |
| 887 | "tcl.h version (%s) doesn't match libtcl.a version (%s)" \ |
Guido van Rossum | 9580609 | 1997-02-15 18:33:24 +0000 | [diff] [blame] | 888 | % (_tkinter.TCL_VERSION, tcl_version) |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 889 | if TkVersion < 4.0: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 890 | raise RuntimeError, \ |
| 891 | "Tk 4.0 or higher is required; found Tk %s" \ |
| 892 | % str(TkVersion) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 893 | self.tk.createcommand('tkerror', _tkerror) |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 894 | self.tk.createcommand('exit', _exit) |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 895 | self.readprofile(baseName, className) |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 896 | if _support_default_root and not _default_root: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 897 | _default_root = self |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 898 | def destroy(self): |
| 899 | for c in self.children.values(): c.destroy() |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 900 | self.tk.call('destroy', self._w) |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 901 | Misc.destroy(self) |
Guido van Rossum | d6615ab | 1997-08-05 02:35:01 +0000 | [diff] [blame] | 902 | global _default_root |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 903 | if _support_default_root and _default_root is self: |
Guido van Rossum | d6615ab | 1997-08-05 02:35:01 +0000 | [diff] [blame] | 904 | _default_root = None |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 905 | def readprofile(self, baseName, className): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 906 | import os |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 907 | if os.environ.has_key('HOME'): home = os.environ['HOME'] |
| 908 | else: home = os.curdir |
| 909 | class_tcl = os.path.join(home, '.%s.tcl' % className) |
| 910 | class_py = os.path.join(home, '.%s.py' % className) |
| 911 | base_tcl = os.path.join(home, '.%s.tcl' % baseName) |
| 912 | base_py = os.path.join(home, '.%s.py' % baseName) |
| 913 | dir = {'self': self} |
| 914 | exec 'from Tkinter import *' in dir |
| 915 | if os.path.isfile(class_tcl): |
| 916 | print 'source', `class_tcl` |
| 917 | self.tk.call('source', class_tcl) |
| 918 | if os.path.isfile(class_py): |
| 919 | print 'execfile', `class_py` |
| 920 | execfile(class_py, dir) |
| 921 | if os.path.isfile(base_tcl): |
| 922 | print 'source', `base_tcl` |
| 923 | self.tk.call('source', base_tcl) |
| 924 | if os.path.isfile(base_py): |
| 925 | print 'execfile', `base_py` |
| 926 | execfile(base_py, dir) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 927 | def report_callback_exception(self, exc, val, tb): |
| 928 | import traceback |
| 929 | print "Exception in Tkinter callback" |
| 930 | traceback.print_exception(exc, val, tb) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 931 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 932 | # Ideally, the classes Pack, Place and Grid disappear, the |
| 933 | # pack/place/grid methods are defined on the Widget class, and |
| 934 | # everybody uses w.pack_whatever(...) instead of Pack.whatever(w, |
| 935 | # ...), with pack(), place() and grid() being short for |
| 936 | # pack_configure(), place_configure() and grid_columnconfigure(), and |
| 937 | # forget() being short for pack_forget(). As a practical matter, I'm |
| 938 | # afraid that there is too much code out there that may be using the |
| 939 | # Pack, Place or Grid class, so I leave them intact -- but only as |
| 940 | # backwards compatibility features. Also note that those methods that |
| 941 | # take a master as argument (e.g. pack_propagate) have been moved to |
| 942 | # the Misc class (which now incorporates all methods common between |
| 943 | # toplevel and interior widgets). Again, for compatibility, these are |
| 944 | # copied into the Pack, Place or Grid class. |
| 945 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 946 | class Pack: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 947 | def pack_configure(self, cnf={}, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 948 | self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 949 | ('pack', 'configure', self._w) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 950 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 951 | pack = configure = config = pack_configure |
| 952 | def pack_forget(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 953 | self.tk.call('pack', 'forget', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 954 | forget = pack_forget |
| 955 | def pack_info(self): |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 956 | words = self.tk.splitlist( |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 957 | self.tk.call('pack', 'info', self._w)) |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 958 | dict = {} |
| 959 | for i in range(0, len(words), 2): |
| 960 | key = words[i][1:] |
| 961 | value = words[i+1] |
Guido van Rossum | a5f875f | 1996-05-16 17:50:07 +0000 | [diff] [blame] | 962 | if value[:1] == '.': |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 963 | value = self._nametowidget(value) |
| 964 | dict[key] = value |
| 965 | return dict |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 966 | info = pack_info |
| 967 | propagate = pack_propagate = Misc.pack_propagate |
| 968 | slaves = pack_slaves = Misc.pack_slaves |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 969 | |
| 970 | class Place: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 971 | def place_configure(self, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 972 | for k in ['in_']: |
| 973 | if kw.has_key(k): |
| 974 | kw[k[:-1]] = kw[k] |
| 975 | del kw[k] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 976 | self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 977 | ('place', 'configure', self._w) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 978 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 979 | place = configure = config = place_configure |
| 980 | def place_forget(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 981 | self.tk.call('place', 'forget', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 982 | forget = place_forget |
| 983 | def place_info(self): |
Guido van Rossum | 63e39ae | 1996-05-16 17:53:48 +0000 | [diff] [blame] | 984 | words = self.tk.splitlist( |
| 985 | self.tk.call('place', 'info', self._w)) |
| 986 | dict = {} |
| 987 | for i in range(0, len(words), 2): |
| 988 | key = words[i][1:] |
| 989 | value = words[i+1] |
| 990 | if value[:1] == '.': |
| 991 | value = self._nametowidget(value) |
| 992 | dict[key] = value |
| 993 | return dict |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 994 | info = place_info |
| 995 | slaves = place_slaves = Misc.place_slaves |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 996 | |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 997 | class Grid: |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 998 | # Thanks to Masazumi Yoshikawa (yosikawa@isi.edu) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 999 | def grid_configure(self, cnf={}, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1000 | self.tk.call( |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1001 | ('grid', 'configure', self._w) |
| 1002 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1003 | grid = configure = config = grid_configure |
| 1004 | bbox = grid_bbox = Misc.grid_bbox |
| 1005 | columnconfigure = grid_columnconfigure = Misc.grid_columnconfigure |
| 1006 | def grid_forget(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1007 | self.tk.call('grid', 'forget', self._w) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1008 | forget = grid_forget |
| 1009 | def grid_info(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1010 | words = self.tk.splitlist( |
| 1011 | self.tk.call('grid', 'info', self._w)) |
| 1012 | dict = {} |
| 1013 | for i in range(0, len(words), 2): |
| 1014 | key = words[i][1:] |
| 1015 | value = words[i+1] |
Guido van Rossum | a5f875f | 1996-05-16 17:50:07 +0000 | [diff] [blame] | 1016 | if value[:1] == '.': |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1017 | value = self._nametowidget(value) |
| 1018 | dict[key] = value |
| 1019 | return dict |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1020 | info = grid_info |
| 1021 | def grid_location(self, x, y): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1022 | return self._getints( |
| 1023 | self.tk.call( |
| 1024 | 'grid', 'location', self._w, x, y)) or None |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1025 | location = grid_location |
| 1026 | propagate = grid_propagate = Misc.grid_propagate |
| 1027 | rowconfigure = grid_rowconfigure = Misc.grid_rowconfigure |
| 1028 | size = grid_size = Misc.grid_size |
| 1029 | slaves = grid_slaves = Misc.grid_slaves |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1030 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1031 | class BaseWidget(Misc): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1032 | def _setup(self, master, cnf): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1033 | if _support_default_root: |
| 1034 | global _default_root |
| 1035 | if not master: |
| 1036 | if not _default_root: |
| 1037 | _default_root = Tk() |
| 1038 | master = _default_root |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1039 | if not _default_root: |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1040 | _default_root = master |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1041 | self.master = master |
| 1042 | self.tk = master.tk |
Fred Drake | c8296db | 1997-05-27 22:45:10 +0000 | [diff] [blame] | 1043 | name = None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1044 | if cnf.has_key('name'): |
| 1045 | name = cnf['name'] |
| 1046 | del cnf['name'] |
Fred Drake | c8296db | 1997-05-27 22:45:10 +0000 | [diff] [blame] | 1047 | if not name: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1048 | name = `id(self)` |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1049 | self._name = name |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1050 | if master._w=='.': |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1051 | self._w = '.' + name |
| 1052 | else: |
| 1053 | self._w = master._w + '.' + name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1054 | self.children = {} |
| 1055 | if self.master.children.has_key(self._name): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1056 | self.master.children[self._name].destroy() |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1057 | self.master.children[self._name] = self |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1058 | def __init__(self, master, widgetName, cnf={}, kw={}, extra=()): |
| 1059 | if kw: |
| 1060 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1061 | self.widgetName = widgetName |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1062 | BaseWidget._setup(self, master, cnf) |
Guido van Rossum | ad8b3ba | 1996-07-21 03:05:05 +0000 | [diff] [blame] | 1063 | classes = [] |
| 1064 | for k in cnf.keys(): |
| 1065 | if type(k) is ClassType: |
| 1066 | classes.append((k, cnf[k])) |
| 1067 | del cnf[k] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1068 | self.tk.call( |
| 1069 | (widgetName, self._w) + extra + self._options(cnf)) |
Guido van Rossum | ad8b3ba | 1996-07-21 03:05:05 +0000 | [diff] [blame] | 1070 | for k, v in classes: |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1071 | k.configure(self, v) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1072 | def destroy(self): |
| 1073 | for c in self.children.values(): c.destroy() |
Guido van Rossum | f023ab0 | 1994-08-30 12:13:44 +0000 | [diff] [blame] | 1074 | if self.master.children.has_key(self._name): |
| 1075 | del self.master.children[self._name] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1076 | self.tk.call('destroy', self._w) |
Guido van Rossum | 103cc6d | 1997-04-14 13:30:24 +0000 | [diff] [blame] | 1077 | Misc.destroy(self) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1078 | def _do(self, name, args=()): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1079 | # XXX Obsolete -- better use self.tk.call directly! |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1080 | return self.tk.call((self._w, name) + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1081 | |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1082 | class Widget(BaseWidget, Pack, Place, Grid): |
| 1083 | pass |
| 1084 | |
| 1085 | class Toplevel(BaseWidget, Wm): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1086 | def __init__(self, master=None, cnf={}, **kw): |
| 1087 | if kw: |
| 1088 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1089 | extra = () |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1090 | for wmkey in ['screen', 'class_', 'class', 'visual', |
| 1091 | 'colormap']: |
| 1092 | if cnf.has_key(wmkey): |
| 1093 | val = cnf[wmkey] |
| 1094 | # TBD: a hack needed because some keys |
| 1095 | # are not valid as keyword arguments |
| 1096 | if wmkey[-1] == '_': opt = '-'+wmkey[:-1] |
| 1097 | else: opt = '-'+wmkey |
| 1098 | extra = extra + (opt, val) |
| 1099 | del cnf[wmkey] |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1100 | BaseWidget.__init__(self, master, 'toplevel', cnf, {}, extra) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1101 | root = self._root() |
| 1102 | self.iconname(root.iconname()) |
| 1103 | self.title(root.title()) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1104 | |
| 1105 | class Button(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1106 | def __init__(self, master=None, cnf={}, **kw): |
| 1107 | Widget.__init__(self, master, 'button', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1108 | def tkButtonEnter(self, *dummy): |
| 1109 | self.tk.call('tkButtonEnter', self._w) |
| 1110 | def tkButtonLeave(self, *dummy): |
| 1111 | self.tk.call('tkButtonLeave', self._w) |
| 1112 | def tkButtonDown(self, *dummy): |
| 1113 | self.tk.call('tkButtonDown', self._w) |
| 1114 | def tkButtonUp(self, *dummy): |
| 1115 | self.tk.call('tkButtonUp', self._w) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 1116 | def tkButtonInvoke(self, *dummy): |
| 1117 | self.tk.call('tkButtonInvoke', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1118 | def flash(self): |
| 1119 | self.tk.call(self._w, 'flash') |
| 1120 | def invoke(self): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1121 | return self.tk.call(self._w, 'invoke') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1122 | |
| 1123 | # Indices: |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1124 | # XXX I don't like these -- take them away |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1125 | def AtEnd(): |
| 1126 | return 'end' |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 1127 | def AtInsert(*args): |
| 1128 | s = 'insert' |
| 1129 | for a in args: |
| 1130 | if a: s = s + (' ' + a) |
| 1131 | return s |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1132 | def AtSelFirst(): |
| 1133 | return 'sel.first' |
| 1134 | def AtSelLast(): |
| 1135 | return 'sel.last' |
| 1136 | def At(x, y=None): |
Guido van Rossum | 5e0c25b | 1994-07-12 09:04:41 +0000 | [diff] [blame] | 1137 | if y is None: |
| 1138 | return '@' + `x` |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1139 | else: |
Guido van Rossum | 5e0c25b | 1994-07-12 09:04:41 +0000 | [diff] [blame] | 1140 | return '@' + `x` + ',' + `y` |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1141 | |
| 1142 | class Canvas(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1143 | def __init__(self, master=None, cnf={}, **kw): |
| 1144 | Widget.__init__(self, master, 'canvas', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1145 | def addtag(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1146 | self.tk.call((self._w, 'addtag') + args) |
Guido van Rossum | 5c8c91b | 1996-08-22 23:18:09 +0000 | [diff] [blame] | 1147 | def addtag_above(self, newtag, tagOrId): |
| 1148 | self.addtag(newtag, 'above', tagOrId) |
| 1149 | def addtag_all(self, newtag): |
| 1150 | self.addtag(newtag, 'all') |
| 1151 | def addtag_below(self, newtag, tagOrId): |
| 1152 | self.addtag(newtag, 'below', tagOrId) |
| 1153 | def addtag_closest(self, newtag, x, y, halo=None, start=None): |
| 1154 | self.addtag(newtag, 'closest', x, y, halo, start) |
| 1155 | def addtag_enclosed(self, newtag, x1, y1, x2, y2): |
| 1156 | self.addtag(newtag, 'enclosed', x1, y1, x2, y2) |
| 1157 | def addtag_overlapping(self, newtag, x1, y1, x2, y2): |
| 1158 | self.addtag(newtag, 'overlapping', x1, y1, x2, y2) |
| 1159 | def addtag_withtag(self, newtag, tagOrId): |
| 1160 | self.addtag(newtag, 'withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1161 | def bbox(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1162 | return self._getints( |
| 1163 | self.tk.call((self._w, 'bbox') + args)) or None |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1164 | def tag_unbind(self, tagOrId, sequence, funcid=None): |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 1165 | self.tk.call(self._w, 'bind', tagOrId, sequence, '') |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1166 | if funcid: |
| 1167 | self.deletecommand(funcid) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1168 | def tag_bind(self, tagOrId, sequence=None, func=None, add=None): |
Guido van Rossum | 421bb0e | 1996-07-21 02:19:32 +0000 | [diff] [blame] | 1169 | return self._bind((self._w, 'bind', tagOrId), |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1170 | sequence, func, add) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1171 | def canvasx(self, screenx, gridspacing=None): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1172 | return getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1173 | self._w, 'canvasx', screenx, gridspacing)) |
| 1174 | def canvasy(self, screeny, gridspacing=None): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1175 | return getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1176 | self._w, 'canvasy', screeny, gridspacing)) |
| 1177 | def coords(self, *args): |
Guido van Rossum | 0001a11 | 1998-02-19 21:20:30 +0000 | [diff] [blame] | 1178 | # XXX Should use _flatten on args |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1179 | return map(getdouble, |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1180 | self.tk.splitlist( |
| 1181 | self.tk.call((self._w, 'coords') + args))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1182 | def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={}) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1183 | args = _flatten(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1184 | cnf = args[-1] |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1185 | if type(cnf) in (DictionaryType, TupleType): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1186 | args = args[:-1] |
| 1187 | else: |
| 1188 | cnf = {} |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1189 | return getint(apply( |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1190 | self.tk.call, |
| 1191 | (self._w, 'create', itemType) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1192 | + args + self._options(cnf, kw))) |
| 1193 | def create_arc(self, *args, **kw): |
| 1194 | return self._create('arc', args, kw) |
| 1195 | def create_bitmap(self, *args, **kw): |
| 1196 | return self._create('bitmap', args, kw) |
| 1197 | def create_image(self, *args, **kw): |
| 1198 | return self._create('image', args, kw) |
| 1199 | def create_line(self, *args, **kw): |
| 1200 | return self._create('line', args, kw) |
| 1201 | def create_oval(self, *args, **kw): |
| 1202 | return self._create('oval', args, kw) |
| 1203 | def create_polygon(self, *args, **kw): |
| 1204 | return self._create('polygon', args, kw) |
| 1205 | def create_rectangle(self, *args, **kw): |
| 1206 | return self._create('rectangle', args, kw) |
| 1207 | def create_text(self, *args, **kw): |
| 1208 | return self._create('text', args, kw) |
| 1209 | def create_window(self, *args, **kw): |
| 1210 | return self._create('window', args, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1211 | def dchars(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1212 | self.tk.call((self._w, 'dchars') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1213 | def delete(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1214 | self.tk.call((self._w, 'delete') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1215 | def dtag(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1216 | self.tk.call((self._w, 'dtag') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1217 | def find(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1218 | return self._getints( |
| 1219 | self.tk.call((self._w, 'find') + args)) or () |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1220 | def find_above(self, tagOrId): |
| 1221 | return self.find('above', tagOrId) |
| 1222 | def find_all(self): |
| 1223 | return self.find('all') |
| 1224 | def find_below(self, tagOrId): |
| 1225 | return self.find('below', tagOrId) |
| 1226 | def find_closest(self, x, y, halo=None, start=None): |
| 1227 | return self.find('closest', x, y, halo, start) |
| 1228 | def find_enclosed(self, x1, y1, x2, y2): |
| 1229 | return self.find('enclosed', x1, y1, x2, y2) |
| 1230 | def find_overlapping(self, x1, y1, x2, y2): |
| 1231 | return self.find('overlapping', x1, y1, x2, y2) |
| 1232 | def find_withtag(self, tagOrId): |
| 1233 | return self.find('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1234 | def focus(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1235 | return self.tk.call((self._w, 'focus') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1236 | def gettags(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1237 | return self.tk.splitlist( |
| 1238 | self.tk.call((self._w, 'gettags') + args)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1239 | def icursor(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1240 | self.tk.call((self._w, 'icursor') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1241 | def index(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1242 | return getint(self.tk.call((self._w, 'index') + args)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1243 | def insert(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1244 | self.tk.call((self._w, 'insert') + args) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1245 | def itemcget(self, tagOrId, option): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1246 | return self.tk.call( |
| 1247 | (self._w, 'itemcget') + (tagOrId, '-'+option)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1248 | def itemconfigure(self, tagOrId, cnf=None, **kw): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1249 | if cnf is None and not kw: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1250 | cnf = {} |
| 1251 | for x in self.tk.split( |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1252 | self.tk.call(self._w, |
| 1253 | 'itemconfigure', tagOrId)): |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1254 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1255 | return cnf |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1256 | if type(cnf) == StringType and not kw: |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1257 | x = self.tk.split(self.tk.call( |
| 1258 | self._w, 'itemconfigure', tagOrId, '-'+cnf)) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1259 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1260 | self.tk.call((self._w, 'itemconfigure', tagOrId) + |
| 1261 | self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1262 | itemconfig = itemconfigure |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1263 | def lower(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1264 | self.tk.call((self._w, 'lower') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1265 | def move(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1266 | self.tk.call((self._w, 'move') + args) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1267 | def postscript(self, cnf={}, **kw): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1268 | return self.tk.call((self._w, 'postscript') + |
| 1269 | self._options(cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1270 | def tkraise(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1271 | self.tk.call((self._w, 'raise') + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 1272 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1273 | def scale(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1274 | self.tk.call((self._w, 'scale') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1275 | def scan_mark(self, x, y): |
| 1276 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1277 | def scan_dragto(self, x, y): |
| 1278 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 1279 | def select_adjust(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1280 | self.tk.call(self._w, 'select', 'adjust', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1281 | def select_clear(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1282 | self.tk.call(self._w, 'select', 'clear') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1283 | def select_from(self, tagOrId, index): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1284 | self.tk.call(self._w, 'select', 'from', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1285 | def select_item(self): |
| 1286 | self.tk.call(self._w, 'select', 'item') |
| 1287 | def select_to(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1288 | self.tk.call(self._w, 'select', 'to', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1289 | def type(self, tagOrId): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1290 | return self.tk.call(self._w, 'type', tagOrId) or None |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1291 | def xview(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1292 | if not args: |
| 1293 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1294 | self.tk.call((self._w, 'xview') + args) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1295 | def yview(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1296 | if not args: |
| 1297 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1298 | self.tk.call((self._w, 'yview') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1299 | |
| 1300 | class Checkbutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1301 | def __init__(self, master=None, cnf={}, **kw): |
| 1302 | Widget.__init__(self, master, 'checkbutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1303 | def deselect(self): |
| 1304 | self.tk.call(self._w, 'deselect') |
| 1305 | def flash(self): |
| 1306 | self.tk.call(self._w, 'flash') |
| 1307 | def invoke(self): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1308 | return self.tk.call(self._w, 'invoke') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1309 | def select(self): |
| 1310 | self.tk.call(self._w, 'select') |
| 1311 | def toggle(self): |
| 1312 | self.tk.call(self._w, 'toggle') |
| 1313 | |
| 1314 | class Entry(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1315 | def __init__(self, master=None, cnf={}, **kw): |
| 1316 | Widget.__init__(self, master, 'entry', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1317 | def delete(self, first, last=None): |
| 1318 | self.tk.call(self._w, 'delete', first, last) |
| 1319 | def get(self): |
| 1320 | return self.tk.call(self._w, 'get') |
| 1321 | def icursor(self, index): |
| 1322 | self.tk.call(self._w, 'icursor', index) |
| 1323 | def index(self, index): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1324 | return getint(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1325 | self._w, 'index', index)) |
| 1326 | def insert(self, index, string): |
| 1327 | self.tk.call(self._w, 'insert', index, string) |
| 1328 | def scan_mark(self, x): |
| 1329 | self.tk.call(self._w, 'scan', 'mark', x) |
| 1330 | def scan_dragto(self, x): |
| 1331 | self.tk.call(self._w, 'scan', 'dragto', x) |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1332 | def selection_adjust(self, index): |
| 1333 | self.tk.call(self._w, 'selection', 'adjust', index) |
| 1334 | select_adjust = selection_adjust |
| 1335 | def selection_clear(self): |
| 1336 | self.tk.call(self._w, 'selection', 'clear') |
| 1337 | select_clear = selection_clear |
| 1338 | def selection_from(self, index): |
Guido van Rossum | 42b78e6 | 1996-09-06 14:20:23 +0000 | [diff] [blame] | 1339 | self.tk.call(self._w, 'selection', 'from', index) |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1340 | select_from = selection_from |
| 1341 | def selection_present(self): |
Guido van Rossum | 1d59df2 | 1995-08-11 14:21:06 +0000 | [diff] [blame] | 1342 | return self.tk.getboolean( |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1343 | self.tk.call(self._w, 'selection', 'present')) |
| 1344 | select_present = selection_present |
| 1345 | def selection_range(self, start, end): |
| 1346 | self.tk.call(self._w, 'selection', 'range', start, end) |
| 1347 | select_range = selection_range |
| 1348 | def selection_to(self, index): |
| 1349 | self.tk.call(self._w, 'selection', 'to', index) |
| 1350 | select_to = selection_to |
| 1351 | def xview(self, index): |
| 1352 | self.tk.call(self._w, 'xview', index) |
| 1353 | def xview_moveto(self, fraction): |
| 1354 | self.tk.call(self._w, 'xview', 'moveto', fraction) |
| 1355 | def xview_scroll(self, number, what): |
| 1356 | self.tk.call(self._w, 'xview', 'scroll', number, what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1357 | |
| 1358 | class Frame(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1359 | def __init__(self, master=None, cnf={}, **kw): |
| 1360 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1361 | extra = () |
Fred Drake | 41dc09d | 1997-01-10 15:13:12 +0000 | [diff] [blame] | 1362 | if cnf.has_key('class_'): |
| 1363 | extra = ('-class', cnf['class_']) |
| 1364 | del cnf['class_'] |
| 1365 | elif cnf.has_key('class'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1366 | extra = ('-class', cnf['class']) |
| 1367 | del cnf['class'] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1368 | Widget.__init__(self, master, 'frame', cnf, {}, extra) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1369 | |
| 1370 | class Label(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1371 | def __init__(self, master=None, cnf={}, **kw): |
| 1372 | Widget.__init__(self, master, 'label', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1373 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1374 | class Listbox(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1375 | def __init__(self, master=None, cnf={}, **kw): |
| 1376 | Widget.__init__(self, master, 'listbox', cnf, kw) |
Guido van Rossum | 46f92d2 | 1995-10-11 17:41:00 +0000 | [diff] [blame] | 1377 | def activate(self, index): |
| 1378 | self.tk.call(self._w, 'activate', index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1379 | def bbox(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1380 | return self._getints( |
| 1381 | self.tk.call((self._w, 'bbox') + args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1382 | def curselection(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1383 | # XXX Ought to apply self._getints()... |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1384 | return self.tk.splitlist(self.tk.call( |
| 1385 | self._w, 'curselection')) |
| 1386 | def delete(self, first, last=None): |
| 1387 | self.tk.call(self._w, 'delete', first, last) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1388 | def get(self, first, last=None): |
| 1389 | if last: |
| 1390 | return self.tk.splitlist(self.tk.call( |
| 1391 | self._w, 'get', first, last)) |
| 1392 | else: |
| 1393 | return self.tk.call(self._w, 'get', first) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1394 | def insert(self, index, *elements): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1395 | self.tk.call((self._w, 'insert', index) + elements) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1396 | def nearest(self, y): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1397 | return getint(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1398 | self._w, 'nearest', y)) |
| 1399 | def scan_mark(self, x, y): |
| 1400 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1401 | def scan_dragto(self, x, y): |
| 1402 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1403 | def see(self, index): |
| 1404 | self.tk.call(self._w, 'see', index) |
| 1405 | def index(self, index): |
| 1406 | i = self.tk.call(self._w, 'index', index) |
| 1407 | if i == 'none': return None |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1408 | return getint(i) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1409 | def select_anchor(self, index): |
| 1410 | self.tk.call(self._w, 'selection', 'anchor', index) |
Guido van Rossum | 764d6c7 | 1997-02-14 16:21:16 +0000 | [diff] [blame] | 1411 | selection_anchor = select_anchor |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1412 | def select_clear(self, first, last=None): |
| 1413 | self.tk.call(self._w, |
| 1414 | 'selection', 'clear', first, last) |
Guido van Rossum | 764d6c7 | 1997-02-14 16:21:16 +0000 | [diff] [blame] | 1415 | selection_clear = select_clear |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1416 | def select_includes(self, index): |
| 1417 | return self.tk.getboolean(self.tk.call( |
| 1418 | self._w, 'selection', 'includes', index)) |
Guido van Rossum | 764d6c7 | 1997-02-14 16:21:16 +0000 | [diff] [blame] | 1419 | selection_includes = select_includes |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1420 | def select_set(self, first, last=None): |
| 1421 | self.tk.call(self._w, 'selection', 'set', first, last) |
Guido van Rossum | 764d6c7 | 1997-02-14 16:21:16 +0000 | [diff] [blame] | 1422 | selection_set = select_set |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1423 | def size(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1424 | return getint(self.tk.call(self._w, 'size')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1425 | def xview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1426 | if not what: |
| 1427 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1428 | self.tk.call((self._w, 'xview') + what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1429 | def yview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1430 | if not what: |
| 1431 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1432 | self.tk.call((self._w, 'yview') + what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1433 | |
| 1434 | class Menu(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1435 | def __init__(self, master=None, cnf={}, **kw): |
| 1436 | Widget.__init__(self, master, 'menu', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1437 | def tk_bindForTraversal(self): |
Guido van Rossum | 688bbfc | 1996-09-10 12:39:26 +0000 | [diff] [blame] | 1438 | pass # obsolete since Tk 4.0 |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1439 | def tk_mbPost(self): |
| 1440 | self.tk.call('tk_mbPost', self._w) |
| 1441 | def tk_mbUnpost(self): |
| 1442 | self.tk.call('tk_mbUnpost') |
| 1443 | def tk_traverseToMenu(self, char): |
| 1444 | self.tk.call('tk_traverseToMenu', self._w, char) |
| 1445 | def tk_traverseWithinMenu(self, char): |
| 1446 | self.tk.call('tk_traverseWithinMenu', self._w, char) |
| 1447 | def tk_getMenuButtons(self): |
| 1448 | return self.tk.call('tk_getMenuButtons', self._w) |
| 1449 | def tk_nextMenu(self, count): |
| 1450 | self.tk.call('tk_nextMenu', count) |
| 1451 | def tk_nextMenuEntry(self, count): |
| 1452 | self.tk.call('tk_nextMenuEntry', count) |
| 1453 | def tk_invokeMenu(self): |
| 1454 | self.tk.call('tk_invokeMenu', self._w) |
| 1455 | def tk_firstMenu(self): |
| 1456 | self.tk.call('tk_firstMenu', self._w) |
| 1457 | def tk_mbButtonDown(self): |
| 1458 | self.tk.call('tk_mbButtonDown', self._w) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1459 | def tk_popup(self, x, y, entry=""): |
| 1460 | self.tk.call('tk_popup', self._w, x, y, entry) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1461 | def activate(self, index): |
| 1462 | self.tk.call(self._w, 'activate', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1463 | def add(self, itemType, cnf={}, **kw): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1464 | self.tk.call((self._w, 'add', itemType) + |
| 1465 | self._options(cnf, kw)) |
Guido van Rossum | a1db48b | 1995-10-09 22:37:28 +0000 | [diff] [blame] | 1466 | def add_cascade(self, cnf={}, **kw): |
| 1467 | self.add('cascade', cnf or kw) |
| 1468 | def add_checkbutton(self, cnf={}, **kw): |
| 1469 | self.add('checkbutton', cnf or kw) |
| 1470 | def add_command(self, cnf={}, **kw): |
| 1471 | self.add('command', cnf or kw) |
| 1472 | def add_radiobutton(self, cnf={}, **kw): |
| 1473 | self.add('radiobutton', cnf or kw) |
| 1474 | def add_separator(self, cnf={}, **kw): |
| 1475 | self.add('separator', cnf or kw) |
Guido van Rossum | 2caac73 | 1996-09-05 16:46:31 +0000 | [diff] [blame] | 1476 | def insert(self, index, itemType, cnf={}, **kw): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1477 | self.tk.call((self._w, 'insert', index, itemType) + |
| 1478 | self._options(cnf, kw)) |
Guido van Rossum | 2caac73 | 1996-09-05 16:46:31 +0000 | [diff] [blame] | 1479 | def insert_cascade(self, index, cnf={}, **kw): |
| 1480 | self.insert(index, 'cascade', cnf or kw) |
| 1481 | def insert_checkbutton(self, index, cnf={}, **kw): |
| 1482 | self.insert(index, 'checkbutton', cnf or kw) |
| 1483 | def insert_command(self, index, cnf={}, **kw): |
| 1484 | self.insert(index, 'command', cnf or kw) |
| 1485 | def insert_radiobutton(self, index, cnf={}, **kw): |
| 1486 | self.insert(index, 'radiobutton', cnf or kw) |
| 1487 | def insert_separator(self, index, cnf={}, **kw): |
| 1488 | self.insert(index, 'separator', cnf or kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1489 | def delete(self, index1, index2=None): |
| 1490 | self.tk.call(self._w, 'delete', index1, index2) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1491 | def entrycget(self, index, option): |
Guido van Rossum | 1cd6a45 | 1997-12-30 04:07:19 +0000 | [diff] [blame] | 1492 | return self.tk.call(self._w, 'entrycget', index, '-' + option) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1493 | def entryconfigure(self, index, cnf=None, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1494 | if cnf is None and not kw: |
| 1495 | cnf = {} |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1496 | for x in self.tk.split(self.tk.call( |
| 1497 | (self._w, 'entryconfigure', index))): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1498 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1499 | return cnf |
| 1500 | if type(cnf) == StringType and not kw: |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1501 | x = self.tk.split(self.tk.call( |
| 1502 | (self._w, 'entryconfigure', index, '-'+cnf))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1503 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1504 | self.tk.call((self._w, 'entryconfigure', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1505 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1506 | entryconfig = entryconfigure |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1507 | def index(self, index): |
Guido van Rossum | 535cf0c | 1994-06-27 07:55:59 +0000 | [diff] [blame] | 1508 | i = self.tk.call(self._w, 'index', index) |
| 1509 | if i == 'none': return None |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1510 | return getint(i) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1511 | def invoke(self, index): |
| 1512 | return self.tk.call(self._w, 'invoke', index) |
| 1513 | def post(self, x, y): |
| 1514 | self.tk.call(self._w, 'post', x, y) |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1515 | def type(self, index): |
| 1516 | return self.tk.call(self._w, 'type', index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1517 | def unpost(self): |
| 1518 | self.tk.call(self._w, 'unpost') |
| 1519 | def yposition(self, index): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1520 | return getint(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1521 | self._w, 'yposition', index)) |
| 1522 | |
| 1523 | class Menubutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1524 | def __init__(self, master=None, cnf={}, **kw): |
| 1525 | Widget.__init__(self, master, 'menubutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1526 | |
| 1527 | class Message(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1528 | def __init__(self, master=None, cnf={}, **kw): |
| 1529 | Widget.__init__(self, master, 'message', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1530 | |
| 1531 | class Radiobutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1532 | def __init__(self, master=None, cnf={}, **kw): |
| 1533 | Widget.__init__(self, master, 'radiobutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1534 | def deselect(self): |
| 1535 | self.tk.call(self._w, 'deselect') |
| 1536 | def flash(self): |
| 1537 | self.tk.call(self._w, 'flash') |
| 1538 | def invoke(self): |
Guido van Rossum | 9fd41e3 | 1997-12-29 19:59:33 +0000 | [diff] [blame] | 1539 | return self.tk.call(self._w, 'invoke') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1540 | def select(self): |
| 1541 | self.tk.call(self._w, 'select') |
| 1542 | |
| 1543 | class Scale(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1544 | def __init__(self, master=None, cnf={}, **kw): |
| 1545 | Widget.__init__(self, master, 'scale', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1546 | def get(self): |
Guido van Rossum | 1495747 | 1996-10-23 14:16:28 +0000 | [diff] [blame] | 1547 | value = self.tk.call(self._w, 'get') |
| 1548 | try: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1549 | return getint(value) |
Guido van Rossum | 1495747 | 1996-10-23 14:16:28 +0000 | [diff] [blame] | 1550 | except TclError: |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1551 | return getdouble(value) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1552 | def set(self, value): |
| 1553 | self.tk.call(self._w, 'set', value) |
| 1554 | |
| 1555 | class Scrollbar(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1556 | def __init__(self, master=None, cnf={}, **kw): |
| 1557 | Widget.__init__(self, master, 'scrollbar', cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1558 | def activate(self, index): |
| 1559 | self.tk.call(self._w, 'activate', index) |
| 1560 | def delta(self, deltax, deltay): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1561 | return getdouble( |
| 1562 | self.tk.call(self._w, 'delta', deltax, deltay)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1563 | def fraction(self, x, y): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1564 | return getdouble(self.tk.call(self._w, 'fraction', x, y)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1565 | def identify(self, x, y): |
| 1566 | return self.tk.call(self._w, 'identify', x, y) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1567 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1568 | return self._getdoubles(self.tk.call(self._w, 'get')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1569 | def set(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1570 | self.tk.call((self._w, 'set') + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1571 | |
| 1572 | class Text(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1573 | def __init__(self, master=None, cnf={}, **kw): |
| 1574 | Widget.__init__(self, master, 'text', cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1575 | def bbox(self, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1576 | return self._getints( |
| 1577 | self.tk.call((self._w, 'bbox') + args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1578 | def tk_textSelectTo(self, index): |
| 1579 | self.tk.call('tk_textSelectTo', self._w, index) |
| 1580 | def tk_textBackspace(self): |
| 1581 | self.tk.call('tk_textBackspace', self._w) |
| 1582 | def tk_textIndexCloser(self, a, b, c): |
| 1583 | self.tk.call('tk_textIndexCloser', self._w, a, b, c) |
| 1584 | def tk_textResetAnchor(self, index): |
| 1585 | self.tk.call('tk_textResetAnchor', self._w, index) |
| 1586 | def compare(self, index1, op, index2): |
| 1587 | return self.tk.getboolean(self.tk.call( |
| 1588 | self._w, 'compare', index1, op, index2)) |
| 1589 | def debug(self, boolean=None): |
| 1590 | return self.tk.getboolean(self.tk.call( |
| 1591 | self._w, 'debug', boolean)) |
| 1592 | def delete(self, index1, index2=None): |
| 1593 | self.tk.call(self._w, 'delete', index1, index2) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1594 | def dlineinfo(self, index): |
| 1595 | return self._getints(self.tk.call(self._w, 'dlineinfo', index)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1596 | def get(self, index1, index2=None): |
| 1597 | return self.tk.call(self._w, 'get', index1, index2) |
| 1598 | def index(self, index): |
| 1599 | return self.tk.call(self._w, 'index', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1600 | def insert(self, index, chars, *args): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1601 | self.tk.call((self._w, 'insert', index, chars) + args) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1602 | def mark_gravity(self, markName, direction=None): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1603 | return self.tk.call( |
| 1604 | (self._w, 'mark', 'gravity', markName, direction)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1605 | def mark_names(self): |
| 1606 | return self.tk.splitlist(self.tk.call( |
| 1607 | self._w, 'mark', 'names')) |
| 1608 | def mark_set(self, markName, index): |
| 1609 | self.tk.call(self._w, 'mark', 'set', markName, index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1610 | def mark_unset(self, *markNames): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1611 | self.tk.call((self._w, 'mark', 'unset') + markNames) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1612 | def scan_mark(self, x, y): |
| 1613 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1614 | def scan_dragto(self, x, y): |
| 1615 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1616 | def search(self, pattern, index, stopindex=None, |
| 1617 | forwards=None, backwards=None, exact=None, |
| 1618 | regexp=None, nocase=None, count=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1619 | args = [self._w, 'search'] |
| 1620 | if forwards: args.append('-forwards') |
| 1621 | if backwards: args.append('-backwards') |
| 1622 | if exact: args.append('-exact') |
| 1623 | if regexp: args.append('-regexp') |
| 1624 | if nocase: args.append('-nocase') |
| 1625 | if count: args.append('-count'); args.append(count) |
| 1626 | if pattern[0] == '-': args.append('--') |
| 1627 | args.append(pattern) |
| 1628 | args.append(index) |
| 1629 | if stopindex: args.append(stopindex) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1630 | return self.tk.call(tuple(args)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1631 | def see(self, index): |
| 1632 | self.tk.call(self._w, 'see', index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1633 | def tag_add(self, tagName, index1, index2=None): |
| 1634 | self.tk.call( |
| 1635 | self._w, 'tag', 'add', tagName, index1, index2) |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1636 | def tag_unbind(self, tagName, sequence, funcid=None): |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 1637 | self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '') |
Guido van Rossum | 117a5a8 | 1998-03-27 21:26:51 +0000 | [diff] [blame] | 1638 | if funcid: |
| 1639 | self.deletecommand(funcid) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1640 | def tag_bind(self, tagName, sequence, func, add=None): |
| 1641 | return self._bind((self._w, 'tag', 'bind', tagName), |
| 1642 | sequence, func, add) |
| 1643 | def tag_cget(self, tagName, option): |
Guido van Rossum | 73eba25 | 1996-11-11 19:10:58 +0000 | [diff] [blame] | 1644 | if option[:1] != '-': |
| 1645 | option = '-' + option |
| 1646 | if option[-1:] == '_': |
| 1647 | option = option[:-1] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1648 | return self.tk.call(self._w, 'tag', 'cget', tagName, option) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1649 | def tag_configure(self, tagName, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1650 | if type(cnf) == StringType: |
| 1651 | x = self.tk.split(self.tk.call( |
| 1652 | self._w, 'tag', 'configure', tagName, '-'+cnf)) |
| 1653 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1654 | self.tk.call( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1655 | (self._w, 'tag', 'configure', tagName) |
| 1656 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1657 | tag_config = tag_configure |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1658 | def tag_delete(self, *tagNames): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1659 | self.tk.call((self._w, 'tag', 'delete') + tagNames) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1660 | def tag_lower(self, tagName, belowThis=None): |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 1661 | self.tk.call(self._w, 'tag', 'lower', tagName, belowThis) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1662 | def tag_names(self, index=None): |
| 1663 | return self.tk.splitlist( |
| 1664 | self.tk.call(self._w, 'tag', 'names', index)) |
| 1665 | def tag_nextrange(self, tagName, index1, index2=None): |
| 1666 | return self.tk.splitlist(self.tk.call( |
Guido van Rossum | 903abee | 1995-03-20 15:09:13 +0000 | [diff] [blame] | 1667 | self._w, 'tag', 'nextrange', tagName, index1, index2)) |
Guido van Rossum | f0413d4 | 1997-12-15 17:31:52 +0000 | [diff] [blame] | 1668 | def tag_prevrange(self, tagName, index1, index2=None): |
| 1669 | return self.tk.splitlist(self.tk.call( |
| 1670 | self._w, 'tag', 'prevrange', tagName, index1, index2)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1671 | def tag_raise(self, tagName, aboveThis=None): |
| 1672 | self.tk.call( |
| 1673 | self._w, 'tag', 'raise', tagName, aboveThis) |
| 1674 | def tag_ranges(self, tagName): |
| 1675 | return self.tk.splitlist(self.tk.call( |
| 1676 | self._w, 'tag', 'ranges', tagName)) |
| 1677 | def tag_remove(self, tagName, index1, index2=None): |
| 1678 | self.tk.call( |
Guido van Rossum | 5113569 | 1994-07-06 21:16:58 +0000 | [diff] [blame] | 1679 | self._w, 'tag', 'remove', tagName, index1, index2) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1680 | def window_cget(self, index, option): |
Guido van Rossum | 7814ea6 | 1997-12-11 17:08:52 +0000 | [diff] [blame] | 1681 | if option[:1] != '-': |
| 1682 | option = '-' + option |
| 1683 | if option[-1:] == '_': |
| 1684 | option = option[:-1] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1685 | return self.tk.call(self._w, 'window', 'cget', index, option) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1686 | def window_configure(self, index, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1687 | if type(cnf) == StringType: |
| 1688 | x = self.tk.split(self.tk.call( |
| 1689 | self._w, 'window', 'configure', |
| 1690 | index, '-'+cnf)) |
| 1691 | return (x[0][1:],) + x[1:] |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1692 | self.tk.call( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1693 | (self._w, 'window', 'configure', index) |
| 1694 | + self._options(cnf, kw)) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1695 | window_config = window_configure |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1696 | def window_create(self, index, cnf={}, **kw): |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1697 | self.tk.call( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1698 | (self._w, 'window', 'create', index) |
| 1699 | + self._options(cnf, kw)) |
| 1700 | def window_names(self): |
| 1701 | return self.tk.splitlist( |
| 1702 | self.tk.call(self._w, 'window', 'names')) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1703 | def xview(self, *what): |
| 1704 | if not what: |
| 1705 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1706 | self.tk.call((self._w, 'xview') + what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1707 | def yview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1708 | if not what: |
| 1709 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1710 | self.tk.call((self._w, 'yview') + what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1711 | def yview_pickplace(self, *what): |
Guido van Rossum | 0bd5433 | 1998-05-19 21:18:13 +0000 | [diff] [blame^] | 1712 | self.tk.call((self._w, 'yview', '-pickplace') + what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1713 | |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1714 | class _setit: |
| 1715 | def __init__(self, var, value): |
| 1716 | self.__value = value |
| 1717 | self.__var = var |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1718 | def __call__(self, *args): |
Fred Drake | 0c37369 | 1996-10-21 17:09:31 +0000 | [diff] [blame] | 1719 | self.__var.set(self.__value) |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1720 | |
| 1721 | class OptionMenu(Menubutton): |
Guido van Rossum | bf4d8f9 | 1995-09-01 20:35:37 +0000 | [diff] [blame] | 1722 | def __init__(self, master, variable, value, *values): |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1723 | kw = {"borderwidth": 2, "textvariable": variable, |
| 1724 | "indicatoron": 1, "relief": RAISED, "anchor": "c", |
| 1725 | "highlightthickness": 2} |
| 1726 | Widget.__init__(self, master, "menubutton", kw) |
Guido van Rossum | bf4d8f9 | 1995-09-01 20:35:37 +0000 | [diff] [blame] | 1727 | self.widgetName = 'tk_optionMenu' |
Guido van Rossum | 28574b5 | 1996-10-21 15:16:51 +0000 | [diff] [blame] | 1728 | menu = self.__menu = Menu(self, name="menu", tearoff=0) |
| 1729 | self.menuname = menu._w |
| 1730 | menu.add_command(label=value, command=_setit(variable, value)) |
| 1731 | for v in values: |
| 1732 | menu.add_command(label=v, command=_setit(variable, v)) |
| 1733 | self["menu"] = menu |
| 1734 | |
| 1735 | def __getitem__(self, name): |
| 1736 | if name == 'menu': |
| 1737 | return self.__menu |
| 1738 | return Widget.__getitem__(self, name) |
| 1739 | |
| 1740 | def destroy(self): |
| 1741 | Menubutton.destroy(self) |
| 1742 | self.__menu = None |
Guido van Rossum | bf4d8f9 | 1995-09-01 20:35:37 +0000 | [diff] [blame] | 1743 | |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1744 | class Image: |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1745 | def __init__(self, imgtype, name=None, cnf={}, master=None, **kw): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1746 | self.name = None |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1747 | if not master: |
| 1748 | master = _default_root |
| 1749 | if not master: |
| 1750 | raise RuntimeError, 'Too early to create image' |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1751 | self.tk = master.tk |
Guido van Rossum | 58103d3 | 1996-11-20 22:17:38 +0000 | [diff] [blame] | 1752 | if not name: |
| 1753 | name = `id(self)` |
| 1754 | # The following is needed for systems where id(x) |
| 1755 | # can return a negative number, such as Linux/m68k: |
| 1756 | if name[0] == '-': name = '_' + name[1:] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1757 | if kw and cnf: cnf = _cnfmerge((cnf, kw)) |
| 1758 | elif kw: cnf = kw |
| 1759 | options = () |
| 1760 | for k, v in cnf.items(): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1761 | if callable(v): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1762 | v = self._register(v) |
| 1763 | options = options + ('-'+k, v) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1764 | self.tk.call(('image', 'create', imgtype, name,) + options) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1765 | self.name = name |
| 1766 | def __str__(self): return self.name |
| 1767 | def __del__(self): |
| 1768 | if self.name: |
| 1769 | self.tk.call('image', 'delete', self.name) |
Guido van Rossum | 71b1a90 | 1995-09-18 21:54:35 +0000 | [diff] [blame] | 1770 | def __setitem__(self, key, value): |
| 1771 | self.tk.call(self.name, 'configure', '-'+key, value) |
| 1772 | def __getitem__(self, key): |
| 1773 | return self.tk.call(self.name, 'configure', '-'+key) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1774 | def configure(self, **kw): |
Guido van Rossum | 8371013 | 1996-12-27 15:33:17 +0000 | [diff] [blame] | 1775 | res = () |
| 1776 | for k, v in _cnfmerge(kw).items(): |
| 1777 | if v is not None: |
| 1778 | if k[-1] == '_': k = k[:-1] |
| 1779 | if callable(v): |
| 1780 | v = self._register(v) |
| 1781 | res = res + ('-'+k, v) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1782 | self.tk.call((self.name, 'config') + res) |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1783 | config = configure |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1784 | def height(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1785 | return getint( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1786 | self.tk.call('image', 'height', self.name)) |
| 1787 | def type(self): |
| 1788 | return self.tk.call('image', 'type', self.name) |
| 1789 | def width(self): |
Guido van Rossum | 0132f69 | 1998-04-30 17:50:36 +0000 | [diff] [blame] | 1790 | return getint( |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1791 | self.tk.call('image', 'width', self.name)) |
| 1792 | |
| 1793 | class PhotoImage(Image): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1794 | def __init__(self, name=None, cnf={}, master=None, **kw): |
| 1795 | apply(Image.__init__, (self, 'photo', name, cnf, master), kw) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1796 | def blank(self): |
| 1797 | self.tk.call(self.name, 'blank') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1798 | def cget(self, option): |
| 1799 | return self.tk.call(self.name, 'cget', '-' + option) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1800 | # XXX config |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1801 | def __getitem__(self, key): |
| 1802 | return self.tk.call(self.name, 'cget', '-' + key) |
Guido van Rossum | 5ac00ac | 1997-12-11 02:03:55 +0000 | [diff] [blame] | 1803 | # XXX copy -from, -to, ...? |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1804 | def copy(self): |
| 1805 | destImage = PhotoImage() |
| 1806 | self.tk.call(destImage, 'copy', self.name) |
| 1807 | return destImage |
| 1808 | def zoom(self,x,y=''): |
| 1809 | destImage = PhotoImage() |
| 1810 | if y=='': y=x |
| 1811 | self.tk.call(destImage, 'copy', self.name, '-zoom',x,y) |
| 1812 | return destImage |
| 1813 | def subsample(self,x,y=''): |
| 1814 | destImage = PhotoImage() |
| 1815 | if y=='': y=x |
| 1816 | self.tk.call(destImage, 'copy', self.name, '-subsample',x,y) |
| 1817 | return destImage |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1818 | def get(self, x, y): |
| 1819 | return self.tk.call(self.name, 'get', x, y) |
| 1820 | def put(self, data, to=None): |
| 1821 | args = (self.name, 'put', data) |
| 1822 | if to: |
Fred Drake | b532399 | 1997-12-16 15:03:43 +0000 | [diff] [blame] | 1823 | if to[0] == '-to': |
| 1824 | to = to[1:] |
| 1825 | args = args + ('-to',) + tuple(to) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1826 | self.tk.call(args) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1827 | # XXX read |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1828 | def write(self, filename, format=None, from_coords=None): |
| 1829 | args = (self.name, 'write', filename) |
| 1830 | if format: |
| 1831 | args = args + ('-format', format) |
| 1832 | if from_coords: |
| 1833 | args = args + ('-from',) + tuple(from_coords) |
Guido van Rossum | f975699 | 1998-04-29 21:57:08 +0000 | [diff] [blame] | 1834 | self.tk.call(args) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1835 | |
| 1836 | class BitmapImage(Image): |
Guido van Rossum | c457048 | 1998-03-20 20:45:49 +0000 | [diff] [blame] | 1837 | def __init__(self, name=None, cnf={}, master=None, **kw): |
| 1838 | apply(Image.__init__, (self, 'bitmap', name, cnf, master), kw) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1839 | |
| 1840 | def image_names(): return _default_root.tk.call('image', 'names') |
| 1841 | def image_types(): return _default_root.tk.call('image', 'types') |
| 1842 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1843 | ###################################################################### |
| 1844 | # Extensions: |
| 1845 | |
| 1846 | class Studbutton(Button): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1847 | def __init__(self, master=None, cnf={}, **kw): |
| 1848 | Widget.__init__(self, master, 'studbutton', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1849 | self.bind('<Any-Enter>', self.tkButtonEnter) |
| 1850 | self.bind('<Any-Leave>', self.tkButtonLeave) |
| 1851 | self.bind('<1>', self.tkButtonDown) |
| 1852 | self.bind('<ButtonRelease-1>', self.tkButtonUp) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1853 | |
| 1854 | class Tributton(Button): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1855 | def __init__(self, master=None, cnf={}, **kw): |
| 1856 | Widget.__init__(self, master, 'tributton', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1857 | self.bind('<Any-Enter>', self.tkButtonEnter) |
| 1858 | self.bind('<Any-Leave>', self.tkButtonLeave) |
| 1859 | self.bind('<1>', self.tkButtonDown) |
| 1860 | self.bind('<ButtonRelease-1>', self.tkButtonUp) |
| 1861 | self['fg'] = self['bg'] |
| 1862 | self['activebackground'] = self['bg'] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1863 | |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1864 | ###################################################################### |
| 1865 | # Test: |
| 1866 | |
| 1867 | def _test(): |
| 1868 | root = Tk() |
| 1869 | label = Label(root, text="Proof-of-existence test for Tk") |
| 1870 | label.pack() |
| 1871 | test = Button(root, text="Click me!", |
Guido van Rossum | 368e06b | 1997-11-07 20:38:49 +0000 | [diff] [blame] | 1872 | command=lambda root=root: root.test.configure( |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1873 | text="[%s]" % root.test['text'])) |
| 1874 | test.pack() |
| 1875 | root.test = test |
| 1876 | quit = Button(root, text="QUIT", command=root.destroy) |
| 1877 | quit.pack() |
Guido van Rossum | 16cd332 | 1997-05-09 00:59:43 +0000 | [diff] [blame] | 1878 | root.tkraise() |
Guido van Rossum | c417ef8 | 1996-08-21 23:38:59 +0000 | [diff] [blame] | 1879 | root.mainloop() |
| 1880 | |
| 1881 | if __name__ == '__main__': |
| 1882 | _test() |