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