tix.py 75 KB

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