Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1 | # Tkinter.py -- Tk/Tcl widget wrappers |
| 2 | import tkinter |
| 3 | from tkinter import TclError |
| 4 | |
| 5 | class _Dummy: |
| 6 | def meth(self): return |
| 7 | |
| 8 | def _isfunctype(func): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 9 | return type(func) in CallableTypes |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 10 | |
| 11 | FunctionType = type(_isfunctype) |
| 12 | ClassType = type(_Dummy) |
| 13 | MethodType = type(_Dummy.meth) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 14 | StringType = type('') |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 15 | TupleType = type(()) |
| 16 | ListType = type([]) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 17 | CallableTypes = (FunctionType, MethodType) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 18 | |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 19 | def _tkerror(err): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 20 | pass |
| 21 | |
| 22 | class Event: |
| 23 | pass |
| 24 | |
| 25 | class Misc: |
| 26 | def tk_strictMotif(self, boolean=None): |
| 27 | self.tk.getboolean(self.tk.call( |
| 28 | 'set', 'tk_strictMotif', boolean)) |
| 29 | def waitvar(self, name='VAR'): |
| 30 | self.tk.call('tkwait', 'variable', name) |
| 31 | def setvar(self, name='VAR', value='1'): |
| 32 | self.tk.setvar(name, value) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 33 | def getvar(self, name='VAR'): |
| 34 | return self.tk.getvar(name) |
| 35 | def getint(self, s): |
| 36 | return self.tk.getint(s) |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 37 | def getdouble(self, s): |
| 38 | return self.tk.getdouble(s) |
| 39 | def getboolean(self, s): |
| 40 | return self.tk.getboolean(s) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 41 | def focus_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 42 | self.tk.call('focus', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 43 | focus = focus_set # XXX b/w compat? |
| 44 | def focus_default_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 45 | self.tk.call('focus', 'default', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 46 | def focus_default_none(self): |
| 47 | self.tk.call('focus', 'default', 'none') |
| 48 | focus_default = focus_default_set |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 49 | def focus_none(self): |
| 50 | self.tk.call('focus', 'none') |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 51 | def focus_get(self): |
| 52 | name = self.tk.call('focus') |
| 53 | if name == 'none': return None |
| 54 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 55 | def after(self, ms, func=None, *args): |
| 56 | if not func: |
| 57 | self.tk.call('after', ms) |
| 58 | else: |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 59 | # XXX Disgusting hack to clean up after calling func |
| 60 | tmp = [] |
| 61 | def callit(func=func, args=args, tk=self.tk, tmp=tmp): |
| 62 | try: |
| 63 | apply(func, args) |
| 64 | finally: |
| 65 | tk.deletecommand(tmp[0]) |
| 66 | name = self._register(callit) |
| 67 | tmp.append(name) |
| 68 | self.tk.call('after', ms, name) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 69 | # XXX grab current w/o window argument |
| 70 | def grab_current(self): |
| 71 | name = self.tk.call('grab', 'current', self._w) |
| 72 | if not name: return None |
| 73 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 74 | def grab_release(self): |
| 75 | self.tk.call('grab', 'release', self._w) |
| 76 | def grab_set(self): |
| 77 | self.tk.call('grab', 'set', self._w) |
| 78 | def grab_set_global(self): |
| 79 | self.tk.call('grab', 'set', '-global', self._w) |
| 80 | def grab_status(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 81 | status = self.tk.call('grab', 'status', self._w) |
| 82 | if status == 'none': status = None |
| 83 | return status |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 84 | def lower(self, belowThis=None): |
| 85 | self.tk.call('lower', self._w, belowThis) |
| 86 | def selection_clear(self): |
| 87 | self.tk.call('selection', 'clear', self._w) |
| 88 | def selection_get(self, type=None): |
| 89 | self.tk.call('selection', 'get', type) |
| 90 | def selection_handle(self, func, type=None, format=None): |
| 91 | name = self._register(func) |
| 92 | self.tk.call('selection', 'handle', |
| 93 | self._w, name, type, format) |
| 94 | #XXX def selection_own(self): |
| 95 | # self.tk.call('selection', 'own', self._w) |
| 96 | def send(self, interp, cmd, *args): #XXX |
| 97 | return apply(self.tk.call, ('send', interp, cmd) + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 98 | def lower(self, belowThis=None): |
| 99 | self.tk.call('lift', self._w, belowThis) |
| 100 | def tkraise(self, aboveThis=None): |
| 101 | self.tk.call('raise', self._w, aboveThis) |
| 102 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 103 | def colormodel(self, value=None): |
| 104 | return self.tk.call('tk', 'colormodel', self._w, value) |
| 105 | def winfo_atom(self, name): |
| 106 | return self.tk.getint(self.tk.call('winfo', 'atom', name)) |
| 107 | def winfo_atomname(self, id): |
| 108 | return self.tk.call('winfo', 'atomname', id) |
| 109 | def winfo_cells(self): |
| 110 | return self.tk.getint( |
| 111 | self.tk.call('winfo', 'cells', self._w)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 112 | def winfo_children(self): |
| 113 | return map(self._nametowidget, |
| 114 | self.tk.splitlist(self.tk.call( |
| 115 | 'winfo', 'children', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 116 | def winfo_class(self): |
| 117 | return self.tk.call('winfo', 'class', self._w) |
| 118 | def winfo_containing(self, rootX, rootY): |
| 119 | return self.tk.call('winfo', 'containing', rootx, rootY) |
| 120 | def winfo_depth(self): |
| 121 | return self.tk.getint(self.tk.call('winfo', 'depth', self._w)) |
| 122 | def winfo_exists(self): |
| 123 | return self.tk.getint( |
| 124 | self.tk.call('winfo', 'exists', self._w)) |
| 125 | def winfo_fpixels(self, number): |
| 126 | return self.tk.getdouble(self.tk.call( |
| 127 | 'winfo', 'fpixels', self._w, number)) |
| 128 | def winfo_geometry(self): |
| 129 | return self.tk.call('winfo', 'geometry', self._w) |
| 130 | def winfo_height(self): |
| 131 | return self.tk.getint( |
| 132 | self.tk.call('winfo', 'height', self._w)) |
| 133 | def winfo_id(self): |
| 134 | return self.tk.getint( |
| 135 | self.tk.call('winfo', 'id', self._w)) |
| 136 | def winfo_interps(self): |
| 137 | return self.tk.splitlist( |
| 138 | self.tk.call('winfo', 'interps')) |
| 139 | def winfo_ismapped(self): |
| 140 | return self.tk.getint( |
| 141 | self.tk.call('winfo', 'ismapped', self._w)) |
| 142 | def winfo_name(self): |
| 143 | return self.tk.call('winfo', 'name', self._w) |
| 144 | def winfo_parent(self): |
| 145 | return self.tk.call('winfo', 'parent', self._w) |
| 146 | def winfo_pathname(self, id): |
| 147 | return self.tk.call('winfo', 'pathname', id) |
| 148 | def winfo_pixels(self, number): |
| 149 | return self.tk.getint( |
| 150 | self.tk.call('winfo', 'pixels', self._w, number)) |
| 151 | def winfo_reqheight(self): |
| 152 | return self.tk.getint( |
| 153 | self.tk.call('winfo', 'reqheight', self._w)) |
| 154 | def winfo_reqwidth(self): |
| 155 | return self.tk.getint( |
| 156 | self.tk.call('winfo', 'reqwidth', self._w)) |
| 157 | def winfo_rgb(self, color): |
| 158 | return self._getints( |
| 159 | self.tk.call('winfo', 'rgb', self._w, color)) |
| 160 | def winfo_rootx(self): |
| 161 | return self.tk.getint( |
| 162 | self.tk.call('winfo', 'rootx', self._w)) |
| 163 | def winfo_rooty(self): |
| 164 | return self.tk.getint( |
| 165 | self.tk.call('winfo', 'rooty', self._w)) |
| 166 | def winfo_screen(self): |
| 167 | return self.tk.call('winfo', 'screen', self._w) |
| 168 | def winfo_screencells(self): |
| 169 | return self.tk.getint( |
| 170 | self.tk.call('winfo', 'screencells', self._w)) |
| 171 | def winfo_screendepth(self): |
| 172 | return self.tk.getint( |
| 173 | self.tk.call('winfo', 'screendepth', self._w)) |
| 174 | def winfo_screenheight(self): |
| 175 | return self.tk.getint( |
| 176 | self.tk.call('winfo', 'screenheight', self._w)) |
| 177 | def winfo_screenmmheight(self): |
| 178 | return self.tk.getint( |
| 179 | self.tk.call('winfo', 'screenmmheight', self._w)) |
| 180 | def winfo_screenmmwidth(self): |
| 181 | return self.tk.getint( |
| 182 | self.tk.call('winfo', 'screenmmwidth', self._w)) |
| 183 | def winfo_screenvisual(self): |
| 184 | return self.tk.call('winfo', 'screenvisual', self._w) |
| 185 | def winfo_screenwidth(self): |
| 186 | return self.tk.getint( |
| 187 | self.tk.call('winfo', 'screenwidth', self._w)) |
| 188 | def winfo_toplevel(self): |
| 189 | return self.tk.call('winfo', 'toplevel', self._w) |
| 190 | def winfo_visual(self): |
| 191 | return self.tk.call('winfo', 'visual', self._w) |
| 192 | def winfo_vrootheight(self): |
| 193 | return self.tk.getint( |
| 194 | self.tk.call('winfo', 'vrootheight', self._w)) |
| 195 | def winfo_vrootwidth(self): |
| 196 | return self.tk.getint( |
| 197 | self.tk.call('winfo', 'vrootwidth', self._w)) |
| 198 | def winfo_vrootx(self): |
| 199 | return self.tk.getint( |
| 200 | self.tk.call('winfo', 'vrootx', self._w)) |
| 201 | def winfo_vrooty(self): |
| 202 | return self.tk.getint( |
| 203 | self.tk.call('winfo', 'vrooty', self._w)) |
| 204 | def winfo_width(self): |
| 205 | return self.tk.getint( |
| 206 | self.tk.call('winfo', 'width', self._w)) |
| 207 | def winfo_x(self): |
| 208 | return self.tk.getint( |
| 209 | self.tk.call('winfo', 'x', self._w)) |
| 210 | def winfo_y(self): |
| 211 | return self.tk.getint( |
| 212 | self.tk.call('winfo', 'y', self._w)) |
| 213 | def update(self): |
| 214 | self.tk.call('update') |
| 215 | def update_idletasks(self): |
| 216 | self.tk.call('update', 'idletasks') |
| 217 | def bind(self, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 218 | if add: add = '+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 219 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 220 | self.tk.call('bind', self._w, sequence, |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 221 | (add + name,) + self._subst_prefix) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 222 | def bind_all(self, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 223 | if add: add = '+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 224 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 225 | self.tk.call('bind', 'all' , sequence, |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 226 | (add + `name`,) + self._subst_prefix) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 227 | def bind_class(self, className, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 228 | if add: add = '+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 229 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 230 | self.tk.call('bind', className , sequence, |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 231 | (add + name,) + self._subst_prefix) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 232 | def mainloop(self): |
| 233 | self.tk.mainloop() |
| 234 | def quit(self): |
| 235 | self.tk.quit() |
| 236 | # Utilities |
| 237 | def _getints(self, string): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 238 | if not string: return None |
| 239 | res = () |
| 240 | for v in self.tk.splitlist(string): |
| 241 | res = res + (self.tk.getint(v),) |
| 242 | return res |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 243 | def _getboolean(self, string): |
| 244 | if string: |
| 245 | return self.tk.getboolean(string) |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 246 | # else return None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 247 | def _options(self, cnf): |
| 248 | res = () |
| 249 | for k, v in cnf.items(): |
| 250 | if _isfunctype(v): |
| 251 | v = self._register(v) |
| 252 | res = res + ('-'+k, v) |
| 253 | return res |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 254 | def _nametowidget(self, name): |
| 255 | w = self |
| 256 | if name[0] == '.': |
| 257 | w = w._root() |
| 258 | name = name[1:] |
| 259 | from string import find |
| 260 | while name: |
| 261 | i = find(name, '.') |
| 262 | if i >= 0: |
| 263 | name, tail = name[:i], name[i+1:] |
| 264 | else: |
| 265 | tail = '' |
| 266 | w = w.children[name] |
| 267 | name = tail |
| 268 | return w |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 269 | def _register(self, func, subst=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 270 | f = _CallSafely(func, subst).__call__ |
| 271 | name = `id(f)` |
| 272 | if hasattr(func, 'im_func'): |
| 273 | func = func.im_func |
| 274 | if hasattr(func, 'func_name') and \ |
| 275 | type(func.func_name) == type(''): |
| 276 | name = name + func.func_name |
| 277 | self.tk.createcommand(name, f) |
| 278 | return name |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 279 | def _root(self): |
| 280 | w = self |
| 281 | while w.master: w = w.master |
| 282 | return w |
| 283 | _subst_prefix = ('%#', '%b', '%f', '%h', '%k', |
| 284 | '%s', '%t', '%w', '%x', '%y', |
| 285 | '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y') |
| 286 | def _substitute(self, *args): |
| 287 | tk = self.tk |
| 288 | if len(args) != len(self._subst_prefix): return args |
| 289 | nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args |
| 290 | # Missing: (a, c, d, m, o, v, B, R) |
| 291 | e = Event() |
| 292 | e.serial = tk.getint(nsign) |
| 293 | e.num = tk.getint(b) |
| 294 | try: e.focus = tk.getboolean(f) |
| 295 | except TclError: pass |
| 296 | e.height = tk.getint(h) |
| 297 | e.keycode = tk.getint(k) |
| 298 | e.state = tk.getint(s) |
| 299 | e.time = tk.getint(t) |
| 300 | e.width = tk.getint(w) |
| 301 | e.x = tk.getint(x) |
| 302 | e.y = tk.getint(y) |
| 303 | e.char = A |
| 304 | try: e.send_event = tk.getboolean(E) |
| 305 | except TclError: pass |
| 306 | e.keysym = K |
| 307 | e.keysym_num = tk.getint(N) |
| 308 | e.type = T |
| 309 | e.widget = self._nametowidget(W) |
| 310 | e.x_root = tk.getint(X) |
| 311 | e.y_root = tk.getint(Y) |
| 312 | return (e,) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 313 | |
| 314 | class _CallSafely: |
| 315 | def __init__(self, func, subst=None): |
| 316 | self.func = func |
| 317 | self.subst = subst |
| 318 | def __call__(self, *args): |
| 319 | if self.subst: |
| 320 | args = self.apply_func(self.subst, args) |
| 321 | args = self.apply_func(self.func, args) |
| 322 | def apply_func(self, func, args): |
| 323 | import sys |
| 324 | try: |
| 325 | return apply(func, args) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 326 | except SystemExit, msg: |
| 327 | raise SystemExit, msg |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 328 | except: |
| 329 | try: |
| 330 | try: |
| 331 | t = sys.exc_traceback |
| 332 | while t: |
| 333 | sys.stderr.write( |
| 334 | ' %s, line %s\n' % |
| 335 | (t.tb_frame.f_code, |
| 336 | t.tb_lineno)) |
| 337 | t = t.tb_next |
| 338 | finally: |
| 339 | sys.stderr.write('%s: %s\n' % |
| 340 | (sys.exc_type, |
| 341 | sys.exc_value)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 342 | (sys.last_type, |
| 343 | sys.last_value, |
| 344 | sys.last_traceback) = (sys.exc_type, |
| 345 | sys.exc_value, |
| 346 | sys.exc_traceback) |
| 347 | import pdb |
| 348 | pdb.pm() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 349 | except: |
| 350 | print '*** Error in error handling ***' |
| 351 | print sys.exc_type, ':', sys.exc_value |
| 352 | |
| 353 | class Wm: |
| 354 | def aspect(self, |
| 355 | minNumer=None, minDenom=None, |
| 356 | maxNumer=None, maxDenom=None): |
| 357 | return self._getints( |
| 358 | self.tk.call('wm', 'aspect', self._w, |
| 359 | minNumer, minDenom, |
| 360 | maxNumer, maxDenom)) |
| 361 | def client(self, name=None): |
| 362 | return self.tk.call('wm', 'client', self._w, name) |
| 363 | def command(self, value=None): |
| 364 | return self.tk.call('wm', 'command', self._w, value) |
| 365 | def deiconify(self): |
| 366 | return self.tk.call('wm', 'deiconify', self._w) |
| 367 | def focusmodel(self, model=None): |
| 368 | return self.tk.call('wm', 'focusmodel', self._w, model) |
| 369 | def frame(self): |
| 370 | return self.tk.call('wm', 'frame', self._w) |
| 371 | def geometry(self, newGeometry=None): |
| 372 | return self.tk.call('wm', 'geometry', self._w, newGeometry) |
| 373 | def grid(self, |
| 374 | baseWidht=None, baseHeight=None, |
| 375 | widthInc=None, heightInc=None): |
| 376 | return self._getints(self.tk.call( |
| 377 | 'wm', 'grid', self._w, |
| 378 | baseWidht, baseHeight, widthInc, heightInc)) |
| 379 | def group(self, pathName=None): |
| 380 | return self.tk.call('wm', 'group', self._w, pathName) |
| 381 | def iconbitmap(self, bitmap=None): |
| 382 | return self.tk.call('wm', 'iconbitmap', self._w, bitmap) |
| 383 | def iconify(self): |
| 384 | return self.tk.call('wm', 'iconify', self._w) |
| 385 | def iconmask(self, bitmap=None): |
| 386 | return self.tk.call('wm', 'iconmask', self._w, bitmap) |
| 387 | def iconname(self, newName=None): |
| 388 | return self.tk.call('wm', 'iconname', self._w, newName) |
| 389 | def iconposition(self, x=None, y=None): |
| 390 | return self._getints(self.tk.call( |
| 391 | 'wm', 'iconposition', self._w, x, y)) |
| 392 | def iconwindow(self, pathName=None): |
| 393 | return self.tk.call('wm', 'iconwindow', self._w, pathName) |
| 394 | def maxsize(self, width=None, height=None): |
| 395 | return self._getints(self.tk.call( |
| 396 | 'wm', 'maxsize', self._w, width, height)) |
| 397 | def minsize(self, width=None, height=None): |
| 398 | return self._getints(self.tk.call( |
| 399 | 'wm', 'minsize', self._w, width, height)) |
| 400 | def overrideredirect(self, boolean=None): |
| 401 | return self._getboolean(self.tk.call( |
| 402 | 'wm', 'overrideredirect', self._w, boolean)) |
| 403 | def positionfrom(self, who=None): |
| 404 | return self.tk.call('wm', 'positionfrom', self._w, who) |
| 405 | def protocol(self, name=None, func=None): |
| 406 | if _isfunctype(func): |
| 407 | command = self._register(func) |
| 408 | else: |
| 409 | command = func |
| 410 | return self.tk.call( |
| 411 | 'wm', 'protocol', self._w, name, command) |
| 412 | def sizefrom(self, who=None): |
| 413 | return self.tk.call('wm', 'sizefrom', self._w, who) |
| 414 | def state(self): |
| 415 | return self.tk.call('wm', 'state', self._w) |
| 416 | def title(self, string=None): |
| 417 | return self.tk.call('wm', 'title', self._w, string) |
| 418 | def transient(self, master=None): |
| 419 | return self.tk.call('wm', 'transient', self._w, master) |
| 420 | def withdraw(self): |
| 421 | return self.tk.call('wm', 'withdraw', self._w) |
| 422 | |
| 423 | class Tk(Misc, Wm): |
| 424 | _w = '.' |
| 425 | def __init__(self, screenName=None, baseName=None, className='Tk'): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 426 | self.master = None |
| 427 | self.children = {} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 428 | if baseName is None: |
| 429 | import sys, os |
| 430 | baseName = os.path.basename(sys.argv[0]) |
| 431 | if baseName[-3:] == '.py': baseName = baseName[:-3] |
| 432 | self.tk = tkinter.create(screenName, baseName, className) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 433 | self.tk.createcommand('tkerror', _tkerror) |
| 434 | def destroy(self): |
| 435 | for c in self.children.values(): c.destroy() |
| 436 | del self.master.children[self._name] |
| 437 | self.tk.call('destroy', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 438 | def __str__(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 439 | return self._w |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 440 | |
| 441 | class Pack: |
| 442 | def config(self, cnf={}): |
| 443 | apply(self.tk.call, |
| 444 | ('pack', 'configure', self._w) |
| 445 | + self._options(cnf)) |
| 446 | pack = config |
| 447 | def __setitem__(self, key, value): |
| 448 | Pack.config({key: value}) |
| 449 | def forget(self): |
| 450 | self.tk.call('pack', 'forget', self._w) |
| 451 | def newinfo(self): |
| 452 | return self.tk.call('pack', 'newinfo', self._w) |
| 453 | info = newinfo |
| 454 | def propagate(self, boolean=None): |
| 455 | if boolean: |
| 456 | self.tk.call('pack', 'propagate', self._w) |
| 457 | else: |
| 458 | return self._getboolean(self.tk.call( |
| 459 | 'pack', 'propagate', self._w)) |
| 460 | def slaves(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 461 | return map(self._nametowidget, |
| 462 | self.tk.splitlist( |
| 463 | self.tk.call('pack', 'slaves', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 464 | |
| 465 | class Place: |
| 466 | def config(self, cnf={}): |
| 467 | apply(self.tk.call, |
| 468 | ('place', 'configure', self._w) |
| 469 | + self._options(cnf)) |
| 470 | place = config |
| 471 | def __setitem__(self, key, value): |
| 472 | Place.config({key: value}) |
| 473 | def forget(self): |
| 474 | self.tk.call('place', 'forget', self._w) |
| 475 | def info(self): |
| 476 | return self.tk.call('place', 'info', self._w) |
| 477 | def slaves(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 478 | return map(self._nametowidget, |
| 479 | self.tk.splitlist( |
| 480 | self.tk.call( |
| 481 | 'place', 'slaves', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 482 | |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 483 | _default_root = None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 484 | |
| 485 | class Widget(Misc, Pack, Place): |
| 486 | def __init__(self, master, widgetName, cnf={}, extra=()): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 487 | global _default_root |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 488 | if not master: |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 489 | if not _default_root: |
| 490 | _default_root = Tk() |
| 491 | master = _default_root |
| 492 | if not _default_root: |
| 493 | _default_root = master |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 494 | self.master = master |
| 495 | self.tk = master.tk |
| 496 | if cnf.has_key('name'): |
| 497 | name = cnf['name'] |
| 498 | del cnf['name'] |
| 499 | else: |
| 500 | name = `id(self)` |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 501 | self._name = name |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 502 | if master._w=='.': |
| 503 | self._w = '.' + name |
| 504 | else: |
| 505 | self._w = master._w + '.' + name |
| 506 | self.widgetName = widgetName |
| 507 | apply(self.tk.call, (widgetName, self._w) + extra) |
| 508 | Widget.config(self, cnf) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 509 | self.children = {} |
| 510 | if master.children.has_key(name): |
| 511 | master.children[name].destroy() |
| 512 | master.children[name] = self |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 513 | def config(self, cnf=None): |
| 514 | if cnf is None: |
| 515 | cnf = {} |
| 516 | for x in self.tk.split( |
| 517 | self.tk.call(self._w, 'configure')): |
| 518 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 519 | return cnf |
| 520 | if type(cnf) == StringType: |
| 521 | x = self.tk.split(self.tk.call( |
| 522 | self._w, 'configure', '-'+cnf)) |
| 523 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 524 | for k in cnf.keys(): |
| 525 | if type(k) == ClassType: |
| 526 | k.config(self, cnf[k]) |
| 527 | del cnf[k] |
| 528 | apply(self.tk.call, (self._w, 'configure') |
| 529 | + self._options(cnf)) |
| 530 | def __getitem__(self, key): |
| 531 | v = self.tk.split(self.tk.call( |
| 532 | self._w, 'configure', '-' + key)) |
| 533 | return v[4] |
| 534 | def __setitem__(self, key, value): |
| 535 | Widget.config(self, {key: value}) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 536 | def keys(self): |
| 537 | return map(lambda x: x[0][1:], |
| 538 | self.tk.split(self.tk.call(self._w, 'configure'))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 539 | def __str__(self): |
| 540 | return self._w |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 541 | def destroy(self): |
| 542 | for c in self.children.values(): c.destroy() |
| 543 | del self.master.children[self._name] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 544 | self.tk.call('destroy', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 545 | def _do(self, name, args=()): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 546 | return apply(self.tk.call, (self._w, name) + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 547 | |
| 548 | class Toplevel(Widget, Wm): |
| 549 | def __init__(self, master=None, cnf={}): |
| 550 | extra = () |
| 551 | if cnf.has_key('screen'): |
| 552 | extra = ('-screen', cnf['screen']) |
| 553 | del cnf['screen'] |
| 554 | if cnf.has_key('class'): |
| 555 | extra = extra + ('-class', cnf['class']) |
| 556 | del cnf['class'] |
| 557 | Widget.__init__(self, master, 'toplevel', cnf, extra) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 558 | root = self._root() |
| 559 | self.iconname(root.iconname()) |
| 560 | self.title(root.title()) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 561 | |
| 562 | class Button(Widget): |
| 563 | def __init__(self, master=None, cnf={}): |
| 564 | Widget.__init__(self, master, 'button', cnf) |
| 565 | def tk_butEnter(self): |
| 566 | self.tk.call('tk_butEnter', self._w) |
| 567 | def tk_butLeave(self): |
| 568 | self.tk.call('tk_butLeave', self._w) |
| 569 | def tk_butDown(self): |
| 570 | self.tk.call('tk_butDown', self._w) |
| 571 | def tk_butUp(self): |
| 572 | self.tk.call('tk_butUp', self._w) |
| 573 | def flash(self): |
| 574 | self.tk.call(self._w, 'flash') |
| 575 | def invoke(self): |
| 576 | self.tk.call(self._w, 'invoke') |
| 577 | |
| 578 | # Indices: |
| 579 | def AtEnd(): |
| 580 | return 'end' |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 581 | def AtInsert(*args): |
| 582 | s = 'insert' |
| 583 | for a in args: |
| 584 | if a: s = s + (' ' + a) |
| 585 | return s |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 586 | def AtSelFirst(): |
| 587 | return 'sel.first' |
| 588 | def AtSelLast(): |
| 589 | return 'sel.last' |
| 590 | def At(x, y=None): |
| 591 | if y: |
| 592 | return '@' + `x` + ',' + `y` |
| 593 | else: |
| 594 | return '@' + `x` |
| 595 | |
| 596 | class Canvas(Widget): |
| 597 | def __init__(self, master=None, cnf={}): |
| 598 | Widget.__init__(self, master, 'canvas', cnf) |
| 599 | def addtag(self, *args): |
| 600 | self._do('addtag', args) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 601 | def addtag_above(self, tagOrId): |
| 602 | self.addtag('above', tagOrId) |
| 603 | def addtag_all(self): |
| 604 | self.addtag('all') |
| 605 | def addtag_below(self, tagOrId): |
| 606 | self.addtag('below', tagOrId) |
| 607 | def addtag_closest(self, x, y, halo=None, start=None): |
| 608 | self.addtag('closest', x, y, halo, start) |
| 609 | def addtag_enclosed(self, x1, y1, x2, y2): |
| 610 | self.addtag('enclosed', x1, y1, x2, y2) |
| 611 | def addtag_overlapping(self, x1, y1, x2, y2): |
| 612 | self.addtag('overlapping', x1, y1, x2, y2) |
| 613 | def addtag_withtag(self, tagOrId): |
| 614 | self.addtag('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 615 | def bbox(self, *args): |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 616 | return self._getints(self._do('bbox', args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 617 | def bind(self, tagOrId, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 618 | if add: add='+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 619 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 620 | self.tk.call(self._w, 'bind', tagOrId, sequence, |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 621 | (add + name,) + self._subst_prefix) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 622 | def canvasx(self, screenx, gridspacing=None): |
| 623 | return self.tk.getint(self.tk.call( |
| 624 | self._w, 'canvasx', screenx, gridspacing)) |
| 625 | def canvasy(self, screeny, gridspacing=None): |
| 626 | return self.tk.getint(self.tk.call( |
| 627 | self._w, 'canvasy', screeny, gridspacing)) |
| 628 | def coords(self, *args): |
| 629 | return self._do('coords', args) |
| 630 | def _create(self, itemType, args): # Args: (value, value, ..., cnf={}) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 631 | args = _flatten(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 632 | cnf = args[-1] |
| 633 | if type(cnf) == type({}): |
| 634 | args = args[:-1] |
| 635 | else: |
| 636 | cnf = {} |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 637 | v = (self._w, 'create', itemType) + args |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 638 | for k in cnf.keys(): |
| 639 | v = v + ('-' + k, cnf[k]) |
| 640 | return self.tk.getint(apply(self.tk.call, v)) |
| 641 | def create_arc(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 642 | return Canvas._create(self, 'arc', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 643 | def create_bitmap(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 644 | return Canvas._create(self, 'bitmap', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 645 | def create_line(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 646 | return Canvas._create(self, 'line', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 647 | def create_oval(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 648 | return Canvas._create(self, 'oval', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 649 | def create_polygon(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 650 | return Canvas._create(self, 'polygon', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 651 | def create_rectangle(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 652 | return Canvas._create(self, 'rectangle', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 653 | def create_text(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 654 | return Canvas._create(self, 'text', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 655 | def create_window(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 656 | return Canvas._create(self, 'window', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 657 | def dchars(self, *args): |
| 658 | self._do('dchars', args) |
| 659 | def delete(self, *args): |
| 660 | self._do('delete', args) |
| 661 | def dtag(self, *args): |
| 662 | self._do('dtag', args) |
| 663 | def find(self, *args): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 664 | return self._getints(self._do('find', args)) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 665 | def find_above(self, tagOrId): |
| 666 | return self.find('above', tagOrId) |
| 667 | def find_all(self): |
| 668 | return self.find('all') |
| 669 | def find_below(self, tagOrId): |
| 670 | return self.find('below', tagOrId) |
| 671 | def find_closest(self, x, y, halo=None, start=None): |
| 672 | return self.find('closest', x, y, halo, start) |
| 673 | def find_enclosed(self, x1, y1, x2, y2): |
| 674 | return self.find('enclosed', x1, y1, x2, y2) |
| 675 | def find_overlapping(self, x1, y1, x2, y2): |
| 676 | return self.find('overlapping', x1, y1, x2, y2) |
| 677 | def find_withtag(self, tagOrId): |
| 678 | return self.find('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 679 | def focus(self, *args): |
| 680 | return self._do('focus', args) |
| 681 | def gettags(self, *args): |
| 682 | return self.tk.splitlist(self._do('gettags', args)) |
| 683 | def icursor(self, *args): |
| 684 | self._do('icursor', args) |
| 685 | def index(self, *args): |
| 686 | return self.tk.getint(self._do('index', args)) |
| 687 | def insert(self, *args): |
| 688 | self._do('insert', args) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 689 | def itemconfig(self, tagOrId, cnf=None): |
| 690 | if cnf is None: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 691 | cnf = {} |
| 692 | for x in self.tk.split( |
| 693 | self._do('itemconfigure', (tagOrId))): |
| 694 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 695 | return cnf |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 696 | if type(cnf) == StringType: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame^] | 697 | x = self.tk.split(self._do('itemconfigure', |
| 698 | (tagOrId, '-'+cnf,))) |
| 699 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 700 | self._do('itemconfigure', (tagOrId,) + self._options(cnf)) |
| 701 | def lower(self, *args): |
| 702 | self._do('lower', args) |
| 703 | def move(self, *args): |
| 704 | self._do('move', args) |
| 705 | def postscript(self, cnf={}): |
| 706 | return self._do('postscript', self._options(cnf)) |
| 707 | def tkraise(self, *args): |
| 708 | self._do('raise', args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 709 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 710 | def scale(self, *args): |
| 711 | self._do('scale', args) |
| 712 | def scan_mark(self, x, y): |
| 713 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 714 | def scan_dragto(self, x, y): |
| 715 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 716 | def select_adjust(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 717 | self.tk.call(self._w, 'select', 'adjust', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 718 | def select_clear(self): |
| 719 | self.tk.call(self._w, 'select', 'clear') |
| 720 | def select_from(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 721 | self.tk.call(self._w, 'select', 'from', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 722 | def select_item(self): |
| 723 | self.tk.call(self._w, 'select', 'item') |
| 724 | def select_to(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 725 | self.tk.call(self._w, 'select', 'to', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 726 | def type(self, tagOrId): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 727 | return self.tk.call(self._w, 'type', tagOrId) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 728 | def xview(self, index): |
| 729 | self.tk.call(self._w, 'xview', index) |
| 730 | def yview(self, index): |
| 731 | self.tk.call(self._w, 'yview', index) |
| 732 | |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 733 | def _flatten(tuple): |
| 734 | res = () |
| 735 | for item in tuple: |
| 736 | if type(item) in (TupleType, ListType): |
| 737 | res = res + _flatten(item) |
| 738 | else: |
| 739 | res = res + (item,) |
| 740 | return res |
| 741 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 742 | class Checkbutton(Widget): |
| 743 | def __init__(self, master=None, cnf={}): |
| 744 | Widget.__init__(self, master, 'checkbutton', cnf) |
| 745 | def deselect(self): |
| 746 | self.tk.call(self._w, 'deselect') |
| 747 | def flash(self): |
| 748 | self.tk.call(self._w, 'flash') |
| 749 | def invoke(self): |
| 750 | self.tk.call(self._w, 'invoke') |
| 751 | def select(self): |
| 752 | self.tk.call(self._w, 'select') |
| 753 | def toggle(self): |
| 754 | self.tk.call(self._w, 'toggle') |
| 755 | |
| 756 | class Entry(Widget): |
| 757 | def __init__(self, master=None, cnf={}): |
| 758 | Widget.__init__(self, master, 'entry', cnf) |
| 759 | def tk_entryBackspace(self): |
| 760 | self.tk.call('tk_entryBackspace', self._w) |
| 761 | def tk_entryBackword(self): |
| 762 | self.tk.call('tk_entryBackword', self._w) |
| 763 | def tk_entrySeeCaret(self): |
| 764 | self.tk.call('tk_entrySeeCaret', self._w) |
| 765 | def delete(self, first, last=None): |
| 766 | self.tk.call(self._w, 'delete', first, last) |
| 767 | def get(self): |
| 768 | return self.tk.call(self._w, 'get') |
| 769 | def icursor(self, index): |
| 770 | self.tk.call(self._w, 'icursor', index) |
| 771 | def index(self, index): |
| 772 | return self.tk.getint(self.tk.call( |
| 773 | self._w, 'index', index)) |
| 774 | def insert(self, index, string): |
| 775 | self.tk.call(self._w, 'insert', index, string) |
| 776 | def scan_mark(self, x): |
| 777 | self.tk.call(self._w, 'scan', 'mark', x) |
| 778 | def scan_dragto(self, x): |
| 779 | self.tk.call(self._w, 'scan', 'dragto', x) |
| 780 | def select_adjust(self, index): |
| 781 | self.tk.call(self._w, 'select', 'adjust', index) |
| 782 | def select_clear(self): |
| 783 | self.tk.call(self._w, 'select', 'clear') |
| 784 | def select_from(self, index): |
| 785 | self.tk.call(self._w, 'select', 'from', index) |
| 786 | def select_to(self, index): |
| 787 | self.tk.call(self._w, 'select', 'to', index) |
| 788 | def select_view(self, index): |
| 789 | self.tk.call(self._w, 'select', 'view', index) |
| 790 | |
| 791 | class Frame(Widget): |
| 792 | def __init__(self, master=None, cnf={}): |
| 793 | extra = () |
| 794 | if cnf.has_key('class'): |
| 795 | extra = ('-class', cnf['class']) |
| 796 | del cnf['class'] |
| 797 | Widget.__init__(self, master, 'frame', cnf, extra) |
| 798 | def tk_menuBar(self, *args): |
| 799 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
| 800 | |
| 801 | class Label(Widget): |
| 802 | def __init__(self, master=None, cnf={}): |
| 803 | Widget.__init__(self, master, 'label', cnf) |
| 804 | |
| 805 | class Listbox(Widget): |
| 806 | def __init__(self, master=None, cnf={}): |
| 807 | Widget.__init__(self, master, 'listbox', cnf) |
| 808 | def tk_listboxSingleSelect(self): |
| 809 | self.tk.call('tk_listboxSingleSelect', self._w) |
| 810 | def curselection(self): |
| 811 | return self.tk.splitlist(self.tk.call( |
| 812 | self._w, 'curselection')) |
| 813 | def delete(self, first, last=None): |
| 814 | self.tk.call(self._w, 'delete', first, last) |
| 815 | def get(self, index): |
| 816 | return self.tk.call(self._w, 'get', index) |
| 817 | def insert(self, index, *elements): |
| 818 | apply(self.tk.call, |
| 819 | (self._w, 'insert', index) + elements) |
| 820 | def nearest(self, y): |
| 821 | return self.tk.getint(self.tk.call( |
| 822 | self._w, 'nearest', y)) |
| 823 | def scan_mark(self, x, y): |
| 824 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 825 | def scan_dragto(self, x, y): |
| 826 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 827 | def select_adjust(self, index): |
| 828 | self.tk.call(self._w, 'select', 'adjust', index) |
| 829 | def select_clear(self): |
| 830 | self.tk.call(self._w, 'select', 'clear') |
| 831 | def select_from(self, index): |
| 832 | self.tk.call(self._w, 'select', 'from', index) |
| 833 | def select_to(self, index): |
| 834 | self.tk.call(self._w, 'select', 'to', index) |
| 835 | def size(self): |
| 836 | return self.tk.getint(self.tk.call(self._w, 'size')) |
| 837 | def xview(self, index): |
| 838 | self.tk.call(self._w, 'xview', index) |
| 839 | def yview(self, index): |
| 840 | self.tk.call(self._w, 'yview', index) |
| 841 | |
| 842 | class Menu(Widget): |
| 843 | def __init__(self, master=None, cnf={}): |
| 844 | Widget.__init__(self, master, 'menu', cnf) |
| 845 | def tk_menuBar(self, *args): |
| 846 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
| 847 | def tk_bindForTraversal(self): |
| 848 | self.tk.call('tk_bindForTraversal', self._w) |
| 849 | def tk_mbPost(self): |
| 850 | self.tk.call('tk_mbPost', self._w) |
| 851 | def tk_mbUnpost(self): |
| 852 | self.tk.call('tk_mbUnpost') |
| 853 | def tk_traverseToMenu(self, char): |
| 854 | self.tk.call('tk_traverseToMenu', self._w, char) |
| 855 | def tk_traverseWithinMenu(self, char): |
| 856 | self.tk.call('tk_traverseWithinMenu', self._w, char) |
| 857 | def tk_getMenuButtons(self): |
| 858 | return self.tk.call('tk_getMenuButtons', self._w) |
| 859 | def tk_nextMenu(self, count): |
| 860 | self.tk.call('tk_nextMenu', count) |
| 861 | def tk_nextMenuEntry(self, count): |
| 862 | self.tk.call('tk_nextMenuEntry', count) |
| 863 | def tk_invokeMenu(self): |
| 864 | self.tk.call('tk_invokeMenu', self._w) |
| 865 | def tk_firstMenu(self): |
| 866 | self.tk.call('tk_firstMenu', self._w) |
| 867 | def tk_mbButtonDown(self): |
| 868 | self.tk.call('tk_mbButtonDown', self._w) |
| 869 | def activate(self, index): |
| 870 | self.tk.call(self._w, 'activate', index) |
| 871 | def add(self, itemType, cnf={}): |
| 872 | apply(self.tk.call, (self._w, 'add', itemType) |
| 873 | + self._options(cnf)) |
| 874 | def delete(self, index1, index2=None): |
| 875 | self.tk.call(self._w, 'delete', index1, index2) |
| 876 | def entryconfig(self, index, cnf={}): |
| 877 | apply(self.tk.call, (self._w, 'entryconfigure', index) |
| 878 | + self._options(cnf)) |
| 879 | def index(self, index): |
| 880 | return self.tk.call(self._w, 'index', index) |
| 881 | def invoke(self, index): |
| 882 | return self.tk.call(self._w, 'invoke', index) |
| 883 | def post(self, x, y): |
| 884 | self.tk.call(self._w, 'post', x, y) |
| 885 | def unpost(self): |
| 886 | self.tk.call(self._w, 'unpost') |
| 887 | def yposition(self, index): |
| 888 | return self.tk.getint(self.tk.call( |
| 889 | self._w, 'yposition', index)) |
| 890 | |
| 891 | class Menubutton(Widget): |
| 892 | def __init__(self, master=None, cnf={}): |
| 893 | Widget.__init__(self, master, 'menubutton', cnf) |
| 894 | |
| 895 | class Message(Widget): |
| 896 | def __init__(self, master=None, cnf={}): |
| 897 | Widget.__init__(self, master, 'message', cnf) |
| 898 | |
| 899 | class Radiobutton(Widget): |
| 900 | def __init__(self, master=None, cnf={}): |
| 901 | Widget.__init__(self, master, 'radiobutton', cnf) |
| 902 | def deselect(self): |
| 903 | self.tk.call(self._w, 'deselect') |
| 904 | def flash(self): |
| 905 | self.tk.call(self._w, 'flash') |
| 906 | def invoke(self): |
| 907 | self.tk.call(self._w, 'invoke') |
| 908 | def select(self): |
| 909 | self.tk.call(self._w, 'select') |
| 910 | |
| 911 | class Scale(Widget): |
| 912 | def __init__(self, master=None, cnf={}): |
| 913 | Widget.__init__(self, master, 'scale', cnf) |
| 914 | def get(self): |
| 915 | return self.tk.getint(self.tk.call(self._w, 'get')) |
| 916 | def set(self, value): |
| 917 | self.tk.call(self._w, 'set', value) |
| 918 | |
| 919 | class Scrollbar(Widget): |
| 920 | def __init__(self, master=None, cnf={}): |
| 921 | Widget.__init__(self, master, 'scrollbar', cnf) |
| 922 | def get(self): |
| 923 | return self.tk.getints(self.tk.call(self._w, 'get')) |
| 924 | def set(self, totalUnits, windowUnits, firstUnit, lastUnit): |
| 925 | self.tk.call(self._w, 'set', |
| 926 | totalUnits, windowUnits, firstUnit, lastUnit) |
| 927 | |
| 928 | class Text(Widget): |
| 929 | def __init__(self, master=None, cnf={}): |
| 930 | Widget.__init__(self, master, 'text', cnf) |
| 931 | def tk_textSelectTo(self, index): |
| 932 | self.tk.call('tk_textSelectTo', self._w, index) |
| 933 | def tk_textBackspace(self): |
| 934 | self.tk.call('tk_textBackspace', self._w) |
| 935 | def tk_textIndexCloser(self, a, b, c): |
| 936 | self.tk.call('tk_textIndexCloser', self._w, a, b, c) |
| 937 | def tk_textResetAnchor(self, index): |
| 938 | self.tk.call('tk_textResetAnchor', self._w, index) |
| 939 | def compare(self, index1, op, index2): |
| 940 | return self.tk.getboolean(self.tk.call( |
| 941 | self._w, 'compare', index1, op, index2)) |
| 942 | def debug(self, boolean=None): |
| 943 | return self.tk.getboolean(self.tk.call( |
| 944 | self._w, 'debug', boolean)) |
| 945 | def delete(self, index1, index2=None): |
| 946 | self.tk.call(self._w, 'delete', index1, index2) |
| 947 | def get(self, index1, index2=None): |
| 948 | return self.tk.call(self._w, 'get', index1, index2) |
| 949 | def index(self, index): |
| 950 | return self.tk.call(self._w, 'index', index) |
| 951 | def insert(self, index, chars): |
| 952 | self.tk.call(self._w, 'insert', index, chars) |
| 953 | def mark_names(self): |
| 954 | return self.tk.splitlist(self.tk.call( |
| 955 | self._w, 'mark', 'names')) |
| 956 | def mark_set(self, markName, index): |
| 957 | self.tk.call(self._w, 'mark', 'set', markName, index) |
| 958 | def mark_unset(self, markNames): |
| 959 | apply(self.tk.call, (self._w, 'mark', 'unset') + markNames) |
| 960 | def scan_mark(self, y): |
| 961 | self.tk.call(self._w, 'scan', 'mark', y) |
| 962 | def scan_dragto(self, y): |
| 963 | self.tk.call(self._w, 'scan', 'dragto', y) |
| 964 | def tag_add(self, tagName, index1, index2=None): |
| 965 | self.tk.call( |
| 966 | self._w, 'tag', 'add', tagName, index1, index2) |
| 967 | def tag_bind(self, tagName, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 968 | if add: add='+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 969 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 970 | self.tk.call(self._w, 'tag', 'bind', |
| 971 | tagName, sequence, |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 972 | (add + name,) + self._subst_prefix) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 973 | def tag_config(self, tagName, cnf={}): |
| 974 | apply(self.tk.call, |
| 975 | (self._w, 'tag', 'configure', tagName) |
| 976 | + self._options(cnf)) |
| 977 | def tag_delete(self, tagNames): |
| 978 | apply(self.tk.call, (self._w, 'tag', 'delete') |
| 979 | + tagNames) |
| 980 | def tag_lower(self, tagName, belowThis=None): |
| 981 | self.tk.call(self._w, 'tag', 'lower', |
| 982 | tagName, belowThis) |
| 983 | def tag_names(self, index=None): |
| 984 | return self.tk.splitlist( |
| 985 | self.tk.call(self._w, 'tag', 'names', index)) |
| 986 | def tag_nextrange(self, tagName, index1, index2=None): |
| 987 | return self.tk.splitlist(self.tk.call( |
| 988 | self._w, 'tag', 'nextrange', index1, index2)) |
| 989 | def tag_raise(self, tagName, aboveThis=None): |
| 990 | self.tk.call( |
| 991 | self._w, 'tag', 'raise', tagName, aboveThis) |
| 992 | def tag_ranges(self, tagName): |
| 993 | return self.tk.splitlist(self.tk.call( |
| 994 | self._w, 'tag', 'ranges', tagName)) |
| 995 | def tag_remove(self, tagName, index1, index2=None): |
| 996 | self.tk.call( |
| 997 | self._w, 'tag', 'remove', index1, index2) |
| 998 | def yview(self, what): |
| 999 | self.tk.call(self._w, 'yview', what) |
| 1000 | def yview_pickplace(self, what): |
| 1001 | self.tk.call(self._w, 'yview', '-pickplace', what) |
| 1002 | |
| 1003 | #class Dialog: |
| 1004 | |