Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 1 | # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 2 | # |
| 3 | # $Id$ |
| 4 | # |
| 5 | # tixwidgets.py -- |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 6 | # |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 7 | # For Tix, see http://tix.sourceforge.net |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 8 | # |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 9 | # This is a demo program of some of the Tix widgets available in Python. |
| 10 | # If you have installed Python & Tix properly, you can execute this as |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 11 | # |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 12 | # % python tixwidgets.py |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 13 | # |
| 14 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 15 | import os, os.path, sys, Tix |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 16 | from Tkconstants import * |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 17 | import traceback, tkMessageBox |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 18 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 19 | TCL_DONT_WAIT = 1<<1 |
| 20 | TCL_WINDOW_EVENTS = 1<<2 |
| 21 | TCL_FILE_EVENTS = 1<<3 |
| 22 | TCL_TIMER_EVENTS = 1<<4 |
| 23 | TCL_IDLE_EVENTS = 1<<5 |
| 24 | TCL_ALL_EVENTS = 0 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 25 | |
| 26 | class Demo: |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 27 | def __init__(self, top): |
| 28 | self.root = top |
| 29 | self.exit = -1 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 30 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 31 | self.dir = None # script directory |
| 32 | self.balloon = None # balloon widget |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 33 | self.useBalloons = Tix.StringVar() |
| 34 | self.useBalloons.set('0') |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 35 | self.statusbar = None # status bar widget |
| 36 | self.welmsg = None # Msg widget |
| 37 | self.welfont = '' # font name |
| 38 | self.welsize = '' # font size |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 39 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 40 | progname = sys.argv[0] |
| 41 | dirname = os.path.dirname(progname) |
| 42 | if dirname and dirname != os.curdir: |
| 43 | self.dir = dirname |
| 44 | index = -1 |
| 45 | for i in range(len(sys.path)): |
| 46 | p = sys.path[i] |
| 47 | if p in ("", os.curdir): |
| 48 | index = i |
| 49 | if index >= 0: |
| 50 | sys.path[index] = dirname |
| 51 | else: |
| 52 | sys.path.insert(0, dirname) |
| 53 | else: |
| 54 | self.dir = os.getcwd() |
| 55 | sys.path.insert(0, self.dir+'/samples') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 56 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 57 | def MkMainMenu(self): |
| 58 | top = self.root |
| 59 | w = Tix.Frame(top, bd=2, relief=RAISED) |
| 60 | file = Tix.Menubutton(w, text='File', underline=0, takefocus=0) |
| 61 | help = Tix.Menubutton(w, text='Help', underline=0, takefocus=0) |
| 62 | file.pack(side=LEFT) |
| 63 | help.pack(side=RIGHT) |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 64 | fm = Tix.Menu(file, tearoff=0) |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 65 | file['menu'] = fm |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 66 | hm = Tix.Menu(help, tearoff=0) |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 67 | help['menu'] = hm |
| 68 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 69 | fm.add_command(label='Exit', underline=1, |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 70 | command = lambda self=self: self.quitcmd () ) |
| 71 | hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp, |
| 72 | variable=self.useBalloons) |
| 73 | # The trace variable option doesn't seem to work, instead I use 'command' |
Neal Norwitz | d910855 | 2006-03-17 08:00:19 +0000 | [diff] [blame] | 74 | #w.tk.call('trace', 'variable', self.useBalloons, 'w', ToggleHelp)) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 75 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 76 | return w |
| 77 | |
| 78 | def MkMainNotebook(self): |
| 79 | top = self.root |
| 80 | w = Tix.NoteBook(top, ipadx=5, ipady=5, options=""" |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 81 | tagPadX 6 |
| 82 | tagPadY 4 |
| 83 | borderWidth 2 |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 84 | """) |
| 85 | # This may be required if there is no *Background option |
| 86 | top['bg'] = w['bg'] |
| 87 | |
| 88 | w.add('wel', label='Welcome', underline=0, |
| 89 | createcmd=lambda w=w, name='wel': MkWelcome(w, name)) |
| 90 | w.add('cho', label='Choosers', underline=0, |
| 91 | createcmd=lambda w=w, name='cho': MkChoosers(w, name)) |
| 92 | w.add('scr', label='Scrolled Widgets', underline=0, |
| 93 | createcmd=lambda w=w, name='scr': MkScroll(w, name)) |
| 94 | w.add('mgr', label='Manager Widgets', underline=0, |
| 95 | createcmd=lambda w=w, name='mgr': MkManager(w, name)) |
| 96 | w.add('dir', label='Directory List', underline=0, |
| 97 | createcmd=lambda w=w, name='dir': MkDirList(w, name)) |
| 98 | w.add('exp', label='Run Sample Programs', underline=0, |
| 99 | createcmd=lambda w=w, name='exp': MkSample(w, name)) |
| 100 | return w |
| 101 | |
| 102 | def MkMainStatus(self): |
| 103 | global demo |
| 104 | top = self.root |
| 105 | |
| 106 | w = Tix.Frame(top, relief=Tix.RAISED, bd=1) |
| 107 | demo.statusbar = Tix.Label(w, relief=Tix.SUNKEN, bd=1) |
| 108 | demo.statusbar.form(padx=3, pady=3, left=0, right='%70') |
| 109 | return w |
| 110 | |
| 111 | def build(self): |
| 112 | root = self.root |
| 113 | z = root.winfo_toplevel() |
| 114 | z.wm_title('Tix Widget Demonstration') |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 115 | if z.winfo_screenwidth() <= 800: |
| 116 | z.geometry('790x590+10+10') |
| 117 | else: |
| 118 | z.geometry('890x640+10+10') |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 119 | demo.balloon = Tix.Balloon(root) |
| 120 | frame1 = self.MkMainMenu() |
| 121 | frame2 = self.MkMainNotebook() |
| 122 | frame3 = self.MkMainStatus() |
| 123 | frame1.pack(side=TOP, fill=X) |
| 124 | frame3.pack(side=BOTTOM, fill=X) |
| 125 | frame2.pack(side=TOP, expand=1, fill=BOTH, padx=4, pady=4) |
| 126 | demo.balloon['statusbar'] = demo.statusbar |
| 127 | z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) |
| 128 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 129 | # To show Tcl errors - uncomment this to see the listbox bug. |
| 130 | # Tkinter defines a Tcl tkerror procedure that in effect |
| 131 | # silences all background Tcl error reporting. |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 132 | # root.tk.eval('if {[info commands tkerror] != ""} {rename tkerror pytkerror}') |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 133 | def quitcmd (self): |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 134 | """Quit our mainloop. It is up to you to call root.destroy() after.""" |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 135 | self.exit = 0 |
| 136 | |
| 137 | def loop(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 138 | """This is an explict replacement for _tkinter mainloop() |
| 139 | It lets you catch keyboard interrupts easier, and avoids |
| 140 | the 20 msec. dead sleep() which burns a constant CPU.""" |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 141 | while self.exit < 0: |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 142 | # There are 2 whiles here. The outer one lets you continue |
| 143 | # after a ^C interrupt. |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 144 | try: |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 145 | # This is the replacement for _tkinter mainloop() |
| 146 | # It blocks waiting for the next Tcl event using select. |
| 147 | while self.exit < 0: |
| 148 | self.root.tk.dooneevent(TCL_ALL_EVENTS) |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 149 | except SystemExit: |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 150 | # Tkinter uses SystemExit to exit |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 151 | #print 'Exit' |
| 152 | self.exit = 1 |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 153 | return |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 154 | except KeyboardInterrupt: |
| 155 | if tkMessageBox.askquestion ('Interrupt', 'Really Quit?') == 'yes': |
| 156 | # self.tk.eval('exit') |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 157 | self.exit = 1 |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 158 | return |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 159 | continue |
| 160 | except: |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 161 | # Otherwise it's some other error - be nice and say why |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 162 | t, v, tb = sys.exc_info() |
| 163 | text = "" |
| 164 | for line in traceback.format_exception(t,v,tb): |
| 165 | text += line + '\n' |
| 166 | try: tkMessageBox.showerror ('Error', text) |
| 167 | except: pass |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 168 | self.exit = 1 |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 169 | raise SystemExit(1) |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 170 | |
| 171 | def destroy (self): |
| 172 | self.root.destroy() |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 173 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 174 | def RunMain(root): |
| 175 | global demo |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 176 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 177 | demo = Demo(root) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 178 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 179 | demo.build() |
| 180 | demo.loop() |
| 181 | demo.destroy() |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 182 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 183 | # Tabs |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 184 | def MkWelcome(nb, name): |
| 185 | w = nb.page(name) |
| 186 | bar = MkWelcomeBar(w) |
| 187 | text = MkWelcomeText(w) |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 188 | bar.pack(side=TOP, fill=X, padx=2, pady=2) |
| 189 | text.pack(side=TOP, fill=BOTH, expand=1) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 190 | |
| 191 | def MkWelcomeBar(top): |
| 192 | global demo |
| 193 | |
| 194 | w = Tix.Frame(top, bd=2, relief=Tix.GROOVE) |
| 195 | b1 = Tix.ComboBox(w, command=lambda w=top: MainTextFont(w)) |
| 196 | b2 = Tix.ComboBox(w, command=lambda w=top: MainTextFont(w)) |
| 197 | b1.entry['width'] = 15 |
| 198 | b1.slistbox.listbox['height'] = 3 |
| 199 | b2.entry['width'] = 4 |
| 200 | b2.slistbox.listbox['height'] = 3 |
| 201 | |
| 202 | demo.welfont = b1 |
| 203 | demo.welsize = b2 |
| 204 | |
| 205 | b1.insert(Tix.END, 'Courier') |
| 206 | b1.insert(Tix.END, 'Helvetica') |
| 207 | b1.insert(Tix.END, 'Lucida') |
| 208 | b1.insert(Tix.END, 'Times Roman') |
| 209 | |
| 210 | b2.insert(Tix.END, '8') |
| 211 | b2.insert(Tix.END, '10') |
| 212 | b2.insert(Tix.END, '12') |
| 213 | b2.insert(Tix.END, '14') |
| 214 | b2.insert(Tix.END, '18') |
| 215 | |
| 216 | b1.pick(1) |
| 217 | b2.pick(3) |
| 218 | |
| 219 | b1.pack(side=Tix.LEFT, padx=4, pady=4) |
| 220 | b2.pack(side=Tix.LEFT, padx=4, pady=4) |
| 221 | |
| 222 | demo.balloon.bind_widget(b1, msg='Choose\na font', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 223 | statusmsg='Choose a font for this page') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 224 | demo.balloon.bind_widget(b2, msg='Point size', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 225 | statusmsg='Choose the font size for this page') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 226 | return w |
| 227 | |
| 228 | def MkWelcomeText(top): |
| 229 | global demo |
| 230 | |
| 231 | w = Tix.ScrolledWindow(top, scrollbar='auto') |
| 232 | win = w.window |
| 233 | text = 'Welcome to TIX in Python' |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 234 | title = Tix.Label(win, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 235 | bd=0, width=30, anchor=Tix.N, text=text) |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 236 | msg = Tix.Message(win, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 237 | bd=0, width=400, anchor=Tix.N, |
| 238 | text='Tix is a set of mega-widgets based on TK. This program \ |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 239 | demonstrates the widgets in the Tix widget set. You can choose the pages \ |
| 240 | in this window to look at the corresponding widgets. \n\n\ |
| 241 | To quit this program, choose the "File | Exit" command.\n\n\ |
| 242 | For more information, see http://tix.sourceforge.net.') |
| 243 | title.pack(expand=1, fill=Tix.BOTH, padx=10, pady=10) |
| 244 | msg.pack(expand=1, fill=Tix.BOTH, padx=10, pady=10) |
| 245 | demo.welmsg = msg |
| 246 | return w |
| 247 | |
| 248 | def MainTextFont(w): |
| 249 | global demo |
| 250 | |
| 251 | if not demo.welmsg: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 252 | return |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 253 | font = demo.welfont['value'] |
| 254 | point = demo.welsize['value'] |
| 255 | if font == 'Times Roman': |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 256 | font = 'times' |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 257 | fontstr = '%s %s' % (font, point) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 258 | demo.welmsg['font'] = fontstr |
| 259 | |
| 260 | def ToggleHelp(): |
| 261 | if demo.useBalloons.get() == '1': |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 262 | demo.balloon['state'] = 'both' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 263 | else: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 264 | demo.balloon['state'] = 'none' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 265 | |
| 266 | def MkChoosers(nb, name): |
| 267 | w = nb.page(name) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 268 | options = "label.padX 4" |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 269 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 270 | til = Tix.LabelFrame(w, label='Chooser Widgets', options=options) |
| 271 | cbx = Tix.LabelFrame(w, label='tixComboBox', options=options) |
| 272 | ctl = Tix.LabelFrame(w, label='tixControl', options=options) |
| 273 | sel = Tix.LabelFrame(w, label='tixSelect', options=options) |
| 274 | opt = Tix.LabelFrame(w, label='tixOptionMenu', options=options) |
| 275 | fil = Tix.LabelFrame(w, label='tixFileEntry', options=options) |
| 276 | fbx = Tix.LabelFrame(w, label='tixFileSelectBox', options=options) |
| 277 | tbr = Tix.LabelFrame(w, label='Tool Bar', options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 278 | |
| 279 | MkTitle(til.frame) |
| 280 | MkCombo(cbx.frame) |
| 281 | MkControl(ctl.frame) |
| 282 | MkSelect(sel.frame) |
| 283 | MkOptMenu(opt.frame) |
| 284 | MkFileEnt(fil.frame) |
| 285 | MkFileBox(fbx.frame) |
| 286 | MkToolBar(tbr.frame) |
| 287 | |
| 288 | # First column: comBox and selector |
| 289 | cbx.form(top=0, left=0, right='%33') |
| 290 | sel.form(left=0, right='&'+str(cbx), top=cbx) |
| 291 | opt.form(left=0, right='&'+str(cbx), top=sel, bottom=-1) |
| 292 | |
| 293 | # Second column: title .. etc |
| 294 | til.form(left=cbx, top=0,right='%66') |
| 295 | ctl.form(left=cbx, right='&'+str(til), top=til) |
| 296 | fil.form(left=cbx, right='&'+str(til), top=ctl) |
| 297 | tbr.form(left=cbx, right='&'+str(til), top=fil, bottom=-1) |
| 298 | |
| 299 | # |
| 300 | # Third column: file selection |
| 301 | fbx.form(right=-1, top=0, left='%66') |
| 302 | |
| 303 | def MkCombo(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 304 | options="label.width %d label.anchor %s entry.width %d" % (10, Tix.E, 14) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 305 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 306 | static = Tix.ComboBox(w, label='Static', editable=0, options=options) |
| 307 | editable = Tix.ComboBox(w, label='Editable', editable=1, options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 308 | history = Tix.ComboBox(w, label='History', editable=1, history=1, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 309 | anchor=Tix.E, options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 310 | static.insert(Tix.END, 'January') |
| 311 | static.insert(Tix.END, 'February') |
| 312 | static.insert(Tix.END, 'March') |
| 313 | static.insert(Tix.END, 'April') |
| 314 | static.insert(Tix.END, 'May') |
| 315 | static.insert(Tix.END, 'June') |
| 316 | static.insert(Tix.END, 'July') |
| 317 | static.insert(Tix.END, 'August') |
| 318 | static.insert(Tix.END, 'September') |
| 319 | static.insert(Tix.END, 'October') |
| 320 | static.insert(Tix.END, 'November') |
| 321 | static.insert(Tix.END, 'December') |
| 322 | |
| 323 | editable.insert(Tix.END, 'Angola') |
| 324 | editable.insert(Tix.END, 'Bangladesh') |
| 325 | editable.insert(Tix.END, 'China') |
| 326 | editable.insert(Tix.END, 'Denmark') |
| 327 | editable.insert(Tix.END, 'Ecuador') |
| 328 | |
| 329 | history.insert(Tix.END, '/usr/bin/ksh') |
| 330 | history.insert(Tix.END, '/usr/local/lib/python') |
| 331 | history.insert(Tix.END, '/var/adm') |
| 332 | |
| 333 | static.pack(side=Tix.TOP, padx=5, pady=3) |
| 334 | editable.pack(side=Tix.TOP, padx=5, pady=3) |
| 335 | history.pack(side=Tix.TOP, padx=5, pady=3) |
| 336 | |
| 337 | states = ['Bengal', 'Delhi', 'Karnataka', 'Tamil Nadu'] |
| 338 | |
| 339 | def spin_cmd(w, inc): |
| 340 | idx = states.index(demo_spintxt.get()) + inc |
| 341 | if idx < 0: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 342 | idx = len(states) - 1 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 343 | elif idx >= len(states): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 344 | idx = 0 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 345 | # following doesn't work. |
| 346 | # return states[idx] |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 347 | demo_spintxt.set(states[idx]) # this works |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 348 | |
| 349 | def spin_validate(w): |
| 350 | global states, demo_spintxt |
| 351 | |
| 352 | try: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 353 | i = states.index(demo_spintxt.get()) |
Fred Drake | 7def256 | 2001-05-11 19:44:55 +0000 | [diff] [blame] | 354 | except ValueError: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 355 | return states[0] |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 356 | return states[i] |
| 357 | # why this procedure works as opposed to the previous one beats me. |
| 358 | |
| 359 | def MkControl(w): |
| 360 | global demo_spintxt |
| 361 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 362 | options="label.width %d label.anchor %s entry.width %d" % (10, Tix.E, 13) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 363 | |
| 364 | demo_spintxt = Tix.StringVar() |
| 365 | demo_spintxt.set(states[0]) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 366 | simple = Tix.Control(w, label='Numbers', options=options) |
| 367 | spintxt = Tix.Control(w, label='States', variable=demo_spintxt, |
| 368 | options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 369 | spintxt['incrcmd'] = lambda w=spintxt: spin_cmd(w, 1) |
| 370 | spintxt['decrcmd'] = lambda w=spintxt: spin_cmd(w, -1) |
| 371 | spintxt['validatecmd'] = lambda w=spintxt: spin_validate(w) |
| 372 | |
| 373 | simple.pack(side=Tix.TOP, padx=5, pady=3) |
| 374 | spintxt.pack(side=Tix.TOP, padx=5, pady=3) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 375 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 376 | def MkSelect(w): |
| 377 | options = "label.anchor %s" % Tix.CENTER |
| 378 | |
| 379 | sel1 = Tix.Select(w, label='Mere Mortals', allowzero=1, radio=1, |
| 380 | orientation=Tix.VERTICAL, |
| 381 | labelside=Tix.TOP, |
| 382 | options=options) |
| 383 | sel2 = Tix.Select(w, label='Geeks', allowzero=1, radio=0, |
| 384 | orientation=Tix.VERTICAL, |
| 385 | labelside= Tix.TOP, |
| 386 | options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 387 | |
| 388 | sel1.add('eat', text='Eat') |
| 389 | sel1.add('work', text='Work') |
| 390 | sel1.add('play', text='Play') |
| 391 | sel1.add('party', text='Party') |
| 392 | sel1.add('sleep', text='Sleep') |
| 393 | |
| 394 | sel2.add('eat', text='Eat') |
| 395 | sel2.add('prog1', text='Program') |
| 396 | sel2.add('prog2', text='Program') |
| 397 | sel2.add('prog3', text='Program') |
| 398 | sel2.add('sleep', text='Sleep') |
| 399 | |
| 400 | sel1.pack(side=Tix.LEFT, padx=5, pady=3, fill=Tix.X) |
| 401 | sel2.pack(side=Tix.LEFT, padx=5, pady=3, fill=Tix.X) |
| 402 | |
| 403 | def MkOptMenu(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 404 | options='menubutton.width 15 label.anchor %s' % Tix.E |
| 405 | |
| 406 | m = Tix.OptionMenu(w, label='File Format : ', options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 407 | m.add_command('text', label='Plain Text') |
| 408 | m.add_command('post', label='PostScript') |
| 409 | m.add_command('format', label='Formatted Text') |
| 410 | m.add_command('html', label='HTML') |
| 411 | m.add_command('sep') |
| 412 | m.add_command('tex', label='LaTeX') |
| 413 | m.add_command('rtf', label='Rich Text Format') |
| 414 | |
| 415 | m.pack(fill=Tix.X, padx=5, pady=3) |
| 416 | |
| 417 | def MkFileEnt(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 418 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 419 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 420 | text='Press the "open file" icon button and a TixFileSelectDialog will popup.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 421 | ent = Tix.FileEntry(w, label='Select a file : ') |
| 422 | msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) |
| 423 | ent.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3) |
| 424 | |
| 425 | def MkFileBox(w): |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 426 | """The FileSelectBox is a Motif-style box with various enhancements. |
| 427 | For example, you can adjust the size of the two listboxes |
| 428 | and your past selections are recorded. |
| 429 | """ |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 430 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 431 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 432 | text='The Tix FileSelectBox 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.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 433 | box = Tix.FileSelectBox(w) |
| 434 | msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) |
| 435 | box.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3) |
| 436 | |
| 437 | def MkToolBar(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 438 | """The Select widget is also good for arranging buttons in a tool bar. |
| 439 | """ |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 440 | global demo |
| 441 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 442 | options='frame.borderWidth 1' |
| 443 | |
| 444 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 445 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 446 | text='The Select widget is also good for arranging buttons in a tool bar.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 447 | bar = Tix.Frame(w, bd=2, relief=Tix.RAISED) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 448 | font = Tix.Select(w, allowzero=1, radio=0, label='', options=options) |
| 449 | para = Tix.Select(w, allowzero=0, radio=1, label='', options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 450 | |
| 451 | font.add('bold', bitmap='@' + demo.dir + '/bitmaps/bold.xbm') |
| 452 | font.add('italic', bitmap='@' + demo.dir + '/bitmaps/italic.xbm') |
| 453 | font.add('underline', bitmap='@' + demo.dir + '/bitmaps/underline.xbm') |
| 454 | font.add('capital', bitmap='@' + demo.dir + '/bitmaps/capital.xbm') |
| 455 | |
| 456 | para.add('left', bitmap='@' + demo.dir + '/bitmaps/leftj.xbm') |
| 457 | para.add('right', bitmap='@' + demo.dir + '/bitmaps/rightj.xbm') |
| 458 | para.add('center', bitmap='@' + demo.dir + '/bitmaps/centerj.xbm') |
| 459 | para.add('justify', bitmap='@' + demo.dir + '/bitmaps/justify.xbm') |
| 460 | |
| 461 | msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) |
| 462 | bar.pack(side=Tix.TOP, fill=Tix.X, padx=3, pady=3) |
| 463 | font.pack({'in':bar}, side=Tix.LEFT, padx=3, pady=3) |
| 464 | para.pack({'in':bar}, side=Tix.LEFT, padx=3, pady=3) |
| 465 | |
| 466 | def MkTitle(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 467 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 468 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 469 | text='There are many types of "chooser" widgets that allow the user to input different types of information') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 470 | msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) |
| 471 | |
| 472 | def MkScroll(nb, name): |
| 473 | w = nb.page(name) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 474 | options='label.padX 4' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 475 | |
Martin v. Löwis | 4687428 | 2002-12-06 10:33:45 +0000 | [diff] [blame] | 476 | sls = Tix.LabelFrame(w, label='Tix.ScrolledListBox', options=options) |
| 477 | swn = Tix.LabelFrame(w, label='Tix.ScrolledWindow', options=options) |
| 478 | stx = Tix.LabelFrame(w, label='Tix.ScrolledText', options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 479 | |
| 480 | MkSList(sls.frame) |
| 481 | MkSWindow(swn.frame) |
| 482 | MkSText(stx.frame) |
| 483 | |
| 484 | sls.form(top=0, left=0, right='%33', bottom=-1) |
| 485 | swn.form(top=0, left=sls, right='%66', bottom=-1) |
| 486 | stx.form(top=0, left=swn, right=-1, bottom=-1) |
| 487 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 488 | |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 489 | def MkSList(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 490 | """This TixScrolledListBox is configured so that it uses scrollbars |
| 491 | only when it is necessary. Use the handles to resize the listbox and |
| 492 | watch the scrollbars automatically appear and disappear. """ |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 493 | top = Tix.Frame(w, width=300, height=330) |
| 494 | bot = Tix.Frame(w) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 495 | msg = Tix.Message(top, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 496 | relief=Tix.FLAT, width=200, anchor=Tix.N, |
| 497 | 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.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 498 | |
| 499 | list = Tix.ScrolledListBox(top, scrollbar='auto') |
| 500 | list.place(x=50, y=150, width=120, height=80) |
| 501 | list.listbox.insert(Tix.END, 'Alabama') |
| 502 | list.listbox.insert(Tix.END, 'California') |
| 503 | list.listbox.insert(Tix.END, 'Montana') |
| 504 | list.listbox.insert(Tix.END, 'New Jersey') |
| 505 | list.listbox.insert(Tix.END, 'New York') |
| 506 | list.listbox.insert(Tix.END, 'Pennsylvania') |
| 507 | list.listbox.insert(Tix.END, 'Washington') |
| 508 | |
| 509 | rh = Tix.ResizeHandle(top, bg='black', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 510 | relief=Tix.RAISED, |
| 511 | handlesize=8, gridded=1, minwidth=50, minheight=30) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 512 | btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=list: SList_reset(w,x)) |
| 513 | top.propagate(0) |
| 514 | msg.pack(fill=Tix.X) |
| 515 | btn.pack(anchor=Tix.CENTER) |
| 516 | top.pack(expand=1, fill=Tix.BOTH) |
| 517 | bot.pack(fill=Tix.BOTH) |
| 518 | list.bind('<Map>', func=lambda arg=0, rh=rh, list=list: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 519 | list.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(list))) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 520 | |
| 521 | def SList_reset(rh, list): |
| 522 | list.place(x=50, y=150, width=120, height=80) |
| 523 | list.update() |
| 524 | rh.attach_widget(list) |
| 525 | |
| 526 | def MkSWindow(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 527 | """The ScrolledWindow widget allows you to scroll any kind of Tk |
| 528 | widget. It is more versatile than a scrolled canvas widget. |
| 529 | """ |
| 530 | global demo |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 531 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 532 | text = 'The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.' |
| 533 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 534 | file = os.path.join(demo.dir, 'bitmaps', 'tix.gif') |
| 535 | if not os.path.isfile(file): |
| 536 | text += ' (Image missing)' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 537 | |
| 538 | top = Tix.Frame(w, width=330, height=330) |
| 539 | bot = Tix.Frame(w) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 540 | msg = Tix.Message(top, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 541 | relief=Tix.FLAT, width=200, anchor=Tix.N, |
| 542 | text=text) |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 543 | |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 544 | win = Tix.ScrolledWindow(top, scrollbar='auto') |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 545 | |
Neal Norwitz | 731a986 | 2002-12-10 02:18:49 +0000 | [diff] [blame] | 546 | image1 = win.window.image_create('photo', file=file) |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 547 | lbl = Tix.Label(win.window, image=image1) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 548 | lbl.pack(expand=1, fill=Tix.BOTH) |
| 549 | |
| 550 | win.place(x=30, y=150, width=190, height=120) |
| 551 | |
| 552 | rh = Tix.ResizeHandle(top, bg='black', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 553 | relief=Tix.RAISED, |
| 554 | handlesize=8, gridded=1, minwidth=50, minheight=30) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 555 | btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SWindow_reset(w,x)) |
| 556 | top.propagate(0) |
| 557 | msg.pack(fill=Tix.X) |
| 558 | btn.pack(anchor=Tix.CENTER) |
| 559 | top.pack(expand=1, fill=Tix.BOTH) |
| 560 | bot.pack(fill=Tix.BOTH) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 561 | |
Neal Norwitz | d8b5e3f | 2002-12-30 23:52:01 +0000 | [diff] [blame] | 562 | win.bind('<Map>', func=lambda arg=0, rh=rh, win=win: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 563 | win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win))) |
Neal Norwitz | d8b5e3f | 2002-12-30 23:52:01 +0000 | [diff] [blame] | 564 | |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 565 | def SWindow_reset(rh, win): |
| 566 | win.place(x=30, y=150, width=190, height=120) |
| 567 | win.update() |
| 568 | rh.attach_widget(win) |
| 569 | |
| 570 | def MkSText(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 571 | """The TixScrolledWindow widget allows you to scroll any kind of Tk |
| 572 | widget. It is more versatile than a scrolled canvas widget.""" |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 573 | top = Tix.Frame(w, width=330, height=330) |
| 574 | bot = Tix.Frame(w) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 575 | msg = Tix.Message(top, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 576 | relief=Tix.FLAT, width=200, anchor=Tix.N, |
| 577 | text='The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 578 | |
| 579 | win = Tix.ScrolledText(top, scrollbar='auto') |
Neal Norwitz | d8b5e3f | 2002-12-30 23:52:01 +0000 | [diff] [blame] | 580 | win.text['wrap'] = 'none' |
| 581 | win.text.insert(Tix.END, '''When -scrollbar is set to "auto", the |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 582 | scrollbars are shown only when needed. |
Neal Norwitz | d8b5e3f | 2002-12-30 23:52:01 +0000 | [diff] [blame] | 583 | Additional modifiers can be used to force a |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 584 | scrollbar to be shown or hidden. For example, |
| 585 | "auto -y" means the horizontal scrollbar |
| 586 | should be shown when needed but the vertical |
Neal Norwitz | d8b5e3f | 2002-12-30 23:52:01 +0000 | [diff] [blame] | 587 | scrollbar should always be hidden; |
| 588 | "auto +x" means the vertical scrollbar |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 589 | should be shown when needed but the horizontal |
Neal Norwitz | d8b5e3f | 2002-12-30 23:52:01 +0000 | [diff] [blame] | 590 | scrollbar should always be shown, and so on.''' |
| 591 | ) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 592 | win.place(x=30, y=150, width=190, height=100) |
| 593 | |
| 594 | rh = Tix.ResizeHandle(top, bg='black', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 595 | relief=Tix.RAISED, |
| 596 | handlesize=8, gridded=1, minwidth=50, minheight=30) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 597 | btn = Tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SText_reset(w,x)) |
| 598 | top.propagate(0) |
| 599 | msg.pack(fill=Tix.X) |
| 600 | btn.pack(anchor=Tix.CENTER) |
| 601 | top.pack(expand=1, fill=Tix.BOTH) |
| 602 | bot.pack(fill=Tix.BOTH) |
| 603 | win.bind('<Map>', func=lambda arg=0, rh=rh, win=win: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 604 | win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win))) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 605 | |
| 606 | def SText_reset(rh, win): |
| 607 | win.place(x=30, y=150, width=190, height=120) |
| 608 | win.update() |
| 609 | rh.attach_widget(win) |
| 610 | |
| 611 | def MkManager(nb, name): |
| 612 | w = nb.page(name) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 613 | options='label.padX 4' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 614 | |
Martin v. Löwis | 4687428 | 2002-12-06 10:33:45 +0000 | [diff] [blame] | 615 | pane = Tix.LabelFrame(w, label='Tix.PanedWindow', options=options) |
| 616 | note = Tix.LabelFrame(w, label='Tix.NoteBook', options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 617 | |
| 618 | MkPanedWindow(pane.frame) |
| 619 | MkNoteBook(note.frame) |
| 620 | |
| 621 | pane.form(top=0, left=0, right=note, bottom=-1) |
| 622 | note.form(top=0, right=-1, bottom=-1) |
| 623 | |
| 624 | def MkPanedWindow(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 625 | """The PanedWindow widget allows the user to interactively manipulate |
| 626 | the sizes of several panes. The panes can be arranged either vertically |
| 627 | or horizontally. |
| 628 | """ |
| 629 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 630 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 631 | text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.') |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 632 | group = Tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25') |
| 633 | group.entry.insert(0,'comp.lang.python') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 634 | pane = Tix.PanedWindow(w, orientation='vertical') |
| 635 | |
| 636 | p1 = pane.add('list', min=70, size=100) |
| 637 | p2 = pane.add('text', min=70) |
| 638 | list = Tix.ScrolledListBox(p1) |
| 639 | text = Tix.ScrolledText(p2) |
| 640 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 641 | list.listbox.insert(Tix.END, " 12324 Re: Tkinter is good for your health") |
| 642 | list.listbox.insert(Tix.END, "+ 12325 Re: Tkinter is good for your health") |
| 643 | list.listbox.insert(Tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)") |
| 644 | list.listbox.insert(Tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)") |
| 645 | list.listbox.insert(Tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)") |
| 646 | list.listbox.insert(Tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)") |
| 647 | list.listbox.insert(Tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)") |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 648 | |
| 649 | text.text['bg'] = list.listbox['bg'] |
| 650 | text.text['wrap'] = 'none' |
| 651 | text.text.insert(Tix.END, """ |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 652 | Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 653 | Lines 353 A new way to put text and bitmaps together iNo responses |
| 654 | ioi@blue.seas.upenn.edu Ioi K. Lam at University of Pennsylvania |
| 655 | |
| 656 | Hi, |
| 657 | |
| 658 | I have implemented a new image type called "compound". It allows you |
| 659 | to glue together a bunch of bitmaps, images and text strings together |
| 660 | to form a bigger image. Then you can use this image with widgets that |
| 661 | support the -image option. For example, you can display a text string string |
| 662 | together with a bitmap, at the same time, inside a TK button widget. |
| 663 | """) |
| 664 | list.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6) |
| 665 | text.pack(expand=1, fill=Tix.BOTH, padx=4, pady=6) |
| 666 | |
| 667 | msg.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH) |
| 668 | group.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH) |
| 669 | pane.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH, expand=1) |
| 670 | |
| 671 | def MkNoteBook(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 672 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 673 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 674 | text='The NoteBook widget allows you to layout a complex interface into individual pages.') |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 675 | # prefix = Tix.OptionName(w) |
| 676 | # if not prefix: prefix = '' |
| 677 | # w.option_add('*' + prefix + '*TixNoteBook*tagPadX', 8) |
| 678 | options = "entry.width %d label.width %d label.anchor %s" % (10, 18, Tix.E) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 679 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 680 | nb = Tix.NoteBook(w, ipadx=6, ipady=6, options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 681 | nb.add('hard_disk', label="Hard Disk", underline=0) |
| 682 | nb.add('network', label="Network", underline=0) |
| 683 | |
| 684 | # Frame for the buttons that are present on all pages |
| 685 | common = Tix.Frame(nb.hard_disk) |
| 686 | common.pack(side=Tix.RIGHT, padx=2, pady=2, fill=Tix.Y) |
| 687 | CreateCommonButtons(common) |
| 688 | |
| 689 | # Widgets belonging only to this page |
| 690 | a = Tix.Control(nb.hard_disk, value=12, label='Access Time: ') |
| 691 | w = Tix.Control(nb.hard_disk, value=400, label='Write Throughput: ') |
| 692 | r = Tix.Control(nb.hard_disk, value=400, label='Read Throughput: ') |
| 693 | c = Tix.Control(nb.hard_disk, value=1021, label='Capacity: ') |
| 694 | a.pack(side=Tix.TOP, padx=20, pady=2) |
| 695 | w.pack(side=Tix.TOP, padx=20, pady=2) |
| 696 | r.pack(side=Tix.TOP, padx=20, pady=2) |
| 697 | c.pack(side=Tix.TOP, padx=20, pady=2) |
| 698 | |
| 699 | common = Tix.Frame(nb.network) |
| 700 | common.pack(side=Tix.RIGHT, padx=2, pady=2, fill=Tix.Y) |
| 701 | CreateCommonButtons(common) |
| 702 | |
| 703 | a = Tix.Control(nb.network, value=12, label='Access Time: ') |
| 704 | w = Tix.Control(nb.network, value=400, label='Write Throughput: ') |
| 705 | r = Tix.Control(nb.network, value=400, label='Read Throughput: ') |
| 706 | c = Tix.Control(nb.network, value=1021, label='Capacity: ') |
| 707 | u = Tix.Control(nb.network, value=10, label='Users: ') |
| 708 | a.pack(side=Tix.TOP, padx=20, pady=2) |
| 709 | w.pack(side=Tix.TOP, padx=20, pady=2) |
| 710 | r.pack(side=Tix.TOP, padx=20, pady=2) |
| 711 | c.pack(side=Tix.TOP, padx=20, pady=2) |
| 712 | u.pack(side=Tix.TOP, padx=20, pady=2) |
| 713 | |
| 714 | msg.pack(side=Tix.TOP, padx=3, pady=3, fill=Tix.BOTH) |
| 715 | nb.pack(side=Tix.TOP, padx=5, pady=5, fill=Tix.BOTH, expand=1) |
| 716 | |
| 717 | def CreateCommonButtons(f): |
| 718 | ok = Tix.Button(f, text='OK', width = 6) |
| 719 | cancel = Tix.Button(f, text='Cancel', width = 6) |
| 720 | ok.pack(side=Tix.TOP, padx=2, pady=2) |
| 721 | cancel.pack(side=Tix.TOP, padx=2, pady=2) |
| 722 | |
| 723 | def MkDirList(nb, name): |
| 724 | w = nb.page(name) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 725 | options = "label.padX 4" |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 726 | |
Martin v. Löwis | 4687428 | 2002-12-06 10:33:45 +0000 | [diff] [blame] | 727 | dir = Tix.LabelFrame(w, label='Tix.DirList', options=options) |
| 728 | fsbox = Tix.LabelFrame(w, label='Tix.ExFileSelectBox', options=options) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 729 | MkDirListWidget(dir.frame) |
| 730 | MkExFileWidget(fsbox.frame) |
| 731 | dir.form(top=0, left=0, right='%40', bottom=-1) |
| 732 | fsbox.form(top=0, left='%40', right=-1, bottom=-1) |
| 733 | |
| 734 | def MkDirListWidget(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 735 | """The TixDirList widget gives a graphical representation of the file |
| 736 | system directory and makes it easy for the user to choose and access |
| 737 | directories. |
| 738 | """ |
| 739 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 740 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 741 | text='The Tix DirList widget gives a graphical representation of the file system directory and makes it easy for the user to choose and access directories.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 742 | dirlist = Tix.DirList(w, options='hlist.padY 1 hlist.width 25 hlist.height 16') |
| 743 | msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) |
| 744 | dirlist.pack(side=Tix.TOP, padx=3, pady=3) |
| 745 | |
| 746 | def MkExFileWidget(w): |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 747 | """The TixExFileSelectBox widget is more user friendly than the Motif |
| 748 | style FileSelectBox. """ |
| 749 | msg = Tix.Message(w, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 750 | relief=Tix.FLAT, width=240, anchor=Tix.N, |
| 751 | text='The Tix ExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 752 | # There's a bug in the ComboBoxes - the scrolledlistbox is destroyed |
| 753 | box = Tix.ExFileSelectBox(w, bd=2, relief=Tix.RAISED) |
| 754 | msg.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=3, pady=3) |
| 755 | box.pack(side=Tix.TOP, padx=3, pady=3) |
| 756 | |
| 757 | ### |
| 758 | ### List of all the demos we want to show off |
| 759 | comments = {'widget' : 'Widget Demos', 'image' : 'Image Demos'} |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 760 | samples = {'Balloon' : 'Balloon', |
| 761 | 'Button Box' : 'BtnBox', |
| 762 | 'Combo Box' : 'ComboBox', |
| 763 | 'Compound Image' : 'CmpImg', |
| 764 | 'Directory List' : 'DirList', |
| 765 | 'Directory Tree' : 'DirTree', |
| 766 | 'Control' : 'Control', |
| 767 | 'Notebook' : 'NoteBook', |
| 768 | 'Option Menu' : 'OptMenu', |
| 769 | 'Paned Window' : 'PanedWin', |
| 770 | 'Popup Menu' : 'PopMenu', |
| 771 | 'ScrolledHList (1)' : 'SHList1', |
| 772 | 'ScrolledHList (2)' : 'SHList2', |
| 773 | 'Tree (dynamic)' : 'Tree' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 776 | # There are still a lot of demos to be translated: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 777 | ## set root { |
| 778 | ## {d "File Selectors" file } |
| 779 | ## {d "Hierachical ListBox" hlist } |
| 780 | ## {d "Tabular ListBox" tlist {c tixTList}} |
| 781 | ## {d "Grid Widget" grid {c tixGrid}} |
| 782 | ## {d "Manager Widgets" manager } |
| 783 | ## {d "Scrolled Widgets" scroll } |
| 784 | ## {d "Miscellaneous Widgets" misc } |
| 785 | ## {d "Image Types" image } |
| 786 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 787 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 788 | ## set image { |
| 789 | ## {d "Compound Image" cmpimg } |
| 790 | ## {d "XPM Image" xpm {i pixmap}} |
| 791 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 792 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 793 | ## set cmpimg { |
| 794 | ##done {f "In Buttons" CmpImg.tcl } |
| 795 | ## {f "In NoteBook" CmpImg2.tcl } |
| 796 | ## {f "Notebook Color Tabs" CmpImg4.tcl } |
| 797 | ## {f "Icons" CmpImg3.tcl } |
| 798 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 799 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 800 | ## set xpm { |
| 801 | ## {f "In Button" Xpm.tcl {i pixmap}} |
| 802 | ## {f "In Menu" Xpm1.tcl {i pixmap}} |
| 803 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 804 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 805 | ## set file { |
| 806 | ##added {f DirList DirList.tcl } |
| 807 | ##added {f DirTree DirTree.tcl } |
| 808 | ## {f DirSelectDialog DirDlg.tcl } |
| 809 | ## {f ExFileSelectDialog EFileDlg.tcl } |
| 810 | ## {f FileSelectDialog FileDlg.tcl } |
| 811 | ## {f FileEntry FileEnt.tcl } |
| 812 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 813 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 814 | ## set hlist { |
| 815 | ## {f HList HList1.tcl } |
| 816 | ## {f CheckList ChkList.tcl {c tixCheckList}} |
| 817 | ##done {f "ScrolledHList (1)" SHList.tcl } |
| 818 | ##done {f "ScrolledHList (2)" SHList2.tcl } |
| 819 | ##done {f Tree Tree.tcl } |
| 820 | ##done {f "Tree (Dynamic)" DynTree.tcl {v win}} |
| 821 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 822 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 823 | ## set tlist { |
| 824 | ## {f "ScrolledTList (1)" STList1.tcl {c tixTList}} |
| 825 | ## {f "ScrolledTList (2)" STList2.tcl {c tixTList}} |
| 826 | ## } |
| 827 | ## global tcl_platform |
| 828 | ## # This demo hangs windows |
| 829 | ## if {$tcl_platform(platform) != "windows"} { |
| 830 | ##na lappend tlist {f "TList File Viewer" STList3.tcl {c tixTList}} |
| 831 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 832 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 833 | ## set grid { |
| 834 | ##na {f "Simple Grid" SGrid0.tcl {c tixGrid}} |
| 835 | ##na {f "ScrolledGrid" SGrid1.tcl {c tixGrid}} |
| 836 | ##na {f "Editable Grid" EditGrid.tcl {c tixGrid}} |
| 837 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 838 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 839 | ## set scroll { |
| 840 | ## {f ScrolledListBox SListBox.tcl } |
| 841 | ## {f ScrolledText SText.tcl } |
| 842 | ## {f ScrolledWindow SWindow.tcl } |
| 843 | ##na {f "Canvas Object View" CObjView.tcl {c tixCObjView}} |
| 844 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 845 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 846 | ## set manager { |
| 847 | ## {f ListNoteBook ListNBK.tcl } |
| 848 | ##done {f NoteBook NoteBook.tcl } |
| 849 | ##done {f PanedWindow PanedWin.tcl } |
| 850 | ## } |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 851 | ## |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 852 | ## set misc { |
| 853 | ##done {f Balloon Balloon.tcl } |
| 854 | ##done {f ButtonBox BtnBox.tcl } |
| 855 | ##done {f ComboBox ComboBox.tcl } |
| 856 | ##done {f Control Control.tcl } |
| 857 | ## {f LabelEntry LabEntry.tcl } |
| 858 | ## {f LabelFrame LabFrame.tcl } |
| 859 | ## {f Meter Meter.tcl {c tixMeter}} |
| 860 | ##done {f OptionMenu OptMenu.tcl } |
| 861 | ##done {f PopupMenu PopMenu.tcl } |
| 862 | ## {f Select Select.tcl } |
| 863 | ## {f StdButtonBox StdBBox.tcl } |
| 864 | ## } |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 865 | ## |
| 866 | |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 867 | stypes = {} |
| 868 | stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control', |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 869 | 'Directory List', 'Directory Tree', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 870 | 'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window', |
| 871 | 'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)'] |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 872 | stypes['image'] = ['Compound Image'] |
| 873 | |
| 874 | def MkSample(nb, name): |
| 875 | w = nb.page(name) |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 876 | options = "label.padX 4" |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 877 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 878 | pane = Tix.PanedWindow(w, orientation='horizontal') |
| 879 | pane.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH) |
| 880 | f1 = pane.add('list', expand='1') |
| 881 | f2 = pane.add('text', expand='5') |
| 882 | f1['relief'] = 'flat' |
| 883 | f2['relief'] = 'flat' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 884 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 885 | lab = Tix.LabelFrame(f1, label='Select a sample program:') |
| 886 | lab.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5, pady=5) |
| 887 | lab1 = Tix.LabelFrame(f2, label='Source:') |
| 888 | lab1.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5, pady=5) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 889 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 890 | slb = Tix.Tree(lab.frame, options='hlist.width 20') |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 891 | slb.pack(side=Tix.TOP, expand=1, fill=Tix.BOTH, padx=5) |
| 892 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 893 | stext = Tix.ScrolledText(lab1.frame, name='stext') |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 894 | font = root.tk.eval('tix option get fixed_font') |
| 895 | stext.text.config(font=font) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 896 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 897 | frame = Tix.Frame(lab1.frame, name='frame') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 898 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 899 | run = Tix.Button(frame, text='Run ...', name='run') |
| 900 | view = Tix.Button(frame, text='View Source ...', name='view') |
| 901 | run.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE) |
| 902 | view.pack(side=Tix.LEFT, expand=0, fill=Tix.NONE) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 903 | |
| 904 | stext.text['bg'] = slb.hlist['bg'] |
| 905 | stext.text['state'] = 'disabled' |
| 906 | stext.text['wrap'] = 'none' |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 907 | stext.text['width'] = 80 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 908 | |
Neal Norwitz | ac30ead | 2002-11-14 02:44:08 +0000 | [diff] [blame] | 909 | frame.pack(side=Tix.BOTTOM, expand=0, fill=Tix.X, padx=7) |
| 910 | stext.pack(side=Tix.TOP, expand=0, fill=Tix.BOTH, padx=7) |
| 911 | |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 912 | slb.hlist['separator'] = '.' |
| 913 | slb.hlist['width'] = 25 |
| 914 | slb.hlist['drawbranch'] = 0 |
| 915 | slb.hlist['indent'] = 10 |
| 916 | slb.hlist['wideselect'] = 1 |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 917 | slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run') |
| 918 | slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse') |
| 919 | |
| 920 | run['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run') |
| 921 | view['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'view') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 922 | |
| 923 | for type in ['widget', 'image']: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 924 | if type != 'widget': |
| 925 | x = Tix.Frame(slb.hlist, bd=2, height=2, width=150, |
| 926 | relief=Tix.SUNKEN, bg=slb.hlist['bg']) |
| 927 | slb.hlist.add_child(itemtype=Tix.WINDOW, window=x, state='disabled') |
| 928 | x = slb.hlist.add_child(itemtype=Tix.TEXT, state='disabled', |
| 929 | text=comments[type]) |
| 930 | for key in stypes[type]: |
| 931 | slb.hlist.add_child(x, itemtype=Tix.TEXT, data=key, |
| 932 | text=key) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 933 | slb.hlist.selection_clear() |
| 934 | |
| 935 | run['state'] = 'disabled' |
| 936 | view['state'] = 'disabled' |
| 937 | |
Martin v. Löwis | 652e191 | 2001-11-25 14:50:56 +0000 | [diff] [blame] | 938 | def Sample_Action(w, slb, stext, run, view, action): |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 939 | global demo |
| 940 | |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 941 | hlist = slb.hlist |
| 942 | anchor = hlist.info_anchor() |
| 943 | if not anchor: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 944 | run['state'] = 'disabled' |
| 945 | view['state'] = 'disabled' |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 946 | elif not hlist.info_parent(anchor): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 947 | # a comment |
| 948 | return |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 949 | |
| 950 | run['state'] = 'normal' |
| 951 | view['state'] = 'normal' |
| 952 | key = hlist.info_data(anchor) |
| 953 | title = key |
| 954 | prog = samples[key] |
| 955 | |
| 956 | if action == 'run': |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 957 | exec('import ' + prog) |
| 958 | w = Tix.Toplevel() |
| 959 | w.title(title) |
| 960 | rtn = eval(prog + '.RunSample') |
| 961 | rtn(w) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 962 | elif action == 'view': |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 963 | w = Tix.Toplevel() |
| 964 | w.title('Source view: ' + title) |
| 965 | LoadFile(w, demo.dir + '/samples/' + prog + '.py') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 966 | elif action == 'browse': |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 967 | ReadFile(stext.text, demo.dir + '/samples/' + prog + '.py') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 968 | |
| 969 | def LoadFile(w, fname): |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 970 | global root |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 971 | b = Tix.Button(w, text='Close', command=w.destroy) |
| 972 | t = Tix.ScrolledText(w) |
| 973 | # b.form(left=0, bottom=0, padx=4, pady=4) |
| 974 | # t.form(left=0, bottom=b, right='-0', top=0) |
| 975 | t.pack() |
| 976 | b.pack() |
| 977 | |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 978 | font = root.tk.eval('tix option get fixed_font') |
| 979 | t.text.config(font=font) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 980 | t.text['bd'] = 2 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 981 | t.text['wrap'] = 'none' |
| 982 | |
| 983 | ReadFile(t.text, fname) |
| 984 | |
| 985 | def ReadFile(w, fname): |
| 986 | old_state = w['state'] |
| 987 | w['state'] = 'normal' |
| 988 | w.delete('0.0', Tix.END) |
| 989 | |
| 990 | try: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 991 | f = open(fname) |
| 992 | lines = f.readlines() |
| 993 | for s in lines: |
| 994 | w.insert(Tix.END, s) |
| 995 | f.close() |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 996 | finally: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 997 | # w.see('1.0') |
| 998 | w['state'] = old_state |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 999 | |
| 1000 | if __name__ == '__main__': |
Martin v. Löwis | 20efa68 | 2001-11-11 14:07:37 +0000 | [diff] [blame] | 1001 | root = Tix.Tk() |
| 1002 | RunMain(root) |