Null commit with -f option to force an uprev and put HEADs firmly on the trunk.
[python/dscho.git] / Lib / lib-tk / Tix.py
blobb8346addf4b432aafd9f4e70cf20d3ded9128996
2 # $Id$
4 # Tix.py -- Tix widget wrappers, part of PyTix.
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)
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.
14 # The Tix widgets are represented by a class hierarchy in python with proper
15 # inheritance of base classes.
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.
23 # Compare the demo tixwidgets.py to the original Tcl program and you will
24 # appreciate the advantages.
27 import string
28 from Tkinter import *
29 from Tkinter import _flatten, _cnfmerge, _default_root
31 # WARNING - TkVersion is a limited precision floating point number
32 if TkVersion < 3.999:
33 raise ImportError, "This version of Tix.py requires Tk 4.0 or higher"
35 import _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
39 # Some more constants (for consistency with Tkinter)
40 WINDOW = 'window'
41 TEXT = 'text'
42 STATUS = 'status'
43 IMMEDIATE = 'immediate'
44 IMAGE = 'image'
45 IMAGETEXT = 'imagetext'
46 BALLOON = 'balloon'
47 AUTO = 'auto'
48 ACROSSTOP = 'acrosstop'
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.
53 import Tkinter, os
54 class 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')
68 # The Tix 'tixForm' geometry manager
69 class Form:
70 """The Tix Form geometry manager
72 Widgets can be arranged by specifying attachments to other widgets.
73 See Tix documentation for complete details"""
75 def config(self, cnf={}, **kw):
76 apply(self.tk.call, ('tixForm', self._w) + self._options(cnf, kw))
78 form = config
80 def __setitem__(self, key, value):
81 Form.form({key: value})
83 def check(self):
84 return self.tk.call('tixForm', 'check', self._w)
86 def forget(self):
87 self.tk.call('tixForm', 'forget', self._w)
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)
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)
106 def slaves(self):
107 return map(self._nametowidget,
108 self.tk.splitlist(
109 self.tk.call(
110 'tixForm', 'slaves', self._w)))
113 Tkinter.Widget.__bases__ = Tkinter.Widget.__bases__ + (Form,)
115 class TixWidget(Widget):
116 """A TixWidget class is used to package all (or most) Tix widgets.
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__
126 Both options are for use by subclasses only.
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)
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]
145 self.widgetName = widgetName
146 Widget._setup(self, master, cnf)
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)
153 # Non-static options - to be done via a 'config' command
154 if cnf:
155 Widget.config(self, cnf)
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 = {}
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
172 # Set a variable without calling its action routine
173 def set_silent(self, value):
174 self.tk.call('tixSetSilent', self._w, value)
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)
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
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
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
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)
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.
231 class TixSubWidget(TixWidget):
232 """Subwidget class.
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)"""
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 = []
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
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)
282 # Useful func. to split Tcl lists and return as a dict. From Tkinter.py
283 def _lst2dict(lst):
284 dict = {}
285 for x in lst:
286 dict[x[0][1:]] = (x[0][1:],) + x[1:]
287 return dict
289 # Useful class to create a display style - later shared by many items.
290 # Contributed by Steffen Kremser
291 class DisplayStyle:
292 """DisplayStyle - handle configuration options shared by
293 (multiple) Display Items"""
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) )
304 def __str__(self):
305 return self.stylename
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
317 def delete(self):
318 self.tk.call(self.stylename, 'delete')
319 del(self)
321 def __setitem__(self,key,value):
322 self.tk.call(self.stylename, 'configure', '-%s'%key, value)
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))))
330 def __getitem__(self,key):
331 return self.tk.call(self.stylename, 'cget', '-%s'%key, value)
334 ######################################################
335 ### The Tix Widget classes - in alphabetical order ###
336 ######################################################
338 class Balloon(TixWidget):
339 """Balloon help widget.
341 Subwidget Class
342 --------- -----
343 label Label
344 message Message"""
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)
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))
359 def unbind_widget(self, widget):
360 self.tk.call(self._w, 'unbind', widget._w)
362 class 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)
368 def add(self, name, cnf={}, **kw):
369 """Add a button with given name to box."""
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
376 def invoke(self, name):
377 if self.subwidget_list.has_key(name):
378 self.tk.call(self._w, 'invoke', name)
380 class ComboBox(TixWidget):
381 """ComboBox - an Entry field with a dropdown menu
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"""
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
407 def add_history(self, str):
408 self.tk.call(self._w, 'addhistory', str)
410 def append_history(self, str):
411 self.tk.call(self._w, 'appendhistory', str)
413 def insert(self, index, str):
414 self.tk.call(self._w, 'insert', index, str)
416 def pick(self, index):
417 self.tk.call(self._w, 'pick', index)
419 class Control(TixWidget):
420 """Control - An entry field with value change arrows.
422 Subwidget Class
423 --------- -----
424 incr Button
425 decr Button
426 entry Entry
427 label Label"""
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')
436 def decrement(self):
437 self.tk.call(self._w, 'decr')
439 def increment(self):
440 self.tk.call(self._w, 'incr')
442 def invoke(self):
443 self.tk.call(self._w, 'invoke')
445 def update(self):
446 self.tk.call(self._w, 'update')
448 class DirList(TixWidget):
449 """DirList - Directory Listing.
451 Subwidget Class
452 --------- -----
453 hlist HList
454 hsb Scrollbar
455 vsb Scrollbar"""
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')
463 def chdir(self, dir):
464 self.tk.call(self._w, 'chdir', dir)
466 class DirTree(TixWidget):
467 """DirList - Directory Listing in a hierarchical view.
469 Subwidget Class
470 --------- -----
471 hlist HList
472 hsb Scrollbar
473 vsb Scrollbar"""
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')
481 def chdir(self, dir):
482 self.tk.call(self._w, 'chdir', dir)
484 class ExFileSelectBox(TixWidget):
485 """ExFileSelectBox - MS Windows style file select box.
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"""
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')
509 def filter(self):
510 self.tk.call(self._w, 'filter')
512 def invoke(self):
513 self.tk.call(self._w, 'invoke')
515 class ExFileSelectDialog(TixWidget):
516 """ExFileSelectDialog - MS Windows style file select dialog.
518 Subwidgets Class
519 ---------- -----
520 fsbox ExFileSelectBox"""
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')
527 def popup(self):
528 self.tk.call(self._w, 'popup')
530 def popdown(self):
531 self.tk.call(self._w, 'popdown')
533 class FileSelectBox(TixWidget):
534 """ExFileSelectBox - Motif style file select box.
536 Subwidget Class
537 --------- -----
538 selection ComboBox
539 filter ComboBox
540 dirlist ScrolledListBox
541 filelist ScrolledListBox"""
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')
550 def apply_filter(self): # name of subwidget is same as command
551 self.tk.call(self._w, 'filter')
553 def invoke(self):
554 self.tk.call(self._w, 'invoke')
556 class FileSelectDialog(TixWidget):
557 """FileSelectDialog - Motif style file select dialog.
559 Subwidgets Class
560 ---------- -----
561 btns StdButtonBox
562 fsbox FileSelectBox"""
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')
570 def popup(self):
571 self.tk.call(self._w, 'popup')
573 def popdown(self):
574 self.tk.call(self._w, 'popdown')
576 class FileEntry(TixWidget):
577 """FileEntry - Entry field with button that invokes a FileSelectDialog
579 Subwidgets Class
580 ---------- -----
581 button Button
582 entry Entry"""
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')
590 def invoke(self):
591 self.tk.call(self._w, 'invoke')
593 def file_dialog(self):
594 # XXX return python object
595 pass
597 class HList(TixWidget):
598 """HList - Hierarchy display.
600 Subwidgets - None"""
602 def __init__ (self,master=None,cnf={}, **kw):
603 TixWidget.__init__(self, master, 'tixHList',
604 ['columns', 'options'], cnf, kw)
606 def add(self, entry, cnf={}, **kw):
607 return apply(self.tk.call,
608 (self._w, 'add', entry) + self._options(cnf, kw))
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))
616 def anchor_set(self, entry):
617 self.tk.call(self._w, 'anchor', 'set', entry)
619 def anchor_clear(self):
620 self.tk.call(self._w, 'anchor', 'clear')
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)
629 def delete_all(self):
630 self.tk.call(self._w, 'delete', 'all')
632 def delete_entry(self, entry):
633 self.tk.call(self._w, 'delete', 'entry', entry)
635 def delete_offsprings(self, entry):
636 self.tk.call(self._w, 'delete', 'offsprings', entry)
638 def delete_siblings(self, entry):
639 self.tk.call(self._w, 'delete', 'siblings', entry)
641 def dragsite_set(self, index):
642 self.tk.call(self._w, 'dragsite', 'set', index)
644 def dragsite_clear(self):
645 self.tk.call(self._w, 'dragsite', 'clear')
647 def dropsite_set(self, index):
648 self.tk.call(self._w, 'dropsite', 'set', index)
650 def dropsite_clear(self):
651 self.tk.call(self._w, 'dropsite', 'clear')
653 def header_create(self, col, cnf={}, **kw):
654 apply(self.tk.call,
655 (self._w, 'header', 'create', col) + self._options(cnf, kw))
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))
665 def header_cget(self, col, opt):
666 return self.tk.call(self._w, 'header', 'cget', col, opt)
668 def header_exists(self, col):
669 return self.tk.call(self._w, 'header', 'exists', col)
671 def header_delete(self, col):
672 self.tk.call(self._w, 'header', 'delete', col)
674 def header_size(self, col):
675 return self.tk.call(self._w, 'header', 'size', col)
677 def hide_entry(self, entry):
678 self.tk.call(self._w, 'hide', 'entry', entry)
680 def indicator_create(self, entry, cnf={}, **kw):
681 apply(self.tk.call,
682 (self._w, 'indicator', 'create', entry) + self._options(cnf, kw))
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))
692 def indicator_cget(self, entry, opt):
693 return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
695 def indicator_exists(self, entry):
696 return self.tk.call (self._w, 'indicator', 'exists', entry)
698 def indicator_delete(self, entry):
699 self.tk.call(self._w, 'indicator', 'delete', entry)
701 def indicator_size(self, entry):
702 return self.tk.call(self._w, 'indicator', 'size', entry)
704 def info_anchor(self):
705 return self.tk.call(self._w, 'info', 'anchor')
707 def info_children(self, entry=None):
708 c = self.tk.call(self._w, 'info', 'children', entry)
709 return self.tk.splitlist(c)
711 def info_data(self, entry):
712 return self.tk.call(self._w, 'info', 'data', entry)
714 def info_exists(self, entry):
715 return self.tk.call(self._w, 'info', 'exists', entry)
717 def info_hidden(self, entry):
718 return self.tk.call(self._w, 'info', 'hidden', entry)
720 def info_next(self, entry):
721 return self.tk.call(self._w, 'info', 'next', entry)
723 def info_parent(self, entry):
724 return self.tk.call(self._w, 'info', 'parent', entry)
726 def info_prev(self, entry):
727 return self.tk.call(self._w, 'info', 'prev', entry)
729 def info_selection(self):
730 c = self.tk.call(self._w, 'info', 'selection')
731 return self.tk.splitlist(c)
733 def item_cget(self, col, opt):
734 return self.tk.call(self._w, 'item', 'cget', col, opt)
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))
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))
748 def item_exists(self, entry, col):
749 return self.tk.call(self._w, 'item', 'exists', entry, col)
751 def item_delete(self, entry, col):
752 self.tk.call(self._w, 'item', 'delete', entry, col)
754 def nearest(self, y):
755 return self.tk.call(self._w, 'nearest', y)
757 def see(self, entry):
758 self.tk.call(self._w, 'see', entry)
760 def selection_clear(self, cnf={}, **kw):
761 apply(self.tk.call,
762 (self._w, 'selection', 'clear') + self._options(cnf, kw))
764 def selection_includes(self, entry):
765 return self.tk.call(self._w, 'selection', 'includes', entry)
767 def selection_set(self, first, last=None):
768 self.tk.call(self._w, 'selection', 'set', first, last)
770 def show_entry(self, entry):
771 return self.tk.call(self._w, 'show', 'entry', entry)
773 def xview(self, *args):
774 apply(self.tk.call, (self._w, 'xview') + args)
776 def yview(self, *args):
777 apply(self.tk.call, (self._w, 'yview') + args)
779 class InputOnly(TixWidget):
780 """InputOnly - Invisible widget.
782 Subwidgets - None"""
784 def __init__ (self,master=None,cnf={}, **kw):
785 TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
787 class LabelEntry(TixWidget):
788 """LabelEntry - Entry field with label.
790 Subwidgets Class
791 ---------- -----
792 label Label
793 entry Entry"""
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')
801 class LabelFrame(TixWidget):
802 """LabelFrame - Labelled Frame container.
804 Subwidgets Class
805 ---------- -----
806 label Label
807 frame Frame"""
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')
815 class NoteBook(TixWidget):
816 """NoteBook - Multi-page container widget (tabbed notebook metaphor).
818 Subwidgets Class
819 ---------- -----
820 nbframe NoteBookFrame
821 <pages> g/p widgets added dynamically"""
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)
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]
834 def delete(self, name):
835 self.tk.call(self._w, 'delete', name)
837 def page(self, name):
838 return self.subwidget(name)
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
848 def raise_page(self, name): # raise is a python keyword
849 self.tk.call(self._w, 'raise', name)
851 def raised(self):
852 return self.tk.call(self._w, 'raised')
854 class NoteBookFrame(TixWidget):
855 """Will be added when Tix documentation is available !!!"""
856 pass
858 class OptionMenu(TixWidget):
859 """OptionMenu - Option menu widget.
861 Subwidget Class
862 --------- -----
863 menubutton Menubutton
864 menu Menu"""
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')
871 def add_command(self, name, cnf={}, **kw):
872 apply(self.tk.call,
873 (self._w, 'add', 'command', name) + self._options(cnf, kw))
875 def add_separator(self, name, cnf={}, **kw):
876 apply(self.tk.call,
877 (self._w, 'add', 'separator', name) + self._options(cnf, kw))
879 def delete(self, name):
880 self.tk.call(self._w, 'delete', name)
882 def disable(self, name):
883 self.tk.call(self._w, 'disable', name)
885 def enable(self, name):
886 self.tk.call(self._w, 'enable', name)
888 class PanedWindow(TixWidget):
889 """PanedWindow - Multi-pane container widget. Panes are resizable.
891 Subwidgets Class
892 ---------- -----
893 <panes> g/p widgets added dynamically"""
895 def __init__(self, master, cnf={}, **kw):
896 TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
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]
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
912 class PopupMenu(TixWidget):
913 """PopupMenu widget.
915 Subwidgets Class
916 ---------- -----
917 menubutton Menubutton
918 menu Menu"""
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')
925 def bind_widget(self, widget):
926 self.tk.call(self._w, 'bind', widget._w)
928 def unbind_widget(self, widget):
929 self.tk.call(self._w, 'unbind', widget._w)
931 def post_widget(self, widget, x, y):
932 self.tk.call(self._w, 'post', widget._w, x, y)
934 class ResizeHandle(TixWidget):
935 """Incomplete - no documentation in Tix for this !!!"""
937 def __init__(self, master, cnf={}, **kw):
938 TixWidget.__init__(self, master, 'tixResizeHandle',
939 ['options'], cnf, kw)
941 def attach_widget(self, widget):
942 self.tk.call(self._w, 'attachwidget', widget._w)
944 class ScrolledHList(TixWidget):
945 """ScrolledHList - HList with scrollbars."""
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')
954 class ScrolledListBox(TixWidget):
955 """ScrolledListBox - Listbox with scrollbars."""
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')
963 class ScrolledText(TixWidget):
964 """ScrolledText - Text with scrollbars."""
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')
972 class ScrolledTList(TixWidget):
973 """ScrolledTList - TList with scrollbars."""
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')
982 class ScrolledWindow(TixWidget):
983 """ScrolledWindow - Window with scrollbars."""
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')
991 class Select(TixWidget):
992 """Select - Container for buttons. Can enforce radio buttons etc.
994 Subwidgets are buttons added dynamically"""
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')
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]
1009 def invoke(self, name):
1010 self.tk.call(self._w, 'invoke', name)
1012 class StdButtonBox(TixWidget):
1013 """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
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')
1023 def invoke(self, name):
1024 if self.subwidget_list.has_key(name):
1025 self.tk.call(self._w, 'invoke', name)
1027 class TList(TixWidget):
1028 """TList - Hierarchy display.
1030 Subwidgets - None"""
1032 def __init__ (self,master=None,cnf={}, **kw):
1033 TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
1035 def active_set(self, index):
1036 self.tk.call(self._w, 'active', 'set', index)
1038 def active_clear(self):
1039 self.tk.call(self._w, 'active', 'clear')
1041 def anchor_set(self, index):
1042 self.tk.call(self._w, 'anchor', 'set', index)
1044 def anchor_clear(self):
1045 self.tk.call(self._w, 'anchor', 'clear')
1047 def delete(self, from_, to=None):
1048 self.tk.call(self._w, 'delete', from_, to)
1050 def dragsite_set(self, index):
1051 self.tk.call(self._w, 'dragsite', 'set', index)
1053 def dragsite_clear(self):
1054 self.tk.call(self._w, 'dragsite', 'clear')
1056 def dropsite_set(self, index):
1057 self.tk.call(self._w, 'dropsite', 'set', index)
1059 def dropsite_clear(self):
1060 self.tk.call(self._w, 'dropsite', 'clear')
1062 def insert(self, index, cnf={}, **kw):
1063 apply(self.tk.call,
1064 (self._w, 'insert', index) + self._options(cnf, kw))
1066 def info_active(self):
1067 return self.tk.call(self._w, 'info', 'active')
1069 def info_anchor(self):
1070 return self.tk.call(self._w, 'info', 'anchor')
1072 def info_down(self, index):
1073 return self.tk.call(self._w, 'info', 'down', index)
1075 def info_left(self, index):
1076 return self.tk.call(self._w, 'info', 'left', index)
1078 def info_right(self, index):
1079 return self.tk.call(self._w, 'info', 'right', index)
1081 def info_selection(self):
1082 c = self.tk.call(self._w, 'info', 'selection')
1083 return self.tk.splitlist(c)
1085 def info_size(self):
1086 return self.tk.call(self._w, 'info', 'size')
1088 def info_up(self, index):
1089 return self.tk.call(self._w, 'info', 'up', index)
1091 def nearest(self, x, y):
1092 return self.tk.call(self._w, 'nearest', x, y)
1094 def see(self, index):
1095 self.tk.call(self._w, 'see', index)
1097 def selection_clear(self, cnf={}, **kw):
1098 apply(self.tk.call,
1099 (self._w, 'selection', 'clear') + self._options(cnf, kw))
1101 def selection_includes(self, index):
1102 return self.tk.call(self._w, 'selection', 'includes', index)
1104 def selection_set(self, first, last=None):
1105 self.tk.call(self._w, 'selection', 'set', first, last)
1107 def xview(self, *args):
1108 apply(self.tk.call, (self._w, 'xview') + args)
1110 def yview(self, *args):
1111 apply(self.tk.call, (self._w, 'yview') + args)
1113 class Tree(TixWidget):
1114 """Tree - The tixTree widget (general purpose DirList like widget)"""
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')
1123 def autosetmode(self):
1124 self.tk.call(self._w, 'autosetmode')
1126 def close(self, entrypath):
1127 self.tk.call(self._w, 'close', entrypath)
1129 def getmode(self, entrypath):
1130 return self.tk.call(self._w, 'getmode', entrypath)
1132 def open(self, entrypath):
1133 self.tk.call(self._w, 'open', entrypath)
1135 def setmode(self, entrypath, mode='none'):
1136 self.tk.call(self._w, 'setmode', entrypath, mode)
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 ###########################################################################
1143 class _dummyButton(Button, TixSubWidget):
1144 def __init__(self, master, name, destroy_physically=1):
1145 TixSubWidget.__init__(self, master, name, destroy_physically)
1147 class _dummyCheckbutton(Checkbutton, TixSubWidget):
1148 def __init__(self, master, name, destroy_physically=1):
1149 TixSubWidget.__init__(self, master, name, destroy_physically)
1151 class _dummyEntry(Entry, TixSubWidget):
1152 def __init__(self, master, name, destroy_physically=1):
1153 TixSubWidget.__init__(self, master, name, destroy_physically)
1155 class _dummyFrame(Frame, TixSubWidget):
1156 def __init__(self, master, name, destroy_physically=1):
1157 TixSubWidget.__init__(self, master, name, destroy_physically)
1159 class _dummyLabel(Label, TixSubWidget):
1160 def __init__(self, master, name, destroy_physically=1):
1161 TixSubWidget.__init__(self, master, name, destroy_physically)
1163 class _dummyListbox(Listbox, TixSubWidget):
1164 def __init__(self, master, name, destroy_physically=1):
1165 TixSubWidget.__init__(self, master, name, destroy_physically)
1167 class _dummyMenu(Menu, TixSubWidget):
1168 def __init__(self, master, name, destroy_physically=1):
1169 TixSubWidget.__init__(self, master, name, destroy_physically)
1171 class _dummyMenubutton(Menubutton, TixSubWidget):
1172 def __init__(self, master, name, destroy_physically=1):
1173 TixSubWidget.__init__(self, master, name, destroy_physically)
1175 class _dummyScrollbar(Scrollbar, TixSubWidget):
1176 def __init__(self, master, name, destroy_physically=1):
1177 TixSubWidget.__init__(self, master, name, destroy_physically)
1179 class _dummyText(Text, TixSubWidget):
1180 def __init__(self, master, name, destroy_physically=1):
1181 TixSubWidget.__init__(self, master, name, destroy_physically)
1183 class _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')
1190 class _dummyHList(HList, TixSubWidget):
1191 def __init__(self, master, name, destroy_physically=1):
1192 TixSubWidget.__init__(self, master, name, destroy_physically)
1194 class _dummyTList(TList, TixSubWidget):
1195 def __init__(self, master, name, destroy_physically=1):
1196 TixSubWidget.__init__(self, master, name, destroy_physically)
1198 class _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)
1208 class _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')
1215 class _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')
1227 class _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')
1235 class _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')
1243 class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
1244 def __init__(self, master, name, destroy_physically=0):
1245 TixSubWidget.__init__(self, master, name, destroy_physically)
1247 ########################
1248 ### Utility Routines ###
1249 ########################
1251 # Returns the qualified path name for the widget. Normally used to set
1252 # default options for subwidgets. See tixwidgets.py
1253 def OptionName(widget):
1254 return widget.tk.call('tixOptionName', widget._w)
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}}'
1261 def FileTypeList(dict):
1262 s = ''
1263 for type in dict.keys():
1264 s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
1265 return s