Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 1 | # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 2 | # |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 3 | # $Id$ |
| 4 | # |
| 5 | # Tix Demostration Program |
| 6 | # |
| 7 | # This sample program is structured in such a way so that it can be |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 8 | # executed from the Tix demo program "tixwidgets.py": it must have a |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 9 | # procedure called "RunSample". It should also have the "if" statment |
| 10 | # at the end of this file so that it can be run as a standalone |
| 11 | # program. |
| 12 | |
| 13 | # This file demonstrates the use of the tixOptionMenu widget -- you can |
| 14 | # use it for the user to choose from a fixed set of options |
| 15 | # |
| 16 | import Tix |
| 17 | |
| 18 | options = {'text':'Plain Text', 'post':'PostScript', 'html':'HTML', |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 19 | 'tex':'LaTeX', 'rtf':'Rich Text Format'} |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 20 | |
| 21 | def RunSample(w): |
| 22 | global demo_opt_from, demo_opt_to |
| 23 | |
| 24 | demo_opt_from = Tix.StringVar() |
| 25 | demo_opt_to = Tix.StringVar() |
| 26 | |
| 27 | top = Tix.Frame(w, bd=1, relief=Tix.RAISED) |
| 28 | |
| 29 | from_file = Tix.OptionMenu(top, label="From File Format : ", |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 30 | variable=demo_opt_from, |
| 31 | options = 'label.width 19 label.anchor e menubutton.width 15') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 32 | |
| 33 | to_file = Tix.OptionMenu(top, label="To File Format : ", |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 34 | variable=demo_opt_to, |
| 35 | options='label.width 19 label.anchor e menubutton.width 15') |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 36 | |
| 37 | # Add the available options to the two OptionMenu widgets |
| 38 | # |
| 39 | # [Hint] You have to add the options first before you set the |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 40 | # global variables "demo_opt_from" and "demo_opt_to". Otherwise |
| 41 | # the OptionMenu widget will complain about "unknown options"! |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 42 | # |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame] | 43 | for opt in list(options.keys()): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 44 | from_file.add_command(opt, label=options[opt]) |
| 45 | to_file.add_command(opt, label=options[opt]) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 46 | |
| 47 | demo_opt_from.set('html') |
| 48 | demo_opt_to.set('post') |
| 49 | |
| 50 | from_file.pack(side=Tix.TOP, anchor=Tix.W, pady=3, padx=6) |
| 51 | to_file.pack(side=Tix.TOP, anchor=Tix.W, pady=3, padx=6) |
| 52 | |
| 53 | box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) |
| 54 | box.add('ok', text='Ok', underline=0, width=6, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 55 | command=lambda w=w: ok_command(w)) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 56 | box.add('cancel', text='Cancel', underline=0, width=6, |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 57 | command=lambda w=w: w.destroy()) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 58 | box.pack(side=Tix.BOTTOM, fill=Tix.X) |
| 59 | top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) |
| 60 | |
| 61 | def ok_command(w): |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 62 | # tixDemo:Status "Convert file from %s to %s" % ( demo_opt_from.get(), demo_opt_to.get()) |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 63 | w.destroy() |
| 64 | |
| 65 | if __name__ == '__main__': |
| 66 | root = Tix.Tk() |
| 67 | RunSample(root) |
| 68 | root.mainloop() |