Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ec03e0

Browse files
committed
Patch #485959: Various changes to Tix demos.
1 parent 42ab61e commit 8ec03e0

14 files changed

Lines changed: 401 additions & 302 deletions

File tree

Demo/tix/samples/Balloon.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/local/bin/python
2-
#
1+
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
2+
#
33
# $Id$
44
#
55
# Tix Demostration Program
66
#
77
# This sample program is structured in such a way so that it can be
8-
# executed from the Tix demo program "tixwidgets": it must have a
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
99
# procedure called "RunSample". It should also have the "if" statment
1010
# at the end of this file so that it can be run as a standalone
1111
# program.
@@ -17,29 +17,52 @@
1717

1818
import Tix
1919

20-
def RunSample(w):
21-
status = Tix.Label(w, width=40, relief=Tix.SUNKEN, bd=1)
22-
status.pack(side=Tix.BOTTOM, fill=Tix.Y, padx=2, pady=1)
20+
TCL_ALL_EVENTS = 0
21+
22+
def RunSample (root):
23+
balloon = DemoBalloon(root)
24+
balloon.mainloop()
25+
balloon.destroy()
26+
27+
class DemoBalloon:
28+
def __init__(self, w):
29+
self.root = w
30+
self.exit = -1
31+
32+
z = w.winfo_toplevel()
33+
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
34+
35+
status = Tix.Label(w, width=40, relief=Tix.SUNKEN, bd=1)
36+
status.pack(side=Tix.BOTTOM, fill=Tix.Y, padx=2, pady=1)
2337

24-
# Create two mysterious widgets that need balloon help
25-
button1 = Tix.Button(w, text='Something Unexpected',
26-
command=lambda w=w: w.destroy())
27-
button2 = Tix.Button(w, text='Something Else Unexpected')
28-
button2['command'] = lambda w=button2: w.destroy()
29-
button1.pack(side=Tix.TOP, expand=1)
30-
button2.pack(side=Tix.TOP, expand=1)
38+
# Create two mysterious widgets that need balloon help
39+
button1 = Tix.Button(w, text='Something Unexpected',
40+
command=self.quitcmd)
41+
button2 = Tix.Button(w, text='Something Else Unexpected')
42+
button2['command'] = lambda w=button2: w.destroy()
43+
button1.pack(side=Tix.TOP, expand=1)
44+
button2.pack(side=Tix.TOP, expand=1)
3145

32-
# Create the balloon widget and associate it with the widgets that we want
33-
# to provide tips for:
34-
b = Tix.Balloon(w, statusbar=status)
46+
# Create the balloon widget and associate it with the widgets that we want
47+
# to provide tips for:
48+
b = Tix.Balloon(w, statusbar=status)
3549

36-
b.bind_widget(button1, balloonmsg='Close Window',
37-
statusmsg='Press this button to close this window')
38-
b.bind_widget(button2, balloonmsg='Self-destruct button',
39-
statusmsg='Press this button and it will destroy itself')
50+
b.bind_widget(button1, balloonmsg='Close Window',
51+
statusmsg='Press this button to close this window')
52+
b.bind_widget(button2, balloonmsg='Self-destruct button',
53+
statusmsg='Press this button and it will destroy itself')
54+
55+
def quitcmd (self):
56+
self.exit = 0
57+
58+
def mainloop(self):
59+
foundEvent = 1
60+
while self.exit < 0 and foundEvent > 0:
61+
foundEvent = self.root.tk.dooneevent(TCL_ALL_EVENTS)
62+
63+
def destroy (self):
64+
self.root.destroy()
4065

4166
if __name__ == '__main__':
4267
root = Tix.Tk()
43-
4468
RunSample(root)
45-
root.mainloop()

Demo/tix/samples/BtnBox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/local/bin/python
1+
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
22
#
33
# $Id$
44
#
55
# Tix Demostration Program
66
#
77
# This sample program is structured in such a way so that it can be
8-
# executed from the Tix demo program "tixwidgets": it must have a
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
99
# procedure called "RunSample". It should also have the "if" statment
1010
# at the end of this file so that it can be run as a standalone
1111
# program.

Demo/tix/samples/CmpImg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/local/bin/python
1+
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
22
#
33
# $Id$
44
#
55
# Tix Demostration Program
66
#
77
# This sample program is structured in such a way so that it can be
8-
# executed from the Tix demo program "tixwidgets": it must have a
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
99
# procedure called "RunSample". It should also have the "if" statment
1010
# at the end of this file so that it can be run as a standalone
1111
# program.

Demo/tix/samples/ComboBox.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/local/bin/python
1+
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
22
#
33
# $Id$
44
#
55
# Tix Demostration Program
66
#
77
# This sample program is structured in such a way so that it can be
8-
# executed from the Tix demo program "tixwidgets": it must have a
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
99
# procedure called "RunSample". It should also have the "if" statment
1010
# at the end of this file so that it can be run as a standalone
1111
# program.
@@ -85,13 +85,15 @@ def RunSample(w):
8585
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
8686

