annotate Demo/tix/samples/NoteBook.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 c25e5b620a4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 tixNoteBook widget, which allows
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
14 # you to lay out your interface using a "notebook" metaphore
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 def RunSample(w):
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
19 global root
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
20 root = w
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
21
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
22 # We use these options to set the sizes of the subwidgets inside the
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
23 # notebook, so that they are well-aligned on the screen.
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
24 prefix = Tix.OptionName(w)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
25 if prefix:
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
26 prefix = '*'+prefix
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
27 else:
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
28 prefix = ''
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
29 w.option_add(prefix+'*TixControl*entry.width', 10)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
30 w.option_add(prefix+'*TixControl*label.width', 18)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
31 w.option_add(prefix+'*TixControl*label.anchor', Tix.E)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
32 w.option_add(prefix+'*TixNoteBook*tagPadX', 8)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
33
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
34 # Create the notebook widget and set its backpagecolor to gray.
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
35 # Note that the -backpagecolor option belongs to the "nbframe"
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
36 # subwidget.
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
37 nb = Tix.NoteBook(w, name='nb', ipadx=6, ipady=6)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
38 nb['bg'] = 'gray'
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
39 nb.nbframe['backpagecolor'] = 'gray'
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
40
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
41 # Create the two tabs on the notebook. The -underline option
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
42 # puts a underline on the first character of the labels of the tabs.
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
43 # Keyboard accelerators will be defined automatically according
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
44 # to the underlined character.
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
45 nb.add('hard_disk', label="Hard Disk", underline=0)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
46 nb.add('network', label="Network", underline=0)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
47
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
48 nb.pack(expand=1, fill=Tix.BOTH, padx=5, pady=5 ,side=Tix.TOP)
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 #----------------------------------------
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
51 # Create the first page
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 # Create two frames: one for the common buttons, one for the
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
54 # other widgets
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
55 #
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
56 tab=nb.hard_disk
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
57 f = Tix.Frame(tab)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
58 common = Tix.Frame(tab)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
59
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
60 f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
61 common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
62
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
63 a = Tix.Control(f, value=12, label='Access time: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
64 w = Tix.Control(f, value=400, label='Write Throughput: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
65 r = Tix.Control(f, value=400, label='Read Throughput: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
66 c = Tix.Control(f, value=1021, label='Capacity: ')
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
67
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
68 a.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
69 w.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
70 r.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
71 c.pack(side=Tix.TOP, padx=20, pady=2)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
72
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
73 # Create the common buttons
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
74 createCommonButtons(common)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
75
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
76 #----------------------------------------
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
77 # Create the second page
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
78 #----------------------------------------
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
79
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
80 tab = nb.network
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
81
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
82 f = Tix.Frame(tab)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
83 common = Tix.Frame(tab)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
84
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
85 f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
86 common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
87
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
88 a = Tix.Control(f, value=12, label='Access time: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
89 w = Tix.Control(f, value=400, label='Write Throughput: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
90 r = Tix.Control(f, value=400, label='Read Throughput: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
91 c = Tix.Control(f, value=1021, label='Capacity: ')
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
92 u = Tix.Control(f, value=10, label='Users: ')
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
93
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
94 a.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
95 w.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
96 r.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
97 c.pack(side=Tix.TOP, padx=20, pady=2)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
98 u.pack(side=Tix.TOP, padx=20, pady=2)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
99
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
100 createCommonButtons(common)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
101
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
102 def doDestroy():
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
103 global root
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
104 root.destroy()
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
105
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
106 def createCommonButtons(master):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
107 ok = Tix.Button(master, name='ok', text='OK', width=6,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
108 command=doDestroy)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
109 cancel = Tix.Button(master, name='cancel',
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
110 text='Cancel', width=6,
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
111 command=doDestroy)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
112
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
113 ok.pack(side=Tix.TOP, padx=2, pady=2)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 22345
diff changeset
114 cancel.pack(side=Tix.TOP, padx=2, pady=2)
17098
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
115
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
116 if __name__ == '__main__':
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
117 root = Tix.Tk()
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
118 RunSample(root)
989fed28b74f Patch #410231: Add the Python Tix library.
Martin v. Löwis <martin@v.loewis.de>
parents:
diff changeset
119 root.mainloop()