blob: cfc92e108b76958c1ef8f46f7d6093d9aa9fde31 [file] [log] [blame]
Guido van Rossum18468821994-06-20 07:49:28 +00001# Tkinter.py -- Tk/Tcl widget wrappers
2import tkinter
3from tkinter import TclError
4
5class _Dummy:
6 def meth(self): return
7
8def _isfunctype(func):
Guido van Rossum08a40381994-06-21 11:44:21 +00009 return type(func) in CallableTypes
Guido van Rossum18468821994-06-20 07:49:28 +000010
11FunctionType = type(_isfunctype)
12ClassType = type(_Dummy)
13MethodType = type(_Dummy.meth)
Guido van Rossum08a40381994-06-21 11:44:21 +000014StringType = type('')
Guido van Rossum67ef5f31994-06-20 13:39:14 +000015TupleType = type(())
16ListType = type([])
Guido van Rossum08a40381994-06-21 11:44:21 +000017CallableTypes = (FunctionType, MethodType)
Guido van Rossum18468821994-06-20 07:49:28 +000018
Guido van Rossumaec5dc91994-06-27 07:55:12 +000019_default_root = None
20
Guido van Rossum45853db1994-06-20 12:19:19 +000021def _tkerror(err):
Guido van Rossum18468821994-06-20 07:49:28 +000022 pass
23
24class Event:
25 pass
26
Guido van Rossumaec5dc91994-06-27 07:55:12 +000027_varnum = 0
28class Variable:
29 def __init__(self, master=None):
30 global _default_root
31 global _varnum
32 if master:
33 self._tk = master.tk
34 else:
35 self._tk = _default_root.tk
36 self._name = 'PY_VAR' + `_varnum`
37 _varnum = _varnum + 1
38 def __del__(self):
39 self._tk.unsetvar(self._name)
40 def __str__(self):
41 return self._name
42 def __call__(self, value=None):
43 if value == None:
44 return self.get()
45 else:
46 self.set(value)
47 def set(self, value):
48 return self._tk.setvar(self._name, value)
49
50class StringVar(Variable):
51 def __init__(self, master=None):
52 Variable.__init__(self, master)
53 def get(self):
54 return self._tk.getvar(self._name)
55
56class IntVar(Variable):
57 def __init__(self, master=None):
58 Variable.__init__(self, master)
59 def get(self):
60 return self._tk.getint(self._tk.getvar(self._name))
61
62class DoubleVar(Variable):
63 def __init__(self, master=None):
64 Variable.__init__(self, master)
65 def get(self):
66 return self._tk.getdouble(self._tk.getvar(self._name))
67
68class BooleanVar(Variable):
69 def __init__(self, master=None):
70 Variable.__init__(self, master)
71 def get(self):
72 return self._tk.getboolean(self._tk.getvar(self._name))
73
Guido van Rossum18468821994-06-20 07:49:28 +000074class Misc:
75 def tk_strictMotif(self, boolean=None):
76 self.tk.getboolean(self.tk.call(
77 'set', 'tk_strictMotif', boolean))
Guido van Rossumaec5dc91994-06-27 07:55:12 +000078 def tk_menuBar(self, *args):
79 apply(self.tk.call, ('tk_menuBar', self._w) + args)
80 def waitvar(self, name='PY_VAR'):
Guido van Rossum18468821994-06-20 07:49:28 +000081 self.tk.call('tkwait', 'variable', name)
Guido van Rossum9beb9321994-06-27 23:15:31 +000082 wait_variable = waitvar
83 def wait_window(self, window=None):
84 if window == None:
85 window = self
86 self.tk.call('tkwait', 'window', window._w)
87 def wait_visibility(self, window=None):
88 if window == None:
89 window = self
90 self.tk.call('tkwait', 'visibility', window._w)
91
Guido van Rossumaec5dc91994-06-27 07:55:12 +000092 def setvar(self, name='PY_VAR', value='1'):
Guido van Rossum18468821994-06-20 07:49:28 +000093 self.tk.setvar(name, value)
Guido van Rossumaec5dc91994-06-27 07:55:12 +000094 def getvar(self, name='PY_VAR'):
Guido van Rossum5e8d3721994-06-20 08:12:01 +000095 return self.tk.getvar(name)
96 def getint(self, s):
97 return self.tk.getint(s)
Guido van Rossum1e9e4001994-06-20 09:09:51 +000098 def getdouble(self, s):
99 return self.tk.getdouble(s)
100 def getboolean(self, s):
101 return self.tk.getboolean(s)
Guido van Rossum45853db1994-06-20 12:19:19 +0000102 def focus_set(self):
Guido van Rossum18468821994-06-20 07:49:28 +0000103 self.tk.call('focus', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000104 focus = focus_set # XXX b/w compat?
105 def focus_default_set(self):
Guido van Rossum18468821994-06-20 07:49:28 +0000106 self.tk.call('focus', 'default', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000107 def focus_default_none(self):
108 self.tk.call('focus', 'default', 'none')
109 focus_default = focus_default_set
Guido van Rossum18468821994-06-20 07:49:28 +0000110 def focus_none(self):
111 self.tk.call('focus', 'none')
Guido van Rossum45853db1994-06-20 12:19:19 +0000112 def focus_get(self):
113 name = self.tk.call('focus')
114 if name == 'none': return None
115 return self._nametowidget(name)
Guido van Rossum18468821994-06-20 07:49:28 +0000116 def after(self, ms, func=None, *args):
117 if not func:
118 self.tk.call('after', ms)
119 else:
Guido van Rossum08a40381994-06-21 11:44:21 +0000120 # XXX Disgusting hack to clean up after calling func
121 tmp = []
122 def callit(func=func, args=args, tk=self.tk, tmp=tmp):
123 try:
124 apply(func, args)
125 finally:
126 tk.deletecommand(tmp[0])
127 name = self._register(callit)
128 tmp.append(name)
129 self.tk.call('after', ms, name)
Guido van Rossum45853db1994-06-20 12:19:19 +0000130 # XXX grab current w/o window argument
131 def grab_current(self):
132 name = self.tk.call('grab', 'current', self._w)
133 if not name: return None
134 return self._nametowidget(name)
Guido van Rossum18468821994-06-20 07:49:28 +0000135 def grab_release(self):
136 self.tk.call('grab', 'release', self._w)
137 def grab_set(self):
138 self.tk.call('grab', 'set', self._w)
139 def grab_set_global(self):
140 self.tk.call('grab', 'set', '-global', self._w)
141 def grab_status(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000142 status = self.tk.call('grab', 'status', self._w)
143 if status == 'none': status = None
144 return status
Guido van Rossum18468821994-06-20 07:49:28 +0000145 def lower(self, belowThis=None):
146 self.tk.call('lower', self._w, belowThis)
147 def selection_clear(self):
148 self.tk.call('selection', 'clear', self._w)
149 def selection_get(self, type=None):
Guido van Rossumbd84b041994-07-04 10:48:25 +0000150 return self.tk.call('selection', 'get', type)
Guido van Rossum18468821994-06-20 07:49:28 +0000151 def selection_handle(self, func, type=None, format=None):
152 name = self._register(func)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000153 self.tk.call('selection', 'handle', self._w,
154 name, type, format)
155 def selection_own(self, func=None):
156 name = self._register(func)
157 self.tk.call('selection', 'own', self._w, name)
158 def selection_own_get(self):
159 return self._nametowidget(self.tk.call('selection', 'own'))
160 def send(self, interp, cmd, *args):
Guido van Rossum18468821994-06-20 07:49:28 +0000161 return apply(self.tk.call, ('send', interp, cmd) + args)
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000162 def lower(self, belowThis=None):
163 self.tk.call('lift', self._w, belowThis)
164 def tkraise(self, aboveThis=None):
165 self.tk.call('raise', self._w, aboveThis)
166 lift = tkraise
Guido van Rossum18468821994-06-20 07:49:28 +0000167 def colormodel(self, value=None):
168 return self.tk.call('tk', 'colormodel', self._w, value)
169 def winfo_atom(self, name):
170 return self.tk.getint(self.tk.call('winfo', 'atom', name))
171 def winfo_atomname(self, id):
172 return self.tk.call('winfo', 'atomname', id)
173 def winfo_cells(self):
174 return self.tk.getint(
175 self.tk.call('winfo', 'cells', self._w))
Guido van Rossum45853db1994-06-20 12:19:19 +0000176 def winfo_children(self):
177 return map(self._nametowidget,
178 self.tk.splitlist(self.tk.call(
179 'winfo', 'children', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000180 def winfo_class(self):
181 return self.tk.call('winfo', 'class', self._w)
182 def winfo_containing(self, rootX, rootY):
183 return self.tk.call('winfo', 'containing', rootx, rootY)
184 def winfo_depth(self):
185 return self.tk.getint(self.tk.call('winfo', 'depth', self._w))
186 def winfo_exists(self):
187 return self.tk.getint(
188 self.tk.call('winfo', 'exists', self._w))
189 def winfo_fpixels(self, number):
190 return self.tk.getdouble(self.tk.call(
191 'winfo', 'fpixels', self._w, number))
192 def winfo_geometry(self):
193 return self.tk.call('winfo', 'geometry', self._w)
194 def winfo_height(self):
195 return self.tk.getint(
196 self.tk.call('winfo', 'height', self._w))
197 def winfo_id(self):
198 return self.tk.getint(
199 self.tk.call('winfo', 'id', self._w))
200 def winfo_interps(self):
201 return self.tk.splitlist(
202 self.tk.call('winfo', 'interps'))
203 def winfo_ismapped(self):
204 return self.tk.getint(
205 self.tk.call('winfo', 'ismapped', self._w))
206 def winfo_name(self):
207 return self.tk.call('winfo', 'name', self._w)
208 def winfo_parent(self):
209 return self.tk.call('winfo', 'parent', self._w)
210 def winfo_pathname(self, id):
211 return self.tk.call('winfo', 'pathname', id)
212 def winfo_pixels(self, number):
213 return self.tk.getint(
214 self.tk.call('winfo', 'pixels', self._w, number))
215 def winfo_reqheight(self):
216 return self.tk.getint(
217 self.tk.call('winfo', 'reqheight', self._w))
218 def winfo_reqwidth(self):
219 return self.tk.getint(
220 self.tk.call('winfo', 'reqwidth', self._w))
221 def winfo_rgb(self, color):
222 return self._getints(
223 self.tk.call('winfo', 'rgb', self._w, color))
224 def winfo_rootx(self):
225 return self.tk.getint(
226 self.tk.call('winfo', 'rootx', self._w))
227 def winfo_rooty(self):
228 return self.tk.getint(
229 self.tk.call('winfo', 'rooty', self._w))
230 def winfo_screen(self):
231 return self.tk.call('winfo', 'screen', self._w)
232 def winfo_screencells(self):
233 return self.tk.getint(
234 self.tk.call('winfo', 'screencells', self._w))
235 def winfo_screendepth(self):
236 return self.tk.getint(
237 self.tk.call('winfo', 'screendepth', self._w))
238 def winfo_screenheight(self):
239 return self.tk.getint(
240 self.tk.call('winfo', 'screenheight', self._w))
241 def winfo_screenmmheight(self):
242 return self.tk.getint(
243 self.tk.call('winfo', 'screenmmheight', self._w))
244 def winfo_screenmmwidth(self):
245 return self.tk.getint(
246 self.tk.call('winfo', 'screenmmwidth', self._w))
247 def winfo_screenvisual(self):
248 return self.tk.call('winfo', 'screenvisual', self._w)
249 def winfo_screenwidth(self):
250 return self.tk.getint(
251 self.tk.call('winfo', 'screenwidth', self._w))
252 def winfo_toplevel(self):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000253 return self._nametowidget(self.tk.call(
254 'winfo', 'toplevel', self._w))
Guido van Rossum18468821994-06-20 07:49:28 +0000255 def winfo_visual(self):
256 return self.tk.call('winfo', 'visual', self._w)
257 def winfo_vrootheight(self):
258 return self.tk.getint(
259 self.tk.call('winfo', 'vrootheight', self._w))
260 def winfo_vrootwidth(self):
261 return self.tk.getint(
262 self.tk.call('winfo', 'vrootwidth', self._w))
263 def winfo_vrootx(self):
264 return self.tk.getint(
265 self.tk.call('winfo', 'vrootx', self._w))
266 def winfo_vrooty(self):
267 return self.tk.getint(
268 self.tk.call('winfo', 'vrooty', self._w))
269 def winfo_width(self):
270 return self.tk.getint(
271 self.tk.call('winfo', 'width', self._w))
272 def winfo_x(self):
273 return self.tk.getint(
274 self.tk.call('winfo', 'x', self._w))
275 def winfo_y(self):
276 return self.tk.getint(
277 self.tk.call('winfo', 'y', self._w))
278 def update(self):
279 self.tk.call('update')
280 def update_idletasks(self):
281 self.tk.call('update', 'idletasks')
282 def bind(self, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000283 if add: add = '+'
Guido van Rossum45853db1994-06-20 12:19:19 +0000284 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +0000285 self.tk.call('bind', self._w, sequence,
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000286 (add + name,) + self._subst_format)
Guido van Rossum18468821994-06-20 07:49:28 +0000287 def bind_all(self, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000288 if add: add = '+'
Guido van Rossum45853db1994-06-20 12:19:19 +0000289 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +0000290 self.tk.call('bind', 'all' , sequence,
Guido van Rossumbd84b041994-07-04 10:48:25 +0000291 (add + name,) + self._subst_format)
Guido van Rossum18468821994-06-20 07:49:28 +0000292 def bind_class(self, className, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000293 if add: add = '+'
Guido van Rossum45853db1994-06-20 12:19:19 +0000294 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +0000295 self.tk.call('bind', className , sequence,
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000296 (add + name,) + self._subst_format)
Guido van Rossum18468821994-06-20 07:49:28 +0000297 def mainloop(self):
298 self.tk.mainloop()
299 def quit(self):
300 self.tk.quit()
301 # Utilities
302 def _getints(self, string):
Guido van Rossum45853db1994-06-20 12:19:19 +0000303 if not string: return None
304 res = ()
305 for v in self.tk.splitlist(string):
306 res = res + (self.tk.getint(v),)
307 return res
Guido van Rossum18468821994-06-20 07:49:28 +0000308 def _getboolean(self, string):
309 if string:
310 return self.tk.getboolean(string)
Guido van Rossum1e9e4001994-06-20 09:09:51 +0000311 # else return None
Guido van Rossum18468821994-06-20 07:49:28 +0000312 def _options(self, cnf):
313 res = ()
314 for k, v in cnf.items():
315 if _isfunctype(v):
316 v = self._register(v)
317 res = res + ('-'+k, v)
318 return res
Guido van Rossum45853db1994-06-20 12:19:19 +0000319 def _nametowidget(self, name):
320 w = self
321 if name[0] == '.':
322 w = w._root()
323 name = name[1:]
324 from string import find
325 while name:
326 i = find(name, '.')
327 if i >= 0:
328 name, tail = name[:i], name[i+1:]
329 else:
330 tail = ''
331 w = w.children[name]
332 name = tail
333 return w
Guido van Rossum18468821994-06-20 07:49:28 +0000334 def _register(self, func, subst=None):
Guido van Rossum18468821994-06-20 07:49:28 +0000335 f = _CallSafely(func, subst).__call__
336 name = `id(f)`
337 if hasattr(func, 'im_func'):
338 func = func.im_func
339 if hasattr(func, 'func_name') and \
340 type(func.func_name) == type(''):
341 name = name + func.func_name
342 self.tk.createcommand(name, f)
343 return name
Guido van Rossum9beb9321994-06-27 23:15:31 +0000344 register = _register
Guido van Rossum45853db1994-06-20 12:19:19 +0000345 def _root(self):
346 w = self
347 while w.master: w = w.master
348 return w
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000349 _subst_format = ('%#', '%b', '%f', '%h', '%k',
Guido van Rossum45853db1994-06-20 12:19:19 +0000350 '%s', '%t', '%w', '%x', '%y',
351 '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y')
352 def _substitute(self, *args):
353 tk = self.tk
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000354 if len(args) != len(self._subst_format): return args
Guido van Rossum45853db1994-06-20 12:19:19 +0000355 nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args
356 # Missing: (a, c, d, m, o, v, B, R)
357 e = Event()
358 e.serial = tk.getint(nsign)
359 e.num = tk.getint(b)
360 try: e.focus = tk.getboolean(f)
361 except TclError: pass
362 e.height = tk.getint(h)
363 e.keycode = tk.getint(k)
364 e.state = tk.getint(s)
365 e.time = tk.getint(t)
366 e.width = tk.getint(w)
367 e.x = tk.getint(x)
368 e.y = tk.getint(y)
369 e.char = A
370 try: e.send_event = tk.getboolean(E)
371 except TclError: pass
372 e.keysym = K
373 e.keysym_num = tk.getint(N)
374 e.type = T
375 e.widget = self._nametowidget(W)
376 e.x_root = tk.getint(X)
377 e.y_root = tk.getint(Y)
378 return (e,)
Guido van Rossum18468821994-06-20 07:49:28 +0000379
380class _CallSafely:
381 def __init__(self, func, subst=None):
382 self.func = func
383 self.subst = subst
384 def __call__(self, *args):
385 if self.subst:
386 args = self.apply_func(self.subst, args)
387 args = self.apply_func(self.func, args)
388 def apply_func(self, func, args):
389 import sys
390 try:
391 return apply(func, args)
Guido van Rossum45853db1994-06-20 12:19:19 +0000392 except SystemExit, msg:
393 raise SystemExit, msg
Guido van Rossum18468821994-06-20 07:49:28 +0000394 except:
395 try:
396 try:
397 t = sys.exc_traceback
398 while t:
399 sys.stderr.write(
400 ' %s, line %s\n' %
401 (t.tb_frame.f_code,
402 t.tb_lineno))
403 t = t.tb_next
404 finally:
405 sys.stderr.write('%s: %s\n' %
406 (sys.exc_type,
407 sys.exc_value))
Guido van Rossum45853db1994-06-20 12:19:19 +0000408 (sys.last_type,
409 sys.last_value,
410 sys.last_traceback) = (sys.exc_type,
411 sys.exc_value,
412 sys.exc_traceback)
413 import pdb
414 pdb.pm()
Guido van Rossum18468821994-06-20 07:49:28 +0000415 except:
416 print '*** Error in error handling ***'
417 print sys.exc_type, ':', sys.exc_value
418
419class Wm:
420 def aspect(self,
421 minNumer=None, minDenom=None,
422 maxNumer=None, maxDenom=None):
423 return self._getints(
424 self.tk.call('wm', 'aspect', self._w,
425 minNumer, minDenom,
426 maxNumer, maxDenom))
427 def client(self, name=None):
428 return self.tk.call('wm', 'client', self._w, name)
429 def command(self, value=None):
430 return self.tk.call('wm', 'command', self._w, value)
431 def deiconify(self):
432 return self.tk.call('wm', 'deiconify', self._w)
433 def focusmodel(self, model=None):
434 return self.tk.call('wm', 'focusmodel', self._w, model)
435 def frame(self):
436 return self.tk.call('wm', 'frame', self._w)
437 def geometry(self, newGeometry=None):
438 return self.tk.call('wm', 'geometry', self._w, newGeometry)
439 def grid(self,
440 baseWidht=None, baseHeight=None,
441 widthInc=None, heightInc=None):
442 return self._getints(self.tk.call(
443 'wm', 'grid', self._w,
444 baseWidht, baseHeight, widthInc, heightInc))
445 def group(self, pathName=None):
446 return self.tk.call('wm', 'group', self._w, pathName)
447 def iconbitmap(self, bitmap=None):
448 return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
449 def iconify(self):
450 return self.tk.call('wm', 'iconify', self._w)
451 def iconmask(self, bitmap=None):
452 return self.tk.call('wm', 'iconmask', self._w, bitmap)
453 def iconname(self, newName=None):
454 return self.tk.call('wm', 'iconname', self._w, newName)
455 def iconposition(self, x=None, y=None):
456 return self._getints(self.tk.call(
457 'wm', 'iconposition', self._w, x, y))
458 def iconwindow(self, pathName=None):
459 return self.tk.call('wm', 'iconwindow', self._w, pathName)
460 def maxsize(self, width=None, height=None):
461 return self._getints(self.tk.call(
462 'wm', 'maxsize', self._w, width, height))
463 def minsize(self, width=None, height=None):
464 return self._getints(self.tk.call(
465 'wm', 'minsize', self._w, width, height))
466 def overrideredirect(self, boolean=None):
467 return self._getboolean(self.tk.call(
468 'wm', 'overrideredirect', self._w, boolean))
469 def positionfrom(self, who=None):
470 return self.tk.call('wm', 'positionfrom', self._w, who)
471 def protocol(self, name=None, func=None):
472 if _isfunctype(func):
473 command = self._register(func)
474 else:
475 command = func
476 return self.tk.call(
477 'wm', 'protocol', self._w, name, command)
478 def sizefrom(self, who=None):
479 return self.tk.call('wm', 'sizefrom', self._w, who)
480 def state(self):
481 return self.tk.call('wm', 'state', self._w)
482 def title(self, string=None):
483 return self.tk.call('wm', 'title', self._w, string)
484 def transient(self, master=None):
485 return self.tk.call('wm', 'transient', self._w, master)
486 def withdraw(self):
487 return self.tk.call('wm', 'withdraw', self._w)
488
489class Tk(Misc, Wm):
490 _w = '.'
491 def __init__(self, screenName=None, baseName=None, className='Tk'):
Guido van Rossum45853db1994-06-20 12:19:19 +0000492 self.master = None
493 self.children = {}
Guido van Rossum18468821994-06-20 07:49:28 +0000494 if baseName is None:
495 import sys, os
496 baseName = os.path.basename(sys.argv[0])
497 if baseName[-3:] == '.py': baseName = baseName[:-3]
498 self.tk = tkinter.create(screenName, baseName, className)
Guido van Rossum45853db1994-06-20 12:19:19 +0000499 self.tk.createcommand('tkerror', _tkerror)
500 def destroy(self):
501 for c in self.children.values(): c.destroy()
Guido van Rossumbd84b041994-07-04 10:48:25 +0000502## del self.master.children[self._name]
Guido van Rossum45853db1994-06-20 12:19:19 +0000503 self.tk.call('destroy', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000504 def __str__(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000505 return self._w
Guido van Rossum18468821994-06-20 07:49:28 +0000506
507class Pack:
508 def config(self, cnf={}):
509 apply(self.tk.call,
510 ('pack', 'configure', self._w)
511 + self._options(cnf))
512 pack = config
513 def __setitem__(self, key, value):
514 Pack.config({key: value})
515 def forget(self):
516 self.tk.call('pack', 'forget', self._w)
517 def newinfo(self):
518 return self.tk.call('pack', 'newinfo', self._w)
519 info = newinfo
520 def propagate(self, boolean=None):
521 if boolean:
522 self.tk.call('pack', 'propagate', self._w)
523 else:
524 return self._getboolean(self.tk.call(
525 'pack', 'propagate', self._w))
526 def slaves(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000527 return map(self._nametowidget,
528 self.tk.splitlist(
529 self.tk.call('pack', 'slaves', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000530
531class Place:
532 def config(self, cnf={}):
533 apply(self.tk.call,
534 ('place', 'configure', self._w)
535 + self._options(cnf))
536 place = config
537 def __setitem__(self, key, value):
538 Place.config({key: value})
539 def forget(self):
540 self.tk.call('place', 'forget', self._w)
541 def info(self):
542 return self.tk.call('place', 'info', self._w)
543 def slaves(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000544 return map(self._nametowidget,
545 self.tk.splitlist(
546 self.tk.call(
547 'place', 'slaves', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000548
Guido van Rossum18468821994-06-20 07:49:28 +0000549class Widget(Misc, Pack, Place):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000550 def _setup(self, master, cnf):
Guido van Rossum45853db1994-06-20 12:19:19 +0000551 global _default_root
Guido van Rossum18468821994-06-20 07:49:28 +0000552 if not master:
Guido van Rossum45853db1994-06-20 12:19:19 +0000553 if not _default_root:
554 _default_root = Tk()
555 master = _default_root
556 if not _default_root:
557 _default_root = master
Guido van Rossum18468821994-06-20 07:49:28 +0000558 self.master = master
559 self.tk = master.tk
560 if cnf.has_key('name'):
561 name = cnf['name']
562 del cnf['name']
563 else:
564 name = `id(self)`
Guido van Rossum45853db1994-06-20 12:19:19 +0000565 self._name = name
Guido van Rossum18468821994-06-20 07:49:28 +0000566 if master._w=='.':
567 self._w = '.' + name
568 else:
569 self._w = master._w + '.' + name
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000570 self.children = {}
571 if self.master.children.has_key(self._name):
572 self.master.children[self._name].destroy()
573 self.master.children[self._name] = self
574 def __init__(self, master, widgetName, cnf={}, extra=()):
575 Widget._setup(self, master, cnf)
Guido van Rossum18468821994-06-20 07:49:28 +0000576 self.widgetName = widgetName
577 apply(self.tk.call, (widgetName, self._w) + extra)
578 Widget.config(self, cnf)
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000579 def config(self, cnf=None):
580 if cnf is None:
581 cnf = {}
582 for x in self.tk.split(
583 self.tk.call(self._w, 'configure')):
584 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
585 return cnf
586 if type(cnf) == StringType:
587 x = self.tk.split(self.tk.call(
588 self._w, 'configure', '-'+cnf))
589 return (x[0][1:],) + x[1:]
Guido van Rossum18468821994-06-20 07:49:28 +0000590 for k in cnf.keys():
591 if type(k) == ClassType:
592 k.config(self, cnf[k])
593 del cnf[k]
594 apply(self.tk.call, (self._w, 'configure')
595 + self._options(cnf))
596 def __getitem__(self, key):
Guido van Rossum535cf0c1994-06-27 07:55:59 +0000597 v = self.tk.splitlist(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +0000598 self._w, 'configure', '-' + key))
599 return v[4]
600 def __setitem__(self, key, value):
601 Widget.config(self, {key: value})
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000602 def keys(self):
603 return map(lambda x: x[0][1:],
604 self.tk.split(self.tk.call(self._w, 'configure')))
Guido van Rossum18468821994-06-20 07:49:28 +0000605 def __str__(self):
606 return self._w
Guido van Rossum45853db1994-06-20 12:19:19 +0000607 def destroy(self):
608 for c in self.children.values(): c.destroy()
609 del self.master.children[self._name]
Guido van Rossum18468821994-06-20 07:49:28 +0000610 self.tk.call('destroy', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000611 def _do(self, name, args=()):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000612 return apply(self.tk.call, (self._w, name) + args)
Guido van Rossum18468821994-06-20 07:49:28 +0000613
614class Toplevel(Widget, Wm):
615 def __init__(self, master=None, cnf={}):
616 extra = ()
617 if cnf.has_key('screen'):
618 extra = ('-screen', cnf['screen'])
619 del cnf['screen']
620 if cnf.has_key('class'):
621 extra = extra + ('-class', cnf['class'])
622 del cnf['class']
623 Widget.__init__(self, master, 'toplevel', cnf, extra)
Guido van Rossum45853db1994-06-20 12:19:19 +0000624 root = self._root()
625 self.iconname(root.iconname())
626 self.title(root.title())
Guido van Rossum18468821994-06-20 07:49:28 +0000627
628class Button(Widget):
629 def __init__(self, master=None, cnf={}):
630 Widget.__init__(self, master, 'button', cnf)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000631 def tk_butEnter(self, *dummy):
Guido van Rossum18468821994-06-20 07:49:28 +0000632 self.tk.call('tk_butEnter', self._w)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000633 def tk_butLeave(self, *dummy):
Guido van Rossum18468821994-06-20 07:49:28 +0000634 self.tk.call('tk_butLeave', self._w)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000635 def tk_butDown(self, *dummy):
Guido van Rossum18468821994-06-20 07:49:28 +0000636 self.tk.call('tk_butDown', self._w)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000637 def tk_butUp(self, *dummy):
Guido van Rossum18468821994-06-20 07:49:28 +0000638 self.tk.call('tk_butUp', self._w)
639 def flash(self):
640 self.tk.call(self._w, 'flash')
641 def invoke(self):
642 self.tk.call(self._w, 'invoke')
643
644# Indices:
645def AtEnd():
646 return 'end'
Guido van Rossum1e9e4001994-06-20 09:09:51 +0000647def AtInsert(*args):
648 s = 'insert'
649 for a in args:
650 if a: s = s + (' ' + a)
651 return s
Guido van Rossum18468821994-06-20 07:49:28 +0000652def AtSelFirst():
653 return 'sel.first'
654def AtSelLast():
655 return 'sel.last'
656def At(x, y=None):
657 if y:
658 return '@' + `x` + ',' + `y`
659 else:
660 return '@' + `x`
661
662class Canvas(Widget):
663 def __init__(self, master=None, cnf={}):
664 Widget.__init__(self, master, 'canvas', cnf)
665 def addtag(self, *args):
666 self._do('addtag', args)
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000667 def addtag_above(self, tagOrId):
668 self.addtag('above', tagOrId)
669 def addtag_all(self):
670 self.addtag('all')
671 def addtag_below(self, tagOrId):
672 self.addtag('below', tagOrId)
673 def addtag_closest(self, x, y, halo=None, start=None):
674 self.addtag('closest', x, y, halo, start)
675 def addtag_enclosed(self, x1, y1, x2, y2):
676 self.addtag('enclosed', x1, y1, x2, y2)
677 def addtag_overlapping(self, x1, y1, x2, y2):
678 self.addtag('overlapping', x1, y1, x2, y2)
679 def addtag_withtag(self, tagOrId):
680 self.addtag('withtag', tagOrId)
Guido van Rossum18468821994-06-20 07:49:28 +0000681 def bbox(self, *args):
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000682 return self._getints(self._do('bbox', args)) or None
Guido van Rossum18468821994-06-20 07:49:28 +0000683 def bind(self, tagOrId, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000684 if add: add='+'
Guido van Rossum45853db1994-06-20 12:19:19 +0000685 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +0000686 self.tk.call(self._w, 'bind', tagOrId, sequence,
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000687 (add + name,) + self._subst_format)
Guido van Rossum18468821994-06-20 07:49:28 +0000688 def canvasx(self, screenx, gridspacing=None):
689 return self.tk.getint(self.tk.call(
690 self._w, 'canvasx', screenx, gridspacing))
691 def canvasy(self, screeny, gridspacing=None):
692 return self.tk.getint(self.tk.call(
693 self._w, 'canvasy', screeny, gridspacing))
694 def coords(self, *args):
695 return self._do('coords', args)
696 def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
Guido van Rossum08a40381994-06-21 11:44:21 +0000697 args = _flatten(args)
Guido van Rossum18468821994-06-20 07:49:28 +0000698 cnf = args[-1]
699 if type(cnf) == type({}):
700 args = args[:-1]
701 else:
702 cnf = {}
Guido van Rossum08a40381994-06-21 11:44:21 +0000703 v = (self._w, 'create', itemType) + args
Guido van Rossum18468821994-06-20 07:49:28 +0000704 for k in cnf.keys():
705 v = v + ('-' + k, cnf[k])
706 return self.tk.getint(apply(self.tk.call, v))
707 def create_arc(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000708 return Canvas._create(self, 'arc', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000709 def create_bitmap(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000710 return Canvas._create(self, 'bitmap', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000711 def create_line(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000712 return Canvas._create(self, 'line', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000713 def create_oval(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000714 return Canvas._create(self, 'oval', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000715 def create_polygon(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000716 return Canvas._create(self, 'polygon', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000717 def create_rectangle(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000718 return Canvas._create(self, 'rectangle', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000719 def create_text(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000720 return Canvas._create(self, 'text', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000721 def create_window(self, *args):
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000722 return Canvas._create(self, 'window', args)
Guido van Rossum18468821994-06-20 07:49:28 +0000723 def dchars(self, *args):
724 self._do('dchars', args)
725 def delete(self, *args):
726 self._do('delete', args)
727 def dtag(self, *args):
728 self._do('dtag', args)
729 def find(self, *args):
Guido van Rossum08a40381994-06-21 11:44:21 +0000730 return self._getints(self._do('find', args))
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000731 def find_above(self, tagOrId):
732 return self.find('above', tagOrId)
733 def find_all(self):
734 return self.find('all')
735 def find_below(self, tagOrId):
736 return self.find('below', tagOrId)
737 def find_closest(self, x, y, halo=None, start=None):
738 return self.find('closest', x, y, halo, start)
739 def find_enclosed(self, x1, y1, x2, y2):
740 return self.find('enclosed', x1, y1, x2, y2)
741 def find_overlapping(self, x1, y1, x2, y2):
742 return self.find('overlapping', x1, y1, x2, y2)
743 def find_withtag(self, tagOrId):
744 return self.find('withtag', tagOrId)
Guido van Rossum18468821994-06-20 07:49:28 +0000745 def focus(self, *args):
746 return self._do('focus', args)
747 def gettags(self, *args):
748 return self.tk.splitlist(self._do('gettags', args))
749 def icursor(self, *args):
750 self._do('icursor', args)
751 def index(self, *args):
752 return self.tk.getint(self._do('index', args))
753 def insert(self, *args):
754 self._do('insert', args)
Guido van Rossum08a40381994-06-21 11:44:21 +0000755 def itemconfig(self, tagOrId, cnf=None):
756 if cnf is None:
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000757 cnf = {}
758 for x in self.tk.split(
759 self._do('itemconfigure', (tagOrId))):
760 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
761 return cnf
Guido van Rossum08a40381994-06-21 11:44:21 +0000762 if type(cnf) == StringType:
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000763 x = self.tk.split(self._do('itemconfigure',
764 (tagOrId, '-'+cnf,)))
765 return (x[0][1:],) + x[1:]
Guido van Rossum18468821994-06-20 07:49:28 +0000766 self._do('itemconfigure', (tagOrId,) + self._options(cnf))
767 def lower(self, *args):
768 self._do('lower', args)
769 def move(self, *args):
770 self._do('move', args)
771 def postscript(self, cnf={}):
772 return self._do('postscript', self._options(cnf))
773 def tkraise(self, *args):
774 self._do('raise', args)
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000775 lift = tkraise
Guido van Rossum18468821994-06-20 07:49:28 +0000776 def scale(self, *args):
777 self._do('scale', args)
778 def scan_mark(self, x, y):
779 self.tk.call(self._w, 'scan', 'mark', x, y)
780 def scan_dragto(self, x, y):
781 self.tk.call(self._w, 'scan', 'dragto', x, y)
782 def select_adjust(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +0000783 self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +0000784 def select_clear(self):
785 self.tk.call(self._w, 'select', 'clear')
786 def select_from(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +0000787 self.tk.call(self._w, 'select', 'from', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +0000788 def select_item(self):
789 self.tk.call(self._w, 'select', 'item')
790 def select_to(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +0000791 self.tk.call(self._w, 'select', 'to', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +0000792 def type(self, tagOrId):
Guido van Rossum08a40381994-06-21 11:44:21 +0000793 return self.tk.call(self._w, 'type', tagOrId) or None
Guido van Rossum18468821994-06-20 07:49:28 +0000794 def xview(self, index):
795 self.tk.call(self._w, 'xview', index)
796 def yview(self, index):
797 self.tk.call(self._w, 'yview', index)
798
Guido van Rossum67ef5f31994-06-20 13:39:14 +0000799def _flatten(tuple):
800 res = ()
801 for item in tuple:
802 if type(item) in (TupleType, ListType):
803 res = res + _flatten(item)
804 else:
805 res = res + (item,)
806 return res
807
Guido van Rossum18468821994-06-20 07:49:28 +0000808class Checkbutton(Widget):
809 def __init__(self, master=None, cnf={}):
810 Widget.__init__(self, master, 'checkbutton', cnf)
811 def deselect(self):
812 self.tk.call(self._w, 'deselect')
813 def flash(self):
814 self.tk.call(self._w, 'flash')
815 def invoke(self):
816 self.tk.call(self._w, 'invoke')
817 def select(self):
818 self.tk.call(self._w, 'select')
819 def toggle(self):
820 self.tk.call(self._w, 'toggle')
821
822class Entry(Widget):
823 def __init__(self, master=None, cnf={}):
824 Widget.__init__(self, master, 'entry', cnf)
825 def tk_entryBackspace(self):
826 self.tk.call('tk_entryBackspace', self._w)
827 def tk_entryBackword(self):
828 self.tk.call('tk_entryBackword', self._w)
829 def tk_entrySeeCaret(self):
830 self.tk.call('tk_entrySeeCaret', self._w)
831 def delete(self, first, last=None):
832 self.tk.call(self._w, 'delete', first, last)
833 def get(self):
834 return self.tk.call(self._w, 'get')
835 def icursor(self, index):
836 self.tk.call(self._w, 'icursor', index)
837 def index(self, index):
838 return self.tk.getint(self.tk.call(
839 self._w, 'index', index))
840 def insert(self, index, string):
841 self.tk.call(self._w, 'insert', index, string)
842 def scan_mark(self, x):
843 self.tk.call(self._w, 'scan', 'mark', x)
844 def scan_dragto(self, x):
845 self.tk.call(self._w, 'scan', 'dragto', x)
846 def select_adjust(self, index):
847 self.tk.call(self._w, 'select', 'adjust', index)
848 def select_clear(self):
849 self.tk.call(self._w, 'select', 'clear')
850 def select_from(self, index):
851 self.tk.call(self._w, 'select', 'from', index)
852 def select_to(self, index):
853 self.tk.call(self._w, 'select', 'to', index)
854 def select_view(self, index):
855 self.tk.call(self._w, 'select', 'view', index)
856
857class Frame(Widget):
858 def __init__(self, master=None, cnf={}):
859 extra = ()
860 if cnf.has_key('class'):
861 extra = ('-class', cnf['class'])
862 del cnf['class']
863 Widget.__init__(self, master, 'frame', cnf, extra)
864 def tk_menuBar(self, *args):
865 apply(self.tk.call, ('tk_menuBar', self._w) + args)
866
867class Label(Widget):
868 def __init__(self, master=None, cnf={}):
869 Widget.__init__(self, master, 'label', cnf)
870
871class Listbox(Widget):
872 def __init__(self, master=None, cnf={}):
873 Widget.__init__(self, master, 'listbox', cnf)
874 def tk_listboxSingleSelect(self):
875 self.tk.call('tk_listboxSingleSelect', self._w)
876 def curselection(self):
877 return self.tk.splitlist(self.tk.call(
878 self._w, 'curselection'))
879 def delete(self, first, last=None):
880 self.tk.call(self._w, 'delete', first, last)
881 def get(self, index):
882 return self.tk.call(self._w, 'get', index)
883 def insert(self, index, *elements):
884 apply(self.tk.call,
885 (self._w, 'insert', index) + elements)
886 def nearest(self, y):
887 return self.tk.getint(self.tk.call(
888 self._w, 'nearest', y))
889 def scan_mark(self, x, y):
890 self.tk.call(self._w, 'scan', 'mark', x, y)
891 def scan_dragto(self, x, y):
892 self.tk.call(self._w, 'scan', 'dragto', x, y)
893 def select_adjust(self, index):
894 self.tk.call(self._w, 'select', 'adjust', index)
895 def select_clear(self):
896 self.tk.call(self._w, 'select', 'clear')
897 def select_from(self, index):
898 self.tk.call(self._w, 'select', 'from', index)
899 def select_to(self, index):
900 self.tk.call(self._w, 'select', 'to', index)
901 def size(self):
902 return self.tk.getint(self.tk.call(self._w, 'size'))
903 def xview(self, index):
904 self.tk.call(self._w, 'xview', index)
905 def yview(self, index):
906 self.tk.call(self._w, 'yview', index)
907
908class Menu(Widget):
909 def __init__(self, master=None, cnf={}):
910 Widget.__init__(self, master, 'menu', cnf)
Guido van Rossum18468821994-06-20 07:49:28 +0000911 def tk_bindForTraversal(self):
912 self.tk.call('tk_bindForTraversal', self._w)
913 def tk_mbPost(self):
914 self.tk.call('tk_mbPost', self._w)
915 def tk_mbUnpost(self):
916 self.tk.call('tk_mbUnpost')
917 def tk_traverseToMenu(self, char):
918 self.tk.call('tk_traverseToMenu', self._w, char)
919 def tk_traverseWithinMenu(self, char):
920 self.tk.call('tk_traverseWithinMenu', self._w, char)
921 def tk_getMenuButtons(self):
922 return self.tk.call('tk_getMenuButtons', self._w)
923 def tk_nextMenu(self, count):
924 self.tk.call('tk_nextMenu', count)
925 def tk_nextMenuEntry(self, count):
926 self.tk.call('tk_nextMenuEntry', count)
927 def tk_invokeMenu(self):
928 self.tk.call('tk_invokeMenu', self._w)
929 def tk_firstMenu(self):
930 self.tk.call('tk_firstMenu', self._w)
931 def tk_mbButtonDown(self):
932 self.tk.call('tk_mbButtonDown', self._w)
933 def activate(self, index):
934 self.tk.call(self._w, 'activate', index)
935 def add(self, itemType, cnf={}):
936 apply(self.tk.call, (self._w, 'add', itemType)
937 + self._options(cnf))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000938 def add_cascade(self, cnf={}):
939 self.add('cascade', cnf)
940 def add_checkbutton(self, cnf={}):
941 self.add('checkbutton', cnf)
942 def add_command(self, cnf={}):
943 self.add('command', cnf)
944 def add_radiobutton(self, cnf={}):
945 self.add('radiobutton', cnf)
946 def add_separator(self, cnf={}):
947 self.add('separator', cnf)
Guido van Rossum18468821994-06-20 07:49:28 +0000948 def delete(self, index1, index2=None):
949 self.tk.call(self._w, 'delete', index1, index2)
950 def entryconfig(self, index, cnf={}):
951 apply(self.tk.call, (self._w, 'entryconfigure', index)
952 + self._options(cnf))
953 def index(self, index):
Guido van Rossum535cf0c1994-06-27 07:55:59 +0000954 i = self.tk.call(self._w, 'index', index)
955 if i == 'none': return None
956 return self.tk.getint(i)
Guido van Rossum18468821994-06-20 07:49:28 +0000957 def invoke(self, index):
958 return self.tk.call(self._w, 'invoke', index)
959 def post(self, x, y):
960 self.tk.call(self._w, 'post', x, y)
961 def unpost(self):
962 self.tk.call(self._w, 'unpost')
963 def yposition(self, index):
964 return self.tk.getint(self.tk.call(
965 self._w, 'yposition', index))
966
967class Menubutton(Widget):
968 def __init__(self, master=None, cnf={}):
969 Widget.__init__(self, master, 'menubutton', cnf)
970
971class Message(Widget):
972 def __init__(self, master=None, cnf={}):
973 Widget.__init__(self, master, 'message', cnf)
974
975class Radiobutton(Widget):
976 def __init__(self, master=None, cnf={}):
977 Widget.__init__(self, master, 'radiobutton', cnf)
978 def deselect(self):
979 self.tk.call(self._w, 'deselect')
980 def flash(self):
981 self.tk.call(self._w, 'flash')
982 def invoke(self):
983 self.tk.call(self._w, 'invoke')
984 def select(self):
985 self.tk.call(self._w, 'select')
986
987class Scale(Widget):
988 def __init__(self, master=None, cnf={}):
989 Widget.__init__(self, master, 'scale', cnf)
990 def get(self):
991 return self.tk.getint(self.tk.call(self._w, 'get'))
992 def set(self, value):
993 self.tk.call(self._w, 'set', value)
994
995class Scrollbar(Widget):
996 def __init__(self, master=None, cnf={}):
997 Widget.__init__(self, master, 'scrollbar', cnf)
998 def get(self):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000999 return self._getints(self.tk.call(self._w, 'get'))
Guido van Rossum18468821994-06-20 07:49:28 +00001000 def set(self, totalUnits, windowUnits, firstUnit, lastUnit):
1001 self.tk.call(self._w, 'set',
1002 totalUnits, windowUnits, firstUnit, lastUnit)
1003
1004class Text(Widget):
1005 def __init__(self, master=None, cnf={}):
1006 Widget.__init__(self, master, 'text', cnf)
1007 def tk_textSelectTo(self, index):
1008 self.tk.call('tk_textSelectTo', self._w, index)
1009 def tk_textBackspace(self):
1010 self.tk.call('tk_textBackspace', self._w)
1011 def tk_textIndexCloser(self, a, b, c):
1012 self.tk.call('tk_textIndexCloser', self._w, a, b, c)
1013 def tk_textResetAnchor(self, index):
1014 self.tk.call('tk_textResetAnchor', self._w, index)
1015 def compare(self, index1, op, index2):
1016 return self.tk.getboolean(self.tk.call(
1017 self._w, 'compare', index1, op, index2))
1018 def debug(self, boolean=None):
1019 return self.tk.getboolean(self.tk.call(
1020 self._w, 'debug', boolean))
1021 def delete(self, index1, index2=None):
1022 self.tk.call(self._w, 'delete', index1, index2)
1023 def get(self, index1, index2=None):
1024 return self.tk.call(self._w, 'get', index1, index2)
1025 def index(self, index):
1026 return self.tk.call(self._w, 'index', index)
1027 def insert(self, index, chars):
1028 self.tk.call(self._w, 'insert', index, chars)
1029 def mark_names(self):
1030 return self.tk.splitlist(self.tk.call(
1031 self._w, 'mark', 'names'))
1032 def mark_set(self, markName, index):
1033 self.tk.call(self._w, 'mark', 'set', markName, index)
1034 def mark_unset(self, markNames):
1035 apply(self.tk.call, (self._w, 'mark', 'unset') + markNames)
1036 def scan_mark(self, y):
1037 self.tk.call(self._w, 'scan', 'mark', y)
1038 def scan_dragto(self, y):
1039 self.tk.call(self._w, 'scan', 'dragto', y)
1040 def tag_add(self, tagName, index1, index2=None):
1041 self.tk.call(
1042 self._w, 'tag', 'add', tagName, index1, index2)
1043 def tag_bind(self, tagName, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +00001044 if add: add='+'
Guido van Rossum45853db1994-06-20 12:19:19 +00001045 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +00001046 self.tk.call(self._w, 'tag', 'bind',
1047 tagName, sequence,
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001048 (add + name,) + self._subst_format)
Guido van Rossum18468821994-06-20 07:49:28 +00001049 def tag_config(self, tagName, cnf={}):
1050 apply(self.tk.call,
1051 (self._w, 'tag', 'configure', tagName)
1052 + self._options(cnf))
1053 def tag_delete(self, tagNames):
1054 apply(self.tk.call, (self._w, 'tag', 'delete')
1055 + tagNames)
1056 def tag_lower(self, tagName, belowThis=None):
1057 self.tk.call(self._w, 'tag', 'lower',
1058 tagName, belowThis)
1059 def tag_names(self, index=None):
1060 return self.tk.splitlist(
1061 self.tk.call(self._w, 'tag', 'names', index))
1062 def tag_nextrange(self, tagName, index1, index2=None):
1063 return self.tk.splitlist(self.tk.call(
1064 self._w, 'tag', 'nextrange', index1, index2))
1065 def tag_raise(self, tagName, aboveThis=None):
1066 self.tk.call(
1067 self._w, 'tag', 'raise', tagName, aboveThis)
1068 def tag_ranges(self, tagName):
1069 return self.tk.splitlist(self.tk.call(
1070 self._w, 'tag', 'ranges', tagName))
1071 def tag_remove(self, tagName, index1, index2=None):
1072 self.tk.call(
1073 self._w, 'tag', 'remove', index1, index2)
1074 def yview(self, what):
1075 self.tk.call(self._w, 'yview', what)
1076 def yview_pickplace(self, what):
1077 self.tk.call(self._w, 'yview', '-pickplace', what)
1078
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001079######################################################################
1080# Extensions:
1081
1082class Studbutton(Button):
1083 def __init__(self, master=None, cnf={}):
1084 Widget.__init__(self, master, 'studbutton', cnf)
1085 self.bind('<Any-Enter>', self.tk_butEnter)
1086 self.bind('<Any-Leave>', self.tk_butLeave)
1087 self.bind('<1>', self.tk_butDown)
1088 self.bind('<ButtonRelease-1>', self.tk_butUp)
1089
1090class Tributton(Button):
1091 def __init__(self, master=None, cnf={}):
1092 Widget.__init__(self, master, 'tributton', cnf)
1093 self.bind('<Any-Enter>', self.tk_butEnter)
1094 self.bind('<Any-Leave>', self.tk_butLeave)
1095 self.bind('<1>', self.tk_butDown)
1096 self.bind('<ButtonRelease-1>', self.tk_butUp)
1097