blob: a8c2ea5cca35ccd0e6dc2b6cd605f922cbdda6d8 [file] [log] [blame]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001#
2# $Id$
3#
4# Tix.py -- Tix widget wrappers, part of PyTix.
5#
6# - Sudhir Shenoy (sshenoy@gol.com), Dec. 1995.
7# based on an idea (and a little code !!) of Jean-Marc Lugrin
8# (lugrin@ms.com)
9#
10# NOTE: In order to minimize changes to Tkinter.py, some of the code here
11# (TixWidget.__init__) has been taken from Tkinter (Widget.__init__)
12# and will break if there are major changes in Tkinter.
13#
14# The Tix widgets are represented by a class hierarchy in python with proper
15# inheritance of base classes.
16#
17# As a result after creating a 'w = StdButtonBox', I can write
18# w.ok['text'] = 'Who Cares'
19# or w.ok['bg'] = w['bg']
20# or even w.ok.invoke()
21# etc.
22#
23# Compare the demo tixwidgets.py to the original Tcl program and you will
24# appreciate the advantages.
25#
26
27import string
28from Tkinter import *
29from Tkinter import _flatten, _cnfmerge, _default_root
30
31# WARNING - TkVersion is a limited precision floating point number
32if TkVersion < 3.999:
33 raise ImportError, "This version of Tix.py requires Tk 4.0 or higher"
34
35import _tkinter # If this fails your Python may not be configured for Tk
36# TixVersion = string.atof(tkinter.TIX_VERSION) # If this fails your Python may not be configured for Tix
37# WARNING - TixVersion is a limited precision floating point number
38
39# Some more constants (for consistency with Tkinter)
40WINDOW = 'window'
41TEXT = 'text'
42STATUS = 'status'
43IMMEDIATE = 'immediate'
44IMAGE = 'image'
45IMAGETEXT = 'imagetext'
46BALLOON = 'balloon'
47AUTO = 'auto'
48ACROSSTOP = 'acrosstop'
49
50# BEWARE - this is implemented by copying some code from the Widget class
51# in Tkinter (to override Widget initialization) and is therefore
52# liable to break.
53import Tkinter, os
54class Tk(Tkinter.Tk):
55 """Toplevel widget of Tix which represents mostly the main window
56 of an application. It has an associated Tcl interpreter."""
57 def __init__(self, screenName=None, baseName=None, className='Tk'):
58 Tkinter.Tk.__init__(self, screenName, baseName, className)
59 tixlib = os.environ.get('TIX_LIBRARY')
60 if tixlib is not None:
61 self.tk.eval('global auto_path; lappend auto_path {%s}' % tixlib)
62 self.tk.eval('global tcl_pkgPath; lappend tcl_pkgPath {%s}' % tixlib)
63 # Load Tix - this should work dynamically or statically
64 # If it's static, lib/tix8.1/pkgIndex.tcl should have 'load {} Tix'
65 # If it's dynamic, it should have 'load libtix8.1.8.2.so Tix'
66 self.tk.eval('package require Tix')
67
68# The Tix 'tixForm' geometry manager
69class Form:
70 """The Tix Form geometry manager
71
72 Widgets can be arranged by specifying attachments to other widgets.
73 See Tix documentation for complete details"""
74
75 def config(self, cnf={}, **kw):
76 apply(self.tk.call, ('tixForm', self._w) + self._options(cnf, kw))
77
78 form = config
79
80 def __setitem__(self, key, value):
81 Form.form({key: value})
82
83 def check(self):
84 return self.tk.call('tixForm', 'check', self._w)
85
86 def forget(self):
87 self.tk.call('tixForm', 'forget', self._w)
88
89 def grid(self, xsize=0, ysize=0):
90 if (not xsize) and (not ysize):
91 x = self.tk.call('tixForm', 'grid', self._w)
92 y = self.tk.splitlist(x)
93 z = ()
94 for x in y:
95 z = z + (self.tk.getint(x),)
96 return z
97 self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
98
99 def info(self, option=None):
100 if not option:
101 return self.tk.call('tixForm', 'info', self._w)
102 if option[0] != '-':
103 option = '-' + option
104 return self.tk.call('tixForm', 'info', self._w, option)
105
106 def slaves(self):
107 return map(self._nametowidget,
108 self.tk.splitlist(
109 self.tk.call(
110 'tixForm', 'slaves', self._w)))
111
112
113Tkinter.Widget.__bases__ = Tkinter.Widget.__bases__ + (Form,)
114
115class TixWidget(Widget):
116 """A TixWidget class is used to package all (or most) Tix widgets.
117
118 Widget initialization is extended in two ways:
119 1) It is possible to give a list of options which must be part of
120 the creation command (so called Tix 'static' options). These cannot be
121 given as a 'config' command later.
122 2) It is possible to give the name of an existing TK widget. These are
123 child widgets created automatically by a Tix mega-widget. The Tk call
124 to create these widgets is therefore bypassed in TixWidget.__init__
125
126 Both options are for use by subclasses only.
127 """
128 def __init__ (self, master=None, widgetName=None,
129 static_options=None, cnf={}, kw={}):
130 # Merge keywords and dictionary arguments
131 if kw:
132 cnf = _cnfmerge((cnf, kw))
133 else:
134 cnf = _cnfmerge(cnf)
135
136 # Move static options into extra. static_options must be
137 # a list of keywords (or None).
138 extra=()
139 if static_options:
140 for k,v in cnf.items()[:]:
141 if k in static_options:
142 extra = extra + ('-' + k, v)
143 del cnf[k]
144
145 self.widgetName = widgetName
146 Widget._setup(self, master, cnf)
147
148 # If widgetName is None, this is a dummy creation call where the
149 # corresponding Tk widget has already been created by Tix
150 if widgetName:
151 apply(self.tk.call, (widgetName, self._w) + extra)
152
153 # Non-static options - to be done via a 'config' command
154 if cnf:
155 Widget.config(self, cnf)
156
157 # Dictionary to hold subwidget names for easier access. We can't
158 # use the children list because the public Tix names may not be the
159 # same as the pathname component
160 self.subwidget_list = {}
161
162 # We set up an attribute access function so that it is possible to
163 # do w.ok['text'] = 'Hello' rather than w.subwidget('ok')['text'] = 'Hello'
164 # when w is a StdButtonBox.
165 # We can even do w.ok.invoke() because w.ok is subclassed from the
166 # Button class if you go through the proper constructors
167 def __getattr__(self, name):
168 if self.subwidget_list.has_key(name):
169 return self.subwidget_list[name]
170 raise AttributeError, name
171
172 # Set a variable without calling its action routine
173 def set_silent(self, value):
174 self.tk.call('tixSetSilent', self._w, value)
175
176 # Return the named subwidget (which must have been created by
177 # the sub-class).
178 def subwidget(self, name):
179 n = self._subwidget_name(name)
180 if not n:
181 raise TclError, "Subwidget " + name + " not child of " + self._name
182 # Remove header of name and leading dot
183 n = n[len(self._w)+1:]
184 return self._nametowidget(n)
185
186 # Return all subwidgets
187 def subwidgets_all(self):
188 names = self._subwidget_names()
189 if not names:
190 return []
191 retlist = []
192 for name in names:
193 name = name[len(self._w)+1:]
194 try:
195 retlist.append(self._nametowidget(name))
196 except:
197 # some of the widgets are unknown e.g. border in LabelFrame
198 pass
199 return retlist
200
201 # Get a subwidget name (returns a String, not a Widget !)
202 def _subwidget_name(self,name):
203 try:
204 return self.tk.call(self._w, 'subwidget', name)
205 except TclError:
206 return None
207
208 # Return the name of all subwidgets
209 def _subwidget_names(self):
210 try:
211 x = self.tk.call(self._w, 'subwidgets', '-all')
212 return self.tk.split(x)
213 except TclError:
214 return None
215
216 # Set configuration options for all subwidgets (and self)
217 def config_all(self, option, value):
218 if option == '':
219 return
220 elif type(option) != type(''):
221 option = `option`
222 if type(value) != type(''):
223 value = `value`
224 names = self._subwidget_names()
225 for name in names:
226 self.tk.call(name, 'configure', '-' + option, value)
227
228# Subwidgets are child widgets created automatically by mega-widgets.
229# In python, we have to create these subwidgets manually to mirror their
230# existence in Tk/Tix.
231class TixSubWidget(TixWidget):
232 """Subwidget class.
233
234 This is used to mirror child widgets automatically created
235 by Tix/Tk as part of a mega-widget in Python (which is not informed
236 of this)"""
237
238 def __init__(self, master, name,
239 destroy_physically=1, check_intermediate=1):
240 if check_intermediate:
241 path = master._subwidget_name(name)
242 try:
243 path = path[len(master._w)+1:]
244 plist = string.splitfields(path, '.')
245 except:
246 plist = []
247
248 if (not check_intermediate) or len(plist) < 2:
249 # immediate descendant
250 TixWidget.__init__(self, master, None, None, {'name' : name})
251 else:
252 # Ensure that the intermediate widgets exist
253 parent = master
254 for i in range(len(plist) - 1):
255 n = string.joinfields(plist[:i+1], '.')
256 try:
257 w = master._nametowidget(n)
258 parent = w
259 except KeyError:
260 # Create the intermediate widget
261 parent = TixSubWidget(parent, plist[i],
262 destroy_physically=0,
263 check_intermediate=0)
264 TixWidget.__init__(self, parent, None, None, {'name' : name})
265 self.destroy_physically = destroy_physically
266
267 def destroy(self):
268 # For some widgets e.g., a NoteBook, when we call destructors,
269 # we must be careful not to destroy the frame widget since this
270 # also destroys the parent NoteBook thus leading to an exception
271 # in Tkinter when it finally calls Tcl to destroy the NoteBook
272 for c in self.children.values(): c.destroy()
273 if self.master.children.has_key(self._name):
274 del self.master.children[self._name]
275 if self.master.subwidget_list.has_key(self._name):
276 del self.master.subwidget_list[self._name]
277 if self.destroy_physically:
278 # This is bypassed only for a few widgets
279 self.tk.call('destroy', self._w)
280
281
282# Useful func. to split Tcl lists and return as a dict. From Tkinter.py
283def _lst2dict(lst):
284 dict = {}
285 for x in lst:
286 dict[x[0][1:]] = (x[0][1:],) + x[1:]
287 return dict
288
289# Useful class to create a display style - later shared by many items.
290# Contributed by Steffen Kremser
291class DisplayStyle:
292 """DisplayStyle - handle configuration options shared by
293 (multiple) Display Items"""
294
295 def __init__(self, itemtype, cnf={}, **kw ):
296 master = _default_root # global from Tkinter
297 if not master and cnf.has_key('refwindow'): master=cnf['refwindow']
298 elif not master and kw.has_key('refwindow'): master= kw['refwindow']
299 elif not master: raise RuntimeError, "Too early to create display style: no root window"
300 self.tk = master.tk
301 self.stylename = apply(self.tk.call, ('tixDisplayStyle', itemtype) +
302 self._options(cnf,kw) )
303
304 def __str__(self):
305 return self.stylename
306
307 def _options(self, cnf, kw ):
308 if kw and cnf:
309 cnf = _cnfmerge((cnf, kw))
310 elif kw:
311 cnf = kw
312 opts = ()
313 for k, v in cnf.items():
314 opts = opts + ('-'+k, v)
315 return opts
316
317 def delete(self):
318 self.tk.call(self.stylename, 'delete')
319 del(self)
320
321 def __setitem__(self,key,value):
322 self.tk.call(self.stylename, 'configure', '-%s'%key, value)
323
324 def config(self, cnf={}, **kw):
325 return _lst2dict(
326 self.tk.split(
327 apply(self.tk.call,
328 (self.stylename, 'configure') + self._options(cnf,kw))))
329
330 def __getitem__(self,key):
331 return self.tk.call(self.stylename, 'cget', '-%s'%key, value)
332
333
334######################################################
335### The Tix Widget classes - in alphabetical order ###
336######################################################
337
338class Balloon(TixWidget):
339 """Balloon help widget.
340
341 Subwidget Class
342 --------- -----
343 label Label
344 message Message"""
345
346 def __init__(self, master=None, cnf={}, **kw):
347 TixWidget.__init__(self, master, 'tixBalloon', ['options'], cnf, kw)
348 self.subwidget_list['label'] = _dummyLabel(self, 'label',
349 destroy_physically=0)
350 self.subwidget_list['message'] = _dummyLabel(self, 'message',
351 destroy_physically=0)
352
353 def bind_widget(self, widget, cnf={}, **kw):
354 """Bind balloon widget to another.
355 One balloon widget may be bound to several widgets at the same time"""
356 apply(self.tk.call,
357 (self._w, 'bind', widget._w) + self._options(cnf, kw))
358
359 def unbind_widget(self, widget):
360 self.tk.call(self._w, 'unbind', widget._w)
361
362class ButtonBox(TixWidget):
363 """ButtonBox - A container for pushbuttons"""
364 def __init__(self, master=None, cnf={}, **kw):
365 TixWidget.__init__(self, master, 'tixButtonBox',
366 ['orientation', 'options'], cnf, kw)
367
368 def add(self, name, cnf={}, **kw):
369 """Add a button with given name to box."""
370
371 btn = apply(self.tk.call,
372 (self._w, 'add', name) + self._options(cnf, kw))
373 self.subwidget_list[name] = _dummyButton(self, name)
374 return btn
375
376 def invoke(self, name):
377 if self.subwidget_list.has_key(name):
378 self.tk.call(self._w, 'invoke', name)
379
380class ComboBox(TixWidget):
381 """ComboBox - an Entry field with a dropdown menu
382
383 Subwidget Class
384 --------- -----
385 entry Entry
386 arrow Button
387 slistbox ScrolledListBox
388 tick Button }
389 cross Button } present if created with the fancy option"""
390
391 def __init__ (self, master=None, cnf={}, **kw):
392 TixWidget.__init__(self, master, 'tixComboBox',
393 ['editable', 'dropdown', 'fancy', 'options'],
394 cnf, kw)
395 self.subwidget_list['label'] = _dummyLabel(self, 'label')
396 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
397 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
398 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
399 'slistbox')
400 try:
401 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
402 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
403 except TypeError:
404 # unavailable when -fancy not specified
405 pass
406
407 def add_history(self, str):
408 self.tk.call(self._w, 'addhistory', str)
409
410 def append_history(self, str):
411 self.tk.call(self._w, 'appendhistory', str)
412
413 def insert(self, index, str):
414 self.tk.call(self._w, 'insert', index, str)
415
416 def pick(self, index):
417 self.tk.call(self._w, 'pick', index)
418
419class Control(TixWidget):
420 """Control - An entry field with value change arrows.
421
422 Subwidget Class
423 --------- -----
424 incr Button
425 decr Button
426 entry Entry
427 label Label"""
428
429 def __init__ (self, master=None, cnf={}, **kw):
430 TixWidget.__init__(self, master, 'tixControl', ['options'], cnf, kw)
431 self.subwidget_list['incr'] = _dummyButton(self, 'incr')
432 self.subwidget_list['decr'] = _dummyButton(self, 'decr')
433 self.subwidget_list['label'] = _dummyLabel(self, 'label')
434 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
435
436 def decrement(self):
437 self.tk.call(self._w, 'decr')
438
439 def increment(self):
440 self.tk.call(self._w, 'incr')
441
442 def invoke(self):
443 self.tk.call(self._w, 'invoke')
444
445 def update(self):
446 self.tk.call(self._w, 'update')
447
448class DirList(TixWidget):
449 """DirList - Directory Listing.
450
451 Subwidget Class
452 --------- -----
453 hlist HList
454 hsb Scrollbar
455 vsb Scrollbar"""
456
457 def __init__(self, master, cnf={}, **kw):
458 TixWidget.__init__(self, master, 'tixDirList', ['options'], cnf, kw)
459 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
460 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
461 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
462
463 def chdir(self, dir):
464 self.tk.call(self._w, 'chdir', dir)
465
466class DirTree(TixWidget):
467 """DirList - Directory Listing in a hierarchical view.
468
469 Subwidget Class
470 --------- -----
471 hlist HList
472 hsb Scrollbar
473 vsb Scrollbar"""
474
475 def __init__(self, master, cnf={}, **kw):
476 TixWidget.__init__(self, master, 'tixDirTree', ['options'], cnf, kw)
477 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
478 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
479 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
480
481 def chdir(self, dir):
482 self.tk.call(self._w, 'chdir', dir)
483
484class ExFileSelectBox(TixWidget):
485 """ExFileSelectBox - MS Windows style file select box.
486
487 Subwidget Class
488 --------- -----
489 cancel Button
490 ok Button
491 hidden Checkbutton
492 types ComboBox
493 dir ComboBox
494 file ComboBox
495 dirlist ScrolledListBox
496 filelist ScrolledListBox"""
497
498 def __init__(self, master, cnf={}, **kw):
499 TixWidget.__init__(self, master, 'tixExFileSelectBox', ['options'], cnf, kw)
500 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
501 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
502 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
503 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
504 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
505 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
506 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
507 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
508
509 def filter(self):
510 self.tk.call(self._w, 'filter')
511
512 def invoke(self):
513 self.tk.call(self._w, 'invoke')
514
515class ExFileSelectDialog(TixWidget):
516 """ExFileSelectDialog - MS Windows style file select dialog.
517
518 Subwidgets Class
519 ---------- -----
520 fsbox ExFileSelectBox"""
521
522 def __init__(self, master, cnf={}, **kw):
523 TixWidget.__init__(self, master, 'tixExFileSelectDialog',
524 ['options'], cnf, kw)
525 self.subwidget_list['fsbox'] = _dummyExFileSelectBox(self, 'fsbox')
526
527 def popup(self):
528 self.tk.call(self._w, 'popup')
529
530 def popdown(self):
531 self.tk.call(self._w, 'popdown')
532
533class FileSelectBox(TixWidget):
534 """ExFileSelectBox - Motif style file select box.
535
536 Subwidget Class
537 --------- -----
538 selection ComboBox
539 filter ComboBox
540 dirlist ScrolledListBox
541 filelist ScrolledListBox"""
542
543 def __init__(self, master, cnf={}, **kw):
544 TixWidget.__init__(self, master, 'tixFileSelectBox', ['options'], cnf, kw)
545 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
546 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
547 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
548 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
549
550 def apply_filter(self): # name of subwidget is same as command
551 self.tk.call(self._w, 'filter')
552
553 def invoke(self):
554 self.tk.call(self._w, 'invoke')
555
556class FileSelectDialog(TixWidget):
557 """FileSelectDialog - Motif style file select dialog.
558
559 Subwidgets Class
560 ---------- -----
561 btns StdButtonBox
562 fsbox FileSelectBox"""
563
564 def __init__(self, master, cnf={}, **kw):
565 TixWidget.__init__(self, master, 'tixFileSelectDialog',
566 ['options'], cnf, kw)
567 self.subwidget_list['btns'] = _dummyStdButtonBox(self, 'btns')
568 self.subwidget_list['fsbox'] = _dummyFileSelectBox(self, 'fsbox')
569
570 def popup(self):
571 self.tk.call(self._w, 'popup')
572
573 def popdown(self):
574 self.tk.call(self._w, 'popdown')
575
576class FileEntry(TixWidget):
577 """FileEntry - Entry field with button that invokes a FileSelectDialog
578
579 Subwidgets Class
580 ---------- -----
581 button Button
582 entry Entry"""
583
584 def __init__(self, master, cnf={}, **kw):
585 TixWidget.__init__(self, master, 'tixFileEntry',
586 ['dialogtype', 'options'], cnf, kw)
587 self.subwidget_list['button'] = _dummyButton(self, 'button')
588 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
589
590 def invoke(self):
591 self.tk.call(self._w, 'invoke')
592
593 def file_dialog(self):
594 # XXX return python object
595 pass
596
597class HList(TixWidget):
598 """HList - Hierarchy display.
599
600 Subwidgets - None"""
601
602 def __init__ (self,master=None,cnf={}, **kw):
603 TixWidget.__init__(self, master, 'tixHList',
604 ['columns', 'options'], cnf, kw)
605
606 def add(self, entry, cnf={}, **kw):
607 return apply(self.tk.call,
608 (self._w, 'add', entry) + self._options(cnf, kw))
609
610 def add_child(self, parent=None, cnf={}, **kw):
611 if not parent:
612 parent = ''
613 return apply(self.tk.call,
614 (self._w, 'addchild', parent) + self._options(cnf, kw))
615
616 def anchor_set(self, entry):
617 self.tk.call(self._w, 'anchor', 'set', entry)
618
619 def anchor_clear(self):
620 self.tk.call(self._w, 'anchor', 'clear')
621
622 def column_width(self, col=0, width=None, chars=None):
623 if not chars:
624 return self.tk.call(self._w, 'column', 'width', col, width)
625 else:
626 return self.tk.call(self._w, 'column', 'width', col,
627 '-char', chars)
628
629 def delete_all(self):
630 self.tk.call(self._w, 'delete', 'all')
631
632 def delete_entry(self, entry):
633 self.tk.call(self._w, 'delete', 'entry', entry)
634
635 def delete_offsprings(self, entry):
636 self.tk.call(self._w, 'delete', 'offsprings', entry)
637
638 def delete_siblings(self, entry):
639 self.tk.call(self._w, 'delete', 'siblings', entry)
640
641 def dragsite_set(self, index):
642 self.tk.call(self._w, 'dragsite', 'set', index)
643
644 def dragsite_clear(self):
645 self.tk.call(self._w, 'dragsite', 'clear')
646
647 def dropsite_set(self, index):
648 self.tk.call(self._w, 'dropsite', 'set', index)
649
650 def dropsite_clear(self):
651 self.tk.call(self._w, 'dropsite', 'clear')
652
653 def header_create(self, col, cnf={}, **kw):
654 apply(self.tk.call,
655 (self._w, 'header', 'create', col) + self._options(cnf, kw))
656
657 def header_configure(self, col, cnf={}, **kw):
658 if cnf is None:
659 return _lst2dict(
660 self.tk.split(
661 self.tk.call(self._w, 'header', 'configure', col)))
662 apply(self.tk.call, (self._w, 'header', 'configure', col)
663 + self._options(cnf, kw))
664
665 def header_cget(self, col, opt):
666 return self.tk.call(self._w, 'header', 'cget', col, opt)
667
668 def header_exists(self, col):
669 return self.tk.call(self._w, 'header', 'exists', col)
670
671 def header_delete(self, col):
672 self.tk.call(self._w, 'header', 'delete', col)
673
674 def header_size(self, col):
675 return self.tk.call(self._w, 'header', 'size', col)
676
677 def hide_entry(self, entry):
678 self.tk.call(self._w, 'hide', 'entry', entry)
679
680 def indicator_create(self, entry, cnf={}, **kw):
681 apply(self.tk.call,
682 (self._w, 'indicator', 'create', entry) + self._options(cnf, kw))
683
684 def indicator_configure(self, entry, cnf={}, **kw):
685 if cnf is None:
686 return _lst2dict(
687 self.tk.split(
688 self.tk.call(self._w, 'indicator', 'configure', entry)))
689 apply(self.tk.call,
690 (self._w, 'indicator', 'configure', entry) + self._options(cnf, kw))
691
692 def indicator_cget(self, entry, opt):
693 return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
694
695 def indicator_exists(self, entry):
696 return self.tk.call (self._w, 'indicator', 'exists', entry)
697
698 def indicator_delete(self, entry):
699 self.tk.call(self._w, 'indicator', 'delete', entry)
700
701 def indicator_size(self, entry):
702 return self.tk.call(self._w, 'indicator', 'size', entry)
703
704 def info_anchor(self):
705 return self.tk.call(self._w, 'info', 'anchor')
706
707 def info_children(self, entry=None):
708 c = self.tk.call(self._w, 'info', 'children', entry)
709 return self.tk.splitlist(c)
710
711 def info_data(self, entry):
712 return self.tk.call(self._w, 'info', 'data', entry)
713
714 def info_exists(self, entry):
715 return self.tk.call(self._w, 'info', 'exists', entry)
716
717 def info_hidden(self, entry):
718 return self.tk.call(self._w, 'info', 'hidden', entry)
719
720 def info_next(self, entry):
721 return self.tk.call(self._w, 'info', 'next', entry)
722
723 def info_parent(self, entry):
724 return self.tk.call(self._w, 'info', 'parent', entry)
725
726 def info_prev(self, entry):
727 return self.tk.call(self._w, 'info', 'prev', entry)
728
729 def info_selection(self):
730 c = self.tk.call(self._w, 'info', 'selection')
731 return self.tk.splitlist(c)
732
733 def item_cget(self, col, opt):
734 return self.tk.call(self._w, 'item', 'cget', col, opt)
735
736 def item_configure(self, entry, col, cnf={}, **kw):
737 if cnf is None:
738 return _lst2dict(
739 self.tk.split(
740 self.tk.call(self._w, 'item', 'configure', entry, col)))
741 apply(self.tk.call, (self._w, 'item', 'configure', entry, col) +
742 self._options(cnf, kw))
743
744 def item_create(self, entry, col, cnf={}, **kw):
745 apply(self.tk.call,
746 (self._w, 'item', 'create', entry, col) + self._options(cnf, kw))
747
748 def item_exists(self, entry, col):
749 return self.tk.call(self._w, 'item', 'exists', entry, col)
750
751 def item_delete(self, entry, col):
752 self.tk.call(self._w, 'item', 'delete', entry, col)
753
754 def nearest(self, y):
755 return self.tk.call(self._w, 'nearest', y)
756
757 def see(self, entry):
758 self.tk.call(self._w, 'see', entry)
759
760 def selection_clear(self, cnf={}, **kw):
761 apply(self.tk.call,
762 (self._w, 'selection', 'clear') + self._options(cnf, kw))
763
764 def selection_includes(self, entry):
765 return self.tk.call(self._w, 'selection', 'includes', entry)
766
767 def selection_set(self, first, last=None):
768 self.tk.call(self._w, 'selection', 'set', first, last)
769
770 def show_entry(self, entry):
771 return self.tk.call(self._w, 'show', 'entry', entry)
772
773 def xview(self, *args):
774 apply(self.tk.call, (self._w, 'xview') + args)
775
776 def yview(self, *args):
777 apply(self.tk.call, (self._w, 'yview') + args)
778
779class InputOnly(TixWidget):
780 """InputOnly - Invisible widget.
781
782 Subwidgets - None"""
783
784 def __init__ (self,master=None,cnf={}, **kw):
785 TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
786
787class LabelEntry(TixWidget):
788 """LabelEntry - Entry field with label.
789
790 Subwidgets Class
791 ---------- -----
792 label Label
793 entry Entry"""
794
795 def __init__ (self,master=None,cnf={}, **kw):
796 TixWidget.__init__(self, master, 'tixLabelEntry',
797 ['labelside','options'], cnf, kw)
798 self.subwidget_list['label'] = _dummyLabel(self, 'label')
799 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
800
801class LabelFrame(TixWidget):
802 """LabelFrame - Labelled Frame container.
803
804 Subwidgets Class
805 ---------- -----
806 label Label
807 frame Frame"""
808
809 def __init__ (self,master=None,cnf={}, **kw):
810 TixWidget.__init__(self, master, 'tixLabelFrame',
811 ['labelside','options'], cnf, kw)
812 self.subwidget_list['label'] = _dummyLabel(self, 'label')
813 self.subwidget_list['frame'] = _dummyFrame(self, 'frame')
814
815class NoteBook(TixWidget):
816 """NoteBook - Multi-page container widget (tabbed notebook metaphor).
817
818 Subwidgets Class
819 ---------- -----
820 nbframe NoteBookFrame
821 <pages> g/p widgets added dynamically"""
822
823 def __init__ (self,master=None,cnf={}, **kw):
824 TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw)
825 self.subwidget_list['nbframe'] = TixSubWidget(self, 'nbframe',
826 destroy_physically=0)
827
828 def add(self, name, cnf={}, **kw):
829 apply(self.tk.call,
830 (self._w, 'add', name) + self._options(cnf, kw))
831 self.subwidget_list[name] = TixSubWidget(self, name)
832 return self.subwidget_list[name]
833
834 def delete(self, name):
835 self.tk.call(self._w, 'delete', name)
836
837 def page(self, name):
838 return self.subwidget(name)
839
840 def pages(self):
841 # Can't call subwidgets_all directly because we don't want .nbframe
842 names = self.tk.split(self.tk.call(self._w, 'pages'))
843 ret = []
844 for x in names:
845 ret.append(self.subwidget(x))
846 return ret
847
848 def raise_page(self, name): # raise is a python keyword
849 self.tk.call(self._w, 'raise', name)
850
851 def raised(self):
852 return self.tk.call(self._w, 'raised')
853
854class NoteBookFrame(TixWidget):
855 """Will be added when Tix documentation is available !!!"""
856 pass
857
858class OptionMenu(TixWidget):
859 """OptionMenu - Option menu widget.
860
861 Subwidget Class
862 --------- -----
863 menubutton Menubutton
864 menu Menu"""
865
866 def __init__(self, master, cnf={}, **kw):
867 TixWidget.__init__(self, master, 'tixOptionMenu', ['options'], cnf, kw)
868 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
869 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
870
871 def add_command(self, name, cnf={}, **kw):
872 apply(self.tk.call,
873 (self._w, 'add', 'command', name) + self._options(cnf, kw))
874
875 def add_separator(self, name, cnf={}, **kw):
876 apply(self.tk.call,
877 (self._w, 'add', 'separator', name) + self._options(cnf, kw))
878
879 def delete(self, name):
880 self.tk.call(self._w, 'delete', name)
881
882 def disable(self, name):
883 self.tk.call(self._w, 'disable', name)
884
885 def enable(self, name):
886 self.tk.call(self._w, 'enable', name)
887
888class PanedWindow(TixWidget):
889 """PanedWindow - Multi-pane container widget. Panes are resizable.
890
891 Subwidgets Class
892 ---------- -----
893 <panes> g/p widgets added dynamically"""
894
895 def __init__(self, master, cnf={}, **kw):
896 TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
897
898 def add(self, name, cnf={}, **kw):
899 apply(self.tk.call,
900 (self._w, 'add', name) + self._options(cnf, kw))
901 self.subwidget_list[name] = TixSubWidget(self, name,
902 check_intermediate=0)
903 return self.subwidget_list[name]
904
905 def panes(self):
906 names = self.tk.call(self._w, 'panes')
907 ret = []
908 for x in names:
909 ret.append(self.subwidget(x))
910 return ret
911
912class PopupMenu(TixWidget):
913 """PopupMenu widget.
914
915 Subwidgets Class
916 ---------- -----
917 menubutton Menubutton
918 menu Menu"""
919
920 def __init__(self, master, cnf={}, **kw):
921 TixWidget.__init__(self, master, 'tixPopupMenu', ['options'], cnf, kw)
922 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
923 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
924
925 def bind_widget(self, widget):
926 self.tk.call(self._w, 'bind', widget._w)
927
928 def unbind_widget(self, widget):
929 self.tk.call(self._w, 'unbind', widget._w)
930
931 def post_widget(self, widget, x, y):
932 self.tk.call(self._w, 'post', widget._w, x, y)
933
934class ResizeHandle(TixWidget):
935 """Incomplete - no documentation in Tix for this !!!"""
936
937 def __init__(self, master, cnf={}, **kw):
938 TixWidget.__init__(self, master, 'tixResizeHandle',
939 ['options'], cnf, kw)
940
941 def attach_widget(self, widget):
942 self.tk.call(self._w, 'attachwidget', widget._w)
943
944class ScrolledHList(TixWidget):
945 """ScrolledHList - HList with scrollbars."""
946
947 def __init__(self, master, cnf={}, **kw):
948 TixWidget.__init__(self, master, 'tixScrolledHList', ['options'],
949 cnf, kw)
950 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
951 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
952 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
953
954class ScrolledListBox(TixWidget):
955 """ScrolledListBox - Listbox with scrollbars."""
956
957 def __init__(self, master, cnf={}, **kw):
958 TixWidget.__init__(self, master, 'tixScrolledListBox', ['options'], cnf, kw)
959 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
960 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
961 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
962
963class ScrolledText(TixWidget):
964 """ScrolledText - Text with scrollbars."""
965
966 def __init__(self, master, cnf={}, **kw):
967 TixWidget.__init__(self, master, 'tixScrolledText', ['options'], cnf, kw)
968 self.subwidget_list['text'] = _dummyText(self, 'text')
969 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
970 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
971
972class ScrolledTList(TixWidget):
973 """ScrolledTList - TList with scrollbars."""
974
975 def __init__(self, master, cnf={}, **kw):
976 TixWidget.__init__(self, master, 'tixScrolledTList', ['options'],
977 cnf, kw)
978 self.subwidget_list['tlist'] = _dummyTList(self, 'tlist')
979 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
980 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
981
982class ScrolledWindow(TixWidget):
983 """ScrolledWindow - Window with scrollbars."""
984
985 def __init__(self, master, cnf={}, **kw):
986 TixWidget.__init__(self, master, 'tixScrolledWindow', ['options'], cnf, kw)
987 self.subwidget_list['window'] = _dummyFrame(self, 'window')
988 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
989 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
990
991class Select(TixWidget):
992 """Select - Container for buttons. Can enforce radio buttons etc.
993
994 Subwidgets are buttons added dynamically"""
995
996 def __init__(self, master, cnf={}, **kw):
997 TixWidget.__init__(self, master, 'tixSelect',
998 ['allowzero', 'radio', 'orientation', 'labelside',
999 'options'],
1000 cnf, kw)
1001 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1002
1003 def add(self, name, cnf={}, **kw):
1004 apply(self.tk.call,
1005 (self._w, 'add', name) + self._options(cnf, kw))
1006 self.subwidget_list[name] = _dummyButton(self, name)
1007 return self.subwidget_list[name]
1008
1009 def invoke(self, name):
1010 self.tk.call(self._w, 'invoke', name)
1011
1012class StdButtonBox(TixWidget):
1013 """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
1014
1015 def __init__(self, master=None, cnf={}, **kw):
1016 TixWidget.__init__(self, master, 'tixStdButtonBox',
1017 ['orientation', 'options'], cnf, kw)
1018 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1019 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1020 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1021 self.subwidget_list['help'] = _dummyButton(self, 'help')
1022
1023 def invoke(self, name):
1024 if self.subwidget_list.has_key(name):
1025 self.tk.call(self._w, 'invoke', name)
1026
1027class TList(TixWidget):
1028 """TList - Hierarchy display.
1029
1030 Subwidgets - None"""
1031
1032 def __init__ (self,master=None,cnf={}, **kw):
1033 TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
1034
1035 def active_set(self, index):
1036 self.tk.call(self._w, 'active', 'set', index)
1037
1038 def active_clear(self):
1039 self.tk.call(self._w, 'active', 'clear')
1040
1041 def anchor_set(self, index):
1042 self.tk.call(self._w, 'anchor', 'set', index)
1043
1044 def anchor_clear(self):
1045 self.tk.call(self._w, 'anchor', 'clear')
1046
1047 def delete(self, from_, to=None):
1048 self.tk.call(self._w, 'delete', from_, to)
1049
1050 def dragsite_set(self, index):
1051 self.tk.call(self._w, 'dragsite', 'set', index)
1052
1053 def dragsite_clear(self):
1054 self.tk.call(self._w, 'dragsite', 'clear')
1055
1056 def dropsite_set(self, index):
1057 self.tk.call(self._w, 'dropsite', 'set', index)
1058
1059 def dropsite_clear(self):
1060 self.tk.call(self._w, 'dropsite', 'clear')
1061
1062 def insert(self, index, cnf={}, **kw):
1063 apply(self.tk.call,
1064 (self._w, 'insert', index) + self._options(cnf, kw))
1065
1066 def info_active(self):
1067 return self.tk.call(self._w, 'info', 'active')
1068
1069 def info_anchor(self):
1070 return self.tk.call(self._w, 'info', 'anchor')
1071
1072 def info_down(self, index):
1073 return self.tk.call(self._w, 'info', 'down', index)
1074
1075 def info_left(self, index):
1076 return self.tk.call(self._w, 'info', 'left', index)
1077
1078 def info_right(self, index):
1079 return self.tk.call(self._w, 'info', 'right', index)
1080
1081 def info_selection(self):
1082 c = self.tk.call(self._w, 'info', 'selection')
1083 return self.tk.splitlist(c)
1084
1085 def info_size(self):
1086 return self.tk.call(self._w, 'info', 'size')
1087
1088 def info_up(self, index):
1089 return self.tk.call(self._w, 'info', 'up', index)
1090
1091 def nearest(self, x, y):
1092 return self.tk.call(self._w, 'nearest', x, y)
1093
1094 def see(self, index):
1095 self.tk.call(self._w, 'see', index)
1096
1097 def selection_clear(self, cnf={}, **kw):
1098 apply(self.tk.call,
1099 (self._w, 'selection', 'clear') + self._options(cnf, kw))
1100
1101 def selection_includes(self, index):
1102 return self.tk.call(self._w, 'selection', 'includes', index)
1103
1104 def selection_set(self, first, last=None):
1105 self.tk.call(self._w, 'selection', 'set', first, last)
1106
1107 def xview(self, *args):
1108 apply(self.tk.call, (self._w, 'xview') + args)
1109
1110 def yview(self, *args):
1111 apply(self.tk.call, (self._w, 'yview') + args)
1112
1113class Tree(TixWidget):
1114 """Tree - The tixTree widget (general purpose DirList like widget)"""
1115
1116 def __init__(self, master=None, cnf={}, **kw):
1117 TixWidget.__init__(self, master, 'tixTree',
1118 ['options'], cnf, kw)
1119 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1120 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1121 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1122
1123 def autosetmode(self):
1124 self.tk.call(self._w, 'autosetmode')
1125
1126 def close(self, entrypath):
1127 self.tk.call(self._w, 'close', entrypath)
1128
1129 def getmode(self, entrypath):
1130 return self.tk.call(self._w, 'getmode', entrypath)
1131
1132 def open(self, entrypath):
1133 self.tk.call(self._w, 'open', entrypath)
1134
1135 def setmode(self, entrypath, mode='none'):
1136 self.tk.call(self._w, 'setmode', entrypath, mode)
1137
1138###########################################################################
1139### The subclassing below is used to instantiate the subwidgets in each ###
1140### mega widget. This allows us to access their methods directly. ###
1141###########################################################################
1142
1143class _dummyButton(Button, TixSubWidget):
1144 def __init__(self, master, name, destroy_physically=1):
1145 TixSubWidget.__init__(self, master, name, destroy_physically)
1146
1147class _dummyCheckbutton(Checkbutton, TixSubWidget):
1148 def __init__(self, master, name, destroy_physically=1):
1149 TixSubWidget.__init__(self, master, name, destroy_physically)
1150
1151class _dummyEntry(Entry, TixSubWidget):
1152 def __init__(self, master, name, destroy_physically=1):
1153 TixSubWidget.__init__(self, master, name, destroy_physically)
1154
1155class _dummyFrame(Frame, TixSubWidget):
1156 def __init__(self, master, name, destroy_physically=1):
1157 TixSubWidget.__init__(self, master, name, destroy_physically)
1158
1159class _dummyLabel(Label, TixSubWidget):
1160 def __init__(self, master, name, destroy_physically=1):
1161 TixSubWidget.__init__(self, master, name, destroy_physically)
1162
1163class _dummyListbox(Listbox, TixSubWidget):
1164 def __init__(self, master, name, destroy_physically=1):
1165 TixSubWidget.__init__(self, master, name, destroy_physically)
1166
1167class _dummyMenu(Menu, TixSubWidget):
1168 def __init__(self, master, name, destroy_physically=1):
1169 TixSubWidget.__init__(self, master, name, destroy_physically)
1170
1171class _dummyMenubutton(Menubutton, TixSubWidget):
1172 def __init__(self, master, name, destroy_physically=1):
1173 TixSubWidget.__init__(self, master, name, destroy_physically)
1174
1175class _dummyScrollbar(Scrollbar, TixSubWidget):
1176 def __init__(self, master, name, destroy_physically=1):
1177 TixSubWidget.__init__(self, master, name, destroy_physically)
1178
1179class _dummyText(Text, TixSubWidget):
1180 def __init__(self, master, name, destroy_physically=1):
1181 TixSubWidget.__init__(self, master, name, destroy_physically)
1182
1183class _dummyScrolledListBox(ScrolledListBox, TixSubWidget):
1184 def __init__(self, master, name, destroy_physically=1):
1185 TixSubWidget.__init__(self, master, name, destroy_physically)
1186 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1187 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1188 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1189
1190class _dummyHList(HList, TixSubWidget):
1191 def __init__(self, master, name, destroy_physically=1):
1192 TixSubWidget.__init__(self, master, name, destroy_physically)
1193
1194class _dummyTList(TList, TixSubWidget):
1195 def __init__(self, master, name, destroy_physically=1):
1196 TixSubWidget.__init__(self, master, name, destroy_physically)
1197
1198class _dummyComboBox(ComboBox, TixSubWidget):
1199 def __init__(self, master, name, destroy_physically=1):
1200 TixSubWidget.__init__(self, master, name, destroy_physically)
1201 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
1202 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
1203 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
1204 'slistbox')
1205 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox',
1206 destroy_physically=0)
1207
1208class _dummyDirList(DirList, TixSubWidget):
1209 def __init__(self, master, name, destroy_physically=1):
1210 TixSubWidget.__init__(self, master, name, destroy_physically)
1211 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1212 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1213 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1214
1215class _dummyExFileSelectBox(ExFileSelectBox, TixSubWidget):
1216 def __init__(self, master, name, destroy_physically=1):
1217 TixSubWidget.__init__(self, master, name, destroy_physically)
1218 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1219 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1220 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
1221 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
1222 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
1223 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1224 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
1225 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1226
1227class _dummyFileSelectBox(FileSelectBox, TixSubWidget):
1228 def __init__(self, master, name, destroy_physically=1):
1229 TixSubWidget.__init__(self, master, name, destroy_physically)
1230 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1231 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1232 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
1233 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
1234
1235class _dummyStdButtonBox(StdButtonBox, TixSubWidget):
1236 def __init__(self, master, name, destroy_physically=1):
1237 TixSubWidget.__init__(self, master, name, destroy_physically)
1238 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1239 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1240 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1241 self.subwidget_list['help'] = _dummyButton(self, 'help')
1242
1243class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
1244 def __init__(self, master, name, destroy_physically=0):
1245 TixSubWidget.__init__(self, master, name, destroy_physically)
1246
1247########################
1248### Utility Routines ###
1249########################
1250
1251# Returns the qualified path name for the widget. Normally used to set
1252# default options for subwidgets. See tixwidgets.py
1253def OptionName(widget):
1254 return widget.tk.call('tixOptionName', widget._w)
1255
1256# Called with a dictionary argument of the form
1257# {'*.c':'C source files', '*.txt':'Text Files', '*':'All files'}
1258# returns a string which can be used to configure the fsbox file types
1259# in an ExFileSelectBox. i.e.,
1260# '{{*} {* - All files}} {{*.c} {*.c - C source files}} {{*.txt} {*.txt - Text Files}}'
1261def FileTypeList(dict):
1262 s = ''
1263 for type in dict.keys():
1264 s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
1265 return s
1266