blob: 1e3e8565283f803d413b45f9f0d7e4f5539713a6 [file] [log] [blame]
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00002#
3# $Id$
4#
Martin v. Löwisb7b32602001-11-02 23:48:20 +00005# Tix.py -- Tix widget wrappers.
6#
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00007# For Tix, see http://tix.sourceforge.net
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00008#
Moshe Zadka22710822001-03-21 17:24:49 +00009# - Sudhir Shenoy (sshenoy@gol.com), Dec. 1995.
Martin v. Löwisb7b32602001-11-02 23:48:20 +000010# based on an idea of Jean-Marc Lugrin (lugrin@ms.com)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000011#
12# NOTE: In order to minimize changes to Tkinter.py, some of the code here
Moshe Zadka22710822001-03-21 17:24:49 +000013# (TixWidget.__init__) has been taken from Tkinter (Widget.__init__)
14# and will break if there are major changes in Tkinter.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000015#
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
Moshe Zadka22710822001-03-21 17:24:49 +000020# w.ok['text'] = 'Who Cares'
21# or w.ok['bg'] = w['bg']
22# or even w.ok.invoke()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000023# etc.
24#
25# Compare the demo tixwidgets.py to the original Tcl program and you will
26# appreciate the advantages.
27#
28
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000029from Tkinter import *
30from Tkinter import _flatten, _cnfmerge, _default_root
31
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
Neal Norwitzebb41902002-05-31 20:51:31 +000037# TixVersion = float(tkinter.TIX_VERSION) # If this fails your Python may not be configured for Tix
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000038# WARNING - TixVersion is a limited precision floating point number
39
40# Some more constants (for consistency with Tkinter)
41WINDOW = 'window'
42TEXT = 'text'
43STATUS = 'status'
44IMMEDIATE = 'immediate'
45IMAGE = 'image'
46IMAGETEXT = 'imagetext'
47BALLOON = 'balloon'
48AUTO = 'auto'
49ACROSSTOP = 'acrosstop'
50
Fred Drake723293c2001-12-13 04:53:07 +000051# Some constants used by Tkinter dooneevent()
52TCL_DONT_WAIT = 1 << 1
53TCL_WINDOW_EVENTS = 1 << 2
54TCL_FILE_EVENTS = 1 << 3
55TCL_TIMER_EVENTS = 1 << 4
56TCL_IDLE_EVENTS = 1 << 5
57TCL_ALL_EVENTS = 0
58
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000059# BEWARE - this is implemented by copying some code from the Widget class
60# in Tkinter (to override Widget initialization) and is therefore
61# liable to break.
62import Tkinter, os
Martin v. Löwisb7b32602001-11-02 23:48:20 +000063
64# Could probably add this to Tkinter.Misc
65class tixCommand:
Fred Drake723293c2001-12-13 04:53:07 +000066 """The tix commands provide access to miscellaneous elements
Martin v. Löwisb7b32602001-11-02 23:48:20 +000067 of Tix's internal state and the Tix application context.
Fred Drake723293c2001-12-13 04:53:07 +000068 Most of the information manipulated by these commands pertains
69 to the application as a whole, or to a screen or
70 display, rather than to a particular window.
Martin v. Löwisb7b32602001-11-02 23:48:20 +000071
72 This is a mixin class, assumed to be mixed to Tkinter.Tk
73 that supports the self.tk.call method.
74 """
Fred Drake723293c2001-12-13 04:53:07 +000075
Martin v. Löwisb7b32602001-11-02 23:48:20 +000076 def tix_addbitmapdir(self, directory):
Fred Drake723293c2001-12-13 04:53:07 +000077 """Tix maintains a list of directories under which
Martin v. Löwisb7b32602001-11-02 23:48:20 +000078 the tix_getimage and tix_getbitmap commands will
Fred Drake723293c2001-12-13 04:53:07 +000079 search for image files. The standard bitmap directory
80 is $TIX_LIBRARY/bitmaps. The addbitmapdir command
81 adds directory into this list. By using this
Martin v. Löwisb7b32602001-11-02 23:48:20 +000082 command, the image files of an applications can
83 also be located using the tix_getimage or tix_getbitmap
84 command.
85 """
86 return self.tk.call('tix', 'addbitmapdir', directory)
87
88 def tix_cget(self, option):
89 """Returns the current value of the configuration
90 option given by option. Option may be any of the
91 options described in the CONFIGURATION OPTIONS section.
92 """
93 return self.tk.call('tix', 'cget', option)
94
95 def tix_configure(self, cnf=None, **kw):
Fred Drake723293c2001-12-13 04:53:07 +000096 """Query or modify the configuration options of the Tix application
97 context. If no option is specified, returns a dictionary all of the
98 available options. If option is specified with no value, then the
99 command returns a list describing the one named option (this list
100 will be identical to the corresponding sublist of the value
101 returned if no option is specified). If one or more option-value
102 pairs are specified, then the command modifies the given option(s)
103 to have the given value(s); in this case the command returns an
104 empty string. Option may be any of the configuration options.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000105 """
Fred Drake723293c2001-12-13 04:53:07 +0000106 # Copied from Tkinter.py
107 if kw:
108 cnf = _cnfmerge((cnf, kw))
109 elif cnf:
110 cnf = _cnfmerge(cnf)
111 if cnf is None:
112 cnf = {}
113 for x in self.tk.split(self.tk.call('tix', 'configure')):
114 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
115 return cnf
116 if isinstance(cnf, StringType):
117 x = self.tk.split(self.tk.call('tix', 'configure', '-'+cnf))
118 return (x[0][1:],) + x[1:]
119 return self.tk.call(('tix', 'configure') + self._options(cnf))
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000120
121 def tix_filedialog(self, dlgclass=None):
Fred Drake723293c2001-12-13 04:53:07 +0000122 """Returns the file selection dialog that may be shared among
123 different calls from this application. This command will create a
124 file selection dialog widget when it is called the first time. This
125 dialog will be returned by all subsequent calls to tix_filedialog.
126 An optional dlgclass parameter can be passed to specified what type
127 of file selection dialog widget is desired. Possible options are
128 tix FileSelectDialog or tixExFileSelectDialog.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000129 """
130 if dlgclass is not None:
131 return self.tk.call('tix', 'filedialog', dlgclass)
132 else:
133 return self.tk.call('tix', 'filedialog')
134
135 def tix_getbitmap(self, name):
Fred Drake723293c2001-12-13 04:53:07 +0000136 """Locates a bitmap file of the name name.xpm or name in one of the
137 bitmap directories (see the tix_addbitmapdir command above). By
138 using tix_getbitmap, you can avoid hard coding the pathnames of the
139 bitmap files in your application. When successful, it returns the
140 complete pathname of the bitmap file, prefixed with the character
141 '@'. The returned value can be used to configure the -bitmap
142 option of the TK and Tix widgets.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000143 """
144 return self.tk.call('tix', 'getbitmap', name)
145
146 def tix_getimage(self, name):
Fred Drake723293c2001-12-13 04:53:07 +0000147 """Locates an image file of the name name.xpm, name.xbm or name.ppm
148 in one of the bitmap directories (see the addbitmapdir command
149 above). If more than one file with the same name (but different
150 extensions) exist, then the image type is chosen according to the
151 depth of the X display: xbm images are chosen on monochrome
152 displays and color images are chosen on color displays. By using
153 tix_ getimage, you can advoid hard coding the pathnames of the
154 image files in your application. When successful, this command
155 returns the name of the newly created image, which can be used to
156 configure the -image option of the Tk and Tix widgets.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000157 """
158 return self.tk.call('tix', 'getimage', name)
159
160 def tix_option_get(self, name):
161 """Gets the options manitained by the Tix
Fred Drake723293c2001-12-13 04:53:07 +0000162 scheme mechanism. Available options include:
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000163
164 active_bg active_fg bg
165 bold_font dark1_bg dark1_fg
166 dark2_bg dark2_fg disabled_fg
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000167 fg fixed_font font
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000168 inactive_bg inactive_fg input1_bg
169 input2_bg italic_font light1_bg
170 light1_fg light2_bg light2_fg
171 menu_font output1_bg output2_bg
172 select_bg select_fg selector
173 """
174 # could use self.tk.globalgetvar('tixOption', name)
175 return self.tk.call('tix', 'option', 'get', name)
176
177 def tix_resetoptions(self, newScheme, newFontSet, newScmPrio=None):
Fred Drake723293c2001-12-13 04:53:07 +0000178 """Resets the scheme and fontset of the Tix application to
179 newScheme and newFontSet, respectively. This affects only those
180 widgets created after this call. Therefore, it is best to call the
181 resetoptions command before the creation of any widgets in a Tix
182 application.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000183
Fred Drake723293c2001-12-13 04:53:07 +0000184 The optional parameter newScmPrio can be given to reset the
185 priority level of the Tk options set by the Tix schemes.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000186
Fred Drake723293c2001-12-13 04:53:07 +0000187 Because of the way Tk handles the X option database, after Tix has
188 been has imported and inited, it is not possible to reset the color
189 schemes and font sets using the tix config command. Instead, the
190 tix_resetoptions command must be used.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000191 """
192 if newScmPrio is not None:
193 return self.tk.call('tix', 'resetoptions', newScheme, newFontSet, newScmPrio)
194 else:
195 return self.tk.call('tix', 'resetoptions', newScheme, newFontSet)
196
197class Tk(Tkinter.Tk, tixCommand):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000198 """Toplevel widget of Tix which represents mostly the main window
199 of an application. It has an associated Tcl interpreter."""
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000200 def __init__(self, screenName=None, baseName=None, className='Tix'):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000201 Tkinter.Tk.__init__(self, screenName, baseName, className)
Moshe Zadka22710822001-03-21 17:24:49 +0000202 tixlib = os.environ.get('TIX_LIBRARY')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000203 self.tk.eval('global auto_path; lappend auto_path [file dir [info nameof]]')
Moshe Zadka22710822001-03-21 17:24:49 +0000204 if tixlib is not None:
205 self.tk.eval('global auto_path; lappend auto_path {%s}' % tixlib)
206 self.tk.eval('global tcl_pkgPath; lappend tcl_pkgPath {%s}' % tixlib)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000207 # Load Tix - this should work dynamically or statically
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000208 # If it's static, lib/tix8.1/pkgIndex.tcl should have
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000209 # 'load {} Tix'
Fred Drake723293c2001-12-13 04:53:07 +0000210 # If it's dynamic under Unix, lib/tix8.1/pkgIndex.tcl should have
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000211 # 'load libtix8.1.8.3.so Tix'
Moshe Zadka22710822001-03-21 17:24:49 +0000212 self.tk.eval('package require Tix')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000213
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000214
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000215# The Tix 'tixForm' geometry manager
216class Form:
217 """The Tix Form geometry manager
218
219 Widgets can be arranged by specifying attachments to other widgets.
220 See Tix documentation for complete details"""
221
222 def config(self, cnf={}, **kw):
223 apply(self.tk.call, ('tixForm', self._w) + self._options(cnf, kw))
224
225 form = config
226
227 def __setitem__(self, key, value):
Guido van Rossum49fa2bd2001-08-13 14:12:35 +0000228 Form.form(self, {key: value})
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000229
230 def check(self):
231 return self.tk.call('tixForm', 'check', self._w)
232
233 def forget(self):
234 self.tk.call('tixForm', 'forget', self._w)
235
236 def grid(self, xsize=0, ysize=0):
237 if (not xsize) and (not ysize):
238 x = self.tk.call('tixForm', 'grid', self._w)
239 y = self.tk.splitlist(x)
240 z = ()
241 for x in y:
242 z = z + (self.tk.getint(x),)
243 return z
244 self.tk.call('tixForm', 'grid', self._w, xsize, ysize)
245
246 def info(self, option=None):
247 if not option:
248 return self.tk.call('tixForm', 'info', self._w)
249 if option[0] != '-':
250 option = '-' + option
251 return self.tk.call('tixForm', 'info', self._w, option)
252
253 def slaves(self):
254 return map(self._nametowidget,
255 self.tk.splitlist(
256 self.tk.call(
257 'tixForm', 'slaves', self._w)))
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000258
259
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000260
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000261
262Tkinter.Widget.__bases__ = Tkinter.Widget.__bases__ + (Form,)
263
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000264class TixWidget(Tkinter.Widget):
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000265 """A TixWidget class is used to package all (or most) Tix widgets.
266
267 Widget initialization is extended in two ways:
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000268 1) It is possible to give a list of options which must be part of
Moshe Zadka22710822001-03-21 17:24:49 +0000269 the creation command (so called Tix 'static' options). These cannot be
270 given as a 'config' command later.
271 2) It is possible to give the name of an existing TK widget. These are
272 child widgets created automatically by a Tix mega-widget. The Tk call
273 to create these widgets is therefore bypassed in TixWidget.__init__
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000274
275 Both options are for use by subclasses only.
276 """
277 def __init__ (self, master=None, widgetName=None,
Moshe Zadka22710822001-03-21 17:24:49 +0000278 static_options=None, cnf={}, kw={}):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000279 # Merge keywords and dictionary arguments
280 if kw:
Moshe Zadka22710822001-03-21 17:24:49 +0000281 cnf = _cnfmerge((cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000282 else:
283 cnf = _cnfmerge(cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000284
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000285 # Move static options into extra. static_options must be
286 # a list of keywords (or None).
287 extra=()
Neal Norwitzf539bde2002-11-14 02:43:40 +0000288
289 # 'options' is always a static option
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000290 if static_options:
Neal Norwitzf539bde2002-11-14 02:43:40 +0000291 static_options.append('options')
292 else:
293 static_options = ['options']
294
295 for k,v in cnf.items()[:]:
296 if k in static_options:
297 extra = extra + ('-' + k, v)
298 del cnf[k]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000299
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000300 self.widgetName = widgetName
301 Widget._setup(self, master, cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000302
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000303 # If widgetName is None, this is a dummy creation call where the
304 # corresponding Tk widget has already been created by Tix
305 if widgetName:
306 apply(self.tk.call, (widgetName, self._w) + extra)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000307
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000308 # Non-static options - to be done via a 'config' command
309 if cnf:
310 Widget.config(self, cnf)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000311
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000312 # Dictionary to hold subwidget names for easier access. We can't
313 # use the children list because the public Tix names may not be the
314 # same as the pathname component
315 self.subwidget_list = {}
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000316
317 # We set up an attribute access function so that it is possible to
318 # do w.ok['text'] = 'Hello' rather than w.subwidget('ok')['text'] = 'Hello'
319 # when w is a StdButtonBox.
320 # We can even do w.ok.invoke() because w.ok is subclassed from the
321 # Button class if you go through the proper constructors
322 def __getattr__(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000323 if self.subwidget_list.has_key(name):
324 return self.subwidget_list[name]
325 raise AttributeError, name
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000326
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000327 def set_silent(self, value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000328 """Set a variable without calling its action routine"""
329 self.tk.call('tixSetSilent', self._w, value)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000330
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000331 def subwidget(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000332 """Return the named subwidget (which must have been created by
333 the sub-class)."""
334 n = self._subwidget_name(name)
335 if not n:
336 raise TclError, "Subwidget " + name + " not child of " + self._name
337 # Remove header of name and leading dot
338 n = n[len(self._w)+1:]
339 return self._nametowidget(n)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000340
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000341 def subwidgets_all(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000342 """Return all subwidgets."""
343 names = self._subwidget_names()
344 if not names:
345 return []
346 retlist = []
347 for name in names:
348 name = name[len(self._w)+1:]
349 try:
350 retlist.append(self._nametowidget(name))
351 except:
352 # some of the widgets are unknown e.g. border in LabelFrame
353 pass
354 return retlist
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000355
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000356 def _subwidget_name(self,name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000357 """Get a subwidget name (returns a String, not a Widget !)"""
358 try:
359 return self.tk.call(self._w, 'subwidget', name)
360 except TclError:
361 return None
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000362
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000363 def _subwidget_names(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000364 """Return the name of all subwidgets."""
365 try:
366 x = self.tk.call(self._w, 'subwidgets', '-all')
367 return self.tk.split(x)
368 except TclError:
369 return None
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000370
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000371 def config_all(self, option, value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000372 """Set configuration options for all subwidgets (and self)."""
373 if option == '':
374 return
375 elif not isinstance(option, StringType):
376 option = `option`
377 if not isinstance(value, StringType):
378 value = `value`
379 names = self._subwidget_names()
380 for name in names:
381 self.tk.call(name, 'configure', '-' + option, value)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000382
383# Subwidgets are child widgets created automatically by mega-widgets.
384# In python, we have to create these subwidgets manually to mirror their
385# existence in Tk/Tix.
386class TixSubWidget(TixWidget):
387 """Subwidget class.
388
389 This is used to mirror child widgets automatically created
390 by Tix/Tk as part of a mega-widget in Python (which is not informed
391 of this)"""
392
393 def __init__(self, master, name,
Moshe Zadka22710822001-03-21 17:24:49 +0000394 destroy_physically=1, check_intermediate=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000395 if check_intermediate:
396 path = master._subwidget_name(name)
397 try:
398 path = path[len(master._w)+1:]
Neal Norwitzebb41902002-05-31 20:51:31 +0000399 plist = path.split('.')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000400 except:
401 plist = []
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000402
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000403 if (not check_intermediate) or len(plist) < 2:
404 # immediate descendant
405 TixWidget.__init__(self, master, None, None, {'name' : name})
406 else:
407 # Ensure that the intermediate widgets exist
408 parent = master
409 for i in range(len(plist) - 1):
Neal Norwitzebb41902002-05-31 20:51:31 +0000410 n = '.'.join(plist[:i+1])
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000411 try:
412 w = master._nametowidget(n)
413 parent = w
414 except KeyError:
415 # Create the intermediate widget
416 parent = TixSubWidget(parent, plist[i],
Neal Norwitzf539bde2002-11-14 02:43:40 +0000417 destroy_physically=0,
418 check_intermediate=0)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000419 TixWidget.__init__(self, parent, None, None, {'name' : name})
420 self.destroy_physically = destroy_physically
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000421
422 def destroy(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000423 # For some widgets e.g., a NoteBook, when we call destructors,
424 # we must be careful not to destroy the frame widget since this
425 # also destroys the parent NoteBook thus leading to an exception
426 # in Tkinter when it finally calls Tcl to destroy the NoteBook
427 for c in self.children.values(): c.destroy()
428 if self.master.children.has_key(self._name):
429 del self.master.children[self._name]
430 if self.master.subwidget_list.has_key(self._name):
431 del self.master.subwidget_list[self._name]
432 if self.destroy_physically:
433 # This is bypassed only for a few widgets
434 self.tk.call('destroy', self._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000435
436
437# Useful func. to split Tcl lists and return as a dict. From Tkinter.py
438def _lst2dict(lst):
439 dict = {}
440 for x in lst:
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000441 dict[x[0][1:]] = (x[0][1:],) + x[1:]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000442 return dict
443
444# Useful class to create a display style - later shared by many items.
445# Contributed by Steffen Kremser
446class DisplayStyle:
447 """DisplayStyle - handle configuration options shared by
448 (multiple) Display Items"""
449
450 def __init__(self, itemtype, cnf={}, **kw ):
Moshe Zadka22710822001-03-21 17:24:49 +0000451 master = _default_root # global from Tkinter
452 if not master and cnf.has_key('refwindow'): master=cnf['refwindow']
453 elif not master and kw.has_key('refwindow'): master= kw['refwindow']
454 elif not master: raise RuntimeError, "Too early to create display style: no root window"
455 self.tk = master.tk
456 self.stylename = apply(self.tk.call, ('tixDisplayStyle', itemtype) +
457 self._options(cnf,kw) )
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000458
459 def __str__(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000460 return self.stylename
461
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000462 def _options(self, cnf, kw ):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000463 if kw and cnf:
464 cnf = _cnfmerge((cnf, kw))
465 elif kw:
466 cnf = kw
467 opts = ()
468 for k, v in cnf.items():
469 opts = opts + ('-'+k, v)
470 return opts
471
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000472 def delete(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000473 self.tk.call(self.stylename, 'delete')
474
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000475 def __setitem__(self,key,value):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000476 self.tk.call(self.stylename, 'configure', '-%s'%key, value)
477
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000478 def config(self, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000479 return _lst2dict(
480 self.tk.split(
Neal Norwitzf539bde2002-11-14 02:43:40 +0000481 apply(self.tk.call,
482 (self.stylename, 'configure') + self._options(cnf,kw))))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000483
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000484 def __getitem__(self,key):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000485 return self.tk.call(self.stylename, 'cget', '-%s'%key)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000486
487
488######################################################
489### The Tix Widget classes - in alphabetical order ###
490######################################################
491
492class Balloon(TixWidget):
493 """Balloon help widget.
494
Moshe Zadka22710822001-03-21 17:24:49 +0000495 Subwidget Class
496 --------- -----
Fred Drake723293c2001-12-13 04:53:07 +0000497 label Label
498 message Message"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000499
500 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis652e1912001-11-25 14:50:56 +0000501 # static seem to be -installcolormap -initwait -statusbar -cursor
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000502 static = ['options', 'installcolormap', 'initwait', 'statusbar',
503 'cursor']
504 TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
505 self.subwidget_list['label'] = _dummyLabel(self, 'label',
506 destroy_physically=0)
507 self.subwidget_list['message'] = _dummyLabel(self, 'message',
508 destroy_physically=0)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000509
510 def bind_widget(self, widget, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000511 """Bind balloon widget to another.
512 One balloon widget may be bound to several widgets at the same time"""
513 apply(self.tk.call,
514 (self._w, 'bind', widget._w) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000515
516 def unbind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000517 self.tk.call(self._w, 'unbind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000518
519class ButtonBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000520 """ButtonBox - A container for pushbuttons.
521 Subwidgets are the buttons added with the add method.
522 """
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000523 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000524 TixWidget.__init__(self, master, 'tixButtonBox',
525 ['orientation', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000526
527 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000528 """Add a button with given name to box."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000529
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000530 btn = apply(self.tk.call,
531 (self._w, 'add', name) + self._options(cnf, kw))
532 self.subwidget_list[name] = _dummyButton(self, name)
533 return btn
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000534
535 def invoke(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000536 if self.subwidget_list.has_key(name):
537 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000538
539class ComboBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000540 """ComboBox - an Entry field with a dropdown menu. The user can select a
541 choice by either typing in the entry subwdget or selecting from the
542 listbox subwidget.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000543
Moshe Zadka22710822001-03-21 17:24:49 +0000544 Subwidget Class
545 --------- -----
546 entry Entry
547 arrow Button
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000548 slistbox ScrolledListBox
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000549 tick Button
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000550 cross Button : present if created with the fancy option"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000551
552 def __init__ (self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000553 TixWidget.__init__(self, master, 'tixComboBox',
554 ['editable', 'dropdown', 'fancy', 'options'],
555 cnf, kw)
556 self.subwidget_list['label'] = _dummyLabel(self, 'label')
557 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
558 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
559 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
560 'slistbox')
561 try:
562 self.subwidget_list['tick'] = _dummyButton(self, 'tick')
563 self.subwidget_list['cross'] = _dummyButton(self, 'cross')
564 except TypeError:
565 # unavailable when -fancy not specified
566 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000567
568 def add_history(self, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000569 self.tk.call(self._w, 'addhistory', str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000570
571 def append_history(self, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000572 self.tk.call(self._w, 'appendhistory', str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000573
574 def insert(self, index, str):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000575 self.tk.call(self._w, 'insert', index, str)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000576
577 def pick(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000578 self.tk.call(self._w, 'pick', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000579
580class Control(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000581 """Control - An entry field with value change arrows. The user can
582 adjust the value by pressing the two arrow buttons or by entering
583 the value directly into the entry. The new value will be checked
584 against the user-defined upper and lower limits.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000585
Moshe Zadka22710822001-03-21 17:24:49 +0000586 Subwidget Class
587 --------- -----
588 incr Button
589 decr Button
590 entry Entry
591 label Label"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000592
593 def __init__ (self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000594 TixWidget.__init__(self, master, 'tixControl', ['options'], cnf, kw)
595 self.subwidget_list['incr'] = _dummyButton(self, 'incr')
596 self.subwidget_list['decr'] = _dummyButton(self, 'decr')
597 self.subwidget_list['label'] = _dummyLabel(self, 'label')
598 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000599
600 def decrement(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000601 self.tk.call(self._w, 'decr')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000602
603 def increment(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000604 self.tk.call(self._w, 'incr')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000605
606 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000607 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000608
609 def update(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000610 self.tk.call(self._w, 'update')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000611
612class DirList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000613 """DirList - displays a list view of a directory, its previous
614 directories and its sub-directories. The user can choose one of
615 the directories displayed in the list or change to another directory.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000616
Moshe Zadka22710822001-03-21 17:24:49 +0000617 Subwidget Class
618 --------- -----
619 hlist HList
620 hsb Scrollbar
621 vsb Scrollbar"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000622
623 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000624 TixWidget.__init__(self, master, 'tixDirList', ['options'], cnf, kw)
625 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
626 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
627 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000628
629 def chdir(self, dir):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000630 self.tk.call(self._w, 'chdir', dir)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000631
632class DirTree(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000633 """DirTree - Directory Listing in a hierarchical view.
634 Displays a tree view of a directory, its previous directories and its
635 sub-directories. The user can choose one of the directories displayed
636 in the list or change to another directory.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000637
Moshe Zadka22710822001-03-21 17:24:49 +0000638 Subwidget Class
639 --------- -----
Neal Norwitzf539bde2002-11-14 02:43:40 +0000640 hlist HList
641 hsb Scrollbar
642 vsb Scrollbar"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000643
644 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000645 TixWidget.__init__(self, master, 'tixDirTree', ['options'], cnf, kw)
646 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
647 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
648 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000649
650 def chdir(self, dir):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000651 self.tk.call(self._w, 'chdir', dir)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000652
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000653class DirSelectBox(TixWidget):
654 """DirSelectBox - Motif style file select box.
655 It is generally used for
656 the user to choose a file. FileSelectBox stores the files mostly
657 recently selected into a ComboBox widget so that they can be quickly
658 selected again.
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000659
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000660 Subwidget Class
661 --------- -----
662 selection ComboBox
Neal Norwitzf539bde2002-11-14 02:43:40 +0000663 filter ComboBox
664 dirlist ScrolledListBox
665 filelist ScrolledListBox"""
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000666
667 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000668 TixWidget.__init__(self, master, 'tixDirSelectBox', ['options'], cnf, kw)
669 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
670 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000671
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000672class ExFileSelectBox(TixWidget):
673 """ExFileSelectBox - MS Windows style file select box.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000674 It provides an convenient method for the user to select files.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000675
Moshe Zadka22710822001-03-21 17:24:49 +0000676 Subwidget Class
677 --------- -----
678 cancel Button
679 ok Button
680 hidden Checkbutton
681 types ComboBox
682 dir ComboBox
683 file ComboBox
684 dirlist ScrolledListBox
685 filelist ScrolledListBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000686
687 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000688 TixWidget.__init__(self, master, 'tixExFileSelectBox', ['options'], cnf, kw)
689 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
690 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
691 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
692 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
693 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
694 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
695 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
696 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000697
698 def filter(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000699 self.tk.call(self._w, 'filter')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000700
701 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000702 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000703
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000704
705# Should inherit from a Dialog class
706class DirSelectDialog(TixWidget):
707 """The DirSelectDialog widget presents the directories in the file
708 system in a dialog window. The user can use this dialog window to
709 navigate through the file system to select the desired directory.
710
711 Subwidgets Class
712 ---------- -----
713 dirbox DirSelectDialog"""
714
715 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000716 TixWidget.__init__(self, master, 'tixDirSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000717 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000718 self.subwidget_list['dirbox'] = _dummyDirSelectBox(self, 'dirbox')
719 # cancel and ok buttons are missing
720
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000721 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000722 self.tk.call(self._w, 'popup')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000723
724 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000725 self.tk.call(self._w, 'popdown')
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000726
727
728# Should inherit from a Dialog class
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000729class ExFileSelectDialog(TixWidget):
730 """ExFileSelectDialog - MS Windows style file select dialog.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000731 It provides an convenient method for the user to select files.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000732
Moshe Zadka22710822001-03-21 17:24:49 +0000733 Subwidgets Class
734 ---------- -----
735 fsbox ExFileSelectBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000736
737 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000738 TixWidget.__init__(self, master, 'tixExFileSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000739 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000740 self.subwidget_list['fsbox'] = _dummyExFileSelectBox(self, 'fsbox')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000741
742 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000743 self.tk.call(self._w, 'popup')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000744
745 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000746 self.tk.call(self._w, 'popdown')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000747
748class FileSelectBox(TixWidget):
749 """ExFileSelectBox - Motif style file select box.
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000750 It is generally used for
751 the user to choose a file. FileSelectBox stores the files mostly
752 recently selected into a ComboBox widget so that they can be quickly
753 selected again.
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000754
Moshe Zadka22710822001-03-21 17:24:49 +0000755 Subwidget Class
756 --------- -----
757 selection ComboBox
Neal Norwitzf539bde2002-11-14 02:43:40 +0000758 filter ComboBox
759 dirlist ScrolledListBox
760 filelist ScrolledListBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000761
762 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000763 TixWidget.__init__(self, master, 'tixFileSelectBox', ['options'], cnf, kw)
764 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
765 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
766 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
767 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000768
Moshe Zadka22710822001-03-21 17:24:49 +0000769 def apply_filter(self): # name of subwidget is same as command
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000770 self.tk.call(self._w, 'filter')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000771
772 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000773 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000774
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000775# Should inherit from a Dialog class
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000776class FileSelectDialog(TixWidget):
777 """FileSelectDialog - Motif style file select dialog.
778
Moshe Zadka22710822001-03-21 17:24:49 +0000779 Subwidgets Class
780 ---------- -----
781 btns StdButtonBox
782 fsbox FileSelectBox"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000783
784 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000785 TixWidget.__init__(self, master, 'tixFileSelectDialog',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000786 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000787 self.subwidget_list['btns'] = _dummyStdButtonBox(self, 'btns')
788 self.subwidget_list['fsbox'] = _dummyFileSelectBox(self, 'fsbox')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000789
790 def popup(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000791 self.tk.call(self._w, 'popup')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000792
793 def popdown(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000794 self.tk.call(self._w, 'popdown')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000795
796class FileEntry(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000797 """FileEntry - Entry field with button that invokes a FileSelectDialog.
798 The user can type in the filename manually. Alternatively, the user can
799 press the button widget that sits next to the entry, which will bring
800 up a file selection dialog.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000801
Moshe Zadka22710822001-03-21 17:24:49 +0000802 Subwidgets Class
803 ---------- -----
804 button Button
805 entry Entry"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000806
807 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000808 TixWidget.__init__(self, master, 'tixFileEntry',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000809 ['dialogtype', 'options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000810 self.subwidget_list['button'] = _dummyButton(self, 'button')
811 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000812
813 def invoke(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000814 self.tk.call(self._w, 'invoke')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000815
816 def file_dialog(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000817 # XXX return python object
818 pass
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000819
820class HList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +0000821 """HList - Hierarchy display widget can be used to display any data
822 that have a hierarchical structure, for example, file system directory
823 trees. The list entries are indented and connected by branch lines
824 according to their places in the hierachy.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000825
826 Subwidgets - None"""
827
828 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000829 TixWidget.__init__(self, master, 'tixHList',
Neal Norwitzf539bde2002-11-14 02:43:40 +0000830 ['columns', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000831
832 def add(self, entry, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000833 return apply(self.tk.call,
Neal Norwitzf539bde2002-11-14 02:43:40 +0000834 (self._w, 'add', entry) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000835
836 def add_child(self, parent=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000837 if not parent:
838 parent = ''
839 return apply(self.tk.call,
Neal Norwitzf539bde2002-11-14 02:43:40 +0000840 (self._w, 'addchild', parent) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000841
842 def anchor_set(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000843 self.tk.call(self._w, 'anchor', 'set', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000844
845 def anchor_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000846 self.tk.call(self._w, 'anchor', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000847
848 def column_width(self, col=0, width=None, chars=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000849 if not chars:
850 return self.tk.call(self._w, 'column', 'width', col, width)
851 else:
852 return self.tk.call(self._w, 'column', 'width', col,
Neal Norwitzf539bde2002-11-14 02:43:40 +0000853 '-char', chars)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000854
855 def delete_all(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000856 self.tk.call(self._w, 'delete', 'all')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000857
858 def delete_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000859 self.tk.call(self._w, 'delete', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000860
861 def delete_offsprings(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000862 self.tk.call(self._w, 'delete', 'offsprings', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000863
864 def delete_siblings(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000865 self.tk.call(self._w, 'delete', 'siblings', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000866
867 def dragsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000868 self.tk.call(self._w, 'dragsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000869
870 def dragsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000871 self.tk.call(self._w, 'dragsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000872
873 def dropsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000874 self.tk.call(self._w, 'dropsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000875
876 def dropsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000877 self.tk.call(self._w, 'dropsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000878
879 def header_create(self, col, cnf={}, **kw):
Moshe Zadka22710822001-03-21 17:24:49 +0000880 apply(self.tk.call,
881 (self._w, 'header', 'create', col) + self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000882
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000883 def header_configure(self, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000884 if cnf is None:
885 return _lst2dict(
Neal Norwitzf539bde2002-11-14 02:43:40 +0000886 self.tk.split(
887 self.tk.call(self._w, 'header', 'configure', col)))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000888 apply(self.tk.call, (self._w, 'header', 'configure', col)
889 + self._options(cnf, kw))
890
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000891 def header_cget(self, col, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000892 return self.tk.call(self._w, 'header', 'cget', col, opt)
893
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000894 def header_exists(self, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000895 return self.tk.call(self._w, 'header', 'exists', col)
896
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000897 def header_delete(self, col):
Moshe Zadka22710822001-03-21 17:24:49 +0000898 self.tk.call(self._w, 'header', 'delete', col)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000899
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000900 def header_size(self, col):
Moshe Zadka22710822001-03-21 17:24:49 +0000901 return self.tk.call(self._w, 'header', 'size', col)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000902
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000903 def hide_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000904 self.tk.call(self._w, 'hide', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000905
906 def indicator_create(self, entry, cnf={}, **kw):
Moshe Zadka22710822001-03-21 17:24:49 +0000907 apply(self.tk.call,
908 (self._w, 'indicator', 'create', entry) + self._options(cnf, kw))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000909
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000910 def indicator_configure(self, entry, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000911 if cnf is None:
912 return _lst2dict(
Neal Norwitzf539bde2002-11-14 02:43:40 +0000913 self.tk.split(
914 self.tk.call(self._w, 'indicator', 'configure', entry)))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000915 apply(self.tk.call,
916 (self._w, 'indicator', 'configure', entry) + self._options(cnf, kw))
917
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000918 def indicator_cget(self, entry, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000919 return self.tk.call(self._w, 'indicator', 'cget', entry, opt)
920
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000921 def indicator_exists(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000922 return self.tk.call (self._w, 'indicator', 'exists', entry)
923
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000924 def indicator_delete(self, entry):
Moshe Zadka22710822001-03-21 17:24:49 +0000925 self.tk.call(self._w, 'indicator', 'delete', entry)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000926
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000927 def indicator_size(self, entry):
Moshe Zadka22710822001-03-21 17:24:49 +0000928 return self.tk.call(self._w, 'indicator', 'size', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000929
930 def info_anchor(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000931 return self.tk.call(self._w, 'info', 'anchor')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000932
933 def info_children(self, entry=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000934 c = self.tk.call(self._w, 'info', 'children', entry)
935 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000936
937 def info_data(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000938 return self.tk.call(self._w, 'info', 'data', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000939
940 def info_exists(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000941 return self.tk.call(self._w, 'info', 'exists', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000942
943 def info_hidden(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000944 return self.tk.call(self._w, 'info', 'hidden', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000945
946 def info_next(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000947 return self.tk.call(self._w, 'info', 'next', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000948
949 def info_parent(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000950 return self.tk.call(self._w, 'info', 'parent', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000951
952 def info_prev(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000953 return self.tk.call(self._w, 'info', 'prev', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000954
955 def info_selection(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000956 c = self.tk.call(self._w, 'info', 'selection')
957 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000958
Martin v. Löwis3e048482001-10-09 11:50:55 +0000959 def item_cget(self, entry, col, opt):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000960 return self.tk.call(self._w, 'item', 'cget', entry, col, opt)
961
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000962 def item_configure(self, entry, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000963 if cnf is None:
964 return _lst2dict(
Neal Norwitzf539bde2002-11-14 02:43:40 +0000965 self.tk.split(
966 self.tk.call(self._w, 'item', 'configure', entry, col)))
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000967 apply(self.tk.call, (self._w, 'item', 'configure', entry, col) +
968 self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000969
970 def item_create(self, entry, col, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000971 apply(self.tk.call,
972 (self._w, 'item', 'create', entry, col) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000973
974 def item_exists(self, entry, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000975 return self.tk.call(self._w, 'item', 'exists', entry, col)
976
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000977 def item_delete(self, entry, col):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000978 self.tk.call(self._w, 'item', 'delete', entry, col)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000979
980 def nearest(self, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000981 return self.tk.call(self._w, 'nearest', y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000982
983 def see(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000984 self.tk.call(self._w, 'see', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000985
986 def selection_clear(self, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000987 apply(self.tk.call,
988 (self._w, 'selection', 'clear') + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000989
990 def selection_includes(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000991 return self.tk.call(self._w, 'selection', 'includes', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000992
993 def selection_set(self, first, last=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000994 self.tk.call(self._w, 'selection', 'set', first, last)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000995
996 def show_entry(self, entry):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +0000997 return self.tk.call(self._w, 'show', 'entry', entry)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +0000998
999 def xview(self, *args):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001000 apply(self.tk.call, (self._w, 'xview') + args)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001001
1002 def yview(self, *args):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001003 apply(self.tk.call, (self._w, 'yview') + args)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001004
1005class InputOnly(TixWidget):
1006 """InputOnly - Invisible widget.
1007
1008 Subwidgets - None"""
1009
1010 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001011 TixWidget.__init__(self, master, 'tixInputOnly', None, cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001012
1013class LabelEntry(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001014 """LabelEntry - Entry field with label. Packages an entry widget
1015 and a label into one mega widget. It can beused be used to simplify
1016 the creation of ``entry-form'' type of interface.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001017
Moshe Zadka22710822001-03-21 17:24:49 +00001018 Subwidgets Class
1019 ---------- -----
1020 label Label
1021 entry Entry"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001022
1023 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001024 TixWidget.__init__(self, master, 'tixLabelEntry',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001025 ['labelside','options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001026 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1027 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001028
1029class LabelFrame(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001030 """LabelFrame - Labelled Frame container. Packages a frame widget
1031 and a label into one mega widget. To create widgets inside a
1032 LabelFrame widget, one creates the new widgets relative to the
1033 frame subwidget and manage them inside the frame subwidget.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001034
Moshe Zadka22710822001-03-21 17:24:49 +00001035 Subwidgets Class
1036 ---------- -----
1037 label Label
1038 frame Frame"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001039
1040 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001041 TixWidget.__init__(self, master, 'tixLabelFrame',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001042 ['labelside','options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001043 self.subwidget_list['label'] = _dummyLabel(self, 'label')
1044 self.subwidget_list['frame'] = _dummyFrame(self, 'frame')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001045
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001046
1047class ListNoteBook(TixWidget):
1048 """A ListNoteBook widget is very similar to the TixNoteBook widget:
1049 it can be used to display many windows in a limited space using a
1050 notebook metaphor. The notebook is divided into a stack of pages
1051 (windows). At one time only one of these pages can be shown.
1052 The user can navigate through these pages by
1053 choosing the name of the desired page in the hlist subwidget."""
1054
1055 def __init__(self, master, cnf={}, **kw):
Neal Norwitzf539bde2002-11-14 02:43:40 +00001056 TixWidget.__init__(self, master, 'tixListNoteBook', ['options'], cnf, kw)
1057 # Is this necessary? It's not an exposed subwidget in Tix.
1058 self.subwidget_list['pane'] = _dummyPanedWindow(self, 'pane',
1059 destroy_physically=0)
1060 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1061 self.subwidget_list['shlist'] = _dummyScrolledHList(self, 'shlist')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001062
1063 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001064 apply(self.tk.call,
1065 (self._w, 'add', name) + self._options(cnf, kw))
1066 self.subwidget_list[name] = TixSubWidget(self, name)
1067 return self.subwidget_list[name]
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001068
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001069 def page(self, name):
1070 return self.subwidget(name)
1071
1072 def pages(self):
1073 # Can't call subwidgets_all directly because we don't want .nbframe
1074 names = self.tk.split(self.tk.call(self._w, 'pages'))
1075 ret = []
1076 for x in names:
1077 ret.append(self.subwidget(x))
1078 return ret
1079
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001080 def raise_page(self, name): # raise is a python keyword
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001081 self.tk.call(self._w, 'raise', name)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001082
1083class Meter(TixWidget):
1084 """The Meter widget can be used to show the progress of a background
1085 job which may take a long time to execute.
1086 """
1087
1088 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001089 TixWidget.__init__(self, master, 'tixMeter',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001090 ['options'], cnf, kw)
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001091
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001092class NoteBook(TixWidget):
1093 """NoteBook - Multi-page container widget (tabbed notebook metaphor).
1094
Moshe Zadka22710822001-03-21 17:24:49 +00001095 Subwidgets Class
1096 ---------- -----
1097 nbframe NoteBookFrame
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001098 <pages> page widgets added dynamically with the add method"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001099
1100 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001101 TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw)
1102 self.subwidget_list['nbframe'] = TixSubWidget(self, 'nbframe',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001103 destroy_physically=0)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001104
1105 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001106 apply(self.tk.call,
1107 (self._w, 'add', name) + self._options(cnf, kw))
1108 self.subwidget_list[name] = TixSubWidget(self, name)
1109 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001110
1111 def delete(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001112 self.tk.call(self._w, 'delete', name)
1113 self.subwidget_list[name].destroy()
1114 del self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001115
1116 def page(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001117 return self.subwidget(name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001118
1119 def pages(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001120 # Can't call subwidgets_all directly because we don't want .nbframe
1121 names = self.tk.split(self.tk.call(self._w, 'pages'))
1122 ret = []
1123 for x in names:
1124 ret.append(self.subwidget(x))
1125 return ret
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001126
Moshe Zadka22710822001-03-21 17:24:49 +00001127 def raise_page(self, name): # raise is a python keyword
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001128 self.tk.call(self._w, 'raise', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001129
1130 def raised(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001131 return self.tk.call(self._w, 'raised')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001132
1133class NoteBookFrame(TixWidget):
1134 """Will be added when Tix documentation is available !!!"""
1135 pass
1136
1137class OptionMenu(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001138 """OptionMenu - creates a menu button of options.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001139
Moshe Zadka22710822001-03-21 17:24:49 +00001140 Subwidget Class
1141 --------- -----
Neal Norwitzf539bde2002-11-14 02:43:40 +00001142 menubutton Menubutton
1143 menu Menu"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001144
1145 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001146 TixWidget.__init__(self, master, 'tixOptionMenu', ['options'], cnf, kw)
1147 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1148 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001149
1150 def add_command(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001151 apply(self.tk.call,
1152 (self._w, 'add', 'command', name) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001153
1154 def add_separator(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001155 apply(self.tk.call,
1156 (self._w, 'add', 'separator', name) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001157
1158 def delete(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001159 self.tk.call(self._w, 'delete', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001160
1161 def disable(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001162 self.tk.call(self._w, 'disable', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001163
1164 def enable(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001165 self.tk.call(self._w, 'enable', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001166
1167class PanedWindow(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001168 """PanedWindow - Multi-pane container widget
1169 allows the user to interactively manipulate the sizes of several
1170 panes. The panes can be arranged either vertically or horizontally.The
1171 user changes the sizes of the panes by dragging the resize handle
1172 between two panes.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001173
Moshe Zadka22710822001-03-21 17:24:49 +00001174 Subwidgets Class
1175 ---------- -----
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001176 <panes> g/p widgets added dynamically with the add method."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001177
1178 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001179 TixWidget.__init__(self, master, 'tixPanedWindow', ['orientation', 'options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001180
Neal Norwitzf539bde2002-11-14 02:43:40 +00001181 # add delete forget panecget paneconfigure panes setsize
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001182 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001183 apply(self.tk.call,
1184 (self._w, 'add', name) + self._options(cnf, kw))
1185 self.subwidget_list[name] = TixSubWidget(self, name,
Neal Norwitzf539bde2002-11-14 02:43:40 +00001186 check_intermediate=0)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001187 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001188
Neal Norwitzf539bde2002-11-14 02:43:40 +00001189 def delete(self, name):
1190 self.tk.call(self._w, 'delete', name)
1191 self.subwidget_list[name].destroy()
1192 del self.subwidget_list[name]
1193
1194 def forget(self, name):
1195 self.tk.call(self._w, 'forget', name)
1196
1197 def panecget(self, entry, opt):
1198 return self.tk.call(self._w, 'panecget', entry, opt)
1199
1200 def paneconfigure(self, entry, cnf={}, **kw):
1201 if cnf is None:
1202 return _lst2dict(
1203 self.tk.split(
1204 self.tk.call(self._w, 'paneconfigure', entry)))
1205 apply(self.tk.call,
1206 (self._w, 'paneconfigure', entry) + self._options(cnf, kw))
1207
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001208 def panes(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001209 names = self.tk.call(self._w, 'panes')
1210 ret = []
1211 for x in names:
1212 ret.append(self.subwidget(x))
1213 return ret
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001214
1215class PopupMenu(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001216 """PopupMenu widget can be used as a replacement of the tk_popup command.
1217 The advantage of the Tix PopupMenu widget is it requires less application
1218 code to manipulate.
1219
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001220
Moshe Zadka22710822001-03-21 17:24:49 +00001221 Subwidgets Class
1222 ---------- -----
1223 menubutton Menubutton
1224 menu Menu"""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001225
1226 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001227 TixWidget.__init__(self, master, 'tixPopupMenu', ['options'], cnf, kw)
1228 self.subwidget_list['menubutton'] = _dummyMenubutton(self, 'menubutton')
1229 self.subwidget_list['menu'] = _dummyMenu(self, 'menu')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001230
1231 def bind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001232 self.tk.call(self._w, 'bind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001233
1234 def unbind_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001235 self.tk.call(self._w, 'unbind', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001236
1237 def post_widget(self, widget, x, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001238 self.tk.call(self._w, 'post', widget._w, x, y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001239
1240class ResizeHandle(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001241 """Internal widget to draw resize handles on Scrolled widgets."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001242
1243 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001244 # There seems to be a Tix bug rejecting the configure method
1245 # Let's try making the flags -static
1246 flags = ['options', 'command', 'cursorfg', 'cursorbg',
1247 'handlesize', 'hintcolor', 'hintwidth',
1248 'x', 'y']
1249 # In fact, x y height width are configurable
1250 TixWidget.__init__(self, master, 'tixResizeHandle',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001251 flags, cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001252
1253 def attach_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001254 self.tk.call(self._w, 'attachwidget', widget._w)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001255
Martin v. Löwis652e1912001-11-25 14:50:56 +00001256 def detach_widget(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001257 self.tk.call(self._w, 'detachwidget', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001258
1259 def hide(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001260 self.tk.call(self._w, 'hide', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001261
1262 def show(self, widget):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001263 self.tk.call(self._w, 'show', widget._w)
Martin v. Löwis652e1912001-11-25 14:50:56 +00001264
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001265class ScrolledHList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001266 """ScrolledHList - HList with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001267
1268 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001269 TixWidget.__init__(self, master, 'tixScrolledHList', ['options'],
Neal Norwitzf539bde2002-11-14 02:43:40 +00001270 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001271 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1272 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1273 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001274
1275class ScrolledListBox(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001276 """ScrolledListBox - Listbox with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001277
1278 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001279 TixWidget.__init__(self, master, 'tixScrolledListBox', ['options'], cnf, kw)
1280 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1281 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1282 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001283
1284class ScrolledText(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001285 """ScrolledText - Text with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001286
1287 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001288 TixWidget.__init__(self, master, 'tixScrolledText', ['options'], cnf, kw)
1289 self.subwidget_list['text'] = _dummyText(self, 'text')
1290 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1291 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001292
1293class ScrolledTList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001294 """ScrolledTList - TList with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001295
1296 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001297 TixWidget.__init__(self, master, 'tixScrolledTList', ['options'],
Neal Norwitzf539bde2002-11-14 02:43:40 +00001298 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001299 self.subwidget_list['tlist'] = _dummyTList(self, 'tlist')
1300 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1301 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001302
1303class ScrolledWindow(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001304 """ScrolledWindow - Window with automatic scrollbars."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001305
1306 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001307 TixWidget.__init__(self, master, 'tixScrolledWindow', ['options'], cnf, kw)
1308 self.subwidget_list['window'] = _dummyFrame(self, 'window')
1309 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1310 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001311
1312class Select(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001313 """Select - Container of button subwidgets. It can be used to provide
1314 radio-box or check-box style of selection options for the user.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001315
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001316 Subwidgets are buttons added dynamically using the add method."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001317
1318 def __init__(self, master, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001319 TixWidget.__init__(self, master, 'tixSelect',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001320 ['allowzero', 'radio', 'orientation', 'labelside',
1321 'options'],
1322 cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001323 self.subwidget_list['label'] = _dummyLabel(self, 'label')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001324
1325 def add(self, name, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001326 apply(self.tk.call,
1327 (self._w, 'add', name) + self._options(cnf, kw))
1328 self.subwidget_list[name] = _dummyButton(self, name)
1329 return self.subwidget_list[name]
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001330
1331 def invoke(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001332 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001333
Neal Norwitzf539bde2002-11-14 02:43:40 +00001334class Shell(TixWidget):
1335 """Toplevel window.
1336
1337 Subwidgets - None"""
1338
1339 def __init__ (self,master=None,cnf={}, **kw):
1340 TixWidget.__init__(self, master, 'tixShell', ['options', 'title'], cnf, kw)
1341
1342class DialogShell(TixWidget):
1343 """Toplevel window, with popup popdown and center methods.
1344 It tells the window manager that it is a dialog window and should be
1345 treated specially. The exact treatment depends on the treatment of
1346 the window manager.
1347
1348 Subwidgets - None"""
1349
1350 def __init__ (self,master=None,cnf={}, **kw):
1351 TixWidget.__init__(self, master,
1352 'tixDialogShell',
1353 ['options', 'title', 'mapped',
1354 'minheight', 'minwidth',
1355 'parent', 'transient'], cnf, kw)
1356
1357 def popdown(self):
1358 self.tk.call(self._w, 'popdown')
1359
1360 def popup(self):
1361 self.tk.call(self._w, 'popup')
1362
1363 def center(self):
1364 self.tk.call(self._w, 'center')
1365
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001366class StdButtonBox(TixWidget):
1367 """StdButtonBox - Standard Button Box (OK, Apply, Cancel and Help) """
1368
1369 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001370 TixWidget.__init__(self, master, 'tixStdButtonBox',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001371 ['orientation', 'options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001372 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1373 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1374 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1375 self.subwidget_list['help'] = _dummyButton(self, 'help')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001376
1377 def invoke(self, name):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001378 if self.subwidget_list.has_key(name):
1379 self.tk.call(self._w, 'invoke', name)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001380
1381class TList(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001382 """TList - Hierarchy display widget which can be
1383 used to display data in a tabular format. The list entries of a TList
1384 widget are similar to the entries in the Tk listbox widget. The main
1385 differences are (1) the TList widget can display the list entries in a
1386 two dimensional format and (2) you can use graphical images as well as
1387 multiple colors and fonts for the list entries.
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001388
1389 Subwidgets - None"""
1390
1391 def __init__ (self,master=None,cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001392 TixWidget.__init__(self, master, 'tixTList', ['options'], cnf, kw)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001393
1394 def active_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001395 self.tk.call(self._w, 'active', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001396
1397 def active_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001398 self.tk.call(self._w, 'active', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001399
1400 def anchor_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001401 self.tk.call(self._w, 'anchor', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001402
1403 def anchor_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001404 self.tk.call(self._w, 'anchor', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001405
1406 def delete(self, from_, to=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001407 self.tk.call(self._w, 'delete', from_, to)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001408
1409 def dragsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001410 self.tk.call(self._w, 'dragsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001411
1412 def dragsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001413 self.tk.call(self._w, 'dragsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001414
1415 def dropsite_set(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001416 self.tk.call(self._w, 'dropsite', 'set', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001417
1418 def dropsite_clear(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001419 self.tk.call(self._w, 'dropsite', 'clear')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001420
1421 def insert(self, index, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001422 apply(self.tk.call,
Neal Norwitzf539bde2002-11-14 02:43:40 +00001423 (self._w, 'insert', index) + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001424
1425 def info_active(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001426 return self.tk.call(self._w, 'info', 'active')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001427
1428 def info_anchor(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001429 return self.tk.call(self._w, 'info', 'anchor')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001430
1431 def info_down(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001432 return self.tk.call(self._w, 'info', 'down', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001433
1434 def info_left(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001435 return self.tk.call(self._w, 'info', 'left', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001436
1437 def info_right(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001438 return self.tk.call(self._w, 'info', 'right', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001439
1440 def info_selection(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001441 c = self.tk.call(self._w, 'info', 'selection')
1442 return self.tk.splitlist(c)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001443
1444 def info_size(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001445 return self.tk.call(self._w, 'info', 'size')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001446
1447 def info_up(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001448 return self.tk.call(self._w, 'info', 'up', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001449
1450 def nearest(self, x, y):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001451 return self.tk.call(self._w, 'nearest', x, y)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001452
1453 def see(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001454 self.tk.call(self._w, 'see', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001455
1456 def selection_clear(self, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001457 apply(self.tk.call,
1458 (self._w, 'selection', 'clear') + self._options(cnf, kw))
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001459
1460 def selection_includes(self, index):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001461 return self.tk.call(self._w, 'selection', 'includes', index)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001462
1463 def selection_set(self, first, last=None):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001464 self.tk.call(self._w, 'selection', 'set', first, last)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001465
1466 def xview(self, *args):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001467 apply(self.tk.call, (self._w, 'xview') + args)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001468
1469 def yview(self, *args):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001470 apply(self.tk.call, (self._w, 'yview') + args)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001471
1472class Tree(TixWidget):
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001473 """Tree - The tixTree widget can be used to display hierachical
1474 data in a tree form. The user can adjust
1475 the view of the tree by opening or closing parts of the tree."""
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001476
1477 def __init__(self, master=None, cnf={}, **kw):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001478 TixWidget.__init__(self, master, 'tixTree',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001479 ['options'], cnf, kw)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001480 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1481 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1482 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001483
1484 def autosetmode(self):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001485 self.tk.call(self._w, 'autosetmode')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001486
1487 def close(self, entrypath):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001488 self.tk.call(self._w, 'close', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001489
1490 def getmode(self, entrypath):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001491 return self.tk.call(self._w, 'getmode', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001492
1493 def open(self, entrypath):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001494 self.tk.call(self._w, 'open', entrypath)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001495
1496 def setmode(self, entrypath, mode='none'):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001497 self.tk.call(self._w, 'setmode', entrypath, mode)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001498
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001499
1500# Could try subclassing Tree for CheckList - would need another arg to init
1501class CheckList(TixWidget):
1502 """The CheckList widget
1503 displays a list of items to be selected by the user. CheckList acts
1504 similarly to the Tk checkbutton or radiobutton widgets, except it is
1505 capable of handling many more items than checkbuttons or radiobuttons.
1506 """
1507
1508 def __init__(self, master=None, cnf={}, **kw):
1509 TixWidget.__init__(self, master, 'tixCheckList',
1510 ['options'], cnf, kw)
1511 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1512 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1513 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001514
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001515 def autosetmode(self):
1516 self.tk.call(self._w, 'autosetmode')
1517
1518 def close(self, entrypath):
1519 self.tk.call(self._w, 'close', entrypath)
1520
1521 def getmode(self, entrypath):
1522 return self.tk.call(self._w, 'getmode', entrypath)
1523
1524 def open(self, entrypath):
1525 self.tk.call(self._w, 'open', entrypath)
1526
1527 def getselection(self, mode='on'):
1528 '''Mode can be on, off, default'''
1529 self.tk.call(self._w, 'getselection', mode)
1530
1531 def getstatus(self, entrypath):
1532 self.tk.call(self._w, 'getstatus', entrypath)
1533
1534 def setstatus(self, entrypath, mode='on'):
1535 self.tk.call(self._w, 'setstatus', entrypath, mode)
1536
1537
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001538###########################################################################
1539### The subclassing below is used to instantiate the subwidgets in each ###
1540### mega widget. This allows us to access their methods directly. ###
1541###########################################################################
1542
1543class _dummyButton(Button, TixSubWidget):
1544 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001545 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001546
1547class _dummyCheckbutton(Checkbutton, TixSubWidget):
1548 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001549 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001550
1551class _dummyEntry(Entry, TixSubWidget):
1552 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001553 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001554
1555class _dummyFrame(Frame, TixSubWidget):
1556 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001557 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001558
1559class _dummyLabel(Label, TixSubWidget):
1560 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001561 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001562
1563class _dummyListbox(Listbox, TixSubWidget):
1564 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001565 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001566
1567class _dummyMenu(Menu, TixSubWidget):
1568 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001569 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001570
1571class _dummyMenubutton(Menubutton, TixSubWidget):
1572 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001573 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001574
1575class _dummyScrollbar(Scrollbar, TixSubWidget):
1576 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001577 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001578
1579class _dummyText(Text, TixSubWidget):
1580 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001581 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001582
1583class _dummyScrolledListBox(ScrolledListBox, TixSubWidget):
1584 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001585 TixSubWidget.__init__(self, master, name, destroy_physically)
1586 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox')
1587 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1588 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001589
1590class _dummyHList(HList, TixSubWidget):
1591 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001592 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001593
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001594class _dummyScrolledHList(ScrolledHList, TixSubWidget):
1595 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001596 TixSubWidget.__init__(self, master, name, destroy_physically)
1597 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1598 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1599 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001600
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001601class _dummyTList(TList, TixSubWidget):
1602 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001603 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001604
1605class _dummyComboBox(ComboBox, TixSubWidget):
1606 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001607 TixSubWidget.__init__(self, master, name, destroy_physically)
1608 self.subwidget_list['entry'] = _dummyEntry(self, 'entry')
1609 self.subwidget_list['arrow'] = _dummyButton(self, 'arrow')
1610 # I'm not sure about this destroy_physically=0 in all cases;
1611 # it may depend on if -dropdown is true; I've added as a trial
1612 self.subwidget_list['slistbox'] = _dummyScrolledListBox(self,
Neal Norwitzf539bde2002-11-14 02:43:40 +00001613 'slistbox',
1614 destroy_physically=0)
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001615 self.subwidget_list['listbox'] = _dummyListbox(self, 'listbox',
Neal Norwitzf539bde2002-11-14 02:43:40 +00001616 destroy_physically=0)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001617
1618class _dummyDirList(DirList, TixSubWidget):
1619 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001620 TixSubWidget.__init__(self, master, name, destroy_physically)
1621 self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
1622 self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
1623 self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001624
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001625class _dummyDirSelectBox(DirSelectBox, TixSubWidget):
1626 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001627 TixSubWidget.__init__(self, master, name, destroy_physically)
1628 self.subwidget_list['dirlist'] = _dummyDirList(self, 'dirlist')
1629 self.subwidget_list['dircbx'] = _dummyFileComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001630
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001631class _dummyExFileSelectBox(ExFileSelectBox, TixSubWidget):
1632 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001633 TixSubWidget.__init__(self, master, name, destroy_physically)
1634 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1635 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1636 self.subwidget_list['hidden'] = _dummyCheckbutton(self, 'hidden')
1637 self.subwidget_list['types'] = _dummyComboBox(self, 'types')
1638 self.subwidget_list['dir'] = _dummyComboBox(self, 'dir')
1639 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1640 self.subwidget_list['file'] = _dummyComboBox(self, 'file')
1641 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001642
1643class _dummyFileSelectBox(FileSelectBox, TixSubWidget):
1644 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001645 TixSubWidget.__init__(self, master, name, destroy_physically)
1646 self.subwidget_list['dirlist'] = _dummyScrolledListBox(self, 'dirlist')
1647 self.subwidget_list['filelist'] = _dummyScrolledListBox(self, 'filelist')
1648 self.subwidget_list['filter'] = _dummyComboBox(self, 'filter')
1649 self.subwidget_list['selection'] = _dummyComboBox(self, 'selection')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001650
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001651class _dummyFileComboBox(ComboBox, TixSubWidget):
1652 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001653 TixSubWidget.__init__(self, master, name, destroy_physically)
1654 self.subwidget_list['dircbx'] = _dummyComboBox(self, 'dircbx')
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001655
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001656class _dummyStdButtonBox(StdButtonBox, TixSubWidget):
1657 def __init__(self, master, name, destroy_physically=1):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001658 TixSubWidget.__init__(self, master, name, destroy_physically)
1659 self.subwidget_list['ok'] = _dummyButton(self, 'ok')
1660 self.subwidget_list['apply'] = _dummyButton(self, 'apply')
1661 self.subwidget_list['cancel'] = _dummyButton(self, 'cancel')
1662 self.subwidget_list['help'] = _dummyButton(self, 'help')
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001663
1664class _dummyNoteBookFrame(NoteBookFrame, TixSubWidget):
1665 def __init__(self, master, name, destroy_physically=0):
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001666 TixSubWidget.__init__(self, master, name, destroy_physically)
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001667
Martin v. Löwis01824bf2002-09-19 08:12:55 +00001668class _dummyPanedWindow(PanedWindow, TixSubWidget):
1669 def __init__(self, master, name, destroy_physically=1):
1670 TixSubWidget.__init__(self, master, name, destroy_physically)
1671
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001672########################
1673### Utility Routines ###
1674########################
1675
1676# Returns the qualified path name for the widget. Normally used to set
1677# default options for subwidgets. See tixwidgets.py
1678def OptionName(widget):
1679 return widget.tk.call('tixOptionName', widget._w)
1680
1681# Called with a dictionary argument of the form
1682# {'*.c':'C source files', '*.txt':'Text Files', '*':'All files'}
1683# returns a string which can be used to configure the fsbox file types
1684# in an ExFileSelectBox. i.e.,
1685# '{{*} {* - All files}} {{*.c} {*.c - C source files}} {{*.txt} {*.txt - Text Files}}'
1686def FileTypeList(dict):
1687 s = ''
1688 for type in dict.keys():
Martin v. Löwis0c0d56a2002-03-28 16:26:40 +00001689 s = s + '{{' + type + '} {' + type + ' - ' + dict[type] + '}} '
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00001690 return s
1691
Martin v. Löwisb7b32602001-11-02 23:48:20 +00001692# Still to be done:
1693class CObjView(TixWidget):
1694 """This file implements the Canvas Object View widget. This is a base
1695 class of IconView. It implements automatic placement/adjustment of the
1696 scrollbars according to the canvas objects inside the canvas subwidget.
1697 The scrollbars are adjusted so that the canvas is just large enough
1698 to see all the objects.
1699 """
1700 pass