summaryrefslogtreecommitdiffstats
path: root/Demo/tkinter/guido
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-07-30 18:57:18 (GMT)
committerGuido van Rossum <guido@python.org>1996-07-30 18:57:18 (GMT)
commit89cb67bb642ee958d9f095728c99e943e994ca54 (patch)
tree24f176f21636ab7b3a5cd1cec9948b4e3a1315ff /Demo/tkinter/guido
parentc30e95f4b0fa266df678fe4e307ff6c19a3f9e73 (diff)
downloadcpython-89cb67bb642ee958d9f095728c99e943e994ca54.zip
cpython-89cb67bb642ee958d9f095728c99e943e994ca54.tar.gz
cpython-89cb67bb642ee958d9f095728c99e943e994ca54.tar.bz2
Updated for Python 1.4
Diffstat (limited to 'Demo/tkinter/guido')
-rwxr-xr-xDemo/tkinter/guido/AttrDialog.py105
-rwxr-xr-xDemo/tkinter/guido/ManPage.py28
-rwxr-xr-xDemo/tkinter/guido/ShellWindow.py101
-rwxr-xr-xDemo/tkinter/guido/dialog.py69
-rwxr-xr-xDemo/tkinter/guido/electrons.py11
-rwxr-xr-xDemo/tkinter/guido/hanoi.py13
-rwxr-xr-xDemo/tkinter/guido/kill.py103
-rwxr-xr-xDemo/tkinter/guido/listtree.py11
-rwxr-xr-xDemo/tkinter/guido/svkill.py107
-rwxr-xr-xDemo/tkinter/guido/tkman.py132
10 files changed, 293 insertions, 387 deletions
diff --git a/Demo/tkinter/guido/AttrDialog.py b/Demo/tkinter/guido/AttrDialog.py
index 2b501c70..32b4b7e 100755
--- a/Demo/tkinter/guido/AttrDialog.py
+++ b/Demo/tkinter/guido/AttrDialog.py
@@ -24,12 +24,10 @@ class Option:
self.master = dialog.top
self.default, self.klass = dialog.options[option]
self.var = self.varclass(self.master)
- self.frame = Frame(self.master,
- {Pack: {'expand': 0, 'fill': 'x'}})
- self.label = Label(self.frame,
- {'text': option + ':',
- Pack: {'side': 'left'},
- })
+ self.frame = Frame(self.master)
+ self.frame.pack(fill=X)
+ self.label = Label(self.frame, text=(option + ":"))
+ self.label.pack(side=LEFT)
self.update()
self.addoption()
@@ -53,55 +51,48 @@ class BooleanOption(Option):
def addoption(self):
self.button = Checkbutton(self.frame,
- {'text': 'on/off',
- 'onvalue': '1',
- 'offvalue': '0',
- 'variable': self.var,
- 'relief': 'raised',
- 'borderwidth': 2,
- 'command': self.set,
- Pack: {'side': 'right'},
- })
+ text='on/off',
+ onvalue=1,
+ offvalue=0,
+ variable=self.var,
+ relief=RAISED,
+ borderwidth=2,
+ command=self.set)
+ self.button.pack(side=RIGHT)
class EnumOption(Option):
def addoption(self):
self.button = Menubutton(self.frame,
- {'textvariable': self.var,
- 'relief': 'raised',
- 'borderwidth': 2,
- Pack: {'side': 'right'},
- })
+ textvariable=self.var,
+ relief=RAISED, borderwidth=2)
+ self.button.pack(side=RIGHT)
self.menu = Menu(self.button)
self.button['menu'] = self.menu
for v in self.dialog.classes[self.klass]:
self.menu.add_radiobutton(
- {'label': v,
- 'variable': self.var,
- 'value': v,
- 'command': self.set,
- })
+ label=v,
+ variable=self.var,
+ value=v,
+ command=self.set)
class StringOption(Option):
def addoption(self):
self.entry = Entry(self.frame,
- {'textvariable': self.var,
- 'width': 10,
- 'relief': 'sunken',
- 'borderwidth': 2,
- Pack: {'side': 'right',
- 'fill': 'x', 'expand': 1},
- })
+ textvariable=self.var,
+ width=10,
+ relief=SUNKEN,
+ borderwidth=2)
+ self.entry.pack(side=RIGHT, fill=X, expand=1)
self.entry.bind('<Return>', self.set)
class ReadonlyOption(Option):
def addoption(self):
- self.label = Label(self.frame,
- {'textvariable': self.var,
- 'anchor': 'e',
- Pack: {'side': 'right'}})
+ self.label = Label(self.frame, textvariable=self.var,
+ anchor=E)
+ self.label.pack(side=RIGHT)
class Dialog:
@@ -156,7 +147,7 @@ class PackDialog(Dialog):
Dialog.__init__(self, widget)
def refresh(self):
- self.current = self.widget.newinfo()
+ self.current = self.widget.info()
self.current['.class'] = self.widget.winfo_class()
self.current['.name'] = self.widget._w
@@ -164,8 +155,8 @@ class PackDialog(Dialog):
def set(self, e=None):
self.current = self.var.get()
try:
- Pack.config(self.dialog.widget,
- {self.option: self.current})
+ apply(self.dialog.widget.pack, (),
+ {self.option: self.current})
except TclError, msg:
print msg
self.refresh()
@@ -192,14 +183,14 @@ class PackDialog(Dialog):
}
classes = {
- 'Anchor': ('n','ne', 'e','se', 's','sw', 'w','nw', 'center'),
+ 'Anchor': (N, NE, E, SE, S, SW, W, NW, CENTER),
'Boolean': 'boolean',
'Class': 'readonly',
'Expand': 'boolean',
- 'Fill': ('none', 'x', 'y', 'both'),
+ 'Fill': (NONE, X, Y, BOTH),
'Name': 'readonly',
'Pad': 'pixel',
- 'Side': ('top', 'right', 'bottom', 'left'),
+ 'Side': (TOP, RIGHT, BOTTOM, LEFT),
'Widget': 'readonly',
}
@@ -220,7 +211,7 @@ class RemotePackDialog(PackDialog):
words = self.master.tk.splitlist(
self.master.send(self.app,
'pack',
- 'newinfo',
+ 'info',
self.widget))
except TclError, msg:
print msg
@@ -306,7 +297,7 @@ class WidgetDialog(Dialog):
# Universal classes
classes = {
- 'Anchor': ('n','ne', 'e','se', 's','sw', 'w','nw', 'center'),
+ 'Anchor': (N, NE, E, SE, S, SW, W, NW, CENTER),
'Aspect': 'integer',
'Background': 'color',
'Bitmap': 'bitmap',
@@ -325,16 +316,16 @@ class WidgetDialog(Dialog):
'Geometry': 'geometry',
'Height': 'pixel',
'InsertWidth': 'time',
- 'Justify': ('left', 'center', 'right'),
+ 'Justify': (LEFT, CENTER, RIGHT),
'Label': 'string',
'Length': 'pixel',
'MenuName': 'widget',
'Name': 'readonly',
'OffTime': 'time',
'OnTime': 'time',
- 'Orient': ('horizontal', 'vertical'),
+ 'Orient': (HORIZONTAL, VERTICAL),
'Pad': 'pixel',
- 'Relief': ('raised', 'sunken', 'flat', 'ridge', 'groove'),
+ 'Relief': (RAISED, SUNKEN, FLAT, RIDGE, GROOVE),
'RepeatDelay': 'time',
'RepeatInterval': 'time',
'ScrollCommand': 'command',
@@ -351,12 +342,12 @@ class WidgetDialog(Dialog):
'Variable': 'variable',
'Value': 'string',
'Width': 'pixel',
- 'Wrap': ('none', 'char', 'word'),
+ 'Wrap': (NONE, CHAR, WORD),
}
# Classes that (may) differ per widget type
- _tristate = {'State': ('normal', 'active', 'disabled')}
- _bistate = {'State': ('normal', 'disabled')}
+ _tristate = {'State': (NORMAL, ACTIVE, DISABLED)}
+ _bistate = {'State': (NORMAL, DISABLED)}
addclasses = {
'Button': _tristate,
'Radiobutton': _tristate,
@@ -424,14 +415,12 @@ def test():
if sys.argv[1:]:
remotetest(root, sys.argv[1])
else:
- frame = Frame(root, {'name': 'frame',
- Pack: {'expand': 1, 'fill': 'both'},
- })
- button = Button(frame, {'name': 'button',
- 'text': 'button',
- Pack: {'expand': 1}})
- canvas = Canvas(frame, {'name': 'canvas',
- Pack: {}})
+ frame = Frame(root, name='frame')
+ frame.pack(expand=1, fill=BOTH)
+ button = Button(frame, name='button', text='button')
+ button.pack(expand=1)
+ canvas = Canvas(frame, name='canvas')
+ canvas.pack()
fpd = PackDialog(frame)
fwd = WidgetDialog(frame)
bpd = PackDialog(button)
diff --git a/Demo/tkinter/guido/ManPage.py b/Demo/tkinter/guido/ManPage.py
index 4f0af8c..ccd21b4 100755
--- a/Demo/tkinter/guido/ManPage.py
+++ b/Demo/tkinter/guido/ManPage.py
@@ -20,14 +20,14 @@ ulprog = regex.compile('^[ \t]*[Xv!_][Xv!_ \t]*\n')
class EditableManPage(ScrolledText):
# Initialize instance
- def __init__(self, master=None, cnf={}):
+ def __init__(self, master=None, **cnf):
# Initialize base class
- ScrolledText.__init__(self, master, cnf)
+ apply(ScrolledText.__init__, (self, master), cnf)
# Define tags for formatting styles
- self.tag_config('X', {'underline': 1})
- self.tag_config('!', {'font': BOLDFONT})
- self.tag_config('_', {'font': ITALICFONT})
+ self.tag_config('X', underline=1)
+ self.tag_config('!', font=BOLDFONT)
+ self.tag_config('_', font=ITALICFONT)
# Set state to idle
self.fp = None
@@ -83,8 +83,8 @@ class EditableManPage(ScrolledText):
self.empty = 0
self.buffer = None
savestate = self['state']
- self['state'] = 'normal'
- self.delete('1.0', 'end')
+ self['state'] = NORMAL
+ self.delete('1.0', END)
self['state'] = savestate
# End parsing -- must be busy, need not be at EOF
@@ -133,11 +133,11 @@ class EditableManPage(ScrolledText):
self.empty = 0
return
savestate = self['state']
- self['state'] = 'normal'
+ self['state'] = NORMAL
if TkVersion >= 4.0:
self.mark_set('insert', 'end-1c')
else:
- self.mark_set('insert', 'end')
+ self.mark_set('insert', END)
if self.empty:
# One or more previous lines were empty
# -- insert one blank line in the text
@@ -176,9 +176,9 @@ class EditableManPage(ScrolledText):
class ReadonlyManPage(EditableManPage):
# Initialize instance
- def __init__(self, master=None, cnf={}):
- EditableManPage.__init__(self, master,
- (cnf, {'state': 'disabled'}))
+ def __init__(self, master=None, **cnf):
+ cnf['state'] = DISABLED
+ apply(EditableManPage.__init__, (self, master), cnf)
# Alias
ManPage = ReadonlyManPage
@@ -206,8 +206,8 @@ def test():
name = os.path.join(MANDIR, name)
root = Tk()
root.minsize(1, 1)
- manpage = ManPage(root, {'relief': 'sunken', 'bd': 2,
- Pack: {'expand': 1, 'fill': 'both'}})
+ manpage = ManPage(root, relief=SUNKEN, borderwidth=2)
+ manpage.pack(expand=1, fill=BOTH)
if formatted:
fp = open(name, 'r')
else:
diff --git a/Demo/tkinter/guido/ShellWindow.py b/Demo/tkinter/guido/ShellWindow.py
index 93a13d6..0b59daa 100755
--- a/Demo/tkinter/guido/ShellWindow.py
+++ b/Demo/tkinter/guido/ShellWindow.py
@@ -6,19 +6,12 @@ from ScrolledText import ScrolledText
from Dialog import Dialog
import signal
-TK_READABLE = 1
-TK_WRITABLE = 2
-TK_EXCEPTION = 4
-
BUFSIZE = 512
class ShellWindow(ScrolledText):
- def __init__(self, master = None, cnf = {}):
- try:
- shell = cnf['shell']
- del cnf['shell']
- except KeyError:
+ def __init__(self, master=None, shell=None, **cnf):
+ if not shell:
try:
shell = os.environ['SHELL']
except KeyError:
@@ -27,7 +20,7 @@ class ShellWindow(ScrolledText):
args = string.split(shell)
shell = args[0]
- ScrolledText.__init__(self, master, cnf)
+ apply(ScrolledText.__init__, (self, master), cnf)
self.pos = '1.0'
self.bind('<Return>', self.inputhandler)
self.bind('<Control-c>', self.sigint)
@@ -36,7 +29,7 @@ class ShellWindow(ScrolledText):
self.bind('<Control-d>', self.sendeof)
self.pid, self.fromchild, self.tochild = spawn(shell, args)
- self.tk.createfilehandler(self.fromchild, TK_READABLE,
+ self.tk.createfilehandler(self.fromchild, READABLE,
self.outputhandler)
def outputhandler(self, file, mask):
@@ -54,68 +47,60 @@ class ShellWindow(ScrolledText):
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',),
- })
+ Dialog(self.master,
+ text=msg,
+ title="Exit status",
+ bitmap='warning',
+ default=0,
+ strings=('OK',))
return
- self.insert('end', data)
- self.pos = self.index('end')
- self.yview_pickplace('end')
+ self.insert(END, data)
+ self.pos = self.index("end - 1 char")
+ self.yview_pickplace(END)
def inputhandler(self, *args):
if not self.pid:
- Dialog(self.master, {
- 'text': "No active process",
- 'title': "No process",
- 'bitmap': 'error',
- 'default': 0,
- 'strings': ('OK',),
- })
- return
- self.insert('end', '\n')
- line = self.get(self.pos, 'end')
- self.pos = self.index('end')
+ 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:
- Dialog(self.master, {
- 'text': "No active process",
- 'title': "No process",
- 'bitmap': 'error',
- 'default': 0,
- 'strings': ('OK',),
- })
- return
+ self.no_process()
+ return "break"
os.close(self.tochild)
+ return "break"
def sendsig(self, sig):
if not self.pid:
- Dialog(self.master, {
- 'text': "No active process",
- 'title': "No process",
- 'bitmap': 'error',
- 'default': 0,
- 'strings': ('OK',),
- })
- return
+ self.no_process()
+ return "break"
os.kill(self.pid, sig)
+ return "break"
def sigint(self, *args):
- self.sendsig(signal.SIGINT)
+ return self.sendsig(signal.SIGINT)
def sigquit(self, *args):
- self.sendsig(signal.SIGQUIT)
+ return self.sendsig(signal.SIGQUIT)
def sigterm(self, *args):
- self.sendsig(signal.SIGTERM)
+ return self.sendsig(signal.SIGTERM)
def sigkill(self, *args):
- self.sendsig(signal.SIGKILL)
+ 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()???)
@@ -142,7 +127,7 @@ def spawn(prog, args):
try:
os.execvp(prog, args)
finally:
- print 'execvp failed'
+ sys.stderr.write('execvp failed\n')
os._exit(1)
os.close(p2cread)
os.close(c2pwrite)
@@ -150,13 +135,13 @@ def spawn(prog, args):
def test():
shell = string.join(sys.argv[1:])
- cnf = {}
- if shell:
- cnf['shell'] = shell
root = Tk()
root.minsize(1, 1)
- w = ShellWindow(root, cnf)
- w.pack({'expand': 1, 'fill': 'both'})
+ if shell:
+ w = ShellWindow(root, shell=shell)
+ else:
+ w = ShellWindow(root)
+ w.pack(expand=1, fill=BOTH)
w.focus_set()
w.tk.mainloop()
diff --git a/Demo/tkinter/guido/dialog.py b/Demo/tkinter/guido/dialog.py
index 27cddf0..500a73d 100755
--- a/Demo/tkinter/guido/dialog.py
+++ b/Demo/tkinter/guido/dialog.py
@@ -5,55 +5,49 @@
# Cf. Ousterhout, Tcl and the Tk Toolkit, Figs. 27.2-3, pp. 269-270.
from Tkinter import *
+import sys
+
def dialog(master, title, text, bitmap, default, *args):
# 1. Create the top-level window and divide it into top
# and bottom parts.
- w = Toplevel(master, {'class': 'Dialog'})
+ w = Toplevel(master, class_='Dialog')
w.title(title)
w.iconname('Dialog')
- top = Frame(w, {'relief': 'raised', 'bd': 1,
- Pack: {'side': 'top', 'fill': 'both'}})
- bot = Frame(w, {'relief': 'raised', 'bd': 1,
- Pack: {'side': 'bottom', 'fill': 'both'}})
+ top = Frame(w, relief=RAISED, borderwidth=1)
+ top.pack(side=TOP, fill=BOTH)
+ bot = Frame(w, relief=RAISED, borderwidth=1)
+ bot.pack(side=BOTTOM, fill=BOTH)
# 2. Fill the top part with the bitmap and message.
- msg = Message(top,
- {'width': '3i',
- 'text': text,
- 'font': '-Adobe-Times-Medium-R-Normal-*-180-*',
- Pack: {'side': 'right', 'expand': 1,
- 'fill': 'both',
- 'padx': '3m', 'pady': '3m'}})
+ msg = Message(top, width='3i', text=text,
+ 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,
- 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.
+ var = IntVar()
buttons = []
i = 0
for but in args:
- b = Button(bot, {'text': but,
- 'command': ('set', 'button', i)})
+ 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', 'bd': 1,
- Pack: {'side': 'left', 'expand': 1,
- 'padx': '3m', 'pady': '2m'}})
+ 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'})
+ 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',
- 'ipady': '2m', 'ipady': '1m'})
+ b.pack (side=LEFT, expand=1,
+ padx='3m', pady='3m', ipady='2m', ipady='1m')
i = i+1
# 4. Set up a binding for <Return>, if there's a default,
@@ -61,21 +55,21 @@ def dialog(master, title, text, bitmap, default, *args):
if default >= 0:
w.bind('<Return>',
- lambda e, b=buttons[default], i=default:
+ lambda e, b=buttons[default], v=var, i=default:
(b.flash(),
- b.setvar('button', i)))
+ v.set(i)))
- oldFocus = w.tk.call('focus') # XXX
+ oldFocus = w.focus_get()
w.grab_set()
- w.focus()
+ w.focus_set()
# 5. Wait for the user to respond, then restore the focus
# and return the index of the selected button.
- w.waitvar('button')
+ w.waitvar(var)
w.destroy()
- w.tk.call('focus', oldFocus) # XXX
- return w.getint(w.getvar('button'))
+ if oldFocus: oldFocus.focus_set()
+ return var.get()
# The rest is the test program.
@@ -105,13 +99,10 @@ def test():
global mainWidget
mainWidget = Frame()
Pack.config(mainWidget)
- start = Button(mainWidget,
- {'text': 'Press Here To Start', 'command': go})
+ start = Button(mainWidget, text='Press Here To Start', command=go)
start.pack()
- endit = Button(mainWidget,
- {'text': 'Exit',
- 'command': 'exit',
- Pack: {'fill' : 'both'}})
+ endit = Button(mainWidget, text="Exit", command=sys.exit)
+ endit.pack(fill=BOTH)
mainWidget.mainloop()
if __name__ == '__main__':
diff --git a/Demo/tkinter/guido/electrons.py b/Demo/tkinter/guido/electrons.py
index 5f6c8b5..7296955 100755
--- a/Demo/tkinter/guido/electrons.py
+++ b/Demo/tkinter/guido/electrons.py
@@ -15,7 +15,6 @@
from Tkinter import *
-
# The graphical interface
class Electrons:
@@ -30,14 +29,13 @@ class Electrons:
# Add background bitmap
if bitmap:
self.bitmap = c.create_bitmap(width/2, height/2,
- {'bitmap': bitmap,
- 'foreground': 'blue'})
+ bitmap=bitmap,
+ foreground='blue')
self.pieces = {}
x1, y1, x2, y2 = 10,70,14,74
for i in range(n,0,-1):
- p = c.create_oval(x1, y1, x2, y2,
- {'fill': 'red'})
+ p = c.create_oval(x1, y1, x2, y2, fill='red')
self.pieces[i] = p
y1, y2 = y1 +2, y2 + 2
self.tk.update()
@@ -51,11 +49,12 @@ class Electrons:
y = rand.choice(range(-3,4))
c.move(p, x, y)
self.tk.update()
+
# Run -- never returns
def run(self):
while 1:
self.random_move(self.n)
- self.tk.mainloop() # Hang around...
+
# Main program
def main():
diff --git a/Demo/tkinter/guido/hanoi.py b/Demo/tkinter/guido/hanoi.py
index 848e8e5..2cc4134 100755
--- a/Demo/tkinter/guido/hanoi.py
+++ b/Demo/tkinter/guido/hanoi.py
@@ -36,8 +36,8 @@ class Tkhanoi:
# Add background bitmap
if bitmap:
self.bitmap = c.create_bitmap(width/2, height/2,
- {'bitmap': bitmap,
- 'foreground': 'blue'})
+ bitmap=bitmap,
+ foreground='blue')
# Generate pegs
pegwidth = 10
@@ -46,13 +46,13 @@ class Tkhanoi:
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'})
+ 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'})
+ 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'})
+ p = c.create_rectangle(x1, y1, x2, y2, fill='black')
self.pegs.append(p)
self.tk.update()
@@ -66,8 +66,7 @@ class Tkhanoi:
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'})
+ 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
diff --git a/Demo/tkinter/guido/kill.py b/Demo/tkinter/guido/kill.py
index 8f45a29..24335cc 100755
--- a/Demo/tkinter/guido/kill.py
+++ b/Demo/tkinter/guido/kill.py
@@ -5,14 +5,14 @@ from Tkinter import *
from string import splitfields
from string import split
import commands
-import posix
+import os
class BarButton(Menubutton):
- _CNF = {Pack: {'side': 'left'}}
- def __init__(self, master=None, cnf={}):
- Menubutton.__init__(self, master, (self._CNF, cnf))
- 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)
@@ -27,7 +27,7 @@ class Kill(Frame):
def kill(self, selected):
c = self.format_list[self.format.get()][2]
pid = split(selected)[c]
- posix.system('kill' + ' -9 ' + pid)
+ os.system('kill -9 ' + pid)
self.do_update()
def do_update(self):
name, option, column = self.format_list[self.format.get()]
@@ -35,85 +35,64 @@ class Kill(Frame):
list = splitfields(s, '\n')
self.header.set(list[0])
del list[0]
- y = self.frame.vscroll.get()[2]
+ 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(y)
+ self.frame.list.yview(int(y))
def do_motion(self, e):
- e.widget.select_from(e.widget.nearest(e.y))
+ e.widget.select_clear(0, END)
+ e.widget.select_set(e.widget.nearest(e.y))
def do_leave(self, e):
- e.widget.select_clear()
+ 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={}):
+ def __init__(self, master=None, **cnf):
Frame.__init__(self, master, cnf)
- self.pack({'expand': 'yes', 'fill': 'both'})
- self.bar = Frame(
- self,
- {'name': 'bar',
- 'relief': 'raised',
- 'bd': 2,
- Pack: {'side': 'top',
- 'fill': 'x'}})
- self.bar.file = BarButton(self.bar, {'text': 'File'})
+ 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'})
+ 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})
+ 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', 'bd': 2,
- Pack: {'side': 'top',
- 'expand': 'yes',
- 'fill': 'both'}})
+ 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,
- Pack: {'side': 'top',
- '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.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(
- {'side': 'top',
- 'expand': 'yes',
- 'fill': 'both'})
- self.update = Button(
- self,
- {'text': 'Update',
- 'command': self.do_update,
- Pack: {'expand': 'yes',
- 'fill': 'x'}})
+ 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, {'bd': 5})
+ kill = Kill(None, borderwidth=5)
kill.winfo_toplevel().title('Tkinter Process Killer')
kill.winfo_toplevel().minsize(1, 1)
kill.mainloop()
diff --git a/Demo/tkinter/guido/listtree.py b/Demo/tkinter/guido/listtree.py
index c5e3bc5..523f209 100755
--- a/Demo/tkinter/guido/listtree.py
+++ b/Demo/tkinter/guido/listtree.py
@@ -6,16 +6,16 @@ import string
from Tkinter import *
def listtree(master, app):
- list = Listbox(master, {'name': 'list',
- Pack: {'expand': 1, 'fill': 'both'}})
+ 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))
+## 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:
@@ -28,7 +28,8 @@ def main():
app = sys.argv[1]
tk = Tk()
tk.minsize(1, 1)
- f = Frame(tk, {'name': 'f', Pack: {'expand': 1, 'fill': 'both'}})
+ f = Frame(tk, name='f')
+ f.pack(expand=1, fill=BOTH)
list = listtree(f, app)
tk.mainloop()
diff --git a/Demo/tkinter/guido/svkill.py b/Demo/tkinter/guido/svkill.py
index 2881afd..dd80856 100755
--- a/Demo/tkinter/guido/svkill.py
+++ b/Demo/tkinter/guido/svkill.py
@@ -15,10 +15,10 @@ import os
user = os.environ['LOGNAME']
class BarButton(Menubutton):
- def __init__(self, master=None, cnf={}):
- Menubutton.__init__(self, master, cnf)
- self.pack(side='left')
- self.menu = Menu(self, {'name': '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):
@@ -41,7 +41,7 @@ class Kill(Frame):
def kill(self, selected):
c = self.format_list[self.format.get()][2]
pid = split(selected)[c]
- os.system('kill' + ' -9 ' + pid)
+ os.system('kill -9 ' + pid)
self.do_update()
def do_update(self):
format = self.format_list[self.format.get()][1]
@@ -60,21 +60,17 @@ class Kill(Frame):
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': 'yes', 'fill': 'both'})
- self.bar = Frame(
- self,
- {'name': 'bar',
- 'relief': 'raised',
- 'bd': 2,
- Pack: {'side': 'top',
- 'fill': 'x'}})
- self.bar.file = BarButton(self.bar, {'text': 'File'})
+ def __init__(self, master=None, **cnf):
+ apply(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.bar.format = BarButton(self.bar, {'text': 'Format'})
+ label='Quit', command=self.quit)
+ self.bar.view = BarButton(self.bar, text='View')
+ self.bar.format = BarButton(self.bar, text='Format')
self.view = IntVar(self)
self.view.set(0)
self.format = IntVar(self)
@@ -82,68 +78,51 @@ class Kill(Frame):
for num in range(len(self.view_list)):
label, option = self.view_list[num]
self.bar.view.menu.add_radiobutton(
- {'label': label,
- 'command': self.do_update,
- 'variable': self.view,
- 'value': num})
+ label=label,
+ command=self.do_update,
+ variable=self.view,
+ value=num)
for num in range(len(self.format_list)):
label, option, col = self.format_list[num]
self.bar.format.menu.add_radiobutton(
- {'label': label,
- 'command': self.do_update,
- 'variable': self.format,
- 'value': num})
+ label=label,
+ command=self.do_update,
+ variable=self.format,
+ value=num)
self.bar.tk_menuBar(self.bar.file,
self.bar.view,
self.bar.format)
- self.frame = Frame(
- self,
- {'relief': 'raised', 'bd': 2,
- Pack: {'side': 'top',
- 'expand': 'yes',
- 'fill': 'both'}})
+ 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,
- 'font': '*-Courier-Bold-R-Normal-*-120-*',
- 'textvariable': self.header,
- Pack: {'side': 'top',
- 'fill': 'y',
- 'anchor': 'w'}})
- self.frame.vscroll = Scrollbar(
- self.frame,
- {'orient': 'vertical'})
+ self.frame, relief=FLAT, anchor=NW, borderwidth=0,
+ font='*-Courier-Bold-R-Normal-*-120-*',
+ textvariable=self.header)
+ self.frame.label.pack(fill=Y, anchor=W)
+ self.frame.vscroll = Scrollbar(self.frame, orient=VERTICAL)
self.frame.list = Listbox(
self.frame,
- {'relief': 'sunken',
- 'font': '*-Courier-Medium-R-Normal-*-120-*',
- 'width': 40, 'height': 10,
- 'selectbackground': '#eed5b7',
- 'selectborderwidth': 0,
- 'selectmode': 'browse',
- 'yscroll': self.frame.vscroll.set})
+ relief=SUNKEN,
+ font='*-Courier-Medium-R-Normal-*-120-*',
+ width=40, height=10,
+ selectbackground='#eed5b7',
+ selectborderwidth=0,
+ selectmode=BROWSE,
+ 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(
- {'side': 'top',
- 'expand': 'yes',
- 'fill': 'both'})
- self.update = Button(
- self,
- {'text': 'Update',
- 'command': self.do_update,
- Pack: {'expand': 'no',
- 'fill': 'x'}})
+ 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(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, {'bd': 5})
+ kill = Kill(None, borderwidth=5)
kill.winfo_toplevel().title('Tkinter Process Killer (SYSV)')
kill.winfo_toplevel().minsize(1, 1)
kill.mainloop()
diff --git a/Demo/tkinter/guido/tkman.py b/Demo/tkinter/guido/tkman.py
index cd60487..34ca4a3 100755
--- a/Demo/tkinter/guido/tkman.py
+++ b/Demo/tkinter/guido/tkman.py
@@ -1,4 +1,3 @@
-#! /home/guido/bin.sgi/python
#! /usr/local/bin/python
# Tk man page browser -- currently only shows the Tcl/Tk man pages
@@ -32,81 +31,66 @@ class SelectionBox:
def __init__(self, master=None):
self.choices = []
- self.frame = Frame(master, {
- 'name': 'frame',
- Pack: {'expand': 1, 'fill': 'both'}})
+ self.frame = Frame(master, name="frame")
+ self.frame.pack(expand=1, fill=BOTH)
self.master = self.frame.master
- self.subframe = Frame(self.frame, {
- 'name': 'subframe',
- Pack: {'expand': 0, 'fill': 'both'}})
- self.leftsubframe = Frame(self.subframe, {
- 'name': 'leftsubframe',
- Pack: {'side': 'left', 'expand': 1, 'fill': 'both'}})
- self.rightsubframe = Frame(self.subframe, {
- 'name': 'rightsubframe',
- Pack: {'side': 'right', 'expand': 1, 'fill': 'both'}})
+ self.subframe = Frame(self.frame, name="subframe")
+ self.subframe.pack(expand=0, fill=BOTH)
+ self.leftsubframe = Frame(self.subframe, name='leftsubframe')
+ self.leftsubframe.pack(side=LEFT, expand=1, fill=BOTH)
+ self.rightsubframe = Frame(self.subframe, name='rightsubframe')
+ self.rightsubframe.pack(side=RIGHT, expand=1, fill=BOTH)
self.chaptervar = StringVar(master)
- self.chapter = Menubutton(self.rightsubframe,
- {'name': 'chapter',
- 'text': 'Directory',
- 'relief': 'raised', 'bd': 2,
- Pack: {'side': 'top'}})
- self.chaptermenu = Menu(self.chapter, {'name': 'chaptermenu'})
- self.chaptermenu.add_radiobutton({'label': 'C functions',
- 'value': MAN3DIR,
- 'variable': self.chaptervar,
- 'command': self.newchapter})
- self.chaptermenu.add_radiobutton({'label': 'Tcl/Tk functions',
- 'value': MANNDIR,
- 'variable': self.chaptervar,
- 'command': self.newchapter})
+ self.chapter = Menubutton(self.rightsubframe, name='chapter',
+ text='Directory', relief=RAISED,
+ borderwidth=2)
+ self.chapter.pack(side=TOP)
+ self.chaptermenu = Menu(self.chapter, name='chaptermenu')
+ self.chaptermenu.add_radiobutton(label='C functions',
+ value=MAN3DIR,
+ variable=self.chaptervar,
+ command=self.newchapter)
+ self.chaptermenu.add_radiobutton(label='Tcl/Tk functions',
+ value=MANNDIR,
+ variable=self.chaptervar,
+ command=self.newchapter)
self.chapter['menu'] = self.chaptermenu
- self.listbox = Listbox(self.rightsubframe,
- {'name': 'listbox',
- 'relief': 'sunken', 'bd': 2,
- 'width': 20, 'height': 5,
- Pack: {'expand': 1, 'fill': 'both'}})
- self.l1 = Button(self.leftsubframe,
- {'name': 'l1',
- 'text': 'Display manual page named:',
- 'command': self.entry_cb,
- Pack: {'side': 'top'}})
- self.entry = Entry(self.leftsubframe,
- {'name': 'entry',
- 'relief': 'sunken', 'bd': 2,
- 'width': 20,
- Pack: {'side': 'top',
- 'expand': 0, 'fill': 'x'}})
- self.l2frame = Frame(self.leftsubframe,
- {'name': 'l2frame',
- Pack: {'expand': 0, 'fill': 'none'}})
- self.l2 = Button(self.l2frame,
- {'name': 'l2',
- 'text': 'Search regexp:',
- 'command': self.search_cb,
- Pack: {'side': 'left'}})
- self.casesense = Checkbutton(self.l2frame,
- {'name': 'casesense',
- 'text': 'Case sensitive',
- 'variable': 'casesense',
- 'relief': 'flat',
- Pack: {'side': 'left'}})
- self.search = Entry(self.leftsubframe,
- {'name': 'search',
- 'relief': 'sunken', 'bd': 2,
- 'width': 20,
- Pack: {'side': 'top',
- 'expand': 0, 'fill': 'x'}})
- self.title = Label(self.leftsubframe,
- {'name': 'title',
- 'text': '(none)',
- Pack: {'side': 'bottom'}})
- self.text = ManPage(self.frame,
- {'name': 'text',
- 'relief': 'sunken', 'bd': 2,
- 'wrap': 'none', 'width': 72,
- 'selectbackground': 'pink',
- Pack: {'expand': 1, 'fill': 'both'}})
+ self.listbox = Listbox(self.rightsubframe, name='listbox',
+ relief=SUNKEN, borderwidth=2,
+ width=20, height=5)
+ self.listbox.pack(expand=1, fill=BOTH)
+ self.l1 = Button(self.leftsubframe, name='l1',
+ text='Display manual page named:',
+ command=self.entry_cb)
+ self.l1.pack(side=TOP)
+ self.entry = Entry(self.leftsubframe, name='entry',
+ relief=SUNKEN, borderwidth=2,
+ width=20)
+ self.entry.pack(expand=0, fill=X)
+ self.l2frame = Frame(self.leftsubframe, name='l2frame')
+ self.l2frame.pack(expand=0, fill=NONE)
+ self.l2 = Button(self.l2frame, name='l2',
+ text='Search regexp:',
+ command=self.search_cb)
+ self.l2.pack(side=LEFT)
+ self.casevar = BooleanVar()
+ self.casesense = Checkbutton(self.l2frame, name='casesense',
+ text='Case sensitive',
+ variable=self.casevar,
+ relief=FLAT)
+ self.casesense.pack(side=LEFT)
+ self.search = Entry(self.leftsubframe, name='search',
+ relief=SUNKEN, borderwidth=2,
+ width=20)
+ self.search.pack(expand=0, fill=X)
+ self.title = Label(self.leftsubframe, name='title',
+ text='(none)')
+ self.title.pack(side=BOTTOM)
+ self.text = ManPage(self.frame, name='text',
+ relief=SUNKEN, borderwidth=2,
+ wrap=NONE, width=72,
+ selectbackground='pink')
+ self.text.pack(expand=1, fill=BOTH)
self.entry.bind('<Return>', self.entry_cb)
self.search.bind('<Return>', self.search_cb)
@@ -195,7 +179,7 @@ class SelectionBox:
self.frame.bell()
print 'Empty search string'
return
- if self.frame.tk.getvar('casesense') != '1':
+ if not self.casevar.get():
map = regex.casefold
else:
map = None