8787
def select_month(event=None):
88-
print "Month =", demo_month.get()
88+
# tixDemo:Status "Month = %s" % demo_month.get()
89+
pass
8990

9091
def select_year(event=None):
91-
print "Year =", demo_year.get()
92+
# tixDemo:Status "Year = %s" % demo_year.get()
93+
pass
9294

9395
def ok_command(w):
94-
print "Month =", demo_month.get(), ", Year=", demo_year.get()
96+
# tixDemo:Status "Month = %s, Year= %s" % (demo_month.get(), demo_year.get())
9597
w.destroy()
9698

9799
if __name__ == '__main__':

Demo/tix/samples/Control.py

Lines changed: 77 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/local/bin/python
2-
#
1+
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
2+
#
33
# $Id$
44
#
55
# Tix Demostration Program
66
#
77
# This sample program is structured in such a way so that it can be
8-
# executed from the Tix demo program "tixwidgets": it must have a
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
99
# procedure called "RunSample". It should also have the "if" statment
1010
# at the end of this file so that it can be run as a standalone
1111
# program.
@@ -17,57 +17,82 @@
1717
# This example program uses three Control widgets. One lets you select
1818
# integer values; one lets you select floating point values and the last
1919
# one lets you select a few names.
20-
#
20+
2121
import Tix
2222

23-
def RunSample(w):
24-
global demo_maker, demo_thrust, demo_num_engines
25-
26-
demo_maker = Tix.StringVar()
27-
demo_thrust = Tix.DoubleVar()
28-
demo_num_engines = Tix.IntVar()
29-
demo_maker.set('P&W')
30-
demo_thrust.set(20000.0)
31-
demo_num_engines.set(2)
32-
33-
top = Tix.Frame(w, bd=1, relief=Tix.RAISED)
34-
35-
# $w.top.a allows only integer values
36-
#
37-
# [Hint] The -options switch sets the options of the subwidgets.
38-
# [Hint] We set the label.width subwidget option of the Controls to
39-
# be 16 so that their labels appear to be aligned.
40-
#
41-
a = Tix.Control(top, label='Number of Engines: ', integer=1,
42-
variable=demo_num_engines, min=1, max=4,
43-
options='entry.width 10 label.width 20 label.anchor e')
44-
45-
b = Tix.Control(top, label='Thrust: ', integer=0,
46-
min='10000.0', max='60000.0', step=500,
47-
variable=demo_thrust,
48-
options='entry.width 10 label.width 20 label.anchor e')
49-
50-
c = Tix.Control(top, label='Engine Maker: ', value='P&W',
51-
variable=demo_maker,
52-
options='entry.width 10 label.width 20 label.anchor e')
53-
54-
# We can't define these in the init because the widget 'c' doesn't
55-
# exist yet and we need to reference it
56-
c['incrcmd'] = lambda w=c: adjust_maker(w, 1)
57-
c['decrcmd'] = lambda w=c: adjust_maker(w, -1)
58-
c['validatecmd'] = lambda w=c: validate_maker(w)
59-
60-
a.pack(side=Tix.TOP, anchor=Tix.W)
61-
b.pack(side=Tix.TOP, anchor=Tix.W)
62-
c.pack(side=Tix.TOP, anchor=Tix.W)
63-
64-
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
65-
box.add('ok', text='Ok', underline=0, width=6,
66-
command=lambda w=w: ok_command(w))
67-
box.add('cancel', text='Cancel', underline=0, width=6,
68-
command=lambda w=w: w.destroy())
69-
box.pack(side=Tix.BOTTOM, fill=Tix.X)
70-
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
23+
TCL_ALL_EVENTS = 0
24+
25+
def RunSample (root):
26+
control = DemoControl(root)
27+
control.mainloop()
28+
control.destroy()
29+
30+
class DemoControl:
31+
def __init__(self, w):
32+
self.root = w
33+
self.exit = -1
34+
35+
global demo_maker, demo_thrust, demo_num_engines
36+
37+
demo_maker = Tix.StringVar()
38+
demo_thrust = Tix.DoubleVar()
39+
demo_num_engines = Tix.IntVar()
40+
demo_maker.set('P&W')
41+
demo_thrust.set(20000.0)
42+
demo_num_engines.set(2)
43+
44+
top = Tix.Frame(w, bd=1, relief=Tix.RAISED)
45+
46+
# $w.top.a allows only integer values
47+
#
48+
# [Hint] The -options switch sets the options of the subwidgets.
49+
# [Hint] We set the label.width subwidget option of the Controls to
50+
# be 16 so that their labels appear to be aligned.
51+
#
52+
a = Tix.Control(top, label='Number of Engines: ', integer=1,
53+
variable=demo_num_engines, min=1, max=4,
54+
options='entry.width 10 label.width 20 label.anchor e')
55+
56+
b = Tix.Control(top, label='Thrust: ', integer=0,
57+
min='10000.0', max='60000.0', step=500,
58+
variable=demo_thrust,
59+
options='entry.width 10 label.width 20 label.anchor e')
60+
61+
c = Tix.Control(top, label='Engine Maker: ', value='P&W',
62+
variable=demo_maker,
63+
options='entry.width 10 label.width 20 label.anchor e')
64+
65+
# We can't define these in the init because the widget 'c' doesn't
66+
# exist yet and we need to reference it
67+
c['incrcmd'] = lambda w=c: adjust_maker(w, 1)
68+
c['decrcmd'] = lambda w=c: adjust_maker(w, -1)
69+
c['validatecmd'] = lambda w=c: validate_maker(w)
70+
71+
a.pack(side=Tix.TOP, anchor=Tix.W)
72+
b.pack(side=Tix.TOP, anchor=Tix.W)
73+
c.pack(side=Tix.TOP, anchor=Tix.W)
74+
75+
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
76+
box.add('ok', text='Ok', underline=0, width=6,
77+
command=self.okcmd)
78+
box.add('cancel', text='Cancel', underline=0, width=6,
79+
command=self.quitcmd)
80+
box.pack(side=Tix.BOTTOM, fill=Tix.X)
81+
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
82+
83+
def okcmd (self):
84+
# tixDemo:Status "Selected %d of %s engines each of thrust %d", (demo_num_engines.get(), demo_maker.get(), demo_thrust.get())
85+
self.quitcmd()
86+
87+
def quitcmd (self):
88+
self.exit = 0
89+
90+
def mainloop(self):
91+
while self.exit < 0:
92+
self.root.tk.dooneevent(TCL_ALL_EVENTS)
93+
94+
def destroy (self):
95+
self.root.destroy()
7196

