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