annotate Tools/webchecker/tktools.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 8a7a2f1f88f0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """Assorted Tk-related subroutines used in Grail."""
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 from types import *
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 from Tkinter import *
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 def _clear_entry_widget(event):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 try:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
9 widget = event.widget
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
10 widget.delete(0, INSERT)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 except: pass
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 def install_keybindings(root):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 root.bind_class('Entry', '<Control-u>', _clear_entry_widget)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 def make_toplevel(master, title=None, class_=None):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 """Create a Toplevel widget.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 This is a shortcut for a Toplevel() instantiation plus calls to
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 set the title and icon name of the widget.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 if class_:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
25 widget = Toplevel(master, class_=class_)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
27 widget = Toplevel(master)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 if title:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
29 widget.title(title)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
30 widget.iconname(title)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 return widget
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 def set_transient(widget, master, relx=0.5, rely=0.3, expose=1):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 """Make an existing toplevel widget transient for a master.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 The widget must exist but should not yet have been placed; in
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 other words, this should be called after creating all the
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 subwidget but before letting the user interact.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 widget.withdraw() # Remain invisible while we figure out the geometry
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 widget.transient(master)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 widget.update_idletasks() # Actualize geometry information
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 if master.winfo_ismapped():
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
45 m_width = master.winfo_width()
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
46 m_height = master.winfo_height()
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
47 m_x = master.winfo_rootx()
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
48 m_y = master.winfo_rooty()
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
50 m_width = master.winfo_screenwidth()
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
51 m_height = master.winfo_screenheight()
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
52 m_x = m_y = 0
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 w_width = widget.winfo_reqwidth()
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 w_height = widget.winfo_reqheight()
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 x = m_x + (m_width - w_width) * relx
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 y = m_y + (m_height - w_height) * rely
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 widget.geometry("+%d+%d" % (x, y))
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if expose:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
59 widget.deiconify() # Become visible at the desired location
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 return widget
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 def make_scrollbars(parent, hbar, vbar, pack=1, class_=None, name=None,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
64 takefocus=0):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 """Subroutine to create a frame with scrollbars.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 This is used by make_text_box and similar routines.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 Note: the caller is responsible for setting the x/y scroll command
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 properties (e.g. by calling set_scroll_commands()).
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 Return a tuple containing the hbar, the vbar, and the frame, where
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 hbar and vbar are None if not requested.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 if class_:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
78 if name: frame = Frame(parent, class_=class_, name=name)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
79 else: frame = Frame(parent, class_=class_)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
81 if name: frame = Frame(parent, name=name)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
82 else: frame = Frame(parent)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 if pack:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
85 frame.pack(fill=BOTH, expand=1)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 corner = None
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 if vbar:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
89 if not hbar:
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
90 vbar = Scrollbar(frame, takefocus=takefocus)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
91 vbar.pack(fill=Y, side=RIGHT)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
92 else:
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
93 vbarframe = Frame(frame, borderwidth=0)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
94 vbarframe.pack(fill=Y, side=RIGHT)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
95 vbar = Scrollbar(frame, name="vbar", takefocus=takefocus)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
96 vbar.pack(in_=vbarframe, expand=1, fill=Y, side=TOP)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
97 sbwidth = vbar.winfo_reqwidth()
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
98 corner = Frame(vbarframe, width=sbwidth, height=sbwidth)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
99 corner.propagate(0)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
100 corner.pack(side=BOTTOM)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
102 vbar = None
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 if hbar:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
105 hbar = Scrollbar(frame, orient=HORIZONTAL, name="hbar",
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
106 takefocus=takefocus)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
107 hbar.pack(fill=X, side=BOTTOM)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
109 hbar = None
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
110
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 return hbar, vbar, frame
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 def set_scroll_commands(widget, hbar, vbar):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 """Link a scrollable widget to its scroll bars.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 The scroll bars may be empty.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
119
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
121
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if vbar:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
123 widget['yscrollcommand'] = (vbar, 'set')
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
124 vbar['command'] = (widget, 'yview')
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 if hbar:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
127 widget['xscrollcommand'] = (hbar, 'set')
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
128 hbar['command'] = (widget, 'xview')
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 widget.vbar = vbar
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 widget.hbar = hbar
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
133
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 def make_text_box(parent, width=0, height=0, hbar=0, vbar=1,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
135 fill=BOTH, expand=1, wrap=WORD, pack=1,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
136 class_=None, name=None, takefocus=None):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
137
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 """Subroutine to create a text box.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
139
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 Create:
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 - a both-ways filling and expanding frame, containing:
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 - a text widget on the left, and
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 - possibly a vertical scroll bar on the right.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 - possibly a horizonta; scroll bar at the bottom.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 Return the text widget and the frame widget.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 hbar, vbar, frame = make_scrollbars(parent, hbar, vbar, pack,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
150 class_=class_, name=name,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
151 takefocus=takefocus)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
152
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 widget = Text(frame, wrap=wrap, name="text")
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 if width: widget.config(width=width)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 if height: widget.config(height=height)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 widget.pack(expand=expand, fill=fill, side=LEFT)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 set_scroll_commands(widget, hbar, vbar)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
159
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 return widget, frame
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
162
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 def make_list_box(parent, width=0, height=0, hbar=0, vbar=1,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
164 fill=BOTH, expand=1, pack=1, class_=None, name=None,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
165 takefocus=None):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 """Subroutine to create a list box.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 Like make_text_box().
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 hbar, vbar, frame = make_scrollbars(parent, hbar, vbar, pack,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
172 class_=class_, name=name,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
173 takefocus=takefocus)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
174
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 widget = Listbox(frame, name="listbox")
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 if width: widget.config(width=width)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 if height: widget.config(height=height)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 widget.pack(expand=expand, fill=fill, side=LEFT)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
179
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 set_scroll_commands(widget, hbar, vbar)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
181
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 return widget, frame
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
183
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 def make_canvas(parent, width=0, height=0, hbar=1, vbar=1,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
186 fill=BOTH, expand=1, pack=1, class_=None, name=None,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
187 takefocus=None):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
188
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 """Subroutine to create a canvas.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
190
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 Like make_text_box().
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
192
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
194
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 hbar, vbar, frame = make_scrollbars(parent, hbar, vbar, pack,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
196 class_=class_, name=name,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
197 takefocus=takefocus)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 widget = Canvas(frame, scrollregion=(0, 0, width, height), name="canvas")
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 if width: widget.config(width=width)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 if height: widget.config(height=height)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 widget.pack(expand=expand, fill=fill, side=LEFT)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
203
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 set_scroll_commands(widget, hbar, vbar)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 return widget, frame
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
207
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 def make_form_entry(parent, label, borderwidth=None):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
211
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 """Subroutine to create a form entry.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 Create:
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 - a horizontally filling and expanding frame, containing:
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 - a label on the left, and
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 - a text entry on the right.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
218
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 Return the entry widget and the frame widget.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
220
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
221 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
222
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 frame = Frame(parent)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 frame.pack(fill=X)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
225
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 label = Label(frame, text=label)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 label.pack(side=LEFT)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
228
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
229 if borderwidth is None:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
230 entry = Entry(frame, relief=SUNKEN)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
232 entry = Entry(frame, relief=SUNKEN, borderwidth=borderwidth)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 entry.pack(side=LEFT, fill=X, expand=1)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
234
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 return entry, frame
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 # This is a slightly modified version of the function above. This
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 # version does the proper alighnment of labels with their fields. It
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 # should probably eventually replace make_form_entry altogether.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
240 #
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 # The one annoying bug is that the text entry field should be
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 # expandable while still aligning the colons. This doesn't work yet.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 #
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
244 def make_labeled_form_entry(parent, label, entrywidth=20, entryheight=1,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
245 labelwidth=0, borderwidth=None,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
246 takefocus=None):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 """Subroutine to create a form entry.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
248
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
249 Create:
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 - a horizontally filling and expanding frame, containing:
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
251 - a label on the left, and
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 - a text entry on the right.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
253
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 Return the entry widget and the frame widget.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 if label and label[-1] != ':': label = label + ':'
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
257
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 frame = Frame(parent)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
259
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 label = Label(frame, text=label, width=labelwidth, anchor=E)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 label.pack(side=LEFT)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 if entryheight == 1:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
263 if borderwidth is None:
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
264 entry = Entry(frame, relief=SUNKEN, width=entrywidth)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
265 else:
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
266 entry = Entry(frame, relief=SUNKEN, width=entrywidth,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
267 borderwidth=borderwidth)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
268 entry.pack(side=RIGHT, expand=1, fill=X)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
269 frame.pack(fill=X)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
271 entry = make_text_box(frame, entrywidth, entryheight, 1, 1,
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
272 takefocus=takefocus)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
273 frame.pack(fill=BOTH, expand=1)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 return entry, frame, label
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
276
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
277
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 def make_double_frame(master=None, class_=None, name=None, relief=RAISED,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
279 borderwidth=1):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
280 """Create a pair of frames suitable for 'hosting' a dialog."""
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 if name:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
282 if class_: frame = Frame(master, class_=class_, name=name)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
283 else: frame = Frame(master, name=name)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
285 if class_: frame = Frame(master, class_=class_)
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
286 else: frame = Frame(master)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 top = Frame(frame, name="topframe", relief=relief,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
288 borderwidth=borderwidth)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 bottom = Frame(frame, name="bottomframe")
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 bottom.pack(fill=X, padx='1m', pady='1m', side=BOTTOM)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 top.pack(expand=1, fill=BOTH, padx='1m', pady='1m')
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
292 frame.pack(expand=1, fill=BOTH)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 top = Frame(top)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
294 top.pack(expand=1, fill=BOTH, padx='2m', pady='2m')
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
295
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 return frame, top, bottom
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
297
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
298
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 def make_group_frame(master, name=None, label=None, fill=Y,
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
300 side=None, expand=None, font=None):
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 """Create nested frames with a border and optional label.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 The outer frame is only used to provide the decorative border, to
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 control packing, and to host the label. The inner frame is packed
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
305 to fill the outer frame and should be used as the parent of all
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
306 sub-widgets. Only the inner frame is returned.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
307
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 font = font or "-*-helvetica-medium-r-normal-*-*-100-*-*-*-*-*-*"
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 outer = Frame(master, borderwidth=2, relief=GROOVE)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
311 outer.pack(expand=expand, fill=fill, side=side)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
312 if label:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
313 Label(outer, text=label, font=font, anchor=W).pack(fill=X)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 inner = Frame(master, borderwidth='1m', name=name)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 inner.pack(expand=1, fill=BOTH, in_=outer)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 inner.forget = outer.forget
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 return inner
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
318
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
319
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 def unify_button_widths(*buttons):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 """Make buttons passed in all have the same width.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
322
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 Works for labels and other widgets with the 'text' option.
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
324
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 """
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 wid = 0
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 for btn in buttons:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
328 wid = max(wid, len(btn["text"]))
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 for btn in buttons:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
330 btn["width"] = wid
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
331
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
332
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 def flatten(msg):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 """Turn a list or tuple into a single string -- recursively."""
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 t = type(msg)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 if t in (ListType, TupleType):
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 7887
diff changeset
337 msg = ' '.join(map(flatten, msg))
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 elif t is ClassType:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
339 msg = msg.__name__
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 else:
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
341 msg = str(msg)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 return msg
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
344
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 def boolean(s):
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 """Test whether a string is a Tk boolean, without error checking."""
25219
8a7a2f1f88f0 Apply diff2.txt from SF patch http://www.python.org/sf/572113
Walter Dörwald <walter@livinglogic.de>
parents: 7887
diff changeset
347 if s.lower() in ('', '0', 'no', 'off', 'false'): return 0
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 else: return 1
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
349
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
350
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 def test():
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 """Test make_text_box(), make_form_entry(), flatten(), boolean()."""
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 import sys
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 root = Tk()
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 entry, eframe = make_form_entry(root, 'Boolean:')
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 text, tframe = make_text_box(root)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 def enter(event, entry=entry, text=text):
7887
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
358 s = boolean(entry.get()) and '\nyes' or '\nno'
efbb7e57e6f8 Give in to tabnanny
Guido van Rossum <guido@python.org>
parents: 5082
diff changeset
359 text.insert('end', s)
5082
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 entry.bind('<Return>', enter)
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 entry.insert(END, flatten(sys.argv))
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 root.mainloop()
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
363
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
364
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 if __name__ == '__main__':
2c8812eea637 Check in another copy of tktools.py...
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 test()