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

Skip to content

Commit 89cb67b

Browse files
committed
Updated for Python 1.4
1 parent c30e95f commit 89cb67b

43 files changed

Lines changed: 738 additions & 968 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Demo/tkinter/guido/AttrDialog.py

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ def __init__(self, dialog, option):
2424
self.master = dialog.top
2525
self.default, self.klass = dialog.options[option]
2626
self.var = self.varclass(self.master)
27-
self.frame = Frame(self.master,
28-
{Pack: {'expand': 0, 'fill': 'x'}})
29-
self.label = Label(self.frame,
30-
{'text': option + ':',
31-
Pack: {'side': 'left'},
32-
})
27+
self.frame = Frame(self.master)
28+
self.frame.pack(fill=X)
29+
self.label = Label(self.frame, text=(option + ":"))
30+
self.label.pack(side=LEFT)
3331
self.update()
3432
self.addoption()
3533

@@ -53,55 +51,48 @@ class BooleanOption(Option):
5351

5452
def addoption(self):
5553
self.button = Checkbutton(self.frame,
56-
{'text': 'on/off',
57-
'onvalue': '1',
58-
'offvalue': '0',
59-
'variable': self.var,
60-
'relief': 'raised',
61-
'borderwidth': 2,
62-
'command': self.set,
63-
Pack: {'side': 'right'},
64-
})
54+
text='on/off',
55+
onvalue=1,
56+
offvalue=0,
57+
variable=self.var,
58+
relief=RAISED,
59+
borderwidth=2,
60+
command=self.set)
61+
self.button.pack(side=RIGHT)
6562

6663
class EnumOption(Option):
6764

6865
def addoption(self):
6966
self.button = Menubutton(self.frame,
70-
{'textvariable': self.var,
71-
'relief': 'raised',
72-
'borderwidth': 2,
73-
Pack: {'side': 'right'},
74-
})
67+
textvariable=self.var,
68+
relief=RAISED, borderwidth=2)
69+
self.button.pack(side=RIGHT)
7570
self.menu = Menu(self.button)
7671
self.button['menu'] = self.menu
7772
for v in self.dialog.classes[self.klass]:
7873
self.menu.add_radiobutton(
79-
{'label': v,
80-
'variable': self.var,
81-
'value': v,
82-
'command': self.set,
83-
})
74+
label=v,
75+
variable=self.var,
76+
value=v,
77+
command=self.set)
8478

8579
class StringOption(Option):
8680

8781
def addoption(self):
8882
self.entry = Entry(self.frame,
89-
{'textvariable': self.var,
90-
'width': 10,
91-
'relief': 'sunken',
92-
'borderwidth': 2,
93-
Pack: {'side': 'right',
94-
'fill': 'x', 'expand': 1},
95-
})
83+
textvariable=self.var,
84+
width=10,
85+
relief=SUNKEN,
86+
borderwidth=2)
87+
self.entry.pack(side=RIGHT, fill=X, expand=1)
9688
self.entry.bind('<Return>', self.set)
9789

9890
class ReadonlyOption(Option):
9991

10092
def addoption(self):
101-
self.label = Label(self.frame,
102-
{'textvariable': self.var,
103-
'anchor': 'e',
104-
Pack: {'side': 'right'}})
93+
self.label = Label(self.frame, textvariable=self.var,
94+
anchor=E)
95+
self.label.pack(side=RIGHT)
10596

10697
class Dialog:
10798

@@ -156,16 +147,16 @@ def __init__(self, widget):
156147
Dialog.__init__(self, widget)
157148

158149
def refresh(self):
159-
self.current = self.widget.newinfo()
150+
self.current = self.widget.info()
160151
self.current['.class'] = self.widget.winfo_class()
161152
self.current['.name'] = self.widget._w
162153

163154
class packoption: # Mix-in class
164155
def set(self, e=None):
165156
self.current = self.var.get()
166157
try:
167-
Pack.config(self.dialog.widget,
168-
{self.option: self.current})
158+
apply(self.dialog.widget.pack, (),
159+
{self.option: self.current})
169160
except TclError, msg:
170161
print msg
171162
self.refresh()
@@ -192,14 +183,14 @@ class readonlyoption(packoption, ReadonlyOption): pass
192183
}
193184

194185
classes = {
195-
'Anchor': ('n','ne', 'e','se', 's','sw', 'w','nw', 'center'),
186+
'Anchor': (N, NE, E, SE, S, SW, W, NW, CENTER),
196187
'Boolean': 'boolean',
197188
'Class': 'readonly',
198189
'Expand': 'boolean',
199-
'Fill': ('none', 'x', 'y', 'both'),
190+
'Fill': (NONE, X, Y, BOTH),
200191
'Name': 'readonly',
201192
'Pad': 'pixel',
202-
'Side': ('top', 'right', 'bottom', 'left'),
193+
'Side': (TOP, RIGHT, BOTTOM, LEFT),
203194
'Widget': 'readonly',
204195
}
205196

@@ -220,7 +211,7 @@ def refresh(self):
220211
words = self.master.tk.splitlist(
221212
self.master.send(self.app,
222213
'pack',
223-
'newinfo',
214+
'info',
224215
self.widget))
225216
except TclError, msg:
226217
print msg
@@ -306,7 +297,7 @@ class readonlyoption(widgetoption, ReadonlyOption): pass
306297

