Commit 182b5aca authored by Tim Peters's avatar Tim Peters

Whitespace normalization, via reindent.py.

parent e6ddc8b2
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import Tix import Tix
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
balloon = DemoBalloon(root) balloon = DemoBalloon(root)
......
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -21,7 +21,7 @@ def RunSample(w): ...@@ -21,7 +21,7 @@ def RunSample(w):
# Create the label on the top of the dialog box # Create the label on the top of the dialog box
# #
top = Tix.Label(w, padx=20, pady=10, bd=1, relief=Tix.RAISED, top = Tix.Label(w, padx=20, pady=10, bd=1, relief=Tix.RAISED,
anchor=Tix.CENTER, text='This dialog box is\n a demonstration of the\n tixButtonBox widget') anchor=Tix.CENTER, text='This dialog box is\n a demonstration of the\n tixButtonBox widget')
# Create the button box and add a few buttons in it. Set the # Create the button box and add a few buttons in it. Set the
# -width of all the buttons to the same value so that they # -width of all the buttons to the same value so that they
...@@ -32,9 +32,9 @@ def RunSample(w): ...@@ -32,9 +32,9 @@ def RunSample(w):
# #
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
box.add('ok', text='OK', underline=0, width=5, box.add('ok', text='OK', underline=0, width=5,
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
box.add('close', text='Cancel', underline=0, width=5, box.add('close', text='Cancel', underline=0, width=5,
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
box.pack(side=Tix.BOTTOM, fill=Tix.X) box.pack(side=Tix.BOTTOM, fill=Tix.X)
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
......
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -22,13 +22,13 @@ static char * netw_xpm[] = { ...@@ -22,13 +22,13 @@ static char * netw_xpm[] = {
/* width height ncolors chars_per_pixel */ /* width height ncolors chars_per_pixel */
"32 32 7 1", "32 32 7 1",
/* colors */ /* colors */
" s None c None", " s None c None",
". c #000000000000", ". c #000000000000",
"X c white", "X c white",
"o c #c000c000c000", "o c #c000c000c000",
"O c #404040", "O c #404040",
"+ c blue", "+ c blue",
"@ c red", "@ c red",
/* pixels */ /* pixels */
" ", " ",
" .............. ", " .............. ",
...@@ -69,11 +69,11 @@ static char * drivea_xpm[] = { ...@@ -69,11 +69,11 @@ static char * drivea_xpm[] = {
/* width height ncolors chars_per_pixel */ /* width height ncolors chars_per_pixel */
"32 32 5 1", "32 32 5 1",
/* colors */ /* colors */
" s None c None", " s None c None",
". c #000000000000", ". c #000000000000",
"X c white", "X c white",
"o c #c000c000c000", "o c #c000c000c000",
"O c #800080008000", "O c #800080008000",
/* pixels */ /* pixels */
" ", " ",
" ", " ",
...@@ -146,10 +146,10 @@ static unsigned char drivea_bits[] = { ...@@ -146,10 +146,10 @@ static unsigned char drivea_bits[] = {
def RunSample(w): def RunSample(w):
w.img0 = Tix.Image('pixmap', data=network_pixmap) w.img0 = Tix.Image('pixmap', data=network_pixmap)
if not w.img0: if not w.img0:
w.img0 = Tix.Image('bitmap', data=network_bitmap) w.img0 = Tix.Image('bitmap', data=network_bitmap)
w.img1 = Tix.Image('pixmap', data=hard_disk_pixmap) w.img1 = Tix.Image('pixmap', data=hard_disk_pixmap)
if not w.img0: if not w.img0:
w.img1 = Tix.Image('bitmap', data=hard_disk_bitmap) w.img1 = Tix.Image('bitmap', data=hard_disk_bitmap)
hdd = Tix.Button(w, padx=4, pady=1, width=120) hdd = Tix.Button(w, padx=4, pady=1, width=120)
net = Tix.Button(w, padx=4, pady=1, width=120) net = Tix.Button(w, padx=4, pady=1, width=120)
...@@ -163,7 +163,7 @@ def RunSample(w): ...@@ -163,7 +163,7 @@ def RunSample(w):
w.hdd_img = Tix.Image('compound', window=hdd) w.hdd_img = Tix.Image('compound', window=hdd)
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'line') w.hdd_img.tk.call(str(w.hdd_img), 'add', 'line')
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'text', '-text', 'Hard Disk', w.hdd_img.tk.call(str(w.hdd_img), 'add', 'text', '-text', 'Hard Disk',
'-underline', '0') '-underline', '0')
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'space', '-width', '7') w.hdd_img.tk.call(str(w.hdd_img), 'add', 'space', '-width', '7')
w.hdd_img.tk.call(str(w.hdd_img), 'add', 'image', '-image', w.img1) w.hdd_img.tk.call(str(w.hdd_img), 'add', 'image', '-image', w.img1)
...@@ -175,7 +175,7 @@ def RunSample(w): ...@@ -175,7 +175,7 @@ def RunSample(w):
w.net_img = Tix.Image('compound', window=net) w.net_img = Tix.Image('compound', window=net)
w.net_img.tk.call(str(w.net_img), 'add', 'line') w.net_img.tk.call(str(w.net_img), 'add', 'line')
w.net_img.tk.call(str(w.net_img), 'add', 'text', '-text', 'Network', w.net_img.tk.call(str(w.net_img), 'add', 'text', '-text', 'Network',
'-underline', '0') '-underline', '0')
w.net_img.tk.call(str(w.net_img), 'add', 'space', '-width', '7') w.net_img.tk.call(str(w.net_img), 'add', 'space', '-width', '7')
w.net_img.tk.call(str(w.net_img), 'add', 'image', '-image', w.img0) w.net_img.tk.call(str(w.net_img), 'add', 'image', '-image', w.img0)
...@@ -184,7 +184,7 @@ def RunSample(w): ...@@ -184,7 +184,7 @@ def RunSample(w):
net['image'] = w.net_img net['image'] = w.net_img
close = Tix.Button(w, pady=1, text='Close', close = Tix.Button(w, pady=1, text='Close',
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
hdd.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1) hdd.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1)
net.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1) net.pack(side=Tix.LEFT, padx=10, pady=10, fill=Tix.Y, expand=1)
...@@ -194,4 +194,3 @@ if __name__ == '__main__': ...@@ -194,4 +194,3 @@ if __name__ == '__main__':
root = Tix.Tk() root = Tix.Tk()
RunSample(root) RunSample(root)
root.mainloop() root.mainloop()
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -27,25 +27,25 @@ def RunSample(w): ...@@ -27,25 +27,25 @@ def RunSample(w):
# to invent new months? # to invent new months?
# #
# [Hint] The -options switch sets the options of the subwidgets. # [Hint] The -options switch sets the options of the subwidgets.
# [Hint] We set the label.width subwidget option of both comboboxes to # [Hint] We set the label.width subwidget option of both comboboxes to
# be 10 so that their labels appear to be aligned. # be 10 so that their labels appear to be aligned.
# #
a = Tix.ComboBox(top, label="Month: ", dropdown=1, a = Tix.ComboBox(top, label="Month: ", dropdown=1,
command=select_month, editable=0, variable=demo_month, command=select_month, editable=0, variable=demo_month,
options='listbox.height 6 label.width 10 label.anchor e') options='listbox.height 6 label.width 10 label.anchor e')
# $w.top.b is a non-drop-down combo box. It is not editable: we provide # $w.top.b is a non-drop-down combo box. It is not editable: we provide
# four choices for the user, but he can enter an alternative year if he # four choices for the user, but he can enter an alternative year if he
# wants to. # wants to.
# #
# [Hint] Use the padY and anchor options of the label subwidget to # [Hint] Use the padY and anchor options of the label subwidget to
# align the label with the entry subwidget. # align the label with the entry subwidget.
# [Hint] Notice that you should use padY (the NAME of the option) and not # [Hint] Notice that you should use padY (the NAME of the option) and not
# pady (the SWITCH of the option). # pady (the SWITCH of the option).
# #
b = Tix.ComboBox(top, label="Year: ", dropdown=0, b = Tix.ComboBox(top, label="Year: ", dropdown=0,
command=select_year, editable=1, variable=demo_year, command=select_year, editable=1, variable=demo_year,
options='listbox.height 4 label.padY 5 label.width 10 label.anchor ne') options='listbox.height 4 label.padY 5 label.width 10 label.anchor ne')
a.pack(side=Tix.TOP, anchor=Tix.W) a.pack(side=Tix.TOP, anchor=Tix.W)
b.pack(side=Tix.TOP, anchor=Tix.W) b.pack(side=Tix.TOP, anchor=Tix.W)
...@@ -70,7 +70,7 @@ def RunSample(w): ...@@ -70,7 +70,7 @@ def RunSample(w):
b.insert(Tix.END, '1996') b.insert(Tix.END, '1996')
# Use "tixSetSilent" to set the values of the combo box if you # Use "tixSetSilent" to set the values of the combo box if you
# don't want your -command procedures (cbx:select_month and # don't want your -command procedures (cbx:select_month and
# cbx:select_year) to be called. # cbx:select_year) to be called.
# #
a.set_silent('January') a.set_silent('January')
...@@ -78,9 +78,9 @@ def RunSample(w): ...@@ -78,9 +78,9 @@ def RunSample(w):
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
box.add('ok', text='Ok', underline=0, width=6, box.add('ok', text='Ok', underline=0, width=6,
command=lambda w=w: ok_command(w)) command=lambda w=w: ok_command(w))
box.add('cancel', text='Cancel', underline=0, width=6, box.add('cancel', text='Cancel', underline=0, width=6,
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
box.pack(side=Tix.BOTTOM, fill=Tix.X) box.pack(side=Tix.BOTTOM, fill=Tix.X)
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
import Tix import Tix
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
control = DemoControl(root) control = DemoControl(root)
...@@ -46,7 +46,7 @@ class DemoControl: ...@@ -46,7 +46,7 @@ class DemoControl:
# $w.top.a allows only integer values # $w.top.a allows only integer values
# #
# [Hint] The -options switch sets the options of the subwidgets. # [Hint] The -options switch sets the options of the subwidgets.
# [Hint] We set the label.width subwidget option of the Controls to # [Hint] We set the label.width subwidget option of the Controls to
# be 16 so that their labels appear to be aligned. # be 16 so that their labels appear to be aligned.
# #
a = Tix.Control(top, label='Number of Engines: ', integer=1, a = Tix.Control(top, label='Number of Engines: ', integer=1,
...@@ -83,7 +83,7 @@ class DemoControl: ...@@ -83,7 +83,7 @@ class DemoControl:
def okcmd (self): def okcmd (self):
# tixDemo:Status "Selected %d of %s engines each of thrust %d", (demo_num_engines.get(), demo_maker.get(), demo_thrust.get()) # tixDemo:Status "Selected %d of %s engines each of thrust %d", (demo_num_engines.get(), demo_maker.get(), demo_thrust.get())
self.quitcmd() self.quitcmd()
def quitcmd (self): def quitcmd (self):
self.exit = 0 self.exit = 0
...@@ -100,9 +100,9 @@ def adjust_maker(w, inc): ...@@ -100,9 +100,9 @@ def adjust_maker(w, inc):
i = maker_list.index(demo_maker.get()) i = maker_list.index(demo_maker.get())
i = i + inc i = i + inc
if i >= len(maker_list): if i >= len(maker_list):
i = 0 i = 0
elif i < 0: elif i < 0:
i = len(maker_list) - 1 i = len(maker_list) - 1
# In Tcl/Tix we should return the string maker_list[i]. We can't # In Tcl/Tix we should return the string maker_list[i]. We can't
# do that in Tkinter so we set the global variable. (This works). # do that in Tkinter so we set the global variable. (This works).
...@@ -110,10 +110,10 @@ def adjust_maker(w, inc): ...@@ -110,10 +110,10 @@ def adjust_maker(w, inc):
def validate_maker(w): def validate_maker(w):
try: try:
i = maker_list.index(demo_maker.get()) i = maker_list.index(demo_maker.get())
except ValueError: except ValueError:
# Works here though. Why ? Beats me. # Works here though. Why ? Beats me.
return maker_list[0] return maker_list[0]
# Works here though. Why ? Beats me. # Works here though. Why ? Beats me.
return maker_list[i] return maker_list[i]
......
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
# #
...@@ -19,21 +19,21 @@ ...@@ -19,21 +19,21 @@
import Tix, os, copy import Tix, os, copy
from Tkconstants import * from Tkconstants import *
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
dirlist = DemoDirList(root) dirlist = DemoDirList(root)
dirlist.mainloop() dirlist.mainloop()
dirlist.destroy() dirlist.destroy()
class DemoDirList: class DemoDirList:
def __init__(self, w): def __init__(self, w):
self.root = w self.root = w
self.exit = -1 self.exit = -1
z = w.winfo_toplevel() z = w.winfo_toplevel()
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
# Create the tixDirList and the tixLabelEntry widgets on the on the top # Create the tixDirList and the tixLabelEntry widgets on the on the top
# of the dialog box # of the dialog box
...@@ -48,14 +48,14 @@ class DemoDirList: ...@@ -48,14 +48,14 @@ class DemoDirList:
# #
top.dir = Tix.DirList(top) top.dir = Tix.DirList(top)
top.dir.hlist['width'] = 40 top.dir.hlist['width'] = 40
# When the user presses the ".." button, the selected directory # When the user presses the ".." button, the selected directory
# is "transferred" into the entry widget # is "transferred" into the entry widget
# #
top.btn = Tix.Button(top, text = " >> ", pady = 0) top.btn = Tix.Button(top, text = " >> ", pady = 0)
# We use a LabelEntry to hold the installation directory. The user # We use a LabelEntry to hold the installation directory. The user
# can choose from the DirList widget, or he can type in the directory # can choose from the DirList widget, or he can type in the directory
# manually # manually
# #
top.ent = Tix.LabelEntry(top, label="Installation Directory:", top.ent = Tix.LabelEntry(top, label="Installation Directory:",
...@@ -64,7 +64,7 @@ class DemoDirList: ...@@ -64,7 +64,7 @@ class DemoDirList:
entry.width 40 entry.width 40
label.anchor w label.anchor w
''') ''')
font = self.root.tk.eval('tix option get fixed_font') font = self.root.tk.eval('tix option get fixed_font')
# font = self.root.master.tix_option_get('fixed_font') # font = self.root.master.tix_option_get('fixed_font')
top.ent.entry['font'] = font top.ent.entry['font'] = font
...@@ -129,4 +129,3 @@ if __name__== '__main__' : ...@@ -129,4 +129,3 @@ if __name__== '__main__' :
for line in traceback.format_exception(t,v,tb): for line in traceback.format_exception(t,v,tb):
text = text + line + '\n' text = text + line + '\n'
d = tkMessageBox.showerror ( 'Tix Demo Error', text) d = tkMessageBox.showerror ( 'Tix Demo Error', text)
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
# #
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
import Tix, os, copy import Tix, os, copy
from Tkconstants import * from Tkconstants import *
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
dirtree = DemoDirTree(root) dirtree = DemoDirTree(root)
...@@ -30,7 +30,7 @@ class DemoDirTree: ...@@ -30,7 +30,7 @@ class DemoDirTree:
def __init__(self, w): def __init__(self, w):
self.root = w self.root = w
self.exit = -1 self.exit = -1
z = w.winfo_toplevel() z = w.winfo_toplevel()
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
...@@ -48,14 +48,14 @@ class DemoDirTree: ...@@ -48,14 +48,14 @@ class DemoDirTree:
# #
top.dir = Tix.DirTree(top) top.dir = Tix.DirTree(top)
top.dir.hlist['width'] = 40 top.dir.hlist['width'] = 40
# When the user presses the ".." button, the selected directory # When the user presses the ".." button, the selected directory
# is "transferred" into the entry widget # is "transferred" into the entry widget
# #
top.btn = Tix.Button(top, text = " >> ", pady = 0) top.btn = Tix.Button(top, text = " >> ", pady = 0)
# We use a LabelEntry to hold the installation directory. The user # We use a LabelEntry to hold the installation directory. The user
# can choose from the DirTree widget, or he can type in the directory # can choose from the DirTree widget, or he can type in the directory
# manually # manually
# #
top.ent = Tix.LabelEntry(top, label="Installation Directory:", top.ent = Tix.LabelEntry(top, label="Installation Directory:",
...@@ -115,4 +115,3 @@ class DemoDirTree: ...@@ -115,4 +115,3 @@ class DemoDirTree:
if __name__== '__main__' : if __name__== '__main__' :
root=Tix.Tk() root=Tix.Tk()
RunSample(root) RunSample(root)
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -23,9 +23,9 @@ def RunSample(w): ...@@ -23,9 +23,9 @@ def RunSample(w):
# notebook, so that they are well-aligned on the screen. # notebook, so that they are well-aligned on the screen.
prefix = Tix.OptionName(w) prefix = Tix.OptionName(w)
if prefix: if prefix:
prefix = '*'+prefix prefix = '*'+prefix
else: else:
prefix = '' prefix = ''
w.option_add(prefix+'*TixControl*entry.width', 10) w.option_add(prefix+'*TixControl*entry.width', 10)
w.option_add(prefix+'*TixControl*label.width', 18) w.option_add(prefix+'*TixControl*label.width', 18)
w.option_add(prefix+'*TixControl*label.anchor', Tix.E) w.option_add(prefix+'*TixControl*label.anchor', Tix.E)
...@@ -37,14 +37,14 @@ def RunSample(w): ...@@ -37,14 +37,14 @@ def RunSample(w):
nb = Tix.NoteBook(w, name='nb', ipadx=6, ipady=6) nb = Tix.NoteBook(w, name='nb', ipadx=6, ipady=6)
nb['bg'] = 'gray' nb['bg'] = 'gray'
nb.nbframe['backpagecolor'] = 'gray' nb.nbframe['backpagecolor'] = 'gray'
# Create the two tabs on the notebook. The -underline option # Create the two tabs on the notebook. The -underline option
# puts a underline on the first character of the labels of the tabs. # puts a underline on the first character of the labels of the tabs.
# Keyboard accelerators will be defined automatically according # Keyboard accelerators will be defined automatically according
# to the underlined character. # to the underlined character.
nb.add('hard_disk', label="Hard Disk", underline=0) nb.add('hard_disk', label="Hard Disk", underline=0)
nb.add('network', label="Network", underline=0) nb.add('network', label="Network", underline=0)
nb.pack(expand=1, fill=Tix.BOTH, padx=5, pady=5 ,side=Tix.TOP) nb.pack(expand=1, fill=Tix.BOTH, padx=5, pady=5 ,side=Tix.TOP)
#---------------------------------------- #----------------------------------------
...@@ -56,62 +56,62 @@ def RunSample(w): ...@@ -56,62 +56,62 @@ def RunSample(w):
tab=nb.hard_disk tab=nb.hard_disk
f = Tix.Frame(tab) f = Tix.Frame(tab)
common = Tix.Frame(tab) common = Tix.Frame(tab)
f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1) f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y) common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
a = Tix.Control(f, value=12, label='Access time: ') a = Tix.Control(f, value=12, label='Access time: ')
w = Tix.Control(f, value=400, label='Write Throughput: ') w = Tix.Control(f, value=400, label='Write Throughput: ')
r = Tix.Control(f, value=400, label='Read Throughput: ') r = Tix.Control(f, value=400, label='Read Throughput: ')
c = Tix.Control(f, value=1021, label='Capacity: ') c = Tix.Control(f, value=1021, label='Capacity: ')
a.pack(side=Tix.TOP, padx=20, pady=2) a.pack(side=Tix.TOP, padx=20, pady=2)
w.pack(side=Tix.TOP, padx=20, pady=2) w.pack(side=Tix.TOP, padx=20, pady=2)
r.pack(side=Tix.TOP, padx=20, pady=2) r.pack(side=Tix.TOP, padx=20, pady=2)
c.pack(side=Tix.TOP, padx=20, pady=2) c.pack(side=Tix.TOP, padx=20, pady=2)
# Create the common buttons # Create the common buttons
createCommonButtons(common) createCommonButtons(common)
#---------------------------------------- #----------------------------------------
# Create the second page # Create the second page
#---------------------------------------- #----------------------------------------
tab = nb.network tab = nb.network
f = Tix.Frame(tab) f = Tix.Frame(tab)
common = Tix.Frame(tab) common = Tix.Frame(tab)
f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1) f.pack(side=Tix.LEFT, padx=2, pady=2, fill=Tix.BOTH, expand=1)
common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y) common.pack(side=Tix.RIGHT, padx=2, fill=Tix.Y)
a = Tix.Control(f, value=12, label='Access time: ') a = Tix.Control(f, value=12, label='Access time: ')
w = Tix.Control(f, value=400, label='Write Throughput: ') w = Tix.Control(f, value=400, label='Write Throughput: ')
r = Tix.Control(f, value=400, label='Read Throughput: ') r = Tix.Control(f, value=400, label='Read Throughput: ')
c = Tix.Control(f, value=1021, label='Capacity: ') c = Tix.Control(f, value=1021, label='Capacity: ')
u = Tix.Control(f, value=10, label='Users: ') u = Tix.Control(f, value=10, label='Users: ')
a.pack(side=Tix.TOP, padx=20, pady=2) a.pack(side=Tix.TOP, padx=20, pady=2)
w.pack(side=Tix.TOP, padx=20, pady=2) w.pack(side=Tix.TOP, padx=20, pady=2)
r.pack(side=Tix.TOP, padx=20, pady=2) r.pack(side=Tix.TOP, padx=20, pady=2)
c.pack(side=Tix.TOP, padx=20, pady=2) c.pack(side=Tix.TOP, padx=20, pady=2)
u.pack(side=Tix.TOP, padx=20, pady=2) u.pack(side=Tix.TOP, padx=20, pady=2)
createCommonButtons(common) createCommonButtons(common)
def doDestroy(): def doDestroy():
global root global root
root.destroy() root.destroy()
def createCommonButtons(master): def createCommonButtons(master):
ok = Tix.Button(master, name='ok', text='OK', width=6, ok = Tix.Button(master, name='ok', text='OK', width=6,
command=doDestroy) command=doDestroy)
cancel = Tix.Button(master, name='cancel', cancel = Tix.Button(master, name='cancel',
text='Cancel', width=6, text='Cancel', width=6,
command=doDestroy) command=doDestroy)
ok.pack(side=Tix.TOP, padx=2, pady=2) ok.pack(side=Tix.TOP, padx=2, pady=2)
cancel.pack(side=Tix.TOP, padx=2, pady=2) cancel.pack(side=Tix.TOP, padx=2, pady=2)
if __name__ == '__main__': if __name__ == '__main__':
root = Tix.Tk() root = Tix.Tk()
......
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
import Tix import Tix
options = {'text':'Plain Text', 'post':'PostScript', 'html':'HTML', options = {'text':'Plain Text', 'post':'PostScript', 'html':'HTML',
'tex':'LaTeX', 'rtf':'Rich Text Format'} 'tex':'LaTeX', 'rtf':'Rich Text Format'}
def RunSample(w): def RunSample(w):
global demo_opt_from, demo_opt_to global demo_opt_from, demo_opt_to
...@@ -27,22 +27,22 @@ def RunSample(w): ...@@ -27,22 +27,22 @@ def RunSample(w):
top = Tix.Frame(w, bd=1, relief=Tix.RAISED) top = Tix.Frame(w, bd=1, relief=Tix.RAISED)
from_file = Tix.OptionMenu(top, label="From File Format : ", from_file = Tix.OptionMenu(top, label="From File Format : ",
variable=demo_opt_from, variable=demo_opt_from,
options = 'label.width 19 label.anchor e menubutton.width 15') options = 'label.width 19 label.anchor e menubutton.width 15')
to_file = Tix.OptionMenu(top, label="To File Format : ", to_file = Tix.OptionMenu(top, label="To File Format : ",
variable=demo_opt_to, variable=demo_opt_to,
options='label.width 19 label.anchor e menubutton.width 15') options='label.width 19 label.anchor e menubutton.width 15')
# Add the available options to the two OptionMenu widgets # Add the available options to the two OptionMenu widgets
# #
# [Hint] You have to add the options first before you set the # [Hint] You have to add the options first before you set the
# global variables "demo_opt_from" and "demo_opt_to". Otherwise # global variables "demo_opt_from" and "demo_opt_to". Otherwise
# the OptionMenu widget will complain about "unknown options"! # the OptionMenu widget will complain about "unknown options"!
# #
for opt in options.keys(): for opt in options.keys():
from_file.add_command(opt, label=options[opt]) from_file.add_command(opt, label=options[opt])
to_file.add_command(opt, label=options[opt]) to_file.add_command(opt, label=options[opt])
demo_opt_from.set('html') demo_opt_from.set('html')
demo_opt_to.set('post') demo_opt_to.set('post')
...@@ -52,9 +52,9 @@ def RunSample(w): ...@@ -52,9 +52,9 @@ def RunSample(w):
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
box.add('ok', text='Ok', underline=0, width=6, box.add('ok', text='Ok', underline=0, width=6,
command=lambda w=w: ok_command(w)) command=lambda w=w: ok_command(w))
box.add('cancel', text='Cancel', underline=0, width=6, box.add('cancel', text='Cancel', underline=0, width=6,
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
box.pack(side=Tix.BOTTOM, fill=Tix.X) box.pack(side=Tix.BOTTOM, fill=Tix.X)
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import Tix import Tix
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
panedwin = DemoPanedwin(root) panedwin = DemoPanedwin(root)
......
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
# #
...@@ -27,9 +27,9 @@ def RunSample(w): ...@@ -27,9 +27,9 @@ def RunSample(w):
p.bind_widget(top) p.bind_widget(top)
p.bind_widget(but) p.bind_widget(but)
# Set the entries inside the PopupMenu widget. # Set the entries inside the PopupMenu widget.
# [Hint] You have to manipulate the "menu" subwidget. # [Hint] You have to manipulate the "menu" subwidget.
# $w.top.p itself is NOT a menu widget. # $w.top.p itself is NOT a menu widget.
# [Hint] Watch carefully how the sub-menu is created # [Hint] Watch carefully how the sub-menu is created
# #
p.menu.add_command(label='Desktop', underline=0) p.menu.add_command(label='Desktop', underline=0)
...@@ -45,9 +45,9 @@ def RunSample(w): ...@@ -45,9 +45,9 @@ def RunSample(w):
box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL) box = Tix.ButtonBox(w, orientation=Tix.HORIZONTAL)
box.add('ok', text='Ok', underline=0, width=6, box.add('ok', text='Ok', underline=0, width=6,
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
box.add('cancel', text='Cancel', underline=0, width=6, box.add('cancel', text='Cancel', underline=0, width=6,
command=lambda w=w: w.destroy()) command=lambda w=w: w.destroy())
box.pack(side=Tix.BOTTOM, fill=Tix.X) box.pack(side=Tix.BOTTOM, fill=Tix.X)
top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) top.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
......
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
import Tix import Tix
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
shlist = DemoSHList(root) shlist = DemoSHList(root)
shlist.mainloop() shlist.mainloop()
shlist.destroy() shlist.destroy()
class DemoSHList: class DemoSHList:
def __init__(self, w): def __init__(self, w):
self.root = w self.root = w
...@@ -29,7 +29,7 @@ class DemoSHList: ...@@ -29,7 +29,7 @@ class DemoSHList:
z = w.winfo_toplevel() z = w.winfo_toplevel()
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
# We create the frame and the ScrolledHList widget # We create the frame and the ScrolledHList widget
# at the top of the dialog box # at the top of the dialog box
# #
...@@ -61,7 +61,7 @@ class DemoSHList: ...@@ -61,7 +61,7 @@ class DemoSHList:
hlist=top.a.hlist hlist=top.a.hlist
# Let configure the appearance of the HList subwidget # Let configure the appearance of the HList subwidget
# #
hlist.config( separator='.', width=25, drawbranch=0, indent=10) hlist.config( separator='.', width=25, drawbranch=0, indent=10)
...@@ -71,7 +71,7 @@ class DemoSHList: ...@@ -71,7 +71,7 @@ class DemoSHList:
f=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150, f=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150,
bd=2, relief=Tix.SUNKEN ) bd=2, relief=Tix.SUNKEN )
hlist.add_child( itemtype=Tix.WINDOW, hlist.add_child( itemtype=Tix.WINDOW,
window=f, state=Tix.DISABLED ) window=f, state=Tix.DISABLED )
hlist.add(boss, itemtype=Tix.TEXT, text=name) hlist.add(boss, itemtype=Tix.TEXT, text=name)
...@@ -88,13 +88,13 @@ class DemoSHList: ...@@ -88,13 +88,13 @@ class DemoSHList:
hlist.add( key, text=name ) hlist.add( key, text=name )
# [Hint] Make sure the keys (e.g. 'boss.person') you choose # [Hint] Make sure the keys (e.g. 'boss.person') you choose
# are unique names. If you cannot be sure of this (because of # are unique names. If you cannot be sure of this (because of
# the structure of your database, e.g.) you can use the # the structure of your database, e.g.) you can use the
# "add_child" command instead: # "add_child" command instead:
# #
# hlist.addchild( boss, text=name) # hlist.addchild( boss, text=name)
# ^^^^ # ^^^^
# parent entryPath # parent entryPath
# Use a ButtonBox to hold the buttons. # Use a ButtonBox to hold the buttons.
...@@ -129,4 +129,3 @@ class DemoSHList: ...@@ -129,4 +129,3 @@ class DemoSHList:
if __name__== '__main__' : if __name__== '__main__' :
root=Tix.Tk() root=Tix.Tk()
RunSample(root) RunSample(root)
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -13,18 +13,18 @@ ...@@ -13,18 +13,18 @@
# This file demonstrates how to use multiple columns and multiple styles # This file demonstrates how to use multiple columns and multiple styles
# in the tixHList widget # in the tixHList widget
# #
# In a tixHList widget, you can have one ore more columns. # In a tixHList widget, you can have one ore more columns.
# #
import Tix import Tix
TCL_ALL_EVENTS = 0 TCL_ALL_EVENTS = 0
def RunSample (root): def RunSample (root):
shlist = DemoSHList(root) shlist = DemoSHList(root)
shlist.mainloop() shlist.mainloop()
shlist.destroy() shlist.destroy()
class DemoSHList: class DemoSHList:
def __init__(self, w): def __init__(self, w):
self.root = w self.root = w
...@@ -32,7 +32,7 @@ class DemoSHList: ...@@ -32,7 +32,7 @@ class DemoSHList:
z = w.winfo_toplevel() z = w.winfo_toplevel()
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
# We create the frame and the ScrolledHList widget # We create the frame and the ScrolledHList widget
# at the top of the dialog box # at the top of the dialog box
# #
...@@ -47,7 +47,7 @@ class DemoSHList: ...@@ -47,7 +47,7 @@ class DemoSHList:
hlist=top.a.hlist hlist=top.a.hlist
# Create the title for the HList widget # Create the title for the HList widget
# >> Notice that we have set the hlist.header subwidget option to true # >> Notice that we have set the hlist.header subwidget option to true
# so that the header is displayed # so that the header is displayed
# #
...@@ -72,22 +72,22 @@ class DemoSHList: ...@@ -72,22 +72,22 @@ class DemoSHList:
# This is our little relational database # This is our little relational database
# #
boss = ('doe', 'John Doe', 'Director') boss = ('doe', 'John Doe', 'Director')
managers = [ managers = [
('jeff', 'Jeff Waxman', 'Manager'), ('jeff', 'Jeff Waxman', 'Manager'),
('john', 'John Lee', 'Manager'), ('john', 'John Lee', 'Manager'),
('peter', 'Peter Kenson', 'Manager') ('peter', 'Peter Kenson', 'Manager')
] ]
employees = [ employees = [
('alex', 'john', 'Alex Kellman', 'Clerk'), ('alex', 'john', 'Alex Kellman', 'Clerk'),
('alan', 'john', 'Alan Adams', 'Clerk'), ('alan', 'john', 'Alan Adams', 'Clerk'),
('andy', 'peter', 'Andreas Crawford', 'Salesman'), ('andy', 'peter', 'Andreas Crawford', 'Salesman'),
('doug', 'jeff', 'Douglas Bloom', 'Clerk'), ('doug', 'jeff', 'Douglas Bloom', 'Clerk'),
('jon', 'peter', 'Jon Baraki', 'Salesman'), ('jon', 'peter', 'Jon Baraki', 'Salesman'),
('chris', 'jeff', 'Chris Geoffrey', 'Clerk'), ('chris', 'jeff', 'Chris Geoffrey', 'Clerk'),
('chuck', 'jeff', 'Chuck McLean', 'Cleaner') ('chuck', 'jeff', 'Chuck McLean', 'Cleaner')
] ]
style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist) style['mgr_name'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist)
...@@ -98,7 +98,7 @@ class DemoSHList: ...@@ -98,7 +98,7 @@ class DemoSHList:
style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=hlist) style['empl_posn'] = Tix.DisplayStyle(Tix.TEXT, padx=8, refwindow=hlist)
# Let configure the appearance of the HList subwidget # Let configure the appearance of the HList subwidget
# #
hlist.config(separator='.', width=25, drawbranch=0, indent=10) hlist.config(separator='.', width=25, drawbranch=0, indent=10)
hlist.column_width(0, chars=20) hlist.column_width(0, chars=20)
...@@ -124,10 +124,10 @@ class DemoSHList: ...@@ -124,10 +124,10 @@ class DemoSHList:
for key,mgr,name,posn in employees : for key,mgr,name,posn in employees :
# "." is the separator character we chose above # "." is the separator character we chose above
entrypath = '.' + mgr + '.' + key entrypath = '.' + mgr + '.' + key
# ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ # ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
# parent entryPath / child's name # parent entryPath / child's name
hlist.add(entrypath, text=name, style=style['empl_name']) hlist.add(entrypath, text=name, style=style['empl_name'])
hlist.item_create(entrypath, 1, itemtype=Tix.TEXT, hlist.item_create(entrypath, 1, itemtype=Tix.TEXT,
...@@ -166,4 +166,3 @@ class DemoSHList: ...@@ -166,4 +166,3 @@ class DemoSHList:
if __name__== '__main__' : if __name__== '__main__' :
root=Tix.Tk() root=Tix.Tk()
RunSample(root) RunSample(root)
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
# #
# $Id$ # $Id$
# #
# Tix Demostration Program # Tix Demostration Program
...@@ -34,17 +34,17 @@ def RunSample(w): ...@@ -34,17 +34,17 @@ def RunSample(w):
def adddir(tree, dir): def adddir(tree, dir):
if dir == '/': if dir == '/':
text = '/' text = '/'
else: else:
text = os.path.basename(dir) text = os.path.basename(dir)
tree.hlist.add(dir, itemtype=Tix.IMAGETEXT, text=text, tree.hlist.add(dir, itemtype=Tix.IMAGETEXT, text=text,
image=tree.tk.call('tix', 'getimage', 'folder')) image=tree.tk.call('tix', 'getimage', 'folder'))
try: try:
os.listdir(dir) os.listdir(dir)
tree.setmode(dir, 'open') tree.setmode(dir, 'open')
except os.error: except os.error:
# No read permission ? # No read permission ?
pass pass
# This function is called whenever the user presses the (+) indicator or # This function is called whenever the user presses the (+) indicator or
# double clicks on a directory whose mode is "open". It loads the files # double clicks on a directory whose mode is "open". It loads the files
...@@ -57,22 +57,22 @@ def adddir(tree, dir): ...@@ -57,22 +57,22 @@ def adddir(tree, dir):
def opendir(tree, dir): def opendir(tree, dir):
entries = tree.hlist.info_children(dir) entries = tree.hlist.info_children(dir)
if entries: if entries:
# We have already loaded this directory. Let's just # We have already loaded this directory. Let's just
# show all the child entries # show all the child entries
# #
# Note: since we load the directory only once, it will not be # Note: since we load the directory only once, it will not be
# refreshed if the you add or remove files from this # refreshed if the you add or remove files from this
# directory. # directory.
# #
for entry in entries: for entry in entries:
tree.hlist.show_entry(entry) tree.hlist.show_entry(entry)
files = os.listdir(dir) files = os.listdir(dir)
for file in files: for file in files:
if os.path.isdir(dir + '/' + file): if os.path.isdir(dir + '/' + file):
adddir(tree, dir + '/' + file) adddir(tree, dir + '/' + file)
else: else:
tree.hlist.add(dir + '/' + file, itemtype=Tix.IMAGETEXT, text=file, tree.hlist.add(dir + '/' + file, itemtype=Tix.IMAGETEXT, text=file,
image=tree.tk.call('tix', 'getimage', 'file')) image=tree.tk.call('tix', 'getimage', 'file'))
if __name__ == '__main__': if __name__ == '__main__':
root = Tix.Tk() root = Tix.Tk()
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -9,135 +9,135 @@ from Tkinter import * ...@@ -9,135 +9,135 @@ from Tkinter import *
from ScrolledText import ScrolledText from ScrolledText import ScrolledText
class MimeViewer: class MimeViewer:
def __init__(self, parent, title, msg): def __init__(self, parent, title, msg):
self.title = title self.title = title
self.msg = msg self.msg = msg
self.frame = Frame(parent, {'relief': 'raised', 'bd': 2}) self.frame = Frame(parent, {'relief': 'raised', 'bd': 2})
self.frame.packing = {'expand': 0, 'fill': 'both'} self.frame.packing = {'expand': 0, 'fill': 'both'}
self.button = Checkbutton(self.frame, self.button = Checkbutton(self.frame,
{'text': title, {'text': title,
'command': self.toggle}) 'command': self.toggle})
self.button.pack({'anchor': 'w'}) self.button.pack({'anchor': 'w'})
headertext = msg.getheadertext( headertext = msg.getheadertext(
lambda x: x != 'received' and x[:5] != 'x400-') lambda x: x != 'received' and x[:5] != 'x400-')
height = countlines(headertext, 4) height = countlines(headertext, 4)
if height: if height:
self.htext = ScrolledText(self.frame, self.htext = ScrolledText(self.frame,
{'height': height, {'height': height,
'width': 80, 'width': 80,
'wrap': 'none', 'wrap': 'none',
'relief': 'raised', 'relief': 'raised',
'bd': 2}) 'bd': 2})
self.htext.packing = {'expand': 1, 'fill': 'both', self.htext.packing = {'expand': 1, 'fill': 'both',
'after': self.button} 'after': self.button}
self.htext.insert('end', headertext) self.htext.insert('end', headertext)
else: else:
self.htext = Frame(self.frame, self.htext = Frame(self.frame,
{'relief': 'raised', 'bd': 2}) {'relief': 'raised', 'bd': 2})
self.htext.packing = {'side': 'top', self.htext.packing = {'side': 'top',
'ipady': 2, 'ipady': 2,
'fill': 'x', 'fill': 'x',
'after': self.button} 'after': self.button}
body = msg.getbody() body = msg.getbody()
if type(body) == StringType: if type(body) == StringType:
self.pad = None self.pad = None
height = countlines(body, 10) height = countlines(body, 10)
if height: if height:
self.btext = ScrolledText(self.frame, self.btext = ScrolledText(self.frame,
{'height': height, {'height': height,
'width': 80, 'width': 80,
'wrap': 'none', 'wrap': 'none',
'relief': 'raised', 'relief': 'raised',
'bd': 2}) 'bd': 2})
self.btext.packing = {'expand': 1, self.btext.packing = {'expand': 1,
'fill': 'both'} 'fill': 'both'}
self.btext.insert('end', body) self.btext.insert('end', body)
else: else:
self.btext = None self.btext = None
self.parts = None self.parts = None
else: else:
self.pad = Frame(self.frame, self.pad = Frame(self.frame,
{'relief': 'flat', 'bd': 2}) {'relief': 'flat', 'bd': 2})
self.pad.packing = {'side': 'left', 'ipadx': 10, self.pad.packing = {'side': 'left', 'ipadx': 10,
'fill': 'y', 'after': self.htext} 'fill': 'y', 'after': self.htext}
self.parts = [] self.parts = []
for i in range(len(body)): for i in range(len(body)):
p = MimeViewer(self.frame, p = MimeViewer(self.frame,
'%s.%d' % (title, i+1), '%s.%d' % (title, i+1),
body[i]) body[i])
self.parts.append(p) self.parts.append(p)
self.btext = None self.btext = None
self.collapsed = 1 self.collapsed = 1
def pack(self): def pack(self):
self.frame.pack(self.frame.packing) self.frame.pack(self.frame.packing)
def destroy(self): def destroy(self):
self.frame.destroy() self.frame.destroy()
def show(self): def show(self):
if self.collapsed: if self.collapsed:
self.button.invoke() self.button.invoke()
def toggle(self): def toggle(self):
if self.collapsed: if self.collapsed:
self.explode() self.explode()
else: else:
self.collapse() self.collapse()
def collapse(self): def collapse(self):
self.collapsed = 1 self.collapsed = 1
for comp in self.htext, self.btext, self.pad: for comp in self.htext, self.btext, self.pad:
if comp: if comp:
comp.forget() comp.forget()
if self.parts: if self.parts:
for part in self.parts: for part in self.parts:
part.frame.forget() part.frame.forget()
self.frame.pack({'expand': 0}) self.frame.pack({'expand': 0})
def explode(self): def explode(self):
self.collapsed = 0 self.collapsed = 0
for comp in self.htext, self.btext, self.pad: for comp in self.htext, self.btext, self.pad:
if comp: comp.pack(comp.packing) if comp: comp.pack(comp.packing)
if self.parts: if self.parts:
for part in self.parts: for part in self.parts:
part.pack() part.pack()
self.frame.pack({'expand': 1}) self.frame.pack({'expand': 1})
def countlines(str, limit): def countlines(str, limit):
i = 0 i = 0
n = 0 n = 0
while n < limit: while n < limit:
i = string.find(str, '\n', i) i = string.find(str, '\n', i)
if i < 0: break if i < 0: break
n = n+1 n = n+1
i = i+1 i = i+1
return n return n
def main(): def main():
import sys import sys
import getopt import getopt
import mhlib import mhlib
opts, args = getopt.getopt(sys.argv[1:], '') opts, args = getopt.getopt(sys.argv[1:], '')
for o, a in opts: for o, a in opts:
pass pass
message = None message = None
folder = 'inbox' folder = 'inbox'
for arg in args: for arg in args:
if arg[:1] == '+': if arg[:1] == '+':
folder = arg[1:] folder = arg[1:]
else: else:
message = string.atoi(arg) message = string.atoi(arg)
mh = mhlib.MH() mh = mhlib.MH()
f = mh.openfolder(folder) f = mh.openfolder(folder)
if not message: if not message:
message = f.getcurrent() message = f.getcurrent()
m = f.openmessage(message) m = f.openmessage(message)
root = Tk() root = Tk()
tk = root.tk tk = root.tk
top = MimeViewer(root, '+%s/%d' % (folder, message), m) top = MimeViewer(root, '+%s/%d' % (folder, message), m)
top.pack() top.pack()
top.show() top.show()
root.minsize(1, 1) root.minsize(1, 1)
tk.mainloop() tk.mainloop()
if __name__ == '__main__': main() if __name__ == '__main__': main()
...@@ -10,142 +10,142 @@ BUFSIZE = 512 ...@@ -10,142 +10,142 @@ BUFSIZE = 512
class ShellWindow(ScrolledText): class ShellWindow(ScrolledText):
def __init__(self, master=None, shell=None, **cnf): def __init__(self, master=None, shell=None, **cnf):
if not shell: if not shell:
try: try:
shell = os.environ['SHELL'] shell = os.environ['SHELL']
except KeyError: except KeyError:
shell = '/bin/sh' shell = '/bin/sh'
shell = shell + ' -i' shell = shell + ' -i'
args = string.split(shell) args = string.split(shell)
shell = args[0] shell = args[0]
apply(ScrolledText.__init__, (self, master), cnf) apply(ScrolledText.__init__, (self, master), cnf)
self.pos = '1.0' self.pos = '1.0'
self.bind('<Return>', self.inputhandler) self.bind('<Return>', self.inputhandler)
self.bind('<Control-c>', self.sigint) self.bind('<Control-c>', self.sigint)
self.bind('<Control-t>', self.sigterm) self.bind('<Control-t>', self.sigterm)
self.bind('<Control-k>', self.sigkill) self.bind('<Control-k>', self.sigkill)
self.bind('<Control-d>', self.sendeof) self.bind('<Control-d>', self.sendeof)
self.pid, self.fromchild, self.tochild = spawn(shell, args) self.pid, self.fromchild, self.tochild = spawn(shell, args)
self.tk.createfilehandler(self.fromchild, READABLE, self.tk.createfilehandler(self.fromchild, READABLE,
self.outputhandler) self.outputhandler)
def outputhandler(self, file, mask): def outputhandler(self, file, mask):
data = os.read(file, BUFSIZE) data = os.read(file, BUFSIZE)
if not data: if not data:
self.tk.deletefilehandler(file) self.tk.deletefilehandler(file)
pid, sts = os.waitpid(self.pid, 0) pid, sts = os.waitpid(self.pid, 0)
print 'pid', pid, 'status', sts print 'pid', pid, 'status', sts
self.pid = None self.pid = None
detail = sts>>8 detail = sts>>8
cause = sts & 0xff cause = sts & 0xff
if cause == 0: if cause == 0:
msg = "exit status %d" % detail msg = "exit status %d" % detail
else: else:
msg = "killed by signal %d" % (cause & 0x7f) msg = "killed by signal %d" % (cause & 0x7f)
if cause & 0x80: if cause & 0x80:
msg = msg + " -- core dumped" msg = msg + " -- core dumped"
Dialog(self.master, Dialog(self.master,
text=msg, text=msg,
title="Exit status", title="Exit status",
bitmap='warning', bitmap='warning',
default=0, default=0,
strings=('OK',)) strings=('OK',))
return return
self.insert(END, data) self.insert(END, data)
self.pos = self.index("end - 1 char") self.pos = self.index("end - 1 char")
self.yview_pickplace(END) self.yview_pickplace(END)
def inputhandler(self, *args): def inputhandler(self, *args):
if not self.pid: if not self.pid:
self.no_process() self.no_process()
return "break" return "break"
self.insert(END, "\n") self.insert(END, "\n")
line = self.get(self.pos, "end - 1 char") line = self.get(self.pos, "end - 1 char")
self.pos = self.index(END) self.pos = self.index(END)
os.write(self.tochild, line) os.write(self.tochild, line)
return "break" return "break"
def sendeof(self, *args): def sendeof(self, *args):
if not self.pid: if not self.pid:
self.no_process() self.no_process()
return "break" return "break"
os.close(self.tochild) os.close(self.tochild)
return "break" return "break"
def sendsig(self, sig): def sendsig(self, sig):
if not self.pid: if not self.pid:
self.no_process() self.no_process()
return "break" return "break"
os.kill(self.pid, sig) os.kill(self.pid, sig)
return "break" return "break"
def sigint(self, *args): def sigint(self, *args):
return self.sendsig(signal.SIGINT) return self.sendsig(signal.SIGINT)
def sigquit(self, *args): def sigquit(self, *args):
return self.sendsig(signal.SIGQUIT) return self.sendsig(signal.SIGQUIT)
def sigterm(self, *args): def sigterm(self, *args):
return self.sendsig(signal.SIGTERM) return self.sendsig(signal.SIGTERM)
def sigkill(self, *args): def sigkill(self, *args):
return self.sendsig(signal.SIGKILL) return self.sendsig(signal.SIGKILL)
def no_process(self): def no_process(self):
Dialog(self.master, Dialog(self.master,
text="No active process", text="No active process",
title="No process", title="No process",
bitmap='error', bitmap='error',
default=0, default=0,
strings=('OK',)) strings=('OK',))
MAXFD = 100 # Max number of file descriptors (os.getdtablesize()???) MAXFD = 100 # Max number of file descriptors (os.getdtablesize()???)
def spawn(prog, args): def spawn(prog, args):
p2cread, p2cwrite = os.pipe() p2cread, p2cwrite = os.pipe()
c2pread, c2pwrite = os.pipe() c2pread, c2pwrite = os.pipe()
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
# Child # Child
for i in 0, 1, 2: for i in 0, 1, 2:
try: try:
os.close(i) os.close(i)
except os.error: except os.error:
pass pass
if os.dup(p2cread) <> 0: if os.dup(p2cread) <> 0:
sys.stderr.write('popen2: bad read dup\n') sys.stderr.write('popen2: bad read dup\n')
if os.dup(c2pwrite) <> 1: if os.dup(c2pwrite) <> 1:
sys.stderr.write('popen2: bad write dup\n') sys.stderr.write('popen2: bad write dup\n')
if os.dup(c2pwrite) <> 2: if os.dup(c2pwrite) <> 2:
sys.stderr.write('popen2: bad write dup\n') sys.stderr.write('popen2: bad write dup\n')
for i in range(3, MAXFD): for i in range(3, MAXFD):
try: try:
os.close(i) os.close(i)
except: except:
pass pass
try: try:
os.execvp(prog, args) os.execvp(prog, args)
finally: finally:
sys.stderr.write('execvp failed\n') sys.stderr.write('execvp failed\n')
os._exit(1) os._exit(1)
os.close(p2cread) os.close(p2cread)
os.close(c2pwrite) os.close(c2pwrite)
return pid, c2pread, p2cwrite return pid, c2pread, p2cwrite
def test(): def test():
shell = string.join(sys.argv[1:]) shell = string.join(sys.argv[1:])
root = Tk() root = Tk()
root.minsize(1, 1) root.minsize(1, 1)
if shell: if shell:
w = ShellWindow(root, shell=shell) w = ShellWindow(root, shell=shell)
else: else:
w = ShellWindow(root) w = ShellWindow(root)
w.pack(expand=1, fill=BOTH) w.pack(expand=1, fill=BOTH)
w.focus_set() w.focus_set()
w.tk.mainloop() w.tk.mainloop()
if __name__ == '__main__': if __name__ == '__main__':
test() test()
...@@ -9,7 +9,7 @@ from Canvas import Oval, Group, CanvasText ...@@ -9,7 +9,7 @@ from Canvas import Oval, Group, CanvasText
class Group(Group): class Group(Group):
def bind(self, sequence=None, command=None): def bind(self, sequence=None, command=None):
return self.canvas.tag_bind(self.id, sequence, command) return self.canvas.tag_bind(self.id, sequence, command)
class Object: class Object:
...@@ -33,45 +33,45 @@ class Object: ...@@ -33,45 +33,45 @@ class Object:
""" """
def __init__(self, canvas, x=0, y=0, fill='red', text='object'): def __init__(self, canvas, x=0, y=0, fill='red', text='object'):
self.canvas = canvas self.canvas = canvas
self.x = x self.x = x
self.y = y self.y = y
self.pile = None self.pile = None
self.group = Group(self.canvas) self.group = Group(self.canvas)
self.createitems(fill, text) self.createitems(fill, text)
def __str__(self): def __str__(self):
return str(self.group) return str(self.group)
def createitems(self, fill, text): def createitems(self, fill, text):
self.__oval = Oval(self.canvas, self.__oval = Oval(self.canvas,
self.x-20, self.y-10, self.x+20, self.y+10, self.x-20, self.y-10, self.x+20, self.y+10,
fill=fill, width=3) fill=fill, width=3)
self.group.addtag_withtag(self.__oval) self.group.addtag_withtag(self.__oval)
self.__text = CanvasText(self.canvas, self.__text = CanvasText(self.canvas,
self.x, self.y, text=text) self.x, self.y, text=text)
self.group.addtag_withtag(self.__text) self.group.addtag_withtag(self.__text)
def moveby(self, dx, dy): def moveby(self, dx, dy):
if dx == dy == 0: if dx == dy == 0:
return return
self.group.move(dx, dy) self.group.move(dx, dy)
self.x = self.x + dx self.x = self.x + dx
self.y = self.y + dy self.y = self.y + dy
def moveto(self, x, y): def moveto(self, x, y):
self.moveby(x - self.x, y - self.y) self.moveby(x - self.x, y - self.y)
def transfer(self, pile): def transfer(self, pile):
if self.pile: if self.pile:
self.pile.delete(self) self.pile.delete(self)
self.pile = None self.pile = None
self.pile = pile self.pile = pile
if self.pile: if self.pile:
self.pile.add(self) self.pile.add(self)
def tkraise(self): def tkraise(self):
self.group.tkraise() self.group.tkraise()
class Bottom(Object): class Bottom(Object):
...@@ -79,10 +79,10 @@ class Bottom(Object): ...@@ -79,10 +79,10 @@ class Bottom(Object):
"""An object to serve as the bottom of a pile.""" """An object to serve as the bottom of a pile."""
def createitems(self, *args): def createitems(self, *args):
self.__oval = Oval(self.canvas, self.__oval = Oval(self.canvas,
self.x-20, self.y-10, self.x+20, self.y+10, self.x-20, self.y-10, self.x+20, self.y+10,
fill='gray', outline='') fill='gray', outline='')
self.group.addtag_withtag(self.__oval) self.group.addtag_withtag(self.__oval)
class Pile: class Pile:
...@@ -90,86 +90,86 @@ class Pile: ...@@ -90,86 +90,86 @@ class Pile:
"""A group of graphical objects.""" """A group of graphical objects."""
def __init__(self, canvas, x, y, tag=None): def __init__(self, canvas, x, y, tag=None):
self.canvas = canvas self.canvas = canvas
self.x = x self.x = x
self.y = y self.y = y
self.objects = [] self.objects = []
self.bottom = Bottom(self.canvas, self.x, self.y) self.bottom = Bottom(self.canvas, self.x, self.y)
self.group = Group(self.canvas, tag=tag) self.group = Group(self.canvas, tag=tag)
self.group.addtag_withtag(self.bottom.group) self.group.addtag_withtag(self.bottom.group)
self.bindhandlers() self.bindhandlers()
def bindhandlers(self): def bindhandlers(self):
self.group.bind('<1>', self.clickhandler) self.group.bind('<1>', self.clickhandler)
self.group.bind('<Double-1>', self.doubleclickhandler) self.group.bind('<Double-1>', self.doubleclickhandler)
def add(self, object): def add(self, object):
self.objects.append(object) self.objects.append(object)
self.group.addtag_withtag(object.group) self.group.addtag_withtag(object.group)
self.position(object) self.position(object)
def delete(self, object): def delete(self, object):
object.group.dtag(self.group) object.group.dtag(self.group)
self.objects.remove(object) self.objects.remove(object)
def position(self, object): def position(self, object):
object.tkraise() object.tkraise()
i = self.objects.index(object) i = self.objects.index(object)
object.moveto(self.x + i*4, self.y + i*8) object.moveto(self.x + i*4, self.y + i*8)
def clickhandler(self, event): def clickhandler(self, event):
pass pass
def doubleclickhandler(self, event): def doubleclickhandler(self, event):
pass pass
class MovingPile(Pile): class MovingPile(Pile):
def bindhandlers(self): def bindhandlers(self):
Pile.bindhandlers(self) Pile.bindhandlers(self)
self.group.bind('<B1-Motion>', self.motionhandler) self.group.bind('<B1-Motion>', self.motionhandler)
self.group.bind('<ButtonRelease-1>', self.releasehandler) self.group.bind('<ButtonRelease-1>', self.releasehandler)
movethis = None movethis = None
def clickhandler(self, event): def clickhandler(self, event):
tags = self.canvas.gettags('current') tags = self.canvas.gettags('current')
for i in range(len(self.objects)): for i in range(len(self.objects)):
o = self.objects[i] o = self.objects[i]
if o.group.tag in tags: if o.group.tag in tags:
break break
else: else:
self.movethis = None self.movethis = None
return return
self.movethis = self.objects[i:] self.movethis = self.objects[i:]
for o in self.movethis: for o in self.movethis:
o.tkraise() o.tkraise()
self.lastx = event.x self.lastx = event.x
self.lasty = event.y self.lasty = event.y
doubleclickhandler = clickhandler doubleclickhandler = clickhandler
def motionhandler(self, event): def motionhandler(self, event):
if not self.movethis: if not self.movethis:
return return
dx = event.x - self.lastx dx = event.x - self.lastx
dy = event.y - self.lasty dy = event.y - self.lasty
self.lastx = event.x self.lastx = event.x
self.lasty = event.y self.lasty = event.y
for o in self.movethis: for o in self.movethis:
o.moveby(dx, dy) o.moveby(dx, dy)
def releasehandler(self, event): def releasehandler(self, event):
objects = self.movethis objects = self.movethis
if not objects: if not objects:
return return
self.movethis = None self.movethis = None
self.finishmove(objects) self.finishmove(objects)
def finishmove(self, objects): def finishmove(self, objects):
for o in objects: for o in objects:
self.position(o) self.position(o)
class Pile1(MovingPile): class Pile1(MovingPile):
...@@ -179,29 +179,29 @@ class Pile1(MovingPile): ...@@ -179,29 +179,29 @@ class Pile1(MovingPile):
tag = 'p1' tag = 'p1'
def __init__(self, demo): def __init__(self, demo):
self.demo = demo self.demo = demo
MovingPile.__init__(self, self.demo.canvas, self.x, self.y, self.tag) MovingPile.__init__(self, self.demo.canvas, self.x, self.y, self.tag)
def doubleclickhandler(self, event): def doubleclickhandler(self, event):
try: try:
o = self.objects[-1] o = self.objects[-1]
except IndexError: except IndexError:
return return
o.transfer(self.other()) o.transfer(self.other())
MovingPile.doubleclickhandler(self, event) MovingPile.doubleclickhandler(self, event)
def other(self): def other(self):
return self.demo.p2 return self.demo.p2
def finishmove(self, objects): def finishmove(self, objects):
o = objects[0] o = objects[0]
p = self.other() p = self.other()
x, y = o.x, o.y x, y = o.x, o.y
if (x-p.x)**2 + (y-p.y)**2 < (x-self.x)**2 + (y-self.y)**2: if (x-p.x)**2 + (y-p.y)**2 < (x-self.x)**2 + (y-self.y)**2:
for o in objects: for o in objects:
o.transfer(p) o.transfer(p)
else: else:
MovingPile.finishmove(self, objects) MovingPile.finishmove(self, objects)
class Pile2(Pile1): class Pile2(Pile1):
...@@ -210,26 +210,26 @@ class Pile2(Pile1): ...@@ -210,26 +210,26 @@ class Pile2(Pile1):
tag = 'p2' tag = 'p2'
def other(self): def other(self):
return self.demo.p1 return self.demo.p1
class Demo: class Demo:
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self.canvas = Canvas(master, self.canvas = Canvas(master,
width=200, height=200, width=200, height=200,
background='yellow', background='yellow',
relief=SUNKEN, borderwidth=2) relief=SUNKEN, borderwidth=2)
self.canvas.pack(expand=1, fill=BOTH) self.canvas.pack(expand=1, fill=BOTH)
self.p1 = Pile1(self) self.p1 = Pile1(self)
self.p2 = Pile2(self) self.p2 = Pile2(self)
o1 = Object(self.canvas, fill='red', text='o1') o1 = Object(self.canvas, fill='red', text='o1')
o2 = Object(self.canvas, fill='green', text='o2') o2 = Object(self.canvas, fill='green', text='o2')
o3 = Object(self.canvas, fill='light blue', text='o3') o3 = Object(self.canvas, fill='light blue', text='o3')
o1.transfer(self.p1) o1.transfer(self.p1)
o2.transfer(self.p1) o2.transfer(self.p1)
o3.transfer(self.p2) o3.transfer(self.p2)
# Main function, run when invoked as a stand-alone Python program. # Main function, run when invoked as a stand-alone Python program.
......
...@@ -25,11 +25,11 @@ def dialog(master, title, text, bitmap, default, *args): ...@@ -25,11 +25,11 @@ def dialog(master, title, text, bitmap, default, *args):
# 2. Fill the top part with the bitmap and message. # 2. Fill the top part with the bitmap and message.
msg = Message(top, width='3i', text=text, msg = Message(top, width='3i', text=text,
font='-Adobe-Times-Medium-R-Normal-*-180-*') font='-Adobe-Times-Medium-R-Normal-*-180-*')
msg.pack(side=RIGHT, expand=1, fill=BOTH, padx='3m', pady='3m') msg.pack(side=RIGHT, expand=1, fill=BOTH, padx='3m', pady='3m')
if bitmap: if bitmap:
bm = Label(top, bitmap=bitmap) bm = Label(top, bitmap=bitmap)
bm.pack(side=LEFT, padx='3m', pady='3m') bm.pack(side=LEFT, padx='3m', pady='3m')
# 3. Create a row of buttons at the bottom of the dialog. # 3. Create a row of buttons at the bottom of the dialog.
...@@ -37,27 +37,27 @@ def dialog(master, title, text, bitmap, default, *args): ...@@ -37,27 +37,27 @@ def dialog(master, title, text, bitmap, default, *args):
buttons = [] buttons = []
i = 0 i = 0
for but in args: for but in args:
b = Button(bot, text=but, command=lambda v=var,i=i: v.set(i)) b = Button(bot, text=but, command=lambda v=var,i=i: v.set(i))
buttons.append(b) buttons.append(b)
if i == default: if i == default:
bd = Frame(bot, relief=SUNKEN, borderwidth=1) bd = Frame(bot, relief=SUNKEN, borderwidth=1)
bd.pack(side=LEFT, expand=1, padx='3m', pady='2m') bd.pack(side=LEFT, expand=1, padx='3m', pady='2m')
b.lift() b.lift()
b.pack (in_=bd, side=LEFT, b.pack (in_=bd, side=LEFT,
padx='2m', pady='2m', ipadx='2m', ipady='1m') padx='2m', pady='2m', ipadx='2m', ipady='1m')
else: else:
b.pack (side=LEFT, expand=1, b.pack (side=LEFT, expand=1,
padx='3m', pady='3m', ipadx='2m', ipady='1m') padx='3m', pady='3m', ipadx='2m', ipady='1m')
i = i+1 i = i+1
# 4. Set up a binding for <Return>, if there's a default, # 4. Set up a binding for <Return>, if there's a default,
# set a grab, and claim the focus too. # set a grab, and claim the focus too.
if default >= 0: if default >= 0:
w.bind('<Return>', w.bind('<Return>',
lambda e, b=buttons[default], v=var, i=default: lambda e, b=buttons[default], v=var, i=default:
(b.flash(), (b.flash(),
v.set(i))) v.set(i)))
oldFocus = w.focus_get() oldFocus = w.focus_get()
w.grab_set() w.grab_set()
...@@ -75,23 +75,23 @@ def dialog(master, title, text, bitmap, default, *args): ...@@ -75,23 +75,23 @@ def dialog(master, title, text, bitmap, default, *args):
def go(): def go():
i = dialog(mainWidget, i = dialog(mainWidget,
'Not Responding', 'Not Responding',
"The file server isn't responding right now; " "The file server isn't responding right now; "
"I'll keep trying.", "I'll keep trying.",
'', '',
-1, -1,
'OK') 'OK')
print 'pressed button', i print 'pressed button', i
i = dialog(mainWidget, i = dialog(mainWidget,
'File Modified', 'File Modified',
'File "tcl.h" has been modified since ' 'File "tcl.h" has been modified since '
'the last time it was saved. ' 'the last time it was saved. '
'Do you want to save it before exiting the application?', 'Do you want to save it before exiting the application?',
'warning', 'warning',
0, 0,
'Save File', 'Save File',
'Discard Changes', 'Discard Changes',
'Return To Editor') 'Return To Editor')
print 'pressed button', i print 'pressed button', i
def test(): def test():
......
#! /usr/bin/env python #! /usr/bin/env python
# Simulate "electrons" migrating across the screen. # Simulate "electrons" migrating across the screen.
# An optional bitmap file in can be in the background. # An optional bitmap file in can be in the background.
# #
# Usage: electrons [n [bitmapfile]] # Usage: electrons [n [bitmapfile]]
...@@ -18,74 +18,74 @@ import random ...@@ -18,74 +18,74 @@ import random
# The graphical interface # The graphical interface
class Electrons: class Electrons:
# Create our objects # Create our objects
def __init__(self, n, bitmap = None): def __init__(self, n, bitmap = None):
self.n = n self.n = n
self.tk = tk = Tk() self.tk = tk = Tk()
self.canvas = c = Canvas(tk) self.canvas = c = Canvas(tk)
c.pack() c.pack()
width, height = tk.getint(c['width']), tk.getint(c['height']) width, height = tk.getint(c['width']), tk.getint(c['height'])
# Add background bitmap # Add background bitmap
if bitmap: if bitmap:
self.bitmap = c.create_bitmap(width/2, height/2, self.bitmap = c.create_bitmap(width/2, height/2,
bitmap=bitmap, bitmap=bitmap,
foreground='blue') foreground='blue')
self.pieces = [] self.pieces = []
x1, y1, x2, y2 = 10,70,14,74 x1, y1, x2, y2 = 10,70,14,74
for i in range(n): for i in range(n):
p = c.create_oval(x1, y1, x2, y2, fill='red') p = c.create_oval(x1, y1, x2, y2, fill='red')
self.pieces.append(p) self.pieces.append(p)
y1, y2 = y1 +2, y2 + 2 y1, y2 = y1 +2, y2 + 2
self.tk.update() self.tk.update()
def random_move(self, n): def random_move(self, n):
c = self.canvas c = self.canvas
for p in self.pieces: for p in self.pieces:
x = random.choice(range(-2,4)) x = random.choice(range(-2,4))
y = random.choice(range(-3,4)) y = random.choice(range(-3,4))
c.move(p, x, y) c.move(p, x, y)
self.tk.update() self.tk.update()
# Run -- allow 500 movemens # Run -- allow 500 movemens
def run(self): def run(self):
try: try:
for i in range(500): for i in range(500):
self.random_move(self.n) self.random_move(self.n)
except TclError: except TclError:
try: try:
self.tk.destroy() self.tk.destroy()
except TclError: except TclError:
pass pass
# Main program # Main program
def main(): def main():
import sys, string import sys, string
# First argument is number of electrons, default 30 # First argument is number of electrons, default 30
if sys.argv[1:]: if sys.argv[1:]:
n = string.atoi(sys.argv[1]) n = string.atoi(sys.argv[1])
else: else:
n = 30 n = 30
# Second argument is bitmap file, default none # Second argument is bitmap file, default none
if sys.argv[2:]: if sys.argv[2:]:
bitmap = sys.argv[2] bitmap = sys.argv[2]
# Reverse meaning of leading '@' compared to Tk # Reverse meaning of leading '@' compared to Tk
if bitmap[0] == '@': bitmap = bitmap[1:] if bitmap[0] == '@': bitmap = bitmap[1:]
else: bitmap = '@' + bitmap else: bitmap = '@' + bitmap
else: else:
bitmap = None bitmap = None
# Create the graphical objects... # Create the graphical objects...
h = Electrons(n, bitmap) h = Electrons(n, bitmap)
# ...and run! # ...and run!
h.run() h.run()
# Call main when run as script # Call main when run as script
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -16,139 +16,139 @@ from Tkinter import * ...@@ -16,139 +16,139 @@ from Tkinter import *
# Basic Towers-of-Hanoi algorithm: move n pieces from a to b, using c # Basic Towers-of-Hanoi algorithm: move n pieces from a to b, using c
# as temporary. For each move, call report() # as temporary. For each move, call report()
def hanoi(n, a, b, c, report): def hanoi(n, a, b, c, report):
if n <= 0: return if n <= 0: return
hanoi(n-1, a, c, b, report) hanoi(n-1, a, c, b, report)
report(n, a, b) report(n, a, b)
hanoi(n-1, c, b, a, report) hanoi(n-1, c, b, a, report)
# The graphical interface # The graphical interface
class Tkhanoi: class Tkhanoi:
# Create our objects # Create our objects
def __init__(self, n, bitmap = None): def __init__(self, n, bitmap = None):
self.n = n self.n = n
self.tk = tk = Tk() self.tk = tk = Tk()
self.canvas = c = Canvas(tk) self.canvas = c = Canvas(tk)
c.pack() c.pack()
width, height = tk.getint(c['width']), tk.getint(c['height']) width, height = tk.getint(c['width']), tk.getint(c['height'])
# Add background bitmap # Add background bitmap
if bitmap: if bitmap:
self.bitmap = c.create_bitmap(width/2, height/2, self.bitmap = c.create_bitmap(width/2, height/2,
bitmap=bitmap, bitmap=bitmap,
foreground='blue') foreground='blue')
# Generate pegs # Generate pegs
pegwidth = 10 pegwidth = 10
pegheight = height/2 pegheight = height/2
pegdist = width/3 pegdist = width/3
x1, y1 = (pegdist-pegwidth)/2, height*1/3 x1, y1 = (pegdist-pegwidth)/2, height*1/3
x2, y2 = x1+pegwidth, y1+pegheight x2, y2 = x1+pegwidth, y1+pegheight
self.pegs = [] self.pegs = []
p = c.create_rectangle(x1, y1, x2, y2, fill='black') p = c.create_rectangle(x1, y1, x2, y2, fill='black')
self.pegs.append(p) self.pegs.append(p)
x1, x2 = x1+pegdist, x2+pegdist x1, x2 = x1+pegdist, x2+pegdist
p = c.create_rectangle(x1, y1, x2, y2, fill='black') p = c.create_rectangle(x1, y1, x2, y2, fill='black')
self.pegs.append(p) self.pegs.append(p)
x1, x2 = x1+pegdist, x2+pegdist x1, x2 = x1+pegdist, x2+pegdist
p = c.create_rectangle(x1, y1, x2, y2, fill='black') p = c.create_rectangle(x1, y1, x2, y2, fill='black')
self.pegs.append(p) self.pegs.append(p)
self.tk.update() self.tk.update()
# Generate pieces # Generate pieces
pieceheight = pegheight/16 pieceheight = pegheight/16
maxpiecewidth = pegdist*2/3 maxpiecewidth = pegdist*2/3
minpiecewidth = 2*pegwidth minpiecewidth = 2*pegwidth
self.pegstate = [[], [], []] self.pegstate = [[], [], []]
self.pieces = {} self.pieces = {}
x1, y1 = (pegdist-maxpiecewidth)/2, y2-pieceheight-2 x1, y1 = (pegdist-maxpiecewidth)/2, y2-pieceheight-2
x2, y2 = x1+maxpiecewidth, y1+pieceheight x2, y2 = x1+maxpiecewidth, y1+pieceheight
dx = (maxpiecewidth-minpiecewidth) / (2*max(1, n-1)) dx = (maxpiecewidth-minpiecewidth) / (2*max(1, n-1))
for i in range(n, 0, -1): for i in range(n, 0, -1):
p = c.create_rectangle(x1, y1, x2, y2, fill='red') p = c.create_rectangle(x1, y1, x2, y2, fill='red')
self.pieces[i] = p self.pieces[i] = p
self.pegstate[0].append(i) self.pegstate[0].append(i)
x1, x2 = x1 + dx, x2-dx x1, x2 = x1 + dx, x2-dx
y1, y2 = y1 - pieceheight-2, y2-pieceheight-2 y1, y2 = y1 - pieceheight-2, y2-pieceheight-2
self.tk.update() self.tk.update()
self.tk.after(25) self.tk.after(25)
# Run -- never returns # Run -- never returns
def run(self): def run(self):
while 1: while 1:
hanoi(self.n, 0, 1, 2, self.report) hanoi(self.n, 0, 1, 2, self.report)
hanoi(self.n, 1, 2, 0, self.report) hanoi(self.n, 1, 2, 0, self.report)
hanoi(self.n, 2, 0, 1, self.report) hanoi(self.n, 2, 0, 1, self.report)
hanoi(self.n, 0, 2, 1, self.report) hanoi(self.n, 0, 2, 1, self.report)
hanoi(self.n, 2, 1, 0, self.report) hanoi(self.n, 2, 1, 0, self.report)
hanoi(self.n, 1, 0, 2, self.report) hanoi(self.n, 1, 0, 2, self.report)
# Reporting callback for the actual hanoi function # Reporting callback for the actual hanoi function
def report(self, i, a, b): def report(self, i, a, b):
if self.pegstate[a][-1] != i: raise RuntimeError # Assertion if self.pegstate[a][-1] != i: raise RuntimeError # Assertion
del self.pegstate[a][-1] del self.pegstate[a][-1]
p = self.pieces[i] p = self.pieces[i]
c = self.canvas c = self.canvas
# Lift the piece above peg a # Lift the piece above peg a
ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a]) ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a])
while 1: while 1:
x1, y1, x2, y2 = c.bbox(p) x1, y1, x2, y2 = c.bbox(p)
if y2 < ay1: break if y2 < ay1: break
c.move(p, 0, -1) c.move(p, 0, -1)
self.tk.update() self.tk.update()
# Move it towards peg b # Move it towards peg b
bx1, by1, bx2, by2 = c.bbox(self.pegs[b]) bx1, by1, bx2, by2 = c.bbox(self.pegs[b])
newcenter = (bx1+bx2)/2 newcenter = (bx1+bx2)/2
while 1: while 1:
x1, y1, x2, y2 = c.bbox(p) x1, y1, x2, y2 = c.bbox(p)
center = (x1+x2)/2 center = (x1+x2)/2
if center == newcenter: break if center == newcenter: break
if center > newcenter: c.move(p, -1, 0) if center > newcenter: c.move(p, -1, 0)
else: c.move(p, 1, 0) else: c.move(p, 1, 0)
self.tk.update() self.tk.update()
# Move it down on top of the previous piece # Move it down on top of the previous piece
pieceheight = y2-y1 pieceheight = y2-y1
newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2 newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2
while 1: while 1:
x1, y1, x2, y2 = c.bbox(p) x1, y1, x2, y2 = c.bbox(p)
if y2 >= newbottom: break if y2 >= newbottom: break
c.move(p, 0, 1) c.move(p, 0, 1)
self.tk.update() self.tk.update()
# Update peg state # Update peg state
self.pegstate[b].append(i) self.pegstate[b].append(i)
# Main program # Main program
def main(): def main():
import sys, string import sys, string
# First argument is number of pegs, default 4 # First argument is number of pegs, default 4
if sys.argv[1:]: if sys.argv[1:]:
n = string.atoi(sys.argv[1]) n = string.atoi(sys.argv[1])
else: else:
n = 4 n = 4
# Second argument is bitmap file, default none # Second argument is bitmap file, default none
if sys.argv[2:]: if sys.argv[2:]:
bitmap = sys.argv[2] bitmap = sys.argv[2]
# Reverse meaning of leading '@' compared to Tk # Reverse meaning of leading '@' compared to Tk
if bitmap[0] == '@': bitmap = bitmap[1:] if bitmap[0] == '@': bitmap = bitmap[1:]
else: bitmap = '@' + bitmap else: bitmap = '@' + bitmap
else: else:
bitmap = None bitmap = None
# Create the graphical objects... # Create the graphical objects...
h = Tkhanoi(n, bitmap) h = Tkhanoi(n, bitmap)
# ...and run! # ...and run!
h.run() h.run()
# Call main when run as script # Call main when run as script
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -4,14 +4,14 @@ import sys ...@@ -4,14 +4,14 @@ import sys
from Tkinter import * from Tkinter import *
def main(): def main():
root = Tk() root = Tk()
button = Button(root) button = Button(root)
button['text'] = 'Hello, world' button['text'] = 'Hello, world'
button['command'] = quit_callback # See below button['command'] = quit_callback # See below
button.pack() button.pack()
root.mainloop() root.mainloop()
def quit_callback(): def quit_callback():
sys.exit(0) sys.exit(0)
main() main()
...@@ -8,92 +8,91 @@ import commands ...@@ -8,92 +8,91 @@ import commands
import os import os
class BarButton(Menubutton): class BarButton(Menubutton):
def __init__(self, master=None, **cnf): def __init__(self, master=None, **cnf):
apply(Menubutton.__init__, (self, master), cnf) apply(Menubutton.__init__, (self, master), cnf)
self.pack(side=LEFT) self.pack(side=LEFT)
self.menu = Menu(self, name='menu') self.menu = Menu(self, name='menu')
self['menu'] = self.menu self['menu'] = self.menu
class Kill(Frame): class Kill(Frame):
# List of (name, option, pid_column) # List of (name, option, pid_column)
format_list = [('Default', '', 0), format_list = [('Default', '', 0),
('Long', '-l', 2), ('Long', '-l', 2),
('User', '-u', 1), ('User', '-u', 1),
('Jobs', '-j', 1), ('Jobs', '-j', 1),
('Signal', '-s', 1), ('Signal', '-s', 1),
('Memory', '-m', 0), ('Memory', '-m', 0),
('VM', '-v', 0), ('VM', '-v', 0),
('Hex', '-X', 0)] ('Hex', '-X', 0)]
def kill(self, selected): def kill(self, selected):
c = self.format_list[self.format.get()][2] c = self.format_list[self.format.get()][2]
pid = split(selected)[c] pid = split(selected)[c]
os.system('kill -9 ' + pid) os.system('kill -9 ' + pid)
self.do_update() self.do_update()
def do_update(self): def do_update(self):
name, option, column = self.format_list[self.format.get()] name, option, column = self.format_list[self.format.get()]
s = commands.getoutput('ps -w ' + option) s = commands.getoutput('ps -w ' + option)
list = splitfields(s, '\n') list = splitfields(s, '\n')
self.header.set(list[0]) self.header.set(list[0])
del list[0] del list[0]
y = self.frame.vscroll.get()[0] y = self.frame.vscroll.get()[0]
self.frame.list.delete(0, AtEnd()) self.frame.list.delete(0, AtEnd())
for line in list: for line in list:
self.frame.list.insert(0, line) self.frame.list.insert(0, line)
self.frame.list.yview(int(y)) self.frame.list.yview(int(y))
def do_motion(self, e): def do_motion(self, e):
e.widget.select_clear(0, END) e.widget.select_clear(0, END)
e.widget.select_set(e.widget.nearest(e.y)) e.widget.select_set(e.widget.nearest(e.y))
def do_leave(self, e): def do_leave(self, e):
e.widget.select_clear(0, END) e.widget.select_clear(0, END)
def do_1(self, e): def do_1(self, e):
self.kill(e.widget.get(e.widget.nearest(e.y))) self.kill(e.widget.get(e.widget.nearest(e.y)))
def __init__(self, master=None, **cnf): def __init__(self, master=None, **cnf):
Frame.__init__(self, master, cnf) Frame.__init__(self, master, cnf)
self.pack(expand=1, fill=BOTH) self.pack(expand=1, fill=BOTH)
self.bar = Frame(self, name='bar', relief=RAISED, self.bar = Frame(self, name='bar', relief=RAISED,
borderwidth=2) borderwidth=2)
self.bar.pack(fill=X) self.bar.pack(fill=X)
self.bar.file = BarButton(self.bar, text='File') self.bar.file = BarButton(self.bar, text='File')
self.bar.file.menu.add_command( self.bar.file.menu.add_command(
label='Quit', command=self.quit) label='Quit', command=self.quit)
self.bar.view = BarButton(self.bar, text='View') self.bar.view = BarButton(self.bar, text='View')
self.format = IntVar(self) self.format = IntVar(self)
self.format.set(2) self.format.set(2)
for num in range(len(self.format_list)): for num in range(len(self.format_list)):
self.bar.view.menu.add_radiobutton( self.bar.view.menu.add_radiobutton(
label=self.format_list[num][0], label=self.format_list[num][0],
command=self.do_update, command=self.do_update,
variable=self.format, variable=self.format,
value=num) value=num)
#self.bar.view.menu.add_separator() #self.bar.view.menu.add_separator()
#XXX ... #XXX ...
self.bar.tk_menuBar(self.bar.file, self.bar.view) self.bar.tk_menuBar(self.bar.file, self.bar.view)
self.frame = Frame(self, relief=RAISED, borderwidth=2) self.frame = Frame(self, relief=RAISED, borderwidth=2)
self.frame.pack(expand=1, fill=BOTH) self.frame.pack(expand=1, fill=BOTH)
self.header = StringVar(self) self.header = StringVar(self)
self.frame.label = Label(self.frame, relief=FLAT, anchor=NW, self.frame.label = Label(self.frame, relief=FLAT, anchor=NW,
borderwidth=0, borderwidth=0,
textvariable=self.header) textvariable=self.header)
self.frame.label.pack(fill=X) self.frame.label.pack(fill=X)
self.frame.vscroll = Scrollbar(self.frame, orient=VERTICAL) self.frame.vscroll = Scrollbar(self.frame, orient=VERTICAL)
self.frame.list = Listbox(self.frame, relief=SUNKEN, self.frame.list = Listbox(self.frame, relief=SUNKEN,
selectbackground='#eed5b7', selectbackground='#eed5b7',
selectborderwidth=0, selectborderwidth=0,
yscroll=self.frame.vscroll.set) yscroll=self.frame.vscroll.set)
self.frame.vscroll['command'] = self.frame.list.yview self.frame.vscroll['command'] = self.frame.list.yview
self.frame.vscroll.pack(side=RIGHT, fill=Y) self.frame.vscroll.pack(side=RIGHT, fill=Y)
self.frame.list.pack(expand=1, fill=BOTH) self.frame.list.pack(expand=1, fill=BOTH)
self.update = Button(self, text="Update", self.update = Button(self, text="Update",
command=self.do_update) command=self.do_update)
self.update.pack(expand=1, fill=X) self.update.pack(expand=1, fill=X)
self.frame.list.bind('<Motion>', self.do_motion) self.frame.list.bind('<Motion>', self.do_motion)
self.frame.list.bind('<Leave>', self.do_leave) self.frame.list.bind('<Leave>', self.do_leave)
self.frame.list.bind('<1>', self.do_1) self.frame.list.bind('<1>', self.do_1)
self.do_update() self.do_update()
if __name__ == '__main__': if __name__ == '__main__':
kill = Kill(None, borderwidth=5) kill = Kill(None, borderwidth=5)
kill.winfo_toplevel().title('Tkinter Process Killer') kill.winfo_toplevel().title('Tkinter Process Killer')
kill.winfo_toplevel().minsize(1, 1) kill.winfo_toplevel().minsize(1, 1)
kill.mainloop() kill.mainloop()
...@@ -6,32 +6,32 @@ import string ...@@ -6,32 +6,32 @@ import string
from Tkinter import * from Tkinter import *
def listtree(master, app): def listtree(master, app):
list = Listbox(master, name='list') list = Listbox(master, name='list')
list.pack(expand=1, fill=BOTH) list.pack(expand=1, fill=BOTH)
listnodes(list, app, '.', 0) listnodes(list, app, '.', 0)
return list return list
def listnodes(list, app, widget, level): def listnodes(list, app, widget, level):
klass = list.send(app, 'winfo', 'class', widget) klass = list.send(app, 'winfo', 'class', widget)
## i = string.rindex(widget, '.') ## i = string.rindex(widget, '.')
## list.insert(END, '%s%s (%s)' % ((level-1)*'. ', widget[i:], klass)) ## list.insert(END, '%s%s (%s)' % ((level-1)*'. ', widget[i:], klass))
list.insert(END, '%s (%s)' % (widget, klass)) list.insert(END, '%s (%s)' % (widget, klass))
children = list.tk.splitlist( children = list.tk.splitlist(
list.send(app, 'winfo', 'children', widget)) list.send(app, 'winfo', 'children', widget))
for c in children: for c in children:
listnodes(list, app, c, level+1) listnodes(list, app, c, level+1)
def main(): def main():
if not sys.argv[1:]: if not sys.argv[1:]:
sys.stderr.write('Usage: listtree appname\n') sys.stderr.write('Usage: listtree appname\n')
sys.exit(2) sys.exit(2)
app = sys.argv[1] app = sys.argv[1]
tk = Tk() tk = Tk()
tk.minsize(1, 1) tk.minsize(1, 1)
f = Frame(tk, name='f') f = Frame(tk, name='f')
f.pack(expand=1, fill=BOTH) f.pack(expand=1, fill=BOTH)
list = listtree(f, app) list = listtree(f, app)
tk.mainloop() tk.mainloop()
if __name__ == '__main__': if __name__ == '__main__':
main() main()
This diff is collapsed.
...@@ -7,35 +7,35 @@ from Tkinter import * ...@@ -7,35 +7,35 @@ from Tkinter import *
class App: class App:
def __init__(self, master): def __init__(self, master):
self.master = master self.master = master
self.menubar = Menu(self.master) self.menubar = Menu(self.master)
self.filemenu = Menu(self.menubar) self.filemenu = Menu(self.menubar)
self.filemenu.add_command(label="New")
self.filemenu.add_command(label="Open...")
self.filemenu.add_command(label="Close")
self.filemenu.add_separator()
self.filemenu.add_command(label="Quit", command=self.master.quit)
self.editmenu = Menu(self.menubar) self.filemenu.add_command(label="New")
self.filemenu.add_command(label="Open...")
self.filemenu.add_command(label="Close")
self.filemenu.add_separator()
self.filemenu.add_command(label="Quit", command=self.master.quit)
self.editmenu.add_command(label="Cut") self.editmenu = Menu(self.menubar)
self.editmenu.add_command(label="Copy")
self.editmenu.add_command(label="Paste") self.editmenu.add_command(label="Cut")
self.editmenu.add_command(label="Copy")
self.editmenu.add_command(label="Paste")
self.helpmenu = Menu(self.menubar, name='help') self.helpmenu = Menu(self.menubar, name='help')
self.helpmenu.add_command(label="About...") self.helpmenu.add_command(label="About...")
self.menubar.add_cascade(label="File", menu=self.filemenu) self.menubar.add_cascade(label="File", menu=self.filemenu)
self.menubar.add_cascade(label="Edit", menu=self.editmenu) self.menubar.add_cascade(label="Edit", menu=self.editmenu)
self.menubar.add_cascade(label="Help", menu=self.helpmenu) self.menubar.add_cascade(label="Help", menu=self.helpmenu)
self.top = Toplevel(menu=self.menubar) self.top = Toplevel(menu=self.menubar)
# Rest of app goes here... # Rest of app goes here...
def main(): def main():
root = Tk() root = Tk()
......
...@@ -12,12 +12,12 @@ here and hope that the person who requested it sees this! ...@@ -12,12 +12,12 @@ here and hope that the person who requested it sees this!
All this does is put up a canvas and draw a smooth black line All this does is put up a canvas and draw a smooth black line
whenever you have the mouse button down, but hopefully it will whenever you have the mouse button down, but hopefully it will
be enough to start with.. It would be easy enough to add some be enough to start with.. It would be easy enough to add some
options like other shapes or colors... options like other shapes or colors...
yours, yours,
dave mitchell dave mitchell
davem@magnet.com davem@magnet.com
""" """
from Tkinter import * from Tkinter import *
...@@ -28,33 +28,33 @@ b1 = "up" ...@@ -28,33 +28,33 @@ b1 = "up"
xold, yold = None, None xold, yold = None, None
def main(): def main():
root = Tk() root = Tk()
drawing_area = Canvas(root) drawing_area = Canvas(root)
drawing_area.pack() drawing_area.pack()
drawing_area.bind("<Motion>", motion) drawing_area.bind("<Motion>", motion)
drawing_area.bind("<ButtonPress-1>", b1down) drawing_area.bind("<ButtonPress-1>", b1down)
drawing_area.bind("<ButtonRelease-1>", b1up) drawing_area.bind("<ButtonRelease-1>", b1up)
root.mainloop() root.mainloop()
def b1down(event): def b1down(event):
global b1 global b1
b1 = "down" # you only want to draw when the button is down b1 = "down" # you only want to draw when the button is down
# because "Motion" events happen -all the time- # because "Motion" events happen -all the time-
def b1up(event): def b1up(event):
global b1, xold, yold global b1, xold, yold
b1 = "up" b1 = "up"
xold = None # reset the line when you let go of the button xold = None # reset the line when you let go of the button
yold = None yold = None
def motion(event): def motion(event):
if b1 == "down": if b1 == "down":
global xold, yold global xold, yold
if xold != None and yold != None: if xold != None and yold != None:
event.widget.create_line(xold,yold,event.x,event.y,smooth=TRUE) event.widget.create_line(xold,yold,event.x,event.y,smooth=TRUE)
# here's where you draw it. smooth. neat. # here's where you draw it. smooth. neat.
xold = event.x xold = event.x
yold = event.y yold = event.y
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -28,7 +28,7 @@ s = Scrollbar(f, relief=FLAT) ...@@ -28,7 +28,7 @@ s = Scrollbar(f, relief=FLAT)
s.pack(side=RIGHT, fill=Y) s.pack(side=RIGHT, fill=Y)
t = Text(f, relief=RAISED, borderwidth=2, yscrollcommand=s.set, setgrid=1) t = Text(f, relief=RAISED, borderwidth=2, yscrollcommand=s.set, setgrid=1)
t.pack(side=LEFT, fill=BOTH, expand=1) t.pack(side=LEFT, fill=BOTH, expand=1)
t.tag_config('bold', font='-Adobe-Courier-Bold-R-Normal-*-120-*') t.tag_config('bold', font='-Adobe-Courier-Bold-R-Normal-*-120-*')
s['command'] = t.yview s['command'] = t.yview
root.title('Tk Remote Controller') root.title('Tk Remote Controller')
...@@ -42,7 +42,7 @@ file_m = Menu(file) ...@@ -42,7 +42,7 @@ file_m = Menu(file)
file['menu'] = file_m file['menu'] = file_m
file_m_apps = Menu(file_m, tearoff=0) file_m_apps = Menu(file_m, tearoff=0)
file_m.add_cascade(label='Select Application', underline=0, file_m.add_cascade(label='Select Application', underline=0,
menu=file_m_apps) menu=file_m_apps)
file_m.add_command(label='Quit', underline=0, command=sys.exit) file_m.add_command(label='Quit', underline=0, command=sys.exit)
# 3. Create bindings for text widget to allow commands to be # 3. Create bindings for text widget to allow commands to be
...@@ -51,46 +51,46 @@ file_m.add_command(label='Quit', underline=0, command=sys.exit) ...@@ -51,46 +51,46 @@ file_m.add_command(label='Quit', underline=0, command=sys.exit)
# insertion point). # insertion point).
def single1(e): def single1(e):
x = e.x x = e.x
y = e.y y = e.y
t.setvar('tk_priv(selectMode)', 'char') t.setvar('tk_priv(selectMode)', 'char')
t.mark_set('anchor', At(x, y)) t.mark_set('anchor', At(x, y))
# Should focus W # Should focus W
t.bind('<1>', single1) t.bind('<1>', single1)
def double1(e): def double1(e):
x = e.x x = e.x
y = e.y y = e.y
t.setvar('tk_priv(selectMode)', 'word') t.setvar('tk_priv(selectMode)', 'word')
t.tk_textSelectTo(At(x, y)) t.tk_textSelectTo(At(x, y))
t.bind('<Double-1>', double1) t.bind('<Double-1>', double1)
def triple1(e): def triple1(e):
x = e.x x = e.x
y = e.y y = e.y
t.setvar('tk_priv(selectMode)', 'line') t.setvar('tk_priv(selectMode)', 'line')
t.tk_textSelectTo(At(x, y)) t.tk_textSelectTo(At(x, y))
t.bind('<Triple-1>', triple1) t.bind('<Triple-1>', triple1)
def returnkey(e): def returnkey(e):
t.insert(AtInsert(), '\n') t.insert(AtInsert(), '\n')
invoke() invoke()
t.bind('<Return>', returnkey) t.bind('<Return>', returnkey)
def controlv(e): def controlv(e):
t.insert(AtInsert(), t.selection_get()) t.insert(AtInsert(), t.selection_get())
t.yview_pickplace(AtInsert()) t.yview_pickplace(AtInsert())
if t.index(AtInsert())[-2:] == '.0': if t.index(AtInsert())[-2:] == '.0':
invoke() invoke()
t.bind('<Control-v>', controlv) t.bind('<Control-v>', controlv)
# 4. Procedure to backspace over one character, as long as # 4. Procedure to backspace over one character, as long as
# the character isn't part of the prompt. # the character isn't part of the prompt.
def backspace(e): def backspace(e):
if t.index('promptEnd') != t.index('insert - 1 char'): if t.index('promptEnd') != t.index('insert - 1 char'):
t.delete('insert - 1 char', AtInsert()) t.delete('insert - 1 char', AtInsert())
t.yview_pickplace(AtInsert()) t.yview_pickplace(AtInsert())
t.bind('<BackSpace>', backspace) t.bind('<BackSpace>', backspace)
t.bind('<Control-h>', backspace) t.bind('<Control-h>', backspace)
t.bind('<Delete>', backspace) t.bind('<Delete>', backspace)
...@@ -103,49 +103,49 @@ t.bind('<Delete>', backspace) ...@@ -103,49 +103,49 @@ t.bind('<Delete>', backspace)
# a new prompt. # a new prompt.
def invoke(): def invoke():
cmd = t.get('promptEnd + 1 char', AtInsert()) cmd = t.get('promptEnd + 1 char', AtInsert())
if t.getboolean(tk.call('info', 'complete', cmd)): # XXX if t.getboolean(tk.call('info', 'complete', cmd)): # XXX
if app == root.winfo_name(): if app == root.winfo_name():
msg = tk.call('eval', cmd) # XXX msg = tk.call('eval', cmd) # XXX
else: else:
msg = t.send(app, cmd) msg = t.send(app, cmd)
if msg: if msg:
t.insert(AtInsert(), msg + '\n') t.insert(AtInsert(), msg + '\n')
prompt() prompt()
t.yview_pickplace(AtInsert()) t.yview_pickplace(AtInsert())
def prompt(): def prompt():
t.insert(AtInsert(), app + ': ') t.insert(AtInsert(), app + ': ')
t.mark_set('promptEnd', 'insert - 1 char') t.mark_set('promptEnd', 'insert - 1 char')
t.tag_add('bold', 'insert linestart', 'promptEnd') t.tag_add('bold', 'insert linestart', 'promptEnd')
# 6. Procedure to select a new application. Also changes # 6. Procedure to select a new application. Also changes
# the prompt on the current command line to reflect the new # the prompt on the current command line to reflect the new
# name. # name.
def newApp(appName): def newApp(appName):
global app global app
app = appName app = appName
t.delete('promptEnd linestart', 'promptEnd') t.delete('promptEnd linestart', 'promptEnd')
t.insert('promptEnd', appName + ':') t.insert('promptEnd', appName + ':')
t.tag_add('bold', 'promptEnd linestart', 'promptEnd') t.tag_add('bold', 'promptEnd linestart', 'promptEnd')
def fillAppsMenu(): def fillAppsMenu():
file_m_apps.add('command') file_m_apps.add('command')
file_m_apps.delete(0, 'last') file_m_apps.delete(0, 'last')
names = root.winfo_interps() names = root.winfo_interps()
names = map(None, names) # convert tuple to list names = map(None, names) # convert tuple to list
names.sort() names.sort()
for name in names: for name in names:
try: try:
root.send(name, 'winfo name .') root.send(name, 'winfo name .')
except TclError: except TclError:
# Inoperative window -- ignore it # Inoperative window -- ignore it
pass pass
else: else:
file_m_apps.add_command( file_m_apps.add_command(
label=name, label=name,
command=lambda name=name: newApp(name)) command=lambda name=name: newApp(name))
file_m_apps['postcommand'] = fillAppsMenu file_m_apps['postcommand'] = fillAppsMenu
mBar.tk_menuBar(file) mBar.tk_menuBar(file)
......
This diff is collapsed.
This diff is collapsed.
...@@ -315,7 +315,7 @@ class BaseCell: ...@@ -315,7 +315,7 @@ class BaseCell:
"""Abstract base class for sheet cells. """Abstract base class for sheet cells.
Subclasses may but needn't provide the following APIs: Subclasses may but needn't provide the following APIs:
cell.reset() -- prepare for recalculation cell.reset() -- prepare for recalculation
cell.recalc(rexec) -> value -- recalculate formula cell.recalc(rexec) -> value -- recalculate formula
cell.format() -> (value, alignment) -- return formatted value cell.format() -> (value, alignment) -- return formatted value
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -6,4 +6,3 @@ Module for using panels with curses. ...@@ -6,4 +6,3 @@ Module for using panels with curses.
__revision__ = "$Id$" __revision__ = "$Id$"
from _curses_panel import * from _curses_panel import *
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment