blob: d69fb3a104fd1455b41aeb6b0a496d4e684e7e5a [file] [log] [blame]
Georg Brandl33cece02008-05-20 06:58:21 +00001# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
2#
3# $Id$
4#
5# Tix.py -- Tix widget wrappers.
6#
7# For Tix, see http://tix.sourceforge.net
8#
9# - Sudhir Shenoy (sshenoy@gol.com), Dec. 1995.
10# based on an idea of Jean-Marc Lugrin (lugrin@ms.com)
11#
12# NOTE: In order to minimize changes to Tkinter.py, some of the code here
13# (TixWidget.__init__) has been taken from Tkinter (Widget.__init__)
14# and will break if there are major changes in Tkinter.
15#
16# The Tix widgets are represented by a class hierarchy in python with proper
17# inheritance of base classes.
18#
19# As a result after creating a 'w = StdButtonBox', I can write
20# w.ok['text'] = 'Who Cares'
21# or w.ok['bg'] = w['bg']
22# or even w.ok.invoke()
23# etc.
24#
25# Compare the demo tixwidgets.py to the original Tcl program and you will
26# appreciate the advantages.
27#
28
Georg Brandl6634bf22008-05-20 07:13:37 +000029from Tkinter import *
30from Tkinter import _flatten, _cnfmerge, _default_root
Georg Brandl33cece02008-05-20 06:58:21 +000031
32# WARNING - TkVersion is a limited precision floating point number
33if TkVersion < 3.999:
34 raise ImportError, "This version of Tix.py requires Tk 4.0 or higher"
35
36import _tkinter # If this fails your Python may not be configured for Tk
37
38# Some more constants (for consistency with Tkinter)
39WINDOW = 'window'
40TEXT = 'text'
41STATUS = 'status'
42IMMEDIATE = 'immediate'
43IMAGE = 'image'
44IMAGETEXT = 'imagetext'
45BALLOON = 'balloon'
46AUTO = 'auto'
47ACROSSTOP = 'acrosstop'
48
Guilherme Polo6b3c7092009-08-18 14:23:00 +000049# A few useful constants for the Grid widget
50ASCII = 'ascii'
51CELL = 'cell'
52COLUMN = 'column'
53DECREASING = 'decreasing'
54INCREASING = 'increasing'
55INTEGER = 'integer'
56MAIN = 'main'
57MAX = 'max'
58REAL = 'real'
59ROW = 'row'
60S_REGION = 's-region'
61X_REGION = 'x-region'
62Y_REGION = 'y-region'
63
Georg Brandl33cece02008-05-20 06:58:21 +000064# Some constants used by Tkinter dooneevent()
65TCL_DONT_WAIT = 1 << 1
66TCL_WINDOW_EVENTS = 1 << 2
67TCL_FILE_EVENTS = 1 << 3
68TCL_TIMER_EVENTS = 1 << 4
69TCL_IDLE_EVENTS = 1 << 5
70TCL_ALL_EVENTS = 0
71
72# BEWARE - this is implemented by copying some code from the Widget class
73# in Tkinter (to override Widget initialization) and is therefore
74# liable to break.
Georg Brandl6634bf22008-05-20 07:13:37 +000075import Tkinter, os
Georg Brandl33cece02008-05-20 06:58:21 +000076
77# Could probably add this to Tkinter.Misc
78class tixCommand:
79 """The tix commands provide access to miscellaneous elements
80 of Tix's internal state and the Tix application context.
81 Most of the information manipulated by these commands pertains
82 to the application as a whole, or to a screen or
83 display, rather than to a particular window.
84
85 This is a mixin class, assumed to be mixed to Tkinter.Tk
86 that supports the self.tk.call method.
87 """
88
89 def tix_addbitmapdir(self, directory):
90 """Tix maintains a list of directories under which
91 the tix_getimage and tix_getbitmap commands will
92 search for image files. The standard bitmap directory
93 is $TIX_LIBRARY/bitmaps. The addbitmapdir command
94 adds directory into this list. By using this
95 command, the image files of an applications can
96 also be located using the tix_getimage or tix_getbitmap
97 command.
98 """
99 return self.tk.call('tix', 'addbitmapdir', directory)
100
101 def tix_cget(self, option):
102 """Returns the current value of the configuration
103 option given by option. Option may be any of the
104 options described in the CONFIGURATION OPTIONS section.
105 """
106 return self.tk.call('tix', 'cget', option)
107
108 def tix_configure(self, cnf=None, **kw):
109 """Query or modify the configuration options of the Tix application
110 context. If no option is specified, returns a dictionary all of the
111 available options. If option is specified with no value, then the
112 command returns a list describing the one named option (this list
113 will be identical to the corresponding sublist of the value
114 returned if no option is specified). If one or more option-value
115 pairs are specified, then the command modifies the given option(s)
116 to have the given value(s); in this case the command returns an
117 empty string. Option may be any of the configuration options.
118 """
119 # Copied from Tkinter.py
120 if kw:
121 cnf = _cnfmerge((cnf, kw))
122 elif cnf:
123 cnf = _cnfmerge(cnf)
124 if cnf is None:
125 cnf = {}
126 for x in self.tk.split(self.tk.call('tix', 'configure')):
127 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
128 return cnf
129 if isinstance(cnf, StringType):
130 x = self.tk.split(self.tk.call('tix', 'configure', '-'+cnf))
131 return (x[0][1:],) + x[1:]
132 return self.tk.call(('tix', 'configure') + self._options(cnf))
133
134 def tix_filedialog(self, dlgclass=None):
135 """Returns the file selection dialog that may be shared among
136 different calls from this application. This command will create a
137 file selection dialog widget when it is called the first time. This
138 dialog will be returned by all subsequent calls to tix_filedialog.
139 An optional dlgclass parameter can be passed to specified what type
140 of file selection dialog widget is desired. Possible options are
141 tix FileSelectDialog or tixExFileSelectDialog.
142 """
143 if dlgclass is not None:
144 return self.tk.call('tix', 'filedialog', dlgclass)
145 else:
146 return self.tk.call('tix', 'filedialog')
147
148 def tix_getbitmap(self, name):
149 """Locates a bitmap file of the name name.xpm or name in one of the
150 bitmap directories (see the tix_addbitmapdir command above). By
151 using tix_getbitmap, you can avoid hard coding the pathnames of the
152 bitmap files in your application. When successful, it returns the
153 complete pathname of the bitmap file, prefixed with the character
154 '@'. The returned value can be used to configure the -bitmap
155 option of the TK and Tix widgets.
156 """
157 return self.tk.call('tix', 'getbitmap', name)
158
159 def tix_getimage(self, name):
160 """Locates an image file of the name name.xpm, name.xbm or name.ppm
161 in one of the bitmap directories (see the addbitmapdir command
162 above). If more than one file with the same name (but different
163 extensions) exist, then the image type is chosen according to the
164 depth of the X display: xbm images are chosen on monochrome
165 displays and color images are chosen on color displays. By using
166 tix_ getimage, you can advoid hard coding the pathnames of the
167 image files in your application. When successful, this command
168 returns the name of the newly created image, which can be used to
169 configure the -image option of the Tk and Tix widgets.
170 """
171 return self.tk.call('tix', 'getimage', name)
172
173 def tix_option_get(self, name):
174 """Gets the options manitained by the Tix
175 scheme mechanism. Available options include:
176
177 active_bg active_fg bg
178 bold_font dark1_bg dark1_fg
179 dark2_bg dark2_fg disabled_fg
180 fg fixed_font font
181 inactive_bg inactive_fg input1_bg
182 input2_bg italic_font light1_bg
183 light1_fg light2_bg light2_fg
184 menu_font output1_bg output2_bg
185 select_bg select_fg selector
186 """
187 # could use self.tk.globalgetvar('tixOption', name)
188 return self.tk.call('tix', 'option', 'get', name)
189
190 def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
191 """Resets the scheme and fontset of the Tix application to
192 newScheme and newFontSet, respectively. This affects only those
193 widgets created after this call. Therefore, it is best to call the
194 resetoptions command before the creation of any widgets in a Tix
195 application.
196
197 The optional parameter newScmPrio can be given to reset the
198 priority level of the Tk options set by the Tix schemes.
199
200 Because of the way Tk handles the X option database, after Tix has
201 been has imported and inited, it is not possible to reset the color
202 schemes and font sets using the tix config command. Instead, the
203 tix_resetoptions command must be used.
204 """
205 if newScmPrio is not None:
206 return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
207 else:
208 return self.tk.call('tix', 'resetoptions', newScheme, newFontSet)
209
Georg Brandl6634bf22008-05-20 07:13:37 +0000210class Tk(Tkinter.Tk, tixCommand):
Georg Brandl33cece02008-05-20 06:58:21 +0000211 """Toplevel widget of Tix which represents mostly the main window
212 of an application. It has an associated Tcl interpreter."""
213 def __init__(self, screenName=None, baseName=None, className='Tix'):
Georg Brandl6634bf22008-05-20 07:13:37 +0000214 Tkinter.Tk.__init__(self, screenName, baseName, className)
Georg Brandl33cece02008-05-20 06:58:21 +0000215 tixlib = os.environ.get('TIX_LIBRARY')
216 self.tk.eval('global auto_path; lappend auto_path [file dir [info nameof]]')
217 if tixlib is not None:
218 self.tk.eval('global auto_path; lappend auto_path {%s}' % tixlib)
219 self.tk.eval('global tcl_pkgPath; lappend tcl_pkgPath {%s}' % tixlib)
220 # Load Tix - this should work dynamically or statically
221 # If it's static, tcl/tix8.1/pkgIndex.tcl should have
222 # 'load {} Tix'
223 # If it's dynamic under Unix, tcl/tix8.1/pkgIndex.tcl should have
224 # 'load libtix8.1.8.3.so Tix'
225 self.tk.eval('package require Tix')
226
227 def destroy(self):
228 # For safety, remove an delete_window binding before destroy
229 self.protocol("WM_DELETE_WINDOW", "")
Georg Brandl6634bf22008-05-20 07:13:37 +0000230 Tkinter.Tk.destroy(self)
Georg Brandl33cece02008-05-20 06:58:21 +0000231
232# The Tix 'tixForm' geometry manager
233class Form:
234 """The Tix Form geometry manager
235
236 Widgets can be arranged by specifying attachments to other widgets.
237 See Tix documentation for complete details"""
238
239 def config(self, cnf={}, **kw):
240 self.tk.call('tixForm', self._w, *self._options(cnf, kw))
241
242 form = config
243
244 def __setitem__(self, key, value):
245 Form.form(self, {key: value})
246
247 def check(self):
248 return self.tk.call('tixForm', 'check', self._w)
249
250 def forget(self):
251 self.tk.call('tixForm', 'forget', self._w)
252
253 def grid(self, xsize=0, ysize=0):
254 if (not xsize) and (not ysize):
255 x = self.tk.call('tixForm', 'grid', self._w)
256 y = self.tk.splitlist(x)
257 z = ()
258 for x in y:
259 z = z + (self.tk.getint(x),)
260 return z
261 return self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
262
263 def info(self, option=None):
264 if not option:
265 return self.tk.call('tixForm', 'info', self._w)
266 if option[0] != '-':
267 option = '-' + option
268 return self.tk.call('tixForm', 'info', self._w, option)
269
270 def slaves(self):
271 return map(self._nametowidget,
272 self.tk.splitlist(
273 self.tk.call(
274 'tixForm', 'slaves', self._w)))
275
276
277
Georg Brandl6634bf22008-05-20 07:13:37 +0000278Tkinter.Widget.__bases__ = Tkinter.Widget.__bases__ + (Form,)
Georg Brandl33cece02008-05-20 06:58:21 +0000279
Georg Brandl6634bf22008-05-20 07:13:37 +0000280class TixWidget(Tkinter.Widget):
Georg Brandl33cece02008-05-20 06:58:21 +0000281 """A TixWidget class is used to package all (or most) Tix widgets.
282
283 Widget initialization is extended in two ways:
284 1) It is possible to give a list of options which must be part of
285 the creation command (so called Tix 'static' options). These cannot be
286 given as a 'config' command later.
287 2) It is possible to give the name of an existing TK widget. These are
288 child widgets created automatically by a Tix mega-widget. The Tk call
289 to create these widgets is therefore bypassed in TixWidget.__init__
290
291 Both options are for use by subclasses only.
292 """
293 def __init__ (self, master=None, widgetName=None,
294 static_options=None, cnf={}, kw={}):
295 # Merge keywords and dictionary arguments
296 if kw:
297 cnf = _cnfmerge((cnf, kw))
298 else:
299 cnf = _cnfmerge(cnf)
300
301 # Move static options into extra. static_options must be
302 # a list of keywords (or None).
303 extra=()
304
305 # 'options' is always a static option
306 if static_options:
307 static_options.append('options')
308 else:
309 static_options = ['options']
310
311 for k,v in cnf.items()[:]:
312 if k in static_options:
313 extra = extra + ('-' + k, v)
314 del cnf[k]
315
316 self.widgetName = widgetName
317 Widget._setup(self, master, cnf)
318
319 # If widgetName is None, this is a dummy creation call where the
320 # corresponding Tk widget has already been created by Tix
321 if widgetName:
322 self.tk.call(widgetName, self._w, *extra)
323
324 # Non-static options - to be done via a 'config' command
325 if cnf:
326 Widget.config(self, cnf)
327
328 # Dictionary to hold subwidget names for easier access. We can't
329 # use the children list because the public Tix names may not be the
330 # same as the pathname component
331 self.subwidget_list = {}
332
333 # We set up an attribute access function so that it is possible to
334 # do w.ok['text'] = 'Hello' rather than w.subwidget('ok')['text'] = 'Hello'
335 # when w is a StdButtonBox.
336 # We can even do w.ok.invoke() because w.ok is subclassed from the
337 # Button class if you go through the proper constructors
338 def __getattr__(self, name):
339 if self.subwidget_list.has_key(name):
340 return self.subwidget_list[name]
341 raise AttributeError, name
342
343 def set_silent(self, value):
344 """Set a variable without calling its action routine"""
345 self.tk.call('tixSetSilent', self._w, value)
346
347 def subwidget(self, name):
348 """Return the named subwidget (which must have been created by
349 the sub-class)."""
350 n = self._subwidget_name(name)
351 if not n:
352 raise TclError, "Subwidget " + name + " not child of " + self._name
353 # Remove header of name and leading dot
354 n = n[len(self._w)+1:]
355 return self._nametowidget(n)
356
357 def subwidgets_all(self):
358 """Return all subwidgets."""
359 names = self._subwidget_names()
360 if not names:
361 return []
362 retlist = []
363 for name in names:
364 name = name[len(self._w)+1:]
365 try:
366 retlist.append(self._nametowidget(name))
367 except:
368 # some of the widgets are unknown e.g. border in LabelFrame
369 pass
370 return retlist
371
372 def _subwidget_name(self,name):
373 """Get a subwidget name (returns a String, not a Widget !)"""
374 try:
375 return self.tk.call(self._w, 'subwidget', name)
376 except TclError:
377 return None
378
379 def _subwidget_names(self):
380 """Return the name of all subwidgets."""
381 try:
382 x = self.tk.call(self._w, 'subwidgets', '-all')
383 return self.tk.split(x)
384 except TclError:
385 return None
386
387 def config_all(self, option, value):
388 """Set configuration options for all subwidgets (and self)."""
389 if option == '':
390 return
391 elif not isinstance(option, StringType):
392 option = repr(option)
393 if not isinstance(value, StringType):
394 value = repr(value)
395 names = self._subwidget_names()
396 for name in names:
397 self.tk.call(name, 'configure', '-' + option, value)
398 # These are missing from Tkinter
399 def image_create(self, imgtype, cnf={}, master=None, **kw):
400 if not master:
Georg Brandl6634bf22008-05-20 07:13:37 +0000401 master = Tkinter._default_root
Georg Brandl33cece02008-05-20 06:58:21 +0000402 if not master:
403 raise RuntimeError, 'Too early to create image'
404 if kw and cnf: cnf = _cnfmerge((cnf, kw))
405 elif kw: cnf = kw
406 options = ()
407 for k, v in cnf.items():
408 if callable(v):
409 v = self._register(v)
410 options = options + ('-'+k, v)
411 return master.tk.call(('image', 'create', imgtype,) + options)
412 def image_delete(self, imgname):
413 try:
414 self.tk.call('image', 'delete', imgname)
415 except TclError:
416 # May happen if the root was destroyed
417 pass
418
419# Subwidgets are child widgets created automatically by mega-widgets.
420# In python, we have to create these subwidgets manually to mirror their
421# existence in Tk/Tix.
422class TixSubWidget(TixWidget):
423 """Subwidget class.
424
425 This is used to mirror child widgets automatically created
426 by Tix/Tk as part of a mega-widget in Python (which is not informed
427 of this)"""
428
429 def __init__(self, master, name,
430 destroy_physically=1, check_intermediate=1):
431 if check_intermediate:
432 path = master._subwidget_name(name)
433 try:
434 path = path[len(master._w)+1:]
435 plist = path.split('.')
436 except:
437 plist = []
438
439 if not check_intermediate:
440 # immediate descendant
441 TixWidget.__init__(self, master, None, None, {'name' : name})
442 else:
443 # Ensure that the intermediate widgets exist
444 parent = master
445 for i in range(len(plist) - 1):
446 n = '.'.join(plist[:i+1])
447 try:
448 w = master._nametowidget(n)
449 parent = w
450 except KeyError:
451 # Create the intermediate widget
452 parent = TixSubWidget(parent, plist[i],
453 destroy_physically=0,
454 check_intermediate=0)
455 # The Tk widget name is in plist, not in name
456 if plist:
457 name = plist[-1]
458 TixWidget.__init__(self, parent, None, None, {'name' : name})
459 self.destroy_physically = destroy_physically
460
461 def destroy(self):
462 # For some widgets e.g., a NoteBook, when we call destructors,
463 # we must be careful not to destroy the frame widget since this
464 # also destroys the parent NoteBook thus leading to an exception
465 # in Tkinter when it finally calls Tcl to destroy the NoteBook
466 for c in self.children.values(): c.destroy()
467 if self.master.children.has_key(self._name):
468 del self.master.children[self._name]
469 if self.master.subwidget_list.has_key(self._name):
470 del self.master.subwidget_list[self._name]
471 if self.destroy_physically:
472 # This is bypassed only for a few widgets
473 self.tk.call('destroy', self._w)
474
475
476# Useful func. to split Tcl lists and return as a dict. From Tkinter.py
477def _lst2dict(lst):
478 dict = {}
479 for x in lst:
480 dict[x[0][1:]] = (x[0][1:],) + x[1:]
481 return dict
482
483# Useful class to create a display style - later shared by many items.
484# Contributed by Steffen Kremser
485class DisplayStyle:
486 """DisplayStyle - handle configuration options shared by
487 (multiple) Display Items"""
488
489 def __init__(self, itemtype, cnf={}, **kw):
490 master = _default_root # global from Tkinter
491 if not master and cnf.has_key('refwindow'): master=cnf['refwindow']
492 elif not master and kw.has_key('refwindow'): master= kw['refwindow']
493 elif not master: raise RuntimeError, "Too early to create display style: no root window"
494 self.tk = master.tk
495 self.stylename = self.tk.call('tixDisplayStyle', itemtype,
496 *self._options(cnf,kw) )
497
498 def __str__(self):
499 return self.stylename
500
501 def _options(self, cnf, kw):
502 if kw and cnf:
503 cnf = _cnfmerge((cnf, kw))
504 elif kw:
505 cnf = kw
506 opts = ()
507 for k, v in cnf.items():
508 opts = opts + ('-'+k, v)
509 return opts
510
511 def delete(self):
512 self.tk.call(self.stylename, 'delete')
513
514 def __setitem__(self,key,value):
515 self.tk.call(self.stylename, 'configure', '-%s'%key, value)
516
517 def config(self, cnf={}, **kw):
518 return _lst2dict(
519 self.tk.split(
520 self.tk.call(
521 self.stylename, 'configure', *self._options(cnf,kw))))
522
523 def __getitem__(self,key):
524 return self.tk.call(self.stylename, 'cget', '-%s'%key)
525
526
527######################################################
528### The Tix Widget classes - in alphabetical order ###
529######################################################
530
531class Balloon(TixWidget):
532 """Balloon help widget.
533
534 Subwidget Class
535 --------- -----
536 label Label
537 message Message"""
538
539 # FIXME: It should inherit -superclass tixShell
540 def __init__(self, master=None, cnf={}, **kw):
541 # static seem to be -installcolormap -initwait -statusbar -cursor
542 static = ['options', 'installcolormap', 'initwait', 'statusbar',
543 'cursor']
544 TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
545 self.subwidget_list['label'] = _dummyLabel(self, 'label',
546 destroy_physically=0)
547 self.subwidget_list['message'] = _dummyLabel(self, 'message',
548 destroy_physically=0)
549
550 def bind_widget(self, widget, cnf={}, **kw):
551 """Bind balloon widget to another.
552 One balloon widget may be bound to several widgets at the same time"""
553 self.tk.call(self._w, 'bind', widget._w, *self._options(cnf, kw))
554
555 def unbind_widget(self, widget):
556 self.tk.call(self._w, 'unbind', widget._w)
557
558class ButtonBox(TixWidget):
559 """ButtonBox - A container for pushbuttons.
560 Subwidgets are the buttons added with the add method.
561 """
562 def __init__(self, master=None, cnf={}, **kw):
563 TixWidget.__init__(self, master, 'tixButtonBox',
564 ['orientation', 'options'], cnf, kw)
565
566 def add(self, name, cnf={}, **kw):
567 """Add a button with given name to box."""
568
569 btn = self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
570 self.subwidget_list[name] = _dummyButton(self, name)
571 return btn
572
573 def invoke(self, name):
574 if self.subwidget_list.has_key(name):
575 self.tk.call(self._w, 'invoke', name)
576
577class ComboBox(TixWidget):
578 """ComboBox - an Entry field with a dropdown menu. The user can select a
579 choice by either typing in the entry subwdget or selecting from the
580 listbox subwidget.
581
582 Subwidget Class
583 --------- -----
584 entry Entry
585 arrow Button
586 slistbox ScrolledListBox
587 tick Button
588 cross Button : present if created with the fancy option"""
589
590 # FIXME: It should inherit -superclass tixLabelWidget
591 def __init__ (self, master=None, cnf={}, **kw):
592 TixWidget.__init__(self, master, 'tixComboBox',
593 ['editable', 'dropdown', 'fancy', 'options'],
594 cnf, kw)
595 self.subwidget_list['label'] = _dummyLabel(self, 'label')
596 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
597 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
598 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
599 'slistbox')
600 try:
601 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
602 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
603 except TypeError:
604 # unavailable when -fancy not specified
605 pass
606
607 # align
608
609 def add_history(self, str):
610 self.tk.call(self._w, 'addhistory', str)
611
612 def append_history(self, str):
613 self.tk.call(self._w, 'appendhistory', str)
614
615 def insert(self, index, str):
616 self.tk.call(self._w, 'insert', index, str)
617
618 def pick(self, index):
619 self.tk.call(self._w, 'pick', index)
620
621class Control(TixWidget):
622 """Control - An entry field with value change arrows. The user can
623 adjust the value by pressing the two arrow buttons or by entering
624 the value directly into the entry. The new value will be checked
625 against the user-defined upper and lower limits.
626
627 Subwidget Class
628 --------- -----
629 incr Button
630 decr Button
631 entry Entry
632 label Label"""
633
634 # FIXME: It should inherit -superclass tixLabelWidget
635 def __init__ (self, master=None, cnf={}, **kw):
636 TixWidget.__init__(self, master, 'tixControl', ['options'], cnf, kw)
637 self.subwidget_list['incr'] = _dummyButton(self, 'incr')
638 self.subwidget_list['decr'] = _dummyButton(self, 'decr')
639 self.subwidget_list['label'] = _dummyLabel(self, 'label')
640 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
641
642 def decrement(self):
643 self.tk.call(self._w, 'decr')
644
645 def increment(self):
646 self.tk.call(self._w, 'incr')
647
648 def invoke(self):
649 self.tk.call(self._w, 'invoke')
650
651 def update(self):
652 self.tk.call(self._w, 'update')
653
654class DirList(TixWidget):
655 """DirList - displays a list view of a directory, its previous
656 directories and its sub-directories. The user can choose one of
657 the directories displayed in the list or change to another directory.
658
659 Subwidget Class
660 --------- -----
661 hlist HList
662 hsb Scrollbar
663 vsb Scrollbar"""
664
665 # FIXME: It should inherit -superclass tixScrolledHList
666 def __init__(self, master, cnf={}, **kw):
667 TixWidget.__init__(self, master, 'tixDirList', ['options'], cnf, kw)
668 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
669 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
670 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
671
672 def chdir(self, dir):
673 self.tk.call(self._w, 'chdir', dir)
674
675class DirTree(TixWidget):
676 """DirTree - Directory Listing in a hierarchical view.
677 Displays a tree view of a directory, its previous directories and its
678 sub-directories. The user can choose one of the directories displayed
679 in the list or change to another directory.
680
681 Subwidget Class
682 --------- -----
683 hlist HList
684 hsb Scrollbar
685 vsb Scrollbar"""
686
687 # FIXME: It should inherit -superclass tixScrolledHList
688 def __init__(self, master, cnf={}, **kw):
689 TixWidget.__init__(self, master, 'tixDirTree', ['options'], cnf, kw)
690 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
691 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
692 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
693
694 def chdir(self, dir):
695 self.tk.call(self._w, 'chdir', dir)
696
697class DirSelectBox(TixWidget):
698 """DirSelectBox - Motif style file select box.
699 It is generally used for
700 the user to choose a file. FileSelectBox stores the files mostly
701 recently selected into a ComboBox widget so that they can be quickly
702 selected again.
703
704 Subwidget Class
705 --------- -----
706 selection ComboBox
707 filter ComboBox
708 dirlist ScrolledListBox
709 filelist ScrolledListBox"""
710
711 def __init__(self, master, cnf={}, **kw):
712 TixWidget.__init__(self, master, 'tixDirSelectBox', ['options'], cnf, kw)
713 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
714 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
715
716class ExFileSelectBox(TixWidget):
717 """ExFileSelectBox - MS Windows style file select box.
718 It provides an convenient method for the user to select files.
719
720 Subwidget Class
721 --------- -----
722 cancel Button
723 ok Button
724 hidden Checkbutton
725 types ComboBox
726 dir ComboBox
727 file ComboBox
728 dirlist ScrolledListBox
729 filelist ScrolledListBox"""
730
731 def __init__(self, master, cnf={}, **kw):
732 TixWidget.__init__(self, master, 'tixExFileSelectBox', ['options'], cnf, kw)
733 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
734 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
735 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
736 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
737 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
738 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
739 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
740 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
741
742 def filter(self):
743 self.tk.call(self._w, 'filter')
744
745 def invoke(self):
746 self.tk.call(self._w, 'invoke')
747
748
749# Should inherit from a Dialog class
750class DirSelectDialog(TixWidget):
751 """The DirSelectDialog widget presents the directories in the file
752 system in a dialog window. The user can use this dialog window to
753 navigate through the file system to select the desired directory.
754
755 Subwidgets Class
756 ---------- -----
757 dirbox DirSelectDialog"""
758
759 # FIXME: It should inherit -superclass tixDialogShell
760 def __init__(self, master, cnf={}, **kw):
761 TixWidget.__init__(self, master, 'tixDirSelectDialog',
762 ['options'], cnf, kw)
763 self.subwidget_list['dirbox'] = _dummyDirSelectBox(self, 'dirbox')
764 # cancel and ok buttons are missing
765
766 def popup(self):
767 self.tk.call(self._w, 'popup')
768
769 def popdown(self):
770 self.tk.call(self._w, 'popdown')
771
772
773# Should inherit from a Dialog class
774class ExFileSelectDialog(TixWidget):
775 """ExFileSelectDialog - MS Windows style file select dialog.
776 It provides an convenient method for the user to select files.
777
778 Subwidgets Class
779 ---------- -----
780 fsbox ExFileSelectBox"""
781
782 # FIXME: It should inherit -superclass tixDialogShell
783 def __init__(self, master, cnf={}, **kw):
784 TixWidget.__init__(self, master, 'tixExFileSelectDialog',
785 ['options'], cnf, kw)
786 self.subwidget_list['fsbox'] = _dummyExFileSelectBox(self, 'fsbox')
787
788 def popup(self):
789 self.tk.call(self._w, 'popup')
790
791 def popdown(self):
792 self.tk.call(self._w, 'popdown')
793
794class FileSelectBox(TixWidget):
795 """ExFileSelectBox - Motif style file select box.
796 It is generally used for
797 the user to choose a file. FileSelectBox stores the files mostly
798 recently selected into a ComboBox widget so that they can be quickly
799 selected again.
800
801 Subwidget Class
802 --------- -----
803 selection ComboBox
804 filter ComboBox
805 dirlist ScrolledListBox
806 filelist ScrolledListBox"""
807
808 def __init__(self, master, cnf={}, **kw):
809 TixWidget.__init__(self, master, 'tixFileSelectBox', ['options'], cnf, kw)
810 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
811 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
812 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
813 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
814
815 def apply_filter(self): # name of subwidget is same as command
816 self.tk.call(self._w, 'filter')
817
818 def invoke(self):
819 self.tk.call(self._w, 'invoke')
820
821# Should inherit from a Dialog class
822class FileSelectDialog(TixWidget):
823 """FileSelectDialog - Motif style file select dialog.
824
825 Subwidgets Class
826 ---------- -----
827 btns StdButtonBox
828 fsbox FileSelectBox"""
829
830 # FIXME: It should inherit -superclass tixStdDialogShell
831 def __init__(self, master, cnf={}, **kw):
832 TixWidget.__init__(self, master, 'tixFileSelectDialog',
833 ['options'], cnf, kw)
834 self.subwidget_list['btns'] = _dummyStdButtonBox(self, 'btns')
835 self.subwidget_list['fsbox'] = _dummyFileSelectBox(self, 'fsbox')
836
837 def popup(self):
838 self.tk.call(self._w, 'popup')
839
840 def popdown(self):
841 self.tk.call(self._w, 'popdown')
842
843class FileEntry(TixWidget):
844 """FileEntry - Entry field with button that invokes a FileSelectDialog.
845 The user can type in the filename manually. Alternatively, the user can
846 press the button widget that sits next to the entry, which will bring
847 up a file selection dialog.
848
849 Subwidgets Class
850 ---------- -----
851 button Button
852 entry Entry"""
853
854 # FIXME: It should inherit -superclass tixLabelWidget
855 def __init__(self, master, cnf={}, **kw):
856 TixWidget.__init__(self, master, 'tixFileEntry',
857 ['dialogtype', 'options'], cnf, kw)
858 self.subwidget_list['button'] = _dummyButton(self, 'button')
859 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
860
861 def invoke(self):
862 self.tk.call(self._w, 'invoke')
863
864 def file_dialog(self):
865 # FIXME: return python object
866 pass
867
Guilherme Poloe45f0172009-08-14 14:36:45 +0000868class HList(TixWidget, XView, YView):
Georg Brandl33cece02008-05-20 06:58:21 +0000869 """HList - Hierarchy display widget can be used to display any data
870 that have a hierarchical structure, for example, file system directory
871 trees. The list entries are indented and connected by branch lines
872 according to their places in the hierachy.
873
874 Subwidgets - None"""
875
876 def __init__ (self,master=None,cnf={}, **kw):
877 TixWidget.__init__(self, master, 'tixHList',
878 ['columns', 'options'], cnf, kw)
879
880 def add(self, entry, cnf={}, **kw):
881 return self.tk.call(self._w, 'add', entry, *self._options(cnf, kw))
882
883 def add_child(self, parent=None, cnf={}, **kw):
884 if not parent:
885 parent = ''
886 return self.tk.call(
887 self._w, 'addchild', parent, *self._options(cnf, kw))
888
889 def anchor_set(self, entry):
890 self.tk.call(self._w, 'anchor', 'set', entry)
891
892 def anchor_clear(self):
893 self.tk.call(self._w, 'anchor', 'clear')
894
895 def column_width(self, col=0, width=None, chars=None):
896 if not chars:
897 return self.tk.call(self._w, 'column', 'width', col, width)
898 else:
899 return self.tk.call(self._w, 'column', 'width', col,
900 '-char', chars)
901
902 def delete_all(self):
903 self.tk.call(self._w, 'delete', 'all')
904
905 def delete_entry(self, entry):
906 self.tk.call(self._w, 'delete', 'entry', entry)
907
908 def delete_offsprings(self, entry):
909 self.tk.call(self._w, 'delete', 'offsprings', entry)
910
911 def delete_siblings(self, entry):
912 self.tk.call(self._w, 'delete', 'siblings', entry)
913
914 def dragsite_set(self, index):
915 self.tk.call(self._w, 'dragsite', 'set', index)
916
917 def dragsite_clear(self):
918 self.tk.call(self._w, 'dragsite', 'clear')
919
920 def dropsite_set(self, index):
921 self.tk.call(self._w, 'dropsite', 'set', index)
922
923 def dropsite_clear(self):
924 self.tk.call(self._w, 'dropsite', 'clear')
925
926 def header_create(self, col, cnf={}, **kw):
927 self.tk.call(self._w, 'header', 'create', col, *self._options(cnf, kw))
928
929 def header_configure(self, col, cnf={}, **kw):
930 if cnf is None:
931 return _lst2dict(
932 self.tk.split(
933 self.tk.call(self._w, 'header', 'configure', col)))
934 self.tk.call(self._w, 'header', 'configure', col,
935 *self._options(cnf, kw))
936
937 def header_cget(self, col, opt):
938 return self.tk.call(self._w, 'header', 'cget', col, opt)
939
940 def header_exists(self, col):
941 return self.tk.call(self._w, 'header', 'exists', col)
942
943 def header_delete(self, col):
944 self.tk.call(self._w, 'header', 'delete', col)
945
946 def header_size(self, col):
947 return self.tk.call(self._w, 'header', 'size', col)
948
949 def hide_entry(self, entry):
950 self.tk.call(self._w, 'hide', 'entry', entry)
951
952 def indicator_create(self, entry, cnf={}, **kw):
953 self.tk.call(
954 self._w, 'indicator', 'create', entry, *self._options(cnf, kw))
955
956 def indicator_configure(self, entry, cnf={}, **kw):
957 if cnf is None:
958 return _lst2dict(
959 self.tk.split(
960 self.tk.call(self._w, 'indicator', 'configure', entry)))
961 self.tk.call(
962 self._w, 'indicator', 'configure', entry, *self._options(cnf, kw))
963
964 def indicator_cget(self, entry, opt):
965 return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
966
967 def indicator_exists(self, entry):
968 return self.tk.call (self._w, 'indicator', 'exists', entry)
969
970 def indicator_delete(self, entry):
971 self.tk.call(self._w, 'indicator', 'delete', entry)
972
973 def indicator_size(self, entry):
974 return self.tk.call(self._w, 'indicator', 'size', entry)
975
976 def info_anchor(self):
977 return self.tk.call(self._w, 'info', 'anchor')
978
Guilherme Polo7b50c4f2009-08-18 14:46:57 +0000979 def info_bbox(self, entry):
980 return self._getints(
981 self.tk.call(self._w, 'info', 'bbox', entry)) or None
982
Georg Brandl33cece02008-05-20 06:58:21 +0000983 def info_children(self, entry=None):
984 c = self.tk.call(self._w, 'info', 'children', entry)
985 return self.tk.splitlist(c)
986
987 def info_data(self, entry):
988 return self.tk.call(self._w, 'info', 'data', entry)
989
Guilherme Polo7b50c4f2009-08-18 14:46:57 +0000990 def info_dragsite(self):
991 return self.tk.call(self._w, 'info', 'dragsite')
992
993 def info_dropsite(self):
994 return self.tk.call(self._w, 'info', 'dropsite')
995
Georg Brandl33cece02008-05-20 06:58:21 +0000996 def info_exists(self, entry):
997 return self.tk.call(self._w, 'info', 'exists', entry)
998
999 def info_hidden(self, entry):
1000 return self.tk.call(self._w, 'info', 'hidden', entry)
1001
1002 def info_next(self, entry):
1003 return self.tk.call(self._w, 'info', 'next', entry)
1004
1005 def info_parent(self, entry):
1006 return self.tk.call(self._w, 'info', 'parent', entry)
1007
1008 def info_prev(self, entry):
1009 return self.tk.call(self._w, 'info', 'prev', entry)
1010
1011 def info_selection(self):
1012 c = self.tk.call(self._w, 'info', 'selection')
1013 return self.tk.splitlist(c)
1014
1015 def item_cget(self, entry, col, opt):
1016 return self.tk.call(self._w, 'item', 'cget', entry, col, opt)
1017
1018 def item_configure(self, entry, col, cnf={}, **kw):
1019 if cnf is None:
1020 return _lst2dict(
1021 self.tk.split(
1022 self.tk.call(self._w, 'item', 'configure', entry, col)))
1023 self.tk.call(self._w, 'item', 'configure', entry, col,
1024 *self._options(cnf, kw))
1025
1026 def item_create(self, entry, col, cnf={}, **kw):
1027 self.tk.call(
1028 self._w, 'item', 'create', entry, col, *self._options(cnf, kw))
1029
1030 def item_exists(self, entry, col):
1031 return self.tk.call(self._w, 'item', 'exists', entry, col)
1032
1033 def item_delete(self, entry, col):
1034 self.tk.call(self._w, 'item', 'delete', entry, col)
1035
1036 def entrycget(self, entry, opt):
1037 return self.tk.call(self._w, 'entrycget', entry, opt)
1038
1039 def entryconfigure(self, entry, cnf={}, **kw):
1040 if cnf is None:
1041 return _lst2dict(
1042 self.tk.split(
1043 self.tk.call(self._w, 'entryconfigure', entry)))
1044 self.tk.call(self._w, 'entryconfigure', entry,
1045 *self._options(cnf, kw))
1046
1047 def nearest(self, y):
1048 return self.tk.call(self._w, 'nearest', y)
1049
1050 def see(self, entry):
1051 self.tk.call(self._w, 'see', entry)
1052
1053 def selection_clear(self, cnf={}, **kw):
1054 self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
1055
1056 def selection_includes(self, entry):
1057 return self.tk.call(self._w, 'selection', 'includes', entry)
1058
1059 def selection_set(self, first, last=None):
1060 self.tk.call(self._w, 'selection', 'set', first, last)
1061
1062 def show_entry(self, entry):
1063 return self.tk.call(self._w, 'show', 'entry', entry)
1064
Georg Brandl33cece02008-05-20 06:58:21 +00001065class InputOnly(TixWidget):
1066 """InputOnly - Invisible widget. Unix only.
1067
1068 Subwidgets - None"""
1069
1070 def __init__ (self,master=None,cnf={}, **kw):
1071 TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
1072
1073class LabelEntry(TixWidget):
1074 """LabelEntry - Entry field with label. Packages an entry widget
1075 and a label into one mega widget. It can beused be used to simplify
1076 the creation of ``entry-form'' type of interface.
1077
1078 Subwidgets Class
1079 ---------- -----
1080 label Label
1081 entry Entry"""
1082
1083 def __init__ (self,master=None,cnf={}, **kw):
1084 TixWidget.__init__(self, master, 'tixLabelEntry',
1085 ['labelside','options'], cnf, kw)
1086 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1087 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
1088
1089class LabelFrame(TixWidget):
1090 """LabelFrame - Labelled Frame container. Packages a frame widget
1091 and a label into one mega widget. To create widgets inside a
1092 LabelFrame widget, one creates the new widgets relative to the
1093 frame subwidget and manage them inside the frame subwidget.
1094
1095 Subwidgets Class
1096 ---------- -----
1097 label Label
1098 frame Frame"""
1099
1100 def __init__ (self,master=None,cnf={}, **kw):
1101 TixWidget.__init__(self, master, 'tixLabelFrame',
1102 ['labelside','options'], cnf, kw)
1103 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1104 self.subwidget_list['frame'] = _dummyFrame(self, 'frame')
1105
1106
1107class ListNoteBook(TixWidget):
1108 """A ListNoteBook widget is very similar to the TixNoteBook widget:
1109 it can be used to display many windows in a limited space using a
1110 notebook metaphor. The notebook is divided into a stack of pages
1111 (windows). At one time only one of these pages can be shown.
1112 The user can navigate through these pages by
1113 choosing the name of the desired page in the hlist subwidget."""
1114
1115 def __init__(self, master, cnf={}, **kw):
1116 TixWidget.__init__(self, master, 'tixListNoteBook', ['options'], cnf, kw)
1117 # Is this necessary? It's not an exposed subwidget in Tix.
1118 self.subwidget_list['pane'] = _dummyPanedWindow(self, 'pane',
1119 destroy_physically=0)
1120 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1121 self.subwidget_list['shlist'] = _dummyScrolledHList(self, 'shlist')
1122
1123 def add(self, name, cnf={}, **kw):
1124 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
1125 self.subwidget_list[name] = TixSubWidget(self, name)
1126 return self.subwidget_list[name]
1127
1128 def page(self, name):
1129 return self.subwidget(name)
1130
1131 def pages(self):
1132 # Can't call subwidgets_all directly because we don't want .nbframe
1133 names = self.tk.split(self.tk.call(self._w, 'pages'))
1134 ret = []
1135 for x in names:
1136 ret.append(self.subwidget(x))
1137 return ret
1138
1139 def raise_page(self, name): # raise is a python keyword
1140 self.tk.call(self._w, 'raise', name)
1141
1142class Meter(TixWidget):
1143 """The Meter widget can be used to show the progress of a background
1144 job which may take a long time to execute.
1145 """
1146
1147 def __init__(self, master=None, cnf={}, **kw):
1148 TixWidget.__init__(self, master, 'tixMeter',
1149 ['options'], cnf, kw)
1150
1151class NoteBook(TixWidget):
1152 """NoteBook - Multi-page container widget (tabbed notebook metaphor).
1153
1154 Subwidgets Class
1155 ---------- -----
1156 nbframe NoteBookFrame
1157 <pages> page widgets added dynamically with the add method"""
1158
1159 def __init__ (self,master=None,cnf={}, **kw):
1160 TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw)
1161 self.subwidget_list['nbframe'] = TixSubWidget(self, 'nbframe',
1162 destroy_physically=0)
1163
1164 def add(self, name, cnf={}, **kw):
1165 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
1166 self.subwidget_list[name] = TixSubWidget(self, name)
1167 return self.subwidget_list[name]
1168
1169 def delete(self, name):
1170 self.tk.call(self._w, 'delete', name)
1171 self.subwidget_list[name].destroy()
1172 del self.subwidget_list[name]
1173
1174 def page(self, name):
1175 return self.subwidget(name)
1176
1177 def pages(self):
1178 # Can't call subwidgets_all directly because we don't want .nbframe
1179 names = self.tk.split(self.tk.call(self._w, 'pages'))
1180 ret = []
1181 for x in names:
1182 ret.append(self.subwidget(x))
1183 return ret
1184
1185 def raise_page(self, name): # raise is a python keyword
1186 self.tk.call(self._w, 'raise', name)
1187
1188 def raised(self):
1189 return self.tk.call(self._w, 'raised')
1190
1191class NoteBookFrame(TixWidget):
1192 # FIXME: This is dangerous to expose to be called on its own.
1193 pass
1194
1195class OptionMenu(TixWidget):
1196 """OptionMenu - creates a menu button of options.
1197
1198 Subwidget Class
1199 --------- -----
1200 menubutton Menubutton
1201 menu Menu"""
1202
1203 def __init__(self, master, cnf={}, **kw):
1204 TixWidget.__init__(self, master, 'tixOptionMenu', ['options'], cnf, kw)
1205 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1206 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
1207
1208 def add_command(self, name, cnf={}, **kw):
1209 self.tk.call(self._w, 'add', 'command', name, *self._options(cnf, kw))
1210
1211 def add_separator(self, name, cnf={}, **kw):
1212 self.tk.call(self._w, 'add', 'separator', name, *self._options(cnf, kw))
1213
1214 def delete(self, name):
1215 self.tk.call(self._w, 'delete', name)
1216
1217 def disable(self, name):
1218 self.tk.call(self._w, 'disable', name)
1219
1220 def enable(self, name):
1221 self.tk.call(self._w, 'enable', name)
1222
1223class PanedWindow(TixWidget):
1224 """PanedWindow - Multi-pane container widget
1225 allows the user to interactively manipulate the sizes of several
1226 panes. The panes can be arranged either vertically or horizontally.The
1227 user changes the sizes of the panes by dragging the resize handle
1228 between two panes.
1229
1230 Subwidgets Class
1231 ---------- -----
1232 <panes> g/p widgets added dynamically with the add method."""
1233
1234 def __init__(self, master, cnf={}, **kw):
1235 TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
1236
1237 # add delete forget panecget paneconfigure panes setsize
1238 def add(self, name, cnf={}, **kw):
1239 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
1240 self.subwidget_list[name] = TixSubWidget(self, name,
1241 check_intermediate=0)
1242 return self.subwidget_list[name]
1243
1244 def delete(self, name):
1245 self.tk.call(self._w, 'delete', name)
1246 self.subwidget_list[name].destroy()
1247 del self.subwidget_list[name]
1248
1249 def forget(self, name):
1250 self.tk.call(self._w, 'forget', name)
1251
1252 def panecget(self, entry, opt):
1253 return self.tk.call(self._w, 'panecget', entry, opt)
1254
1255 def paneconfigure(self, entry, cnf={}, **kw):
1256 if cnf is None:
1257 return _lst2dict(
1258 self.tk.split(
1259 self.tk.call(self._w, 'paneconfigure', entry)))
1260 self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
1261
1262 def panes(self):
Guilherme Polo6c823f82009-08-18 13:29:20 +00001263 names = self.tk.splitlist(self.tk.call(self._w, 'panes'))
1264 return [self.subwidget(x) for x in names]
Georg Brandl33cece02008-05-20 06:58:21 +00001265
1266class PopupMenu(TixWidget):
1267 """PopupMenu widget can be used as a replacement of the tk_popup command.
1268 The advantage of the Tix PopupMenu widget is it requires less application
1269 code to manipulate.
1270
1271
1272 Subwidgets Class
1273 ---------- -----
1274 menubutton Menubutton
1275 menu Menu"""
1276
1277 # FIXME: It should inherit -superclass tixShell
1278 def __init__(self, master, cnf={}, **kw):
1279 TixWidget.__init__(self, master, 'tixPopupMenu', ['options'], cnf, kw)
1280 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1281 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
1282
1283 def bind_widget(self, widget):
1284 self.tk.call(self._w, 'bind', widget._w)
1285
1286 def unbind_widget(self, widget):
1287 self.tk.call(self._w, 'unbind', widget._w)
1288
1289 def post_widget(self, widget, x, y):
1290 self.tk.call(self._w, 'post', widget._w, x, y)
1291
1292class ResizeHandle(TixWidget):
1293 """Internal widget to draw resize handles on Scrolled widgets."""
1294 def __init__(self, master, cnf={}, **kw):
1295 # There seems to be a Tix bug rejecting the configure method
1296 # Let's try making the flags -static
1297 flags = ['options', 'command', 'cursorfg', 'cursorbg',
1298 'handlesize', 'hintcolor', 'hintwidth',
1299 'x', 'y']
1300 # In fact, x y height width are configurable
1301 TixWidget.__init__(self, master, 'tixResizeHandle',
1302 flags, cnf, kw)
1303
1304 def attach_widget(self, widget):
1305 self.tk.call(self._w, 'attachwidget', widget._w)
1306
1307 def detach_widget(self, widget):
1308 self.tk.call(self._w, 'detachwidget', widget._w)
1309
1310 def hide(self, widget):
1311 self.tk.call(self._w, 'hide', widget._w)
1312
1313 def show(self, widget):
1314 self.tk.call(self._w, 'show', widget._w)
1315
1316class ScrolledHList(TixWidget):
1317 """ScrolledHList - HList with automatic scrollbars."""
1318
1319 # FIXME: It should inherit -superclass tixScrolledWidget
1320 def __init__(self, master, cnf={}, **kw):
1321 TixWidget.__init__(self, master, 'tixScrolledHList', ['options'],
1322 cnf, kw)
1323 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1324 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1325 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1326
1327class ScrolledListBox(TixWidget):
1328 """ScrolledListBox - Listbox with automatic scrollbars."""
1329
1330 # FIXME: It should inherit -superclass tixScrolledWidget
1331 def __init__(self, master, cnf={}, **kw):
1332 TixWidget.__init__(self, master, 'tixScrolledListBox', ['options'], cnf, kw)
1333 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1334 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1335 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1336
1337class ScrolledText(TixWidget):
1338 """ScrolledText - Text with automatic scrollbars."""
1339
1340 # FIXME: It should inherit -superclass tixScrolledWidget
1341 def __init__(self, master, cnf={}, **kw):
1342 TixWidget.__init__(self, master, 'tixScrolledText', ['options'], cnf, kw)
1343 self.subwidget_list['text'] = _dummyText(self, 'text')
1344 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1345 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1346
1347class ScrolledTList(TixWidget):
1348 """ScrolledTList - TList with automatic scrollbars."""
1349
1350 # FIXME: It should inherit -superclass tixScrolledWidget
1351 def __init__(self, master, cnf={}, **kw):
1352 TixWidget.__init__(self, master, 'tixScrolledTList', ['options'],
1353 cnf, kw)
1354 self.subwidget_list['tlist'] = _dummyTList(self, 'tlist')
1355 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1356 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1357
1358class ScrolledWindow(TixWidget):
1359 """ScrolledWindow - Window with automatic scrollbars."""
1360
1361 # FIXME: It should inherit -superclass tixScrolledWidget
1362 def __init__(self, master, cnf={}, **kw):
1363 TixWidget.__init__(self, master, 'tixScrolledWindow', ['options'], cnf, kw)
1364 self.subwidget_list['window'] = _dummyFrame(self, 'window')
1365 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1366 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1367
1368class Select(TixWidget):
1369 """Select - Container of button subwidgets. It can be used to provide
1370 radio-box or check-box style of selection options for the user.
1371
1372 Subwidgets are buttons added dynamically using the add method."""
1373
1374 # FIXME: It should inherit -superclass tixLabelWidget
1375 def __init__(self, master, cnf={}, **kw):
1376 TixWidget.__init__(self, master, 'tixSelect',
1377 ['allowzero', 'radio', 'orientation', 'labelside',
1378 'options'],
1379 cnf, kw)
1380 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1381
1382 def add(self, name, cnf={}, **kw):
1383 self.tk.call(self._w, 'add', name, *self._options(cnf, kw))
1384 self.subwidget_list[name] = _dummyButton(self, name)
1385 return self.subwidget_list[name]
1386
1387 def invoke(self, name):
1388 self.tk.call(self._w, 'invoke', name)
1389
1390class Shell(TixWidget):
1391 """Toplevel window.
1392
1393 Subwidgets - None"""
1394
1395 def __init__ (self,master=None,cnf={}, **kw):
1396 TixWidget.__init__(self, master, 'tixShell', ['options', 'title'], cnf, kw)
1397
1398class DialogShell(TixWidget):
1399 """Toplevel window, with popup popdown and center methods.
1400 It tells the window manager that it is a dialog window and should be
1401 treated specially. The exact treatment depends on the treatment of
1402 the window manager.
1403
1404 Subwidgets - None"""
1405
1406 # FIXME: It should inherit from Shell
1407 def __init__ (self,master=None,cnf={}, **kw):
1408 TixWidget.__init__(self, master,
1409 'tixDialogShell',
1410 ['options', 'title', 'mapped',
1411 'minheight', 'minwidth',
1412 'parent', 'transient'], cnf, kw)
1413
1414 def popdown(self):
1415 self.tk.call(self._w, 'popdown')
1416
1417 def popup(self):
1418 self.tk.call(self._w, 'popup')
1419
1420 def center(self):
1421 self.tk.call(self._w, 'center')
1422
1423class StdButtonBox(TixWidget):
1424 """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
1425
1426 def __init__(self, master=None, cnf={}, **kw):
1427 TixWidget.__init__(self, master, 'tixStdButtonBox',
1428 ['orientation', 'options'], cnf, kw)
1429 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1430 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1431 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1432 self.subwidget_list['help'] = _dummyButton(self, 'help')
1433
1434 def invoke(self, name):
1435 if self.subwidget_list.has_key(name):
1436 self.tk.call(self._w, 'invoke', name)
1437
Guilherme Poloe45f0172009-08-14 14:36:45 +00001438class TList(TixWidget, XView, YView):
Georg Brandl33cece02008-05-20 06:58:21 +00001439 """TList - Hierarchy display widget which can be
1440 used to display data in a tabular format. The list entries of a TList
1441 widget are similar to the entries in the Tk listbox widget. The main
1442 differences are (1) the TList widget can display the list entries in a
1443 two dimensional format and (2) you can use graphical images as well as
1444 multiple colors and fonts for the list entries.
1445
1446 Subwidgets - None"""
1447
1448 def __init__ (self,master=None,cnf={}, **kw):
1449 TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
1450
1451 def active_set(self, index):
1452 self.tk.call(self._w, 'active', 'set', index)
1453
1454 def active_clear(self):
1455 self.tk.call(self._w, 'active', 'clear')
1456
1457 def anchor_set(self, index):
1458 self.tk.call(self._w, 'anchor', 'set', index)
1459
1460 def anchor_clear(self):
1461 self.tk.call(self._w, 'anchor', 'clear')
1462
1463 def delete(self, from_, to=None):
1464 self.tk.call(self._w, 'delete', from_, to)
1465
1466 def dragsite_set(self, index):
1467 self.tk.call(self._w, 'dragsite', 'set', index)
1468
1469 def dragsite_clear(self):
1470 self.tk.call(self._w, 'dragsite', 'clear')
1471
1472 def dropsite_set(self, index):
1473 self.tk.call(self._w, 'dropsite', 'set', index)
1474
1475 def dropsite_clear(self):
1476 self.tk.call(self._w, 'dropsite', 'clear')
1477
1478 def insert(self, index, cnf={}, **kw):
1479 self.tk.call(self._w, 'insert', index, *self._options(cnf, kw))
1480
1481 def info_active(self):
1482 return self.tk.call(self._w, 'info', 'active')
1483
1484 def info_anchor(self):
1485 return self.tk.call(self._w, 'info', 'anchor')
1486
1487 def info_down(self, index):
1488 return self.tk.call(self._w, 'info', 'down', index)
1489
1490 def info_left(self, index):
1491 return self.tk.call(self._w, 'info', 'left', index)
1492
1493 def info_right(self, index):
1494 return self.tk.call(self._w, 'info', 'right', index)
1495
1496 def info_selection(self):
1497 c = self.tk.call(self._w, 'info', 'selection')
1498 return self.tk.splitlist(c)
1499
1500 def info_size(self):
1501 return self.tk.call(self._w, 'info', 'size')
1502
1503 def info_up(self, index):
1504 return self.tk.call(self._w, 'info', 'up', index)
1505
1506 def nearest(self, x, y):
1507 return self.tk.call(self._w, 'nearest', x, y)
1508
1509 def see(self, index):
1510 self.tk.call(self._w, 'see', index)
1511
1512 def selection_clear(self, cnf={}, **kw):
1513 self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw))
1514
1515 def selection_includes(self, index):
1516 return self.tk.call(self._w, 'selection', 'includes', index)
1517
1518 def selection_set(self, first, last=None):
1519 self.tk.call(self._w, 'selection', 'set', first, last)
1520
Georg Brandl33cece02008-05-20 06:58:21 +00001521class Tree(TixWidget):
1522 """Tree - The tixTree widget can be used to display hierachical
1523 data in a tree form. The user can adjust
1524 the view of the tree by opening or closing parts of the tree."""
1525
1526 # FIXME: It should inherit -superclass tixScrolledWidget
1527 def __init__(self, master=None, cnf={}, **kw):
1528 TixWidget.__init__(self, master, 'tixTree',
1529 ['options'], cnf, kw)
1530 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1531 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1532 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1533
1534 def autosetmode(self):
1535 '''This command calls the setmode method for all the entries in this
1536 Tree widget: if an entry has no child entries, its mode is set to
1537 none. Otherwise, if the entry has any hidden child entries, its mode is
1538 set to open; otherwise its mode is set to close.'''
1539 self.tk.call(self._w, 'autosetmode')
1540
1541 def close(self, entrypath):
1542 '''Close the entry given by entryPath if its mode is close.'''
1543 self.tk.call(self._w, 'close', entrypath)
1544
1545 def getmode(self, entrypath):
1546 '''Returns the current mode of the entry given by entryPath.'''
1547 return self.tk.call(self._w, 'getmode', entrypath)
1548
1549 def open(self, entrypath):
1550 '''Open the entry given by entryPath if its mode is open.'''
1551 self.tk.call(self._w, 'open', entrypath)
1552
1553 def setmode(self, entrypath, mode='none'):
1554 '''This command is used to indicate whether the entry given by
1555 entryPath has children entries and whether the children are visible. mode
1556 must be one of open, close or none. If mode is set to open, a (+)
Walter Dörwald28277092009-05-04 16:03:03 +00001557 indicator is drawn next to the entry. If mode is set to close, a (-)
1558 indicator is drawn next to the entry. If mode is set to none, no
Georg Brandl33cece02008-05-20 06:58:21 +00001559 indicators will be drawn for this entry. The default mode is none. The
1560 open mode indicates the entry has hidden children and this entry can be
1561 opened by the user. The close mode indicates that all the children of the
1562 entry are now visible and the entry can be closed by the user.'''
1563 self.tk.call(self._w, 'setmode', entrypath, mode)
1564
1565
1566# Could try subclassing Tree for CheckList - would need another arg to init
1567class CheckList(TixWidget):
1568 """The CheckList widget
1569 displays a list of items to be selected by the user. CheckList acts
1570 similarly to the Tk checkbutton or radiobutton widgets, except it is
1571 capable of handling many more items than checkbuttons or radiobuttons.
1572 """
1573 # FIXME: It should inherit -superclass tixTree
1574 def __init__(self, master=None, cnf={}, **kw):
1575 TixWidget.__init__(self, master, 'tixCheckList',
Guilherme Polo57f9b722009-08-18 13:33:30 +00001576 ['options', 'radio'], cnf, kw)
Georg Brandl33cece02008-05-20 06:58:21 +00001577 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1578 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1579 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1580
1581 def autosetmode(self):
1582 '''This command calls the setmode method for all the entries in this
1583 Tree widget: if an entry has no child entries, its mode is set to
1584 none. Otherwise, if the entry has any hidden child entries, its mode is
1585 set to open; otherwise its mode is set to close.'''
1586 self.tk.call(self._w, 'autosetmode')
1587
1588 def close(self, entrypath):
1589 '''Close the entry given by entryPath if its mode is close.'''
1590 self.tk.call(self._w, 'close', entrypath)
1591
1592 def getmode(self, entrypath):
1593 '''Returns the current mode of the entry given by entryPath.'''
1594 return self.tk.call(self._w, 'getmode', entrypath)
1595
1596 def open(self, entrypath):
1597 '''Open the entry given by entryPath if its mode is open.'''
1598 self.tk.call(self._w, 'open', entrypath)
1599
1600 def getselection(self, mode='on'):
1601 '''Returns a list of items whose status matches status. If status is
1602 not specified, the list of items in the "on" status will be returned.
1603 Mode can be on, off, default'''
1604 c = self.tk.split(self.tk.call(self._w, 'getselection', mode))
1605 return self.tk.splitlist(c)
1606
1607 def getstatus(self, entrypath):
1608 '''Returns the current status of entryPath.'''
1609 return self.tk.call(self._w, 'getstatus', entrypath)
1610
1611 def setstatus(self, entrypath, mode='on'):
1612 '''Sets the status of entryPath to be status. A bitmap will be
1613 displayed next to the entry its status is on, off or default.'''
1614 self.tk.call(self._w, 'setstatus', entrypath, mode)
1615
1616
1617###########################################################################
1618### The subclassing below is used to instantiate the subwidgets in each ###
1619### mega widget. This allows us to access their methods directly. ###
1620###########################################################################
1621
1622class _dummyButton(Button, TixSubWidget):
1623 def __init__(self, master, name, destroy_physically=1):
1624 TixSubWidget.__init__(self, master, name, destroy_physically)
1625
1626class _dummyCheckbutton(Checkbutton, TixSubWidget):
1627 def __init__(self, master, name, destroy_physically=1):
1628 TixSubWidget.__init__(self, master, name, destroy_physically)
1629
1630class _dummyEntry(Entry, TixSubWidget):
1631 def __init__(self, master, name, destroy_physically=1):
1632 TixSubWidget.__init__(self, master, name, destroy_physically)
1633
1634class _dummyFrame(Frame, TixSubWidget):
1635 def __init__(self, master, name, destroy_physically=1):
1636 TixSubWidget.__init__(self, master, name, destroy_physically)
1637
1638class _dummyLabel(Label, TixSubWidget):
1639 def __init__(self, master, name, destroy_physically=1):
1640 TixSubWidget.__init__(self, master, name, destroy_physically)
1641
1642class _dummyListbox(Listbox, TixSubWidget):
1643 def __init__(self, master, name, destroy_physically=1):
1644 TixSubWidget.__init__(self, master, name, destroy_physically)
1645
1646class _dummyMenu(Menu, TixSubWidget):
1647 def __init__(self, master, name, destroy_physically=1):
1648 TixSubWidget.__init__(self, master, name, destroy_physically)
1649
1650class _dummyMenubutton(Menubutton, TixSubWidget):
1651 def __init__(self, master, name, destroy_physically=1):
1652 TixSubWidget.__init__(self, master, name, destroy_physically)
1653
1654class _dummyScrollbar(Scrollbar, TixSubWidget):
1655 def __init__(self, master, name, destroy_physically=1):
1656 TixSubWidget.__init__(self, master, name, destroy_physically)
1657
1658class _dummyText(Text, TixSubWidget):
1659 def __init__(self, master, name, destroy_physically=1):
1660 TixSubWidget.__init__(self, master, name, destroy_physically)
1661
1662class _dummyScrolledListBox(ScrolledListBox, TixSubWidget):
1663 def __init__(self, master, name, destroy_physically=1):
1664 TixSubWidget.__init__(self, master, name, destroy_physically)
1665 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1666 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1667 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1668
1669class _dummyHList(HList, TixSubWidget):
1670 def __init__(self, master, name, destroy_physically=1):
1671 TixSubWidget.__init__(self, master, name, destroy_physically)
1672
1673class _dummyScrolledHList(ScrolledHList, TixSubWidget):
1674 def __init__(self, master, name, destroy_physically=1):
1675 TixSubWidget.__init__(self, master, name, destroy_physically)
1676 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1677 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1678 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1679
1680class _dummyTList(TList, TixSubWidget):
1681 def __init__(self, master, name, destroy_physically=1):
1682 TixSubWidget.__init__(self, master, name, destroy_physically)
1683
1684class _dummyComboBox(ComboBox, TixSubWidget):
1685 def __init__(self, master, name, destroy_physically=1):
1686 TixSubWidget.__init__(self, master, name, ['fancy',destroy_physically])
1687 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1688 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
1689 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
1690
1691 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
1692 'slistbox')
1693 try:
1694 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
1695 #cross Button : present if created with the fancy option
1696 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
1697 except TypeError:
1698 # unavailable when -fancy not specified
1699 pass
1700
1701class _dummyDirList(DirList, TixSubWidget):
1702 def __init__(self, master, name, destroy_physically=1):
1703 TixSubWidget.__init__(self, master, name, destroy_physically)
1704 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1705 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1706 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
1707
1708class _dummyDirSelectBox(DirSelectBox, TixSubWidget):
1709 def __init__(self, master, name, destroy_physically=1):
1710 TixSubWidget.__init__(self, master, name, destroy_physically)
1711 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
1712 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
1713
1714class _dummyExFileSelectBox(ExFileSelectBox, TixSubWidget):
1715 def __init__(self, master, name, destroy_physically=1):
1716 TixSubWidget.__init__(self, master, name, destroy_physically)
1717 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1718 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1719 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
1720 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
1721 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
1722 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1723 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
1724 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1725
1726class _dummyFileSelectBox(FileSelectBox, TixSubWidget):
1727 def __init__(self, master, name, destroy_physically=1):
1728 TixSubWidget.__init__(self, master, name, destroy_physically)
1729 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1730 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1731 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
1732 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
1733
1734class _dummyFileComboBox(ComboBox, TixSubWidget):
1735 def __init__(self, master, name, destroy_physically=1):
1736 TixSubWidget.__init__(self, master, name, destroy_physically)
1737 self.subwidget_list['dircbx'] = _dummyComboBox(self, 'dircbx')
1738
1739class _dummyStdButtonBox(StdButtonBox, TixSubWidget):
1740 def __init__(self, master, name, destroy_physically=1):
1741 TixSubWidget.__init__(self, master, name, destroy_physically)
1742 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1743 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1744 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1745 self.subwidget_list['help'] = _dummyButton(self, 'help')
1746
1747class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
1748 def __init__(self, master, name, destroy_physically=0):
1749 TixSubWidget.__init__(self, master, name, destroy_physically)
1750
1751class _dummyPanedWindow(PanedWindow, TixSubWidget):
1752 def __init__(self, master, name, destroy_physically=1):
1753 TixSubWidget.__init__(self, master, name, destroy_physically)
1754
1755########################
1756### Utility Routines ###
1757########################
1758
1759#mike Should tixDestroy be exposed as a wrapper? - but not for widgets.
1760
1761def OptionName(widget):
1762 '''Returns the qualified path name for the widget. Normally used to set
1763 default options for subwidgets. See tixwidgets.py'''
1764 return widget.tk.call('tixOptionName', widget._w)
1765
1766# Called with a dictionary argument of the form
1767# {'*.c':'C source files', '*.txt':'Text Files', '*':'All files'}
1768# returns a string which can be used to configure the fsbox file types
1769# in an ExFileSelectBox. i.e.,
1770# '{{*} {* - All files}} {{*.c} {*.c - C source files}} {{*.txt} {*.txt - Text Files}}'
1771def FileTypeList(dict):
1772 s = ''
1773 for type in dict.keys():
1774 s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
1775 return s
1776
1777# Still to be done:
1778# tixIconView
1779class CObjView(TixWidget):
1780 """This file implements the Canvas Object View widget. This is a base
1781 class of IconView. It implements automatic placement/adjustment of the
1782 scrollbars according to the canvas objects inside the canvas subwidget.
1783 The scrollbars are adjusted so that the canvas is just large enough
1784 to see all the objects.
1785 """
1786 # FIXME: It should inherit -superclass tixScrolledWidget
1787 pass
1788
1789
Guilherme Poloe45f0172009-08-14 14:36:45 +00001790class Grid(TixWidget, XView, YView):
Georg Brandl33cece02008-05-20 06:58:21 +00001791 '''The Tix Grid command creates a new window and makes it into a
1792 tixGrid widget. Additional options, may be specified on the command
1793 line or in the option database to configure aspects such as its cursor
1794 and relief.
1795
1796 A Grid widget displays its contents in a two dimensional grid of cells.
1797 Each cell may contain one Tix display item, which may be in text,
1798 graphics or other formats. See the DisplayStyle class for more information
1799 about Tix display items. Individual cells, or groups of cells, can be
1800 formatted with a wide range of attributes, such as its color, relief and
1801 border.
1802
1803 Subwidgets - None'''
1804 # valid specific resources as of Tk 8.4
1805 # editdonecmd, editnotifycmd, floatingcols, floatingrows, formatcmd,
1806 # highlightbackground, highlightcolor, leftmargin, itemtype, selectmode,
1807 # selectunit, topmargin,
1808 def __init__(self, master=None, cnf={}, **kw):
1809 static= []
1810 self.cnf= cnf
1811 TixWidget.__init__(self, master, 'tixGrid', static, cnf, kw)
1812
1813 # valid options as of Tk 8.4
Guilherme Polo6b3c7092009-08-18 14:23:00 +00001814 # anchor, bdtype, cget, configure, delete, dragsite, dropsite, entrycget,
1815 # edit, entryconfigure, format, geometryinfo, info, index, move, nearest,
1816 # selection, set, size, unset, xview, yview
1817 def anchor_clear(self):
1818 """Removes the selection anchor."""
1819 self.tk.call(self, 'anchor', 'clear')
1820
Georg Brandl33cece02008-05-20 06:58:21 +00001821 def anchor_get(self):
1822 "Get the (x,y) coordinate of the current anchor cell"
1823 return self._getints(self.tk.call(self, 'anchor', 'get'))
1824
Guilherme Polo6b3c7092009-08-18 14:23:00 +00001825 def anchor_set(self, x, y):
1826 """Set the selection anchor to the cell at (x, y)."""
1827 self.tk.call(self, 'anchor', 'set', x, y)
1828
Georg Brandl33cece02008-05-20 06:58:21 +00001829 def delete_row(self, from_, to=None):
1830 """Delete rows between from_ and to inclusive.
1831 If to is not provided, delete only row at from_"""
1832 if to is None:
1833 self.tk.call(self, 'delete', 'row', from_)
1834 else:
1835 self.tk.call(self, 'delete', 'row', from_, to)
Guilherme Polo6b3c7092009-08-18 14:23:00 +00001836
Georg Brandl33cece02008-05-20 06:58:21 +00001837 def delete_column(self, from_, to=None):
1838 """Delete columns between from_ and to inclusive.
1839 If to is not provided, delete only column at from_"""
1840 if to is None:
1841 self.tk.call(self, 'delete', 'column', from_)
1842 else:
1843 self.tk.call(self, 'delete', 'column', from_, to)
Guilherme Polo6b3c7092009-08-18 14:23:00 +00001844
1845 def edit_apply(self):
1846 """If any cell is being edited, de-highlight the cell and applies
1847 the changes."""
1848 self.tk.call(self, 'edit', 'apply')
1849
1850 def edit_set(self, x, y):
1851 """Highlights the cell at (x, y) for editing, if the -editnotify
1852 command returns True for this cell."""
1853 self.tk.call(self, 'edit', 'set', x, y)
Georg Brandl33cece02008-05-20 06:58:21 +00001854
1855 def entrycget(self, x, y, option):
1856 "Get the option value for cell at (x,y)"
Guilherme Polo397bd1e2009-08-18 14:34:44 +00001857 if option and option[0] != '-':
1858 option = '-' + option
Georg Brandl33cece02008-05-20 06:58:21 +00001859 return self.tk.call(self, 'entrycget', x, y, option)
1860
Guilherme Polo397bd1e2009-08-18 14:34:44 +00001861 def entryconfigure(self, x, y, cnf=None, **kw):
1862 return self._configure(('entryconfigure', x, y), cnf, kw)
1863
Georg Brandl33cece02008-05-20 06:58:21 +00001864 # def format
1865 # def index
1866
1867 def info_exists(self, x, y):
1868 "Return True if display item exists at (x,y)"
Guilherme Polo397bd1e2009-08-18 14:34:44 +00001869 return self._getboolean(self.tk.call(self, 'info', 'exists', x, y))
Georg Brandl33cece02008-05-20 06:58:21 +00001870
1871 def info_bbox(self, x, y):
1872 # This seems to always return '', at least for 'text' displayitems
1873 return self.tk.call(self, 'info', 'bbox', x, y)
1874
Guilherme Polo6b3c7092009-08-18 14:23:00 +00001875 def move_column(self, from_, to, offset):
1876 """Moves the the range of columns from position FROM through TO by
1877 the distance indicated by OFFSET. For example, move_column(2, 4, 1)
1878 moves the columns 2,3,4 to columns 3,4,5."""
1879 self.tk.call(self, 'move', 'column', from_, to, offset)
1880
1881 def move_row(self, from_, to, offset):
1882 """Moves the the range of rows from position FROM through TO by
1883 the distance indicated by OFFSET.
1884 For example, move_row(2, 4, 1) moves the rows 2,3,4 to rows 3,4,5."""
1885 self.tk.call(self, 'move', 'row', from_, to, offset)
1886
Georg Brandl33cece02008-05-20 06:58:21 +00001887 def nearest(self, x, y):
1888 "Return coordinate of cell nearest pixel coordinate (x,y)"
1889 return self._getints(self.tk.call(self, 'nearest', x, y))
1890
1891 # def selection adjust
1892 # def selection clear
1893 # def selection includes
1894 # def selection set
1895 # def selection toggle
Georg Brandl33cece02008-05-20 06:58:21 +00001896
1897 def set(self, x, y, itemtype=None, **kw):
1898 args= self._options(self.cnf, kw)
1899 if itemtype is not None:
1900 args= ('-itemtype', itemtype) + args
1901 self.tk.call(self, 'set', x, y, *args)
1902
Guilherme Polo6b3c7092009-08-18 14:23:00 +00001903 def size_column(self, index, **kw):
1904 """Queries or sets the size of the column given by
1905 INDEX. INDEX may be any non-negative
1906 integer that gives the position of a given column.
1907 INDEX can also be the string "default"; in this case, this command
1908 queries or sets the default size of all columns.
1909 When no option-value pair is given, this command returns a tuple
1910 containing the current size setting of the given column. When
1911 option-value pairs are given, the corresponding options of the
1912 size setting of the given column are changed. Options may be one
1913 of the follwing:
1914 pad0 pixels
1915 Specifies the paddings to the left of a column.
1916 pad1 pixels
1917 Specifies the paddings to the right of a column.
1918 size val
1919 Specifies the width of a column .
1920 Val may be: "auto" -- the width of the column is set the
1921 the widest cell in the column; a valid Tk screen distance
1922 unit; or a real number following by the word chars
1923 (e.g. 3.4chars) that sets the width of the column to the
1924 given number of characters."""
1925 return self.tk.split(self.tk.call(self._w, 'size', 'column', index,
1926 *self._options({}, kw)))
1927
1928 def size_row(self, index, **kw):
1929 """Queries or sets the size of the row given by
1930 INDEX. INDEX may be any non-negative
1931 integer that gives the position of a given row .
1932 INDEX can also be the string "default"; in this case, this command
1933 queries or sets the default size of all rows.
1934 When no option-value pair is given, this command returns a list con-
1935 taining the current size setting of the given row . When option-value
1936 pairs are given, the corresponding options of the size setting of the
1937 given row are changed. Options may be one of the follwing:
1938 pad0 pixels
1939 Specifies the paddings to the top of a row.
1940 pad1 pixels
1941 Specifies the paddings to the the bottom of a row.
1942 size val
1943 Specifies the height of a row.
1944 Val may be: "auto" -- the height of the row is set the
1945 the highest cell in the row; a valid Tk screen distance
1946 unit; or a real number following by the word chars
1947 (e.g. 3.4chars) that sets the height of the row to the
1948 given number of characters."""
1949 return self.tk.split(self.tk.call(
1950 self, 'size', 'row', index, *self._options({}, kw)))
1951
1952 def unset(self, x, y):
1953 """Clears the cell at (x, y) by removing its display item."""
1954 self.tk.call(self._w, 'unset', x, y)
1955
Georg Brandl33cece02008-05-20 06:58:21 +00001956
Georg Brandl33cece02008-05-20 06:58:21 +00001957class ScrolledGrid(Grid):
1958 '''Scrolled Grid widgets'''
1959
1960 # FIXME: It should inherit -superclass tixScrolledWidget
1961 def __init__(self, master=None, cnf={}, **kw):
1962 static= []
1963 self.cnf= cnf
1964 TixWidget.__init__(self, master, 'tixScrolledGrid', static, cnf, kw)