Mercurial > cpython-lru_cache-weakref
annotate Demo/tix/samples/OptMenu.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | c3a096bfbd6b |
| children | 7d16b42fcdbd |
| rev | line source |
|---|---|
|
22345
1f73251c625a
Patch #485959: Various changes to Tix demos.
Martin v. Löwis <martin@v.loewis.de>
parents:
17098
diff
changeset
|
1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
2 # |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
3 # $Id$ |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
4 # |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
5 # Tix Demostration Program |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
6 # |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
7 # This sample program is structured in such a way so that it can be |
|
22345
1f73251c625a
Patch #485959: Various changes to Tix demos.
Martin v. Löwis <martin@v.loewis.de>
parents:
17098
diff
changeset
|
8 # executed from the Tix demo program "tixwidgets.py": it must have a |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
9 # procedure called "RunSample". It should also have the "if" statment |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
10 # at the end of this file so that it can be run as a standalone |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
11 # program. |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
12 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
13 # This file demonstrates the use of the tixOptionMenu widget -- you can |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
14 # use it for the user to choose from a fixed set of options |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
15 # |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
16 import Tix |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
17 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
18 options = {'text':'Plain Text', 'post':'PostScript', 'html':'HTML', |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
19 'tex':'LaTeX', 'rtf':'Rich Text Format'} |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
20 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
21 def RunSample(w): |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
22 global demo_opt_from, demo_opt_to |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
23 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
24 demo_opt_from = Tix.StringVar() |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
25 demo_opt_to = Tix.StringVar() |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
26 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
27 top = Tix.Frame(w, bd=1, relief=Tix.RAISED) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
28 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
29 from_file = Tix.OptionMenu(top, label="From File Format : ", |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
30 variable=demo_opt_from, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
31 options = 'label.width 19 label.anchor e menubutton.width 15') |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
32 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
33 to_file = Tix.OptionMenu(top, label="To File Format : ", |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
34 variable=demo_opt_to, |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
35 options='label.width 19 label.anchor e menubutton.width 15') |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
36 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
37 # Add the available options to the two OptionMenu widgets |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
38 # |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
39 # [Hint] You have to add the options first before you set the |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
40 # global variables "demo_opt_from" and "demo_opt_to". Otherwise |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
41 # the OptionMenu widget will complain about "unknown options"! |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
42 # |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
43 for opt in options.keys(): |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
44 from_file.add_command(opt, label=options[opt]) |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
45 to_file.add_command(opt, label=options[opt]) |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
46 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
47 demo_opt_from.set('html') |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
48 demo_opt_to.set('post') |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
49 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
50 from_file.pack(side=Tix.TOP, anchor=Tix.W, pady=3, padx=6) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
51 to_file.pack(side=Tix.TOP, anchor=Tix.W, pady=3, padx=6) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
52 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
53 box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
54 box.add('ok', text='Ok', underline=0, width=6, |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
55 command=lambda w=w: ok_command(w)) |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
56 box.add('cancel', text='Cancel', underline=0, width=6, |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
22345
diff
changeset
|
57 command=lambda w=w: w.destroy()) |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
58 box.pack(side=Tix.BOTTOM, fill=Tix.X) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
59 top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
60 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
61 def ok_command(w): |
|
22345
1f73251c625a
Patch #485959: Various changes to Tix demos.
Martin v. Löwis <martin@v.loewis.de>
parents:
17098
diff
changeset
|
62 # tixDemo:Status "Convert file from %s to %s" % ( demo_opt_from.get(), demo_opt_to.get()) |
|
17098
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
63 w.destroy() |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
64 |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
65 if __name__ == '__main__': |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
66 root = Tix.Tk() |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
67 RunSample(root) |
|
989fed28b74f
Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff
changeset
|
68 root.mainloop() |