307298
# Universal classes
308299
classes = {
309-
'Anchor': ('n','ne', 'e','se', 's','sw', 'w','nw', 'center'),
300+
'Anchor': (N, NE, E, SE, S, SW, W, NW, CENTER),
310301
'Aspect': 'integer',
311302
'Background': 'color',
312303
'Bitmap': 'bitmap',
@@ -325,16 +316,16 @@ class readonlyoption(widgetoption, ReadonlyOption): pass
325316
'Geometry': 'geometry',
326317
'Height': 'pixel',
327318
'InsertWidth': 'time',
328-
'Justify': ('left', 'center', 'right'),
319+
'Justify': (LEFT, CENTER, RIGHT),
329320
'Label': 'string',
330321
'Length': 'pixel',
331322
'MenuName': 'widget',
332323
'Name': 'readonly',
333324
'OffTime': 'time',
334325
'OnTime': 'time',
335-
'Orient': ('horizontal', 'vertical'),
326+
'Orient': (HORIZONTAL, VERTICAL),
336327
'Pad': 'pixel',
337-
'Relief': ('raised', 'sunken', 'flat', 'ridge', 'groove'),
328+
'Relief': (RAISED, SUNKEN, FLAT, RIDGE, GROOVE),
338329
'RepeatDelay': 'time',
339330
'RepeatInterval': 'time',
340331
'ScrollCommand': 'command',
@@ -351,12 +342,12 @@ class readonlyoption(widgetoption, ReadonlyOption): pass
351342
'Variable': 'variable',
352343
'Value': 'string',
353344
'Width': 'pixel',
354-
'Wrap': ('none', 'char', 'word'),
345+
'Wrap': (NONE, CHAR, WORD),
355346
}
356347

357348
# Classes that (may) differ per widget type
358-
_tristate = {'State': ('normal', 'active', 'disabled')}
359-
_bistate = {'State': ('normal', 'disabled')}
349+
_tristate = {'State': (NORMAL, ACTIVE, DISABLED)}
350+
_bistate = {'State': (NORMAL, DISABLED)}
360351
addclasses = {
361352
'Button': _tristate,
362353
'Radiobutton': _tristate,
@@ -424,14 +415,12 @@ def test():
424415
if sys.argv[1:]:
425416
remotetest(root, sys.argv[1])
426417
else:
427-
frame = Frame(root, {'name': 'frame',
428-
Pack: {'expand': 1, 'fill': 'both'},
429-
})
430-
button = Button(frame, {'name': 'button',
431-
'text': 'button',
432-
Pack: {'expand': 1}})
433-
canvas = Canvas(frame, {'name': 'canvas',
434-
Pack: {}})
418+
frame = Frame(root, name='frame')
419+
frame.pack(expand=1, fill=BOTH)
420+
button = Button(frame, name='button', text='button')
421+
button.pack(expand=1)
422+
canvas = Canvas(frame, name='canvas')
423+
canvas.pack()
435424
fpd = PackDialog(frame)
436425
fwd = WidgetDialog(frame)
437426
bpd = PackDialog(button)

Demo/tkinter/guido/ManPage.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
class EditableManPage(ScrolledText):
2121

2222
# Initialize instance
23-
def __init__(self, master=None, cnf={}):
23+
def __init__(self, master=None, **cnf):
2424
# Initialize base class
25-
ScrolledText.__init__(self, master, cnf)
25+
apply(ScrolledText.__init__, (self, master), cnf)
2626

2727
# Define tags for formatting styles
28-
self.tag_config('X', {'underline': 1})
29-
self.tag_config('!', {'font': BOLDFONT})
30-
self.tag_config('_', {'font': ITALICFONT})
28+
self.tag_config('X', underline=1)
29+
self.tag_config('!', font=BOLDFONT)
30+
self.tag_config('_', font=ITALICFONT)
3131

3232
# Set state to idle
3333
self.fp = None
@@ -83,8 +83,8 @@ def _startparser(self, fp):
8383
self.empty = 0
8484
self.buffer = None
8585
savestate = self['state']
86-
self['state'] = 'normal'
87-
self.delete('1.0', 'end')
86+
self['state'] = NORMAL
87+
self.delete('1.0', END)
8888
self['state'] = savestate
8989

9090
# End parsing -- must be busy, need not be at EOF
@@ -133,11 +133,11 @@ def _parseline(self, nextline):
133133
self.empty = 0
134134
return
135135
savestate = self['state']
136-
self['state'] = 'normal'
136+
self['state'] = NORMAL
137137
if TkVersion >= 4.0:
138138
self.mark_set('insert', 'end-1c')
139139
else:
140-
self.mark_set('insert', 'end')
140+
self.mark_set('insert', END)
141141
if self.empty:
142142
# One or more previous lines were empty
143143
# -- insert one blank line in the text
@@ -176,9 +176,9 @@ def _insert_prop(self, str, prop = ' '):
176176
class ReadonlyManPage(EditableManPage):
177177

178178
# Initialize instance
179-
def __init__(self, master=None, cnf={}):
180-
EditableManPage.__init__(self, master,
181-
(cnf, {'state': 'disabled'}))
179+
def __init__(self, master=None, **cnf):
180+
cnf['state'] = DISABLED
181+
apply(EditableManPage.__init__, (self, master), cnf)
182182

183183
# Alias
184184
ManPage = ReadonlyManPage
@@ -206,8 +206,8 @@ def test():
206206
name = os.path.join(MANDIR, name)
207207
root = Tk()
208208
root.minsize(1, 1)
209-
manpage = ManPage(root, {'relief': 'sunken', 'bd': 2,
210-
Pack: {'expand': 1, 'fill': 'both'}})
209+
manpage = ManPage(root, relief=SUNKEN, borderwidth=2)
210+
manpage.pack(expand=1, fill=BOTH)
211211
if formatted:
212212
fp = open(name, 'r')
213213
else:

0 commit comments

Comments
 (0)