7297
maker_list = ['P&W', 'GE', 'Rolls Royce']
7398

@@ -92,11 +117,6 @@ def validate_maker(w):
92117
# Works here though. Why ? Beats me.
93118
return maker_list[i]
94119

95-
def ok_command(w):
96-
print "Selected", demo_num_engines.get(), "of", demo_maker.get(), " engines each of thrust", demo_thrust.get()
97-
w.destroy()
98-
99120
if __name__ == '__main__':
100121
root = Tix.Tk()
101122
RunSample(root)
102-
root.mainloop()

Demo/tix/samples/DirList.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Tix Demostration Program
66
#
77
# This sample program is structured in such a way so that it can be
8-
# executed from the Tix demo program "widget": it must have a
8+
# executed from the Tix demo program "tixwidgets.py": it must have a
99
# procedure called "RunSample". It should also have the "if" statment
1010
# at the end of this file so that it can be run as a standalone
1111
# program using tixwish.
@@ -19,15 +19,9 @@
1919
import Tix, os, copy
2020
from Tkconstants import *
2121

22-
TCL_DONT_WAIT = 1<<1
23-
TCL_WINDOW_EVENTS = 1<<2
24-
TCL_FILE_EVENTS = 1<<3
25-
TCL_TIMER_EVENTS = 1<<4
26-
TCL_IDLE_EVENTS = 1<<5
2722
TCL_ALL_EVENTS = 0
2823

2924
def RunSample (root):
30-
global dirlist
3125
dirlist = DemoDirList(root)
3226
dirlist.mainloop()
3327
dirlist.destroy()
@@ -38,7 +32,7 @@ def __init__(self, w):
3832
self.exit = -1
3933

4034
z = w.winfo_toplevel()
41-
z.wm_title('Tix.DirList Widget Demo')
35+
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
4236

4337
# Create the tixDirList and the tixLabelEntry widgets on the on the top
4438
# of the dialog box
@@ -98,7 +92,6 @@ def __init__(self, w):
9892
command = lambda self=self: self.quitcmd () )
9993

10094
box.pack( anchor='s', fill='x', side=BOTTOM)
101-
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
10295

10396
def copy_name (self, dir, ent):
10497
# This should work as it is the entry's textvariable
@@ -108,24 +101,21 @@ def copy_name (self, dir, ent):
108101
ent.entry.insert(0, self.dlist_dir)
109102

110103
def okcmd (self):
111-
# tixDemo:Status "You have selected the directory" + $self.dlist_dir
112-
104+
# tixDemo:Status "You have selected the directory" + self.dlist_dir
113105
self.quitcmd()
114106

115107
def quitcmd (self):
116-
# self.root.destroy()
117108
self.exit = 0
118109

119110
def mainloop(self):
120111
while self.exit < 0:
121112
self.root.tk.dooneevent(TCL_ALL_EVENTS)
122-
# self.root.tk.dooneevent(TCL_DONT_WAIT)
123113

124114
def destroy (self):
125115
self.root.destroy()
126116

127117
# This "if" statement makes it possible to run this script file inside or
128-
# outside of the main demo program "widget".
118+
# outside of the main demo program "tixwidgets.py".
129119
#
130120
if __name__== '__main__' :
131121
import tkMessageBox, traceback

0 commit comments

Comments
 (0)