diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-11-11 14:07:37 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-11-11 14:07:37 (GMT) |
commit | 20efa68be43b18413cc08089211b1351687084af (patch) | |
tree | 8946066fd4bf0909efbe4d5c78757ffe917a7f9d | |
parent | c252e6304e305c7126d1cd440fa8885f94ed09f2 (diff) | |
download | cpython-20efa68be43b18413cc08089211b1351687084af.zip cpython-20efa68be43b18413cc08089211b1351687084af.tar.gz cpython-20efa68be43b18413cc08089211b1351687084af.tar.bz2 |
Patch #473002: Update Demo/tix tixwidgets.py et al.
-rw-r--r-- | Demo/tix/INSTALL.txt | 32 | ||||
-rw-r--r-- | Demo/tix/README.txt | 4 | ||||
-rwxr-xr-x | Demo/tix/samples/DirList.py | 142 | ||||
-rwxr-xr-x | Demo/tix/samples/DirTree.py | 108 | ||||
-rwxr-xr-x | Demo/tix/samples/SHList1.py | 9 | ||||
-rwxr-xr-x | Demo/tix/samples/SHList2.py | 21 | ||||
-rw-r--r-- | Demo/tix/tixwidgets.py | 380 |
7 files changed, 542 insertions, 154 deletions
diff --git a/Demo/tix/INSTALL.txt b/Demo/tix/INSTALL.txt index 9dc3093..ac70b68 100644 --- a/Demo/tix/INSTALL.txt +++ b/Demo/tix/INSTALL.txt @@ -1,25 +1,33 @@ $Id$ -Installing PyTix +Installing Tix.py ---------------- -0) To use PyTix, you need Tcl/Tk (V8.2+), Tix (V8.1+) and Python (V2.1+). - PyTix has been written and tested on a Intel Pentium running RH Linux 5.2 +0) To use Tix.py, you need Tcl/Tk (V8.3.3), Tix (V8.1.1) and Python (V2.1.1). + Tix.py has been written and tested on a Intel Pentium running RH Linux 5.2 and Mandrake Linux 7.0 and Windows with the above mentioned packages. Older versions, e.g. Tix 4.1 and Tk 8.0, might also work. - There is nothing OS-specific in PyTix itself so it should work on + There is nothing OS-specific in Tix.py itself so it should work on any machine with Tix and Python installed. You can get Tcl and Tk from http://dev.scriptics.com and Tix from http://tix.sourceforge.net. -1) Build and install Tcl/Tk 8.2 or 8.3. Build and install Tix 8.1 or better. +1) Build and install Tcl/Tk 8.3. Build and install Tix 8.1. Ensure that Tix is properly installed by running tixwish and executing the demo programs. Under Unix, use the --enable-shared configure option - for all three. We recommend tcl8.2.3 for this release of PyTix. + for all three. We recommend tcl8.3.3 for this release of Tix.py. -2) Modify Modules/Setup.dist and setup.py to change the version of the - tix library from tix4.1.8.0 to tix8.1.8.2 +2a) If you have a distribution like ActiveState with a tcl subdirectory + of $PYTHONHOME, which contains the directories tcl8.3 and tk8.3, + make a directory tix8.1 as well. Recursively copy the files from + <tix>/library to $PYTHONHOME/lib/tix8.1, and copy the dynamic library + (tix8183.dll or libtix8.1.8.3.so) to the same place as the tcl dynamic + libraries ($PYTHONHOME/Dlls or lib/python-2.1/lib-dynload). In this + case you are all installed, and you can skip to the end. + +2b) Modify Modules/Setup.dist and setup.py to change the version of the + tix library from tix4.1.8.0 to tix8.1.8.3 These modified files can be used for Tkinter with or without Tix. 3) The default is to build dynamically, and use the Tcl 'package require'. @@ -44,9 +52,9 @@ _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ # *** Uncomment and edit for TOGL extension only: # -DWITH_TOGL togl.c \ # *** Uncomment and edit for Tix extension only: - -DWITH_TIX -ltix8.1.8.2 \ + -DWITH_TIX -ltix8.1.8.3 \ # *** Uncomment and edit to reflect your Tcl/Tk versions: - -ltk8.2 -ltcl8.2 \ + -ltk8.3 -ltcl8.3 \ # *** Uncomment and edit to reflect where your X11 libraries are: -L/usr/X11R6/lib \ # *** Or uncomment this for Solaris: @@ -69,8 +77,8 @@ If this does not work, you may need to tell python where to find the Tcl, Tk and Tix library files. This is done by setting the TCL_LIBRARY, TK_LIBRARY and TIX_LIBRARY environment variables. Try this: - env TCL_LIBRARY=/usr/local/lib/tcl8.2 \ - TK_LIBRARY=/usr/local/lib/tk8.2 \ + env TCL_LIBRARY=/usr/local/lib/tcl8.3 \ + TK_LIBRARY=/usr/local/lib/tk8.3 \ TIX_LIBRARY=/usr/local/lib/tix8.1 \ /usr/local/bin/python Demo/tix/tixwidgets.py diff --git a/Demo/tix/README.txt b/Demo/tix/README.txt index 15e85cd..e0196ac 100644 --- a/Demo/tix/README.txt +++ b/Demo/tix/README.txt @@ -1,7 +1,7 @@ -About PyTix +About Tix.py ----------- -PyTix is based on an idea of Jean-Marc Lugrin (lugrin@ms.com) who wrote +Tix.py is based on an idea of Jean-Marc Lugrin (lugrin@ms.com) who wrote pytix (another Python-Tix marriage). Tix widgets are an attractive and useful extension to Tk. See http://tix.sourceforge.net for more details about Tix and how to get it. diff --git a/Demo/tix/samples/DirList.py b/Demo/tix/samples/DirList.py new file mode 100755 index 0000000..3064768 --- /dev/null +++ b/Demo/tix/samples/DirList.py @@ -0,0 +1,142 @@ +# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- +# +# $Id$ +# +# Tix Demostration Program +# +# This sample program is structured in such a way so that it can be +# executed from the Tix demo program "widget": it must have a +# procedure called "RunSample". It should also have the "if" statment +# at the end of this file so that it can be run as a standalone +# program using tixwish. + +# This file demonstrates the use of the tixDirList widget -- you can +# use it for the user to select a directory. For example, an installation +# program can use the tixDirList widget to ask the user to select the +# installation directory for an application. +# + +import Tix, os, copy +from Tkconstants import * + +TCL_DONT_WAIT = 1<<1 +TCL_WINDOW_EVENTS = 1<<2 +TCL_FILE_EVENTS = 1<<3 +TCL_TIMER_EVENTS = 1<<4 +TCL_IDLE_EVENTS = 1<<5 +TCL_ALL_EVENTS = 0 + +def RunSample (root): + global dirlist + dirlist = DemoDirList(root) + dirlist.mainloop() + dirlist.destroy() + +class DemoDirList: + def __init__(self, w): + self.root = w + self.exit = -1 + + z = w.winfo_toplevel() + z.wm_title('Tix.DirList Widget Demo') + + # Create the tixDirList and the tixLabelEntry widgets on the on the top + # of the dialog box + + # bg = root.tk.eval('tix option get bg') + # adding bg=bg crashes Windows pythonw tk8.3.3 Python 2.1.0 + + top = Tix.Frame( w, relief=RAISED, bd=1) + + # Create the DirList widget. By default it will show the current + # directory + # + # + top.dir = Tix.DirList(top) + top.dir.hlist['width'] = 40 + + # When the user presses the ".." button, the selected directory + # is "transferred" into the entry widget + # + top.btn = Tix.Button(top, text = " >> ", pady = 0) + + # We use a LabelEntry to hold the installation directory. The user + # can choose from the DirList widget, or he can type in the directory + # manually + # + top.ent = Tix.LabelEntry(top, label="Installation Directory:", + labelside = 'top', + options = ''' + entry.width 40 + label.anchor w + ''') + + font = self.root.tk.eval('tix option get fixed_font') + # font = self.root.master.tix_option_get('fixed_font') + top.ent.entry['font'] = font + + self.dlist_dir = copy.copy(os.curdir) + # This should work setting the entry's textvariable + top.ent.entry['textvariable'] = self.dlist_dir + top.btn['command'] = lambda dir=top.dir, ent=top.ent, self=self: \ + self.copy_name(dir,ent) + + # top.ent.entry.insert(0,'tix'+`self`) + top.ent.entry.bind('<Return>', lambda self=self: self.okcmd () ) + + top.pack( expand='yes', fill='both', side=TOP) + top.dir.pack( expand=1, fill=BOTH, padx=4, pady=4, side=LEFT) + top.btn.pack( anchor='s', padx=4, pady=4, side=LEFT) + top.ent.pack( expand=1, fill=X, anchor='s', padx=4, pady=4, side=LEFT) + + # Use a ButtonBox to hold the buttons. + # + box = Tix.ButtonBox (w, orientation='horizontal') + box.add ('ok', text='Ok', underline=0, width=6, + command = lambda self=self: self.okcmd () ) + box.add ('cancel', text='Cancel', underline=0, width=6, + command = lambda self=self: self.quitcmd () ) + + box.pack( anchor='s', fill='x', side=BOTTOM) + z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) + + def copy_name (self, dir, ent): + # This should work as it is the entry's textvariable + self.dlist_dir = dir.cget('value') + # but it isn't so I'll do it manually + ent.entry.delete(0,'end') + ent.entry.insert(0, self.dlist_dir) + + def okcmd (self): + # tixDemo:Status "You have selected the directory" + $self.dlist_dir + + self.quitcmd() + + def quitcmd (self): + # self.root.destroy() + self.exit = 0 + + def mainloop(self): + while self.exit < 0: + self.root.tk.dooneevent(TCL_ALL_EVENTS) + # self.root.tk.dooneevent(TCL_DONT_WAIT) + + def destroy (self): + self.root.destroy() + +# This "if" statement makes it possible to run this script file inside or +# outside of the main demo program "widget". +# +if __name__== '__main__' : + import tkMessageBox, traceback + + try: + root=Tix.Tk() + RunSample(root) + except: + t, v, tb = sys.exc_info() + text = "Error running the demo script:\n" + for line in traceback.format_exception(t,v,tb): + text = text + line + '\n' + d = tkMessageBox.showerror ( 'Tix Demo Error', text) + diff --git a/Demo/tix/samples/DirTree.py b/Demo/tix/samples/DirTree.py new file mode 100755 index 0000000..7bf813c --- /dev/null +++ b/Demo/tix/samples/DirTree.py @@ -0,0 +1,108 @@ +# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- +# +# $Id$ +# +# Tix Demostration Program +# +# This sample program is structured in such a way so that it can be +# executed from the Tix demo program "widget": it must have a +# procedure called "RunSample". It should also have the "if" statment +# at the end of this file so that it can be run as a standalone +# program using tixwish. + +# This file demonstrates the use of the tixDirTree widget -- you can +# use it for the user to select a directory. For example, an installation +# program can use the tixDirTree widget to ask the user to select the +# installation directory for an application. +# + +import Tix, os, copy +from Tkconstants import * + +def RunSample (w): + DemoDirTree(w) + +class DemoDirTree: + def __init__(self, w): + self.root = w + + z = w.winfo_toplevel() + z.wm_title('Tix.DirTree Widget Demo') + + # Create the tixDirTree and the tixLabelEntry widgets on the on the top + # of the dialog box + + # bg = root.tk.eval('tix option get bg') + # adding bg=bg crashes Windows pythonw tk8.3.3 Python 2.1.0 + + top = Tix.Frame( w, relief=RAISED, bd=1) + + # Create the DirTree widget. By default it will show the current + # directory + # + # + top.dir = Tix.DirTree(top) + top.dir.hlist['width'] = 40 + + # When the user presses the ".." button, the selected directory + # is "transferred" into the entry widget + # + top.btn = Tix.Button(top, text = " >> ", pady = 0) + + # We use a LabelEntry to hold the installation directory. The user + # can choose from the DirTree widget, or he can type in the directory + # manually + # + top.ent = Tix.LabelEntry(top, label="Installation Directory:", + labelside = 'top', + options = ''' + entry.width 40 + label.anchor w + ''') + + self.dlist_dir = copy.copy(os.curdir) + top.ent.entry['textvariable'] = self.dlist_dir + top.btn['command'] = lambda dir=top.dir, ent=top.ent, self=self: \ + self.copy_name(dir,ent) + + top.ent.entry.bind('<Return>', lambda self=self: self.okcmd () ) + + top.pack( expand='yes', fill='both', side=TOP) + top.dir.pack( expand=1, fill=BOTH, padx=4, pady=4, side=LEFT) + top.btn.pack( anchor='s', padx=4, pady=4, side=LEFT) + top.ent.pack( expand=1, fill=X, anchor='s', padx=4, pady=4, side=LEFT) + + # Use a ButtonBox to hold the buttons. + # + box = Tix.ButtonBox (w, orientation='horizontal') + box.add ('ok', text='Ok', underline=0, width=6, + command = lambda self=self: self.okcmd () ) + box.add ('cancel', text='Cancel', underline=0, width=6, + command = lambda self=self: self.quitcmd () ) + + box.pack( anchor='s', fill='x', side=BOTTOM) + + def copy_name (self, dir, ent): + # This should work as it is the entry's textvariable + self.dlist_dir = dir.cget('value') + # but it isn't so I'll do it manually + ent.entry.delete(0,'end') + ent.entry.insert(0, self.dlist_dir) + + def okcmd (self): + # tixDemo:Status "You have selected the directory" + $self.dlist_dir + + self.quitcmd() + + def quitcmd (self): + self.root.destroy() + +# This "if" statement makes it possible to run this script file inside or +# outside of the main demo program "widget". +# +if __name__== '__main__' : + root=Tix.Tk() + RunSample(root) + root.mainloop() + root.destroy() + diff --git a/Demo/tix/samples/SHList1.py b/Demo/tix/samples/SHList1.py index 5122bbc..f4294ee 100755 --- a/Demo/tix/samples/SHList1.py +++ b/Demo/tix/samples/SHList1.py @@ -1,4 +1,4 @@ -#!/usr/local/bin/python +# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # # $Id$ # @@ -57,7 +57,7 @@ def RunSample (w) : for boss,name in bosses : if count : f=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150, - bd=2, relief=Tix.SUNKEN, bg=hlist['bg'] ) + bd=2, relief=Tix.SUNKEN ) hlist.add_child( itemtype=Tix.WINDOW, window=f, state=Tix.DISABLED ) @@ -89,10 +89,10 @@ def RunSample (w) : # box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL ) box.add( 'ok', text='Ok', underline=0, width=6, - command = lambda w=w: w.destroy() ) + command = lambda w=w: w.quit() ) box.add( 'cancel', text='Cancel', underline=0, width=6, - command = lambda w=w: w.destroy() ) + command = lambda w=w: w.quit() ) box.pack( side=Tix.BOTTOM, fill=Tix.X) top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 ) @@ -105,3 +105,4 @@ if __name__== '__main__' : root=Tix.Tk() RunSample(root) root.mainloop() + root.destroy() diff --git a/Demo/tix/samples/SHList2.py b/Demo/tix/samples/SHList2.py index e1a7a7c..db24511 100755 --- a/Demo/tix/samples/SHList2.py +++ b/Demo/tix/samples/SHList2.py @@ -1,4 +1,4 @@ -#!/usr/local/bin/python +# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # # $Id$ # @@ -43,7 +43,7 @@ def RunSample (w) : # First some styles for the headers style={} - style['header'] = Tix.DisplayStyle(Tix.TEXT, fg='black', refwindow=top, + style['header'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top, anchor=Tix.CENTER, padx=8, pady=2, font = boldfont ) hlist.header_create(0, itemtype=Tix.TEXT, text='Name', @@ -78,17 +78,13 @@ def RunSample (w) : ('chuck', 'jeff', 'Chuck McLean', 'Cleaner') ] - style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top, - fg='#202060', selectforeground = '#202060', font = boldfont ) + style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top) - style['mgr_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=top, - fg='#202060', selectforeground='#202060' ) + style['mgr_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=top) - style['empl_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top, - fg='#602020', selectforeground = '#602020', font = boldfont ) + style['empl_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=top) - style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=top, - fg='#602020', selectforeground = '#602020' ) + style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=top) # Let configure the appearance of the HList subwidget # @@ -130,10 +126,10 @@ def RunSample (w) : # box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL ) box.add( 'ok', text='Ok', underline=0, width=6, - command = lambda w=w: w.destroy() ) + command = lambda w=w: w.quit() ) box.add( 'cancel', text='Cancel', underline=0, width=6, - command = lambda w=w: w.destroy() ) + command = lambda w=w: w.quit() ) box.pack( side=Tix.BOTTOM, fill=Tix.X) top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 ) @@ -146,3 +142,4 @@ if __name__== '__main__' : root=Tix.Tk() RunSample(root) root.mainloop() + root.destroy() diff --git a/Demo/tix/tixwidgets.py b/Demo/tix/tixwidgets.py index 556d3b7..177e452 100644 --- a/Demo/tix/tixwidgets.py +++ b/Demo/tix/tixwidgets.py @@ -1,128 +1,163 @@ -#! /usr/local/bin/python +# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # # $Id$ # # tixwidgets.py -- +# +# For Tix, see http://tix.sourceforge.net +# # This is a demo program of all Tix widgets available from Python. If # you have installed Python & Tix properly, you can execute this as # -# % tixwidget.py +# % python tixwidget.py # import os, sys, Tix +from Tkconstants import * -class Demo: - pass - -root = Tix.Tk() - -demo = Demo() -demo.dir = None # script directory -demo.balloon = None # balloon widget -demo.useBalloons = Tix.StringVar() -demo.useBalloons.set('0') -demo.statusbar = None # status bar widget -demo.welmsg = None # Msg widget -demo.welfont = '' # font name -demo.welsize = '' # font size +TCL_DONT_WAIT = 1<<1 +TCL_WINDOW_EVENTS = 1<<2 +TCL_FILE_EVENTS = 1<<3 +TCL_TIMER_EVENTS = 1<<4 +TCL_IDLE_EVENTS = 1<<5 +TCL_ALL_EVENTS = 0 -def main(): +class Demo: + def __init__(self, top): + self.root = top + self.exit = -1 + + self.dir = None # script directory + self.balloon = None # balloon widget + self.useBalloons = Tix.StringVar() + self.useBalloons.set('0') + self.statusbar = None # status bar widget + self.welmsg = None # Msg widget + self.welfont = '' # font name + self.welsize = '' # font size + + progname = sys.argv[0] + dirname = os.path.dirname(progname) + if dirname and dirname != os.curdir: + self.dir = dirname + index = -1 + for i in range(len(sys.path)): + p = sys.path[i] + if p in ("", os.curdir): + index = i + if index >= 0: + sys.path[index] = dirname + else: + sys.path.insert(0, dirname) + else: + self.dir = os.getcwd() + sys.path.insert(0, self.dir+'/samples') + + def MkMainMenu(self): + top = self.root + w = Tix.Frame(top, bd=2, relief=RAISED) + file = Tix.Menubutton(w, text='File', underline=0, takefocus=0) + help = Tix.Menubutton(w, text='Help', underline=0, takefocus=0) + file.pack(side=LEFT) + help.pack(side=RIGHT) + fm = Tix.Menu(file) + file['menu'] = fm + hm = Tix.Menu(help) + help['menu'] = hm + + if w.tk.eval ('info commands console') == "console": + fm.add_command(label='Console', underline=1, + command=lambda w=w: w.tk.eval('console show')) + + fm.add_command(label='Exit', underline=1, accelerator='Ctrl+X', + command = lambda self=self: self.quitcmd () ) + hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp, + variable=self.useBalloons) + # The trace variable option doesn't seem to work, instead I use 'command' + #apply(w.tk.call, ('trace', 'variable', self.useBalloons, 'w', + # ToggleHelp)) + return w + + def MkMainNotebook(self): + top = self.root + w = Tix.NoteBook(top, ipadx=5, ipady=5, options=""" + *TixNoteBook*tagPadX 6 + *TixNoteBook*tagPadY 4 + *TixNoteBook*borderWidth 2 + """) + # This may be required if there is no *Background option + top['bg'] = w['bg'] + + w.add('wel', label='Welcome', underline=0, + createcmd=lambda w=w, name='wel': MkWelcome(w, name)) + w.add('cho', label='Choosers', underline=0, + createcmd=lambda w=w, name='cho': MkChoosers(w, name)) + w.add('scr', label='Scrolled Widgets', underline=0, + createcmd=lambda w=w, name='scr': MkScroll(w, name)) + w.add('mgr', label='Manager Widgets', underline=0, + createcmd=lambda w=w, name='mgr': MkManager(w, name)) + w.add('dir', label='Directory List', underline=0, + createcmd=lambda w=w, name='dir': MkDirList(w, name)) + w.add('exp', label='Run Sample Programs', underline=0, + createcmd=lambda w=w, name='exp': MkSample(w, name)) + return w + + def MkMainStatus(self): + global demo + top = self.root + + w = Tix.Frame(top, relief=Tix.RAISED, bd=1) + demo.statusbar = Tix.Label(w, relief=Tix.SUNKEN, bd=1) + demo.statusbar.form(padx=3, pady=3, left=0, right='%70') + return w + + def build(self): + root = self.root + z = root.winfo_toplevel() + z.wm_title('Tix Widget Demonstration') + z.geometry('790x590+10+10') + + demo.balloon = Tix.Balloon(root) + frame1 = self.MkMainMenu() + frame2 = self.MkMainNotebook() + frame3 = self.MkMainStatus() + frame1.pack(side=TOP, fill=X) + frame3.pack(side=BOTTOM, fill=X) + frame2.pack(side=TOP, expand=1, fill=BOTH, padx=4, pady=4) + demo.balloon['statusbar'] = demo.statusbar + z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) + + def quitcmd (self): + # self.root.destroy() + self.exit = 0 + + def loop(self): + while self.exit < 0: + self.root.tk.dooneevent(TCL_ALL_EVENTS) + # self.root.tk.dooneevent(TCL_DONT_WAIT) + + def destroy (self): + self.root.destroy() + +def RunMain(top): global demo, root - progname = sys.argv[0] - dirname = os.path.dirname(progname) - if dirname and dirname != os.curdir: - demo.dir = dirname - index = -1 - for i in range(len(sys.path)): - p = sys.path[i] - if p in ("", os.curdir): - index = i - if index >= 0: - sys.path[index] = dirname - else: - sys.path.insert(0, dirname) - else: - demo.dir = os.getcwd() - sys.path.insert(0, demo.dir+'/samples') - - root.withdraw() - root = Tix.Toplevel() - root.title('Tix Widget Demonstration') - root.geometry('780x570+50+50') - - demo.balloon = Tix.Balloon(root) - frame1 = MkMainMenu(root) - frame2 = MkMainNotebook(root) - frame3 = MkMainStatus(root) - frame1.pack(side=Tix.TOP, fill=Tix.X) - frame3.pack(side=Tix.BOTTOM, fill=Tix.X) - frame2.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=4, pady=4) - demo.balloon['statusbar'] = demo.statusbar - root.mainloop() - -def exit_cmd(event=None): - sys.exit() - -def MkMainMenu(top): - global demo + demo = Demo(top) - w = Tix.Frame(top, bd=2, relief=Tix.RAISED) - file = Tix.Menubutton(w, text='File', underline=0, takefocus=0) - help = Tix.Menubutton(w, text='Help', underline=0, takefocus=0) - file.pack(side=Tix.LEFT) - help.pack(side=Tix.RIGHT) - fm = Tix.Menu(file) - file['menu'] = fm - hm = Tix.Menu(help) - help['menu'] = hm - - fm.add_command(label='Exit', underline=1, accelerator='Ctrl+X', - command=exit_cmd) - hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp, - variable=demo.useBalloons) - # The trace variable option doesn't seem to work, instead I use 'command' - #apply(w.tk.call, ('trace', 'variable', demo.useBalloons, 'w', - # ToggleHelp)) - top.bind_all("<Control-x>", exit_cmd) - top.bind_all("<Control-X>", exit_cmd) - return w - -def MkMainNotebook(top): - top.option_add('*TixNoteBook*tagPadX', 6) - top.option_add('*TixNoteBook*tagPadY', 4) - top.option_add('*TixNoteBook*borderWidth', 2) - top.option_add('*TixNoteBook*font', - '-*-helvetica-bold-o-normal-*-14-*-*-*-*-*-*-*') - w = Tix.NoteBook(top, ipadx=5, ipady=5) - w.add('wel', label='Welcome', underline=0, - createcmd=lambda w=w, name='wel': MkWelcome(w, name)) - w.add('cho', label='Choosers', underline=0, - createcmd=lambda w=w, name='cho': MkChoosers(w, name)) - w.add('scr', label='Scrolled Widgets', underline=0, - createcmd=lambda w=w, name='scr': MkScroll(w, name)) - w.add('mgr', label='Manager Widgets', underline=0, - createcmd=lambda w=w, name='mgr': MkManager(w, name)) - w.add('dir', label='Directory List', underline=0, - createcmd=lambda w=w, name='dir': MkDirList(w, name)) - w.add('exp', label='Run Sample Programs', underline=0, - createcmd=lambda w=w, name='exp': MkSample(w, name)) - return w - -def MkMainStatus(top): - global demo - - w = Tix.Frame(top, relief=Tix.RAISED, bd=1) - demo.statusbar = Tix.Label(w, relief=Tix.SUNKEN, bd=1, font='-*-helvetica-medium-r-normal-*-14-*-*-*-*-*-*-*') - demo.statusbar.form(padx=3, pady=3, left=0, right='%70') - return w + # top.withdraw() + # root = Tix.Toplevel() + root = top + demo.build() + demo.loop() + demo.destroy() +# Tabs def MkWelcome(nb, name): w = nb.page(name) bar = MkWelcomeBar(w) text = MkWelcomeText(w) - bar.pack(side=Tix.TOP, fill=Tix.X, padx=2, pady=2) - text.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) + bar.pack(side=TOP, fill=X, padx=2, pady=2) + text.pack(side=TOP, fill=BOTH, expand=1) def MkWelcomeBar(top): global demo @@ -167,9 +202,9 @@ def MkWelcomeText(top): w = Tix.ScrolledWindow(top, scrollbar='auto') win = w.window text = 'Welcome to TIX in Python' - title = Tix.Label(win, font='-*-times-bold-r-normal-*-18-*-*-*-*-*-*-*', + title = Tix.Label(win, bd=0, width=30, anchor=Tix.N, text=text) - msg = Tix.Message(win, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(win, bd=0, width=400, anchor=Tix.N, text='Tix is a set of mega-widgets based on TK. This program \ demonstrates the widgets in the Tix widget set. You can choose the pages \ @@ -190,7 +225,7 @@ def MainTextFont(w): point = demo.welsize['value'] if font == 'Times Roman': font = 'times' - fontstr = '-*-%s-bold-r-normal-*-%s-*-*-*-*-*-*-*' % (font, point) + fontstr = '%s %s' % (font, point) demo.welmsg['font'] = fontstr def ToggleHelp(): @@ -360,7 +395,7 @@ def MkOptMenu(w): m.pack(fill=Tix.X, padx=5, pady=3) def MkFileEnt(w): - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='Press the "open file" icon button and a TixFileSelectDialog will popup.') ent = Tix.FileEntry(w, label='Select a file : ') @@ -368,7 +403,7 @@ def MkFileEnt(w): ent.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3) def MkFileBox(w): - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The TixFileSelectBox is a Motif-style box with various enhancements. For example, you can adjust the size of the two listboxes and your past selections are recorded.') box = Tix.FileSelectBox(w) @@ -381,7 +416,7 @@ def MkToolBar(w): prefix = Tix.OptionName(w) if not prefix: prefix = '' w.option_add('*' + prefix + '*TixSelect*frame.borderWidth', 1) - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The Select widget is also good for arranging buttons in a tool bar.') bar = Tix.Frame(w, bd=2, relief=Tix.RAISED) @@ -407,7 +442,7 @@ def MkTitle(w): prefix = Tix.OptionName(w) if not prefix: prefix = '' w.option_add('*' + prefix + '*TixSelect*frame.borderWidth', 1) - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='There are many types of "chooser" widgets that allow the user to input different types of information') msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) @@ -434,7 +469,7 @@ def MkScroll(nb, name): def MkSList(w): top = Tix.Frame(w, width=300, height=330) bot = Tix.Frame(w) - msg = Tix.Message(top, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(top, relief=Tix.FLAT, width=200, anchor=Tix.N, text='This TixScrolledListBox is configured so that it uses scrollbars only when it is necessary. Use the handles to resize the listbox and watch the scrollbars automatically appear and disappear.') @@ -470,7 +505,7 @@ def MkSWindow(w): top = Tix.Frame(w, width=330, height=330) bot = Tix.Frame(w) - msg = Tix.Message(top, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(top, relief=Tix.FLAT, width=200, anchor=Tix.N, text='The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.') win = Tix.ScrolledWindow(top, scrollbar='auto') @@ -500,7 +535,7 @@ def SWindow_reset(rh, win): def MkSText(w): top = Tix.Frame(w, width=330, height=330) bot = Tix.Frame(w) - msg = Tix.Message(top, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(top, relief=Tix.FLAT, width=200, anchor=Tix.N, text='The TixScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.') @@ -543,7 +578,7 @@ def MkManager(nb, name): note.form(top=0, right=-1, bottom=-1) def MkPanedWindow(w): - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.') group = Tix.Label(w, text='Newsgroup: comp.lang.python') @@ -585,7 +620,7 @@ together with a bitmap, at the same time, inside a TK button widget. pane.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH, expand=1) def MkNoteBook(w): - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The NoteBook widget allows you to layout a complex interface into individual pages.') prefix = Tix.OptionName(w) @@ -654,7 +689,7 @@ def MkDirList(nb, name): fsbox.form(top=0, left='%40', right=-1, bottom=-1) def MkDirListWidget(w): - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The TixDirList widget gives a graphical representation of the file system directory and makes it easy for the user to choose and access directories.') dirlist = Tix.DirList(w, options='hlist.padY 1 hlist.width 25 hlist.height 16') @@ -662,7 +697,7 @@ def MkDirListWidget(w): dirlist.pack(side=Tix.TOP, padx=3, pady=3) def MkExFileWidget(w): - msg = Tix.Message(w, font='-*-helvetica-bold-r-normal-*-14-*-*-*-*-*-*-*', + msg = Tix.Message(w, relief=Tix.FLAT, width=240, anchor=Tix.N, text='The TixExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.') # There's a bug in the ComboBoxes - the scrolledlistbox is destroyed @@ -677,6 +712,8 @@ samples = {'Balloon' : 'Balloon', 'Button Box' : 'BtnBox', 'Combo Box' : 'ComboBox', 'Compound Image' : 'CmpImg', + 'Directory List' : 'DirList', + 'Directory Tree' : 'DirTree', 'Control' : 'Control', 'Notebook' : 'NoteBook', 'Option Menu' : 'OptMenu', @@ -686,8 +723,100 @@ samples = {'Balloon' : 'Balloon', 'Tree (dynamic)' : 'Tree' } +# There are still a lot of demos to be translated: +## set root { +## {d "File Selectors" file } +## {d "Hierachical ListBox" hlist } +## {d "Tabular ListBox" tlist {c tixTList}} +## {d "Grid Widget" grid {c tixGrid}} +## {d "Manager Widgets" manager } +## {d "Scrolled Widgets" scroll } +## {d "Miscellaneous Widgets" misc } +## {d "Image Types" image } +## } +## +## set image { +## {d "Compound Image" cmpimg } +## {d "XPM Image" xpm {i pixmap}} +## } +## +## set cmpimg { +## {f "In Buttons" CmpImg.tcl } +## {f "In NoteBook" CmpImg2.tcl } +## {f "Notebook Color Tabs" CmpImg4.tcl } +## {f "Icons" CmpImg3.tcl } +## } +## +## set xpm { +## {f "In Button" Xpm.tcl {i pixmap}} +## {f "In Menu" Xpm1.tcl {i pixmap}} +## } +## +## set file { +##added {f DirList DirList.tcl } +##added {f DirTree DirTree.tcl } +## {f DirSelectDialog DirDlg.tcl } +## {f ExFileSelectDialog EFileDlg.tcl } +## {f FileSelectDialog FileDlg.tcl } +## {f FileEntry FileEnt.tcl } +## } +## +## set hlist { +## {f HList HList1.tcl } +## {f CheckList ChkList.tcl {c tixCheckList}} +##done {f "ScrolledHList (1)" SHList.tcl } +##done {f "ScrolledHList (2)" SHList2.tcl } +##done {f Tree Tree.tcl } +##done {f "Tree (Dynamic)" DynTree.tcl {v win}} +## } +## +## set tlist { +## {f "ScrolledTList (1)" STList1.tcl {c tixTList}} +## {f "ScrolledTList (2)" STList2.tcl {c tixTList}} +## } +## global tcl_platform +## # This demo hangs windows +## if {$tcl_platform(platform) != "windows"} { +##na lappend tlist {f "TList File Viewer" STList3.tcl {c tixTList}} +## } +## +## set grid { +##na {f "Simple Grid" SGrid0.tcl {c tixGrid}} +##na {f "ScrolledGrid" SGrid1.tcl {c tixGrid}} +##na {f "Editable Grid" EditGrid.tcl {c tixGrid}} +## } +## +## set scroll { +## {f ScrolledListBox SListBox.tcl } +## {f ScrolledText SText.tcl } +## {f ScrolledWindow SWindow.tcl } +##na {f "Canvas Object View" CObjView.tcl {c tixCObjView}} +## } +## +## set manager { +##na {f ListNoteBook ListNBK.tcl } +## {f NoteBook NoteBook.tcl } +## {f PanedWindow PanedWin.tcl } +## } +## +## set misc { +##done {f Balloon Balloon.tcl } +##done {f ButtonBox BtnBox.tcl } +##done {f ComboBox ComboBox.tcl } +##done {f Control Control.tcl } +## {f LabelEntry LabEntry.tcl } +## {f LabelFrame LabFrame.tcl } +##na {f Meter Meter.tcl {c tixMeter}} +##done {f OptionMenu OptMenu.tcl } +##done {f PopupMenu PopMenu.tcl } +## {f Select Select.tcl } +## {f StdButtonBox StdBBox.tcl } +## } +## + stypes = {} stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control', + 'Directory List', 'Directory Tree', 'Notebook', 'Option Menu', 'Popup Menu', 'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)'] stypes['image'] = ['Compound Image'] @@ -707,7 +836,9 @@ def MkSample(nb, name): slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb: Sample_Action(w, slb, 'browse') stext = Tix.ScrolledText(w, name='stext') - stext.text.bind('<1>', stext.text.focus()) + font = root.tk.eval('tix option get fixed_font') + stext.text.config(font=font) + # stext.text.bind('<1>', stext.text.focus()) stext.text.bind('<Up>', lambda w=stext.text: w.yview(scroll='-1 unit')) stext.text.bind('<Down>', lambda w=stext.text: w.yview(scroll='1 unit')) stext.text.bind('<Left>', lambda w=stext.text: w.xview(scroll='-1 unit')) @@ -726,7 +857,6 @@ def MkSample(nb, name): stext.text['bg'] = slb.hlist['bg'] stext.text['state'] = 'disabled' stext.text['wrap'] = 'none' - #XXX stext.text['font'] = fixed_font slb.hlist['separator'] = '.' slb.hlist['width'] = 25 @@ -785,6 +915,7 @@ def Sample_Action(w, slb, action): ReadFile(stext.text, demo.dir + '/samples/' + prog + '.py') def LoadFile(w, fname): + global root b = Tix.Button(w, text='Close', command=w.destroy) t = Tix.ScrolledText(w) # b.form(left=0, bottom=0, padx=4, pady=4) @@ -792,9 +923,9 @@ def LoadFile(w, fname): t.pack() b.pack() - t.text['highlightcolor'] = t['bg'] + font = root.tk.eval('tix option get fixed_font') + t.text.config(font=font) t.text['bd'] = 2 - t.text['bg'] = t['bg'] t.text['wrap'] = 'none' ReadFile(t.text, fname) @@ -815,5 +946,6 @@ def ReadFile(w, fname): w['state'] = old_state if __name__ == '__main__': - main() + root = Tix.Tk() + RunMain(root) |