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

Whitespace normalization, via reindent.py.

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