Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
856023a0
Commit
856023a0
authored
Oct 25, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#3018: tkinter demo fixes for py3k.
parent
07e4f156
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
196 additions
and
179 deletions
+196
-179
Demo/tkinter/guido/AttrDialog.py
Demo/tkinter/guido/AttrDialog.py
+2
-3
Demo/tkinter/guido/MimeViewer.py
Demo/tkinter/guido/MimeViewer.py
+33
-17
Demo/tkinter/guido/ShellWindow.py
Demo/tkinter/guido/ShellWindow.py
+4
-5
Demo/tkinter/guido/canvasevents.py
Demo/tkinter/guido/canvasevents.py
+37
-17
Demo/tkinter/guido/dialog.py
Demo/tkinter/guido/dialog.py
+1
-2
Demo/tkinter/guido/electrons.py
Demo/tkinter/guido/electrons.py
+2
-2
Demo/tkinter/guido/hanoi.py
Demo/tkinter/guido/hanoi.py
+2
-2
Demo/tkinter/guido/listtree.py
Demo/tkinter/guido/listtree.py
+0
-3
Demo/tkinter/guido/mbox.py
Demo/tkinter/guido/mbox.py
+25
-22
Demo/tkinter/guido/rmt.py
Demo/tkinter/guido/rmt.py
+1
-1
Demo/tkinter/guido/solitaire.py
Demo/tkinter/guido/solitaire.py
+22
-33
Demo/tkinter/guido/sortvisu.py
Demo/tkinter/guido/sortvisu.py
+54
-51
Demo/tkinter/guido/svkill.py
Demo/tkinter/guido/svkill.py
+2
-6
Demo/tkinter/guido/tkman.py
Demo/tkinter/guido/tkman.py
+9
-9
Demo/tkinter/matt/bind-w-mult-calls-p-type.py
Demo/tkinter/matt/bind-w-mult-calls-p-type.py
+0
-1
Demo/tkinter/matt/entry-with-shared-variable.py
Demo/tkinter/matt/entry-with-shared-variable.py
+1
-2
Demo/tkinter/matt/pong-demo-1.py
Demo/tkinter/matt/pong-demo-1.py
+0
-2
Demo/tkinter/matt/printing-coords-of-items.py
Demo/tkinter/matt/printing-coords-of-items.py
+1
-1
No files found.
Demo/tkinter/guido/AttrDialog.py
View file @
856023a0
...
@@ -120,7 +120,7 @@ class Dialog:
...
@@ -120,7 +120,7 @@ class Dialog:
cl
=
self
.
classes
[
c
]
cl
=
self
.
classes
[
c
]
except
KeyError
:
except
KeyError
:
cl
=
'unknown'
cl
=
'unknown'
if
type
(
cl
)
==
tuple
:
if
type
(
cl
)
is
tuple
:
cl
=
self
.
enumoption
cl
=
self
.
enumoption
elif
cl
==
'boolean'
:
elif
cl
==
'boolean'
:
cl
=
self
.
booleanoption
cl
=
self
.
booleanoption
...
@@ -435,12 +435,11 @@ def remotetest(root, app):
...
@@ -435,12 +435,11 @@ def remotetest(root, app):
list
.
app
=
app
# Pass it on to handler
list
.
app
=
app
# Pass it on to handler
def
opendialogs
(
e
):
def
opendialogs
(
e
):
import
string
list
=
e
.
widget
list
=
e
.
widget
sel
=
list
.
curselection
()
sel
=
list
.
curselection
()
for
i
in
sel
:
for
i
in
sel
:
item
=
list
.
get
(
i
)
item
=
list
.
get
(
i
)
widget
=
string
.
split
(
item
)[
0
]
widget
=
item
.
split
(
)[
0
]
RemoteWidgetDialog
(
list
,
list
.
app
,
widget
)
RemoteWidgetDialog
(
list
,
list
.
app
,
widget
)
if
widget
==
'.'
:
continue
if
widget
==
'.'
:
continue
try
:
try
:
...
...
Demo/tkinter/guido/MimeViewer.py
View file @
856023a0
...
@@ -3,11 +3,27 @@
...
@@ -3,11 +3,27 @@
# View a single MIME multipart message.
# View a single MIME multipart message.
# Display each part as a box.
# Display each part as a box.
import
string
import
os
from
types
import
*
import
sys
import
getopt
import
mailbox
from
tkinter
import
*
from
tkinter
import
*
from
tkinter.scrolledtext
import
ScrolledText
from
tkinter.scrolledtext
import
ScrolledText
MBOXPATH
=
os
.
environ
[
'HOME'
]
+
'/Mail'
class
Error
(
Exception
):
pass
def
getcurrent
(
self
):
"""Return the current message. Raise Error when there is none."""
seqs
=
self
.
get_sequences
()
try
:
return
max
(
seqs
[
'cur'
])
except
(
ValueError
,
KeyError
):
raise
Error
(
"no cur message"
)
class
MimeViewer
:
class
MimeViewer
:
def
__init__
(
self
,
parent
,
title
,
msg
):
def
__init__
(
self
,
parent
,
title
,
msg
):
self
.
title
=
title
self
.
title
=
title
...
@@ -18,8 +34,10 @@ class MimeViewer:
...
@@ -18,8 +34,10 @@ class MimeViewer:
{
'text'
:
title
,
{
'text'
:
title
,
'command'
:
self
.
toggle
})
'command'
:
self
.
toggle
})
self
.
button
.
pack
({
'anchor'
:
'w'
})
self
.
button
.
pack
({
'anchor'
:
'w'
})
headertext
=
msg
.
getheadertext
(
headertext
=
[]
lambda
x
:
x
!=
'received'
and
x
[:
5
]
!=
'x400-'
)
for
item
in
msg
.
items
():
headertext
.
append
(
"%s: %s"
%
item
)
headertext
=
'
\
n
'
.
join
(
headertext
)
height
=
countlines
(
headertext
,
4
)
height
=
countlines
(
headertext
,
4
)
if
height
:
if
height
:
self
.
htext
=
ScrolledText
(
self
.
frame
,
self
.
htext
=
ScrolledText
(
self
.
frame
,
...
@@ -38,8 +56,8 @@ class MimeViewer:
...
@@ -38,8 +56,8 @@ class MimeViewer:
'ipady'
:
2
,
'ipady'
:
2
,
'fill'
:
'x'
,
'fill'
:
'x'
,
'after'
:
self
.
button
}
'after'
:
self
.
button
}
body
=
msg
.
get
body
()
body
=
msg
.
get
_payload
()
if
type
(
body
)
==
StringType
:
if
type
(
body
)
==
str
:
self
.
pad
=
None
self
.
pad
=
None
height
=
countlines
(
body
,
10
)
height
=
countlines
(
body
,
10
)
if
height
:
if
height
:
...
@@ -102,16 +120,13 @@ def countlines(str, limit):
...
@@ -102,16 +120,13 @@ def countlines(str, limit):
i
=
0
i
=
0
n
=
0
n
=
0
while
n
<
limit
:
while
n
<
limit
:
i
=
str
ing
.
find
(
str
,
'
\
n
'
,
i
)
i
=
str
.
find
(
'
\
n
'
,
i
)
if
i
<
0
:
break
if
i
<
0
:
break
n
=
n
+
1
n
=
n
+
1
i
=
i
+
1
i
=
i
+
1
return
n
return
n
def
main
():
def
main
():
import
sys
import
getopt
import
mhlib
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
''
)
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
''
)
for
o
,
a
in
opts
:
for
o
,
a
in
opts
:
pass
pass
...
@@ -121,13 +136,13 @@ def main():
...
@@ -121,13 +136,13 @@ def main():
if
arg
[:
1
]
==
'+'
:
if
arg
[:
1
]
==
'+'
:
folder
=
arg
[
1
:]
folder
=
arg
[
1
:]
else
:
else
:
message
=
string
.
atoi
(
arg
)
message
=
int
(
arg
)
mh
=
m
hlib
.
MH
(
)
mh
=
m
ailbox
.
MH
(
MBOXPATH
)
f
=
mh
.
open
folder
(
folder
)
f
=
mh
.
get_
folder
(
folder
)
if
not
messag
e
:
if
message
is
Non
e
:
message
=
f
.
getcurrent
(
)
message
=
getcurrent
(
f
)
m
=
f
.
openmessage
(
message
)
m
=
mailbox
.
MHMessage
(
f
.
get
(
message
)
)
root
=
Tk
()
root
=
Tk
()
tk
=
root
.
tk
tk
=
root
.
tk
...
@@ -140,4 +155,5 @@ def main():
...
@@ -140,4 +155,5 @@ def main():
tk
.
mainloop
()
tk
.
mainloop
()
if
__name__
==
'__main__'
:
main
()
if
__name__
==
'__main__'
:
main
()
Demo/tkinter/guido/ShellWindow.py
View file @
856023a0
import
os
import
os
import
sys
import
sys
import
string
from
tkinter
import
*
from
tkinter
import
*
from
tkinter.scrolledtext
import
ScrolledText
from
tkinter.scrolledtext
import
ScrolledText
from
tkinter.dialog
import
Dialog
from
tkinter.dialog
import
Dialog
...
@@ -17,7 +16,7 @@ class ShellWindow(ScrolledText):
...
@@ -17,7 +16,7 @@ class ShellWindow(ScrolledText):
except
KeyError
:
except
KeyError
:
shell
=
'/bin/sh'
shell
=
'/bin/sh'
shell
=
shell
+
' -i'
shell
=
shell
+
' -i'
args
=
s
tring
.
split
(
shell
)
args
=
s
hell
.
split
(
)
shell
=
args
[
0
]
shell
=
args
[
0
]
ScrolledText
.
__init__
(
self
,
master
,
**
cnf
)
ScrolledText
.
__init__
(
self
,
master
,
**
cnf
)
...
@@ -33,7 +32,7 @@ class ShellWindow(ScrolledText):
...
@@ -33,7 +32,7 @@ class ShellWindow(ScrolledText):
self
.
outputhandler
)
self
.
outputhandler
)
def
outputhandler
(
self
,
file
,
mask
):
def
outputhandler
(
self
,
file
,
mask
):
data
=
os
.
read
(
file
,
BUFSIZE
)
data
=
os
.
read
(
file
,
BUFSIZE
)
.
decode
()
if
not
data
:
if
not
data
:
self
.
tk
.
deletefilehandler
(
file
)
self
.
tk
.
deletefilehandler
(
file
)
pid
,
sts
=
os
.
waitpid
(
self
.
pid
,
0
)
pid
,
sts
=
os
.
waitpid
(
self
.
pid
,
0
)
...
@@ -65,7 +64,7 @@ class ShellWindow(ScrolledText):
...
@@ -65,7 +64,7 @@ class ShellWindow(ScrolledText):
self
.
insert
(
END
,
"
\
n
"
)
self
.
insert
(
END
,
"
\
n
"
)
line
=
self
.
get
(
self
.
pos
,
"end - 1 char"
)
line
=
self
.
get
(
self
.
pos
,
"end - 1 char"
)
self
.
pos
=
self
.
index
(
END
)
self
.
pos
=
self
.
index
(
END
)
os
.
write
(
self
.
tochild
,
line
)
os
.
write
(
self
.
tochild
,
line
.
encode
()
)
return
"break"
return
"break"
def
sendeof
(
self
,
*
args
):
def
sendeof
(
self
,
*
args
):
...
@@ -132,7 +131,7 @@ def spawn(prog, args):
...
@@ -132,7 +131,7 @@ def spawn(prog, args):
return
pid
,
c2pread
,
p2cwrite
return
pid
,
c2pread
,
p2cwrite
def
test
():
def
test
():
shell
=
string
.
join
(
sys
.
argv
[
1
:
])
shell
=
' '
.
join
(
sys
.
argv
[
1
:
])
root
=
Tk
()
root
=
Tk
()
root
.
minsize
(
1
,
1
)
root
.
minsize
(
1
,
1
)
if
shell
:
if
shell
:
...
...
Demo/tkinter/guido/canvasevents.py
View file @
856023a0
#! /usr/bin/env python3
#! /usr/bin/env python3
from
tkinter
import
*
from
tkinter
import
*
from
Canvas
import
Oval
,
Group
,
CanvasText
# Fix a bug in Canvas.Group as distributed in Python 1.4. The
# Since Canvas.Group is no longer present, the following class reproduces
# distributed bind() method is broken. This is what should be used:
# a subset of the old Group class that is used by this app.
class
Group
:
def
__init__
(
self
,
canvas
,
tag
=
None
):
if
tag
is
None
:
tag
=
'Group%d'
%
id
(
self
)
self
.
tag
=
self
.
id
=
tag
self
.
canvas
=
canvas
self
.
canvas
.
dtag
(
self
.
tag
)
def
__str__
(
self
):
return
self
.
tag
def
_do
(
self
,
cmd
,
*
args
):
return
self
.
canvas
.
tk
.
call
(
self
.
canvas
.
_w
,
cmd
,
self
.
tag
,
*
args
)
def
addtag_withtag
(
self
,
tagOrId
):
self
.
_do
(
'addtag'
,
'withtag'
,
tagOrId
)
def
bind
(
self
,
sequence
=
None
,
command
=
None
,
add
=
None
):
return
self
.
canvas
.
tag_bind
(
self
.
id
,
sequence
,
command
,
add
)
def
move
(
self
,
x_amount
,
y_amount
):
self
.
_do
(
'move'
,
x_amount
,
y_amount
)
def
dtag
(
self
,
tagToDelete
=
None
):
self
.
_do
(
'dtag'
,
tagToDelete
)
def
tkraise
(
self
,
aboveThis
=
None
):
self
.
_do
(
'raise'
,
aboveThis
)
class
Group
(
Group
):
def
bind
(
self
,
sequence
=
None
,
command
=
None
):
return
self
.
canvas
.
tag_bind
(
self
.
id
,
sequence
,
command
)
class
Object
:
class
Object
:
...
@@ -29,7 +55,6 @@ class Object:
...
@@ -29,7 +55,6 @@ class Object:
All instance attributes are public since the derived class may
All instance attributes are public since the derived class may
need them.
need them.
"""
"""
def
__init__
(
self
,
canvas
,
x
=
0
,
y
=
0
,
fill
=
'red'
,
text
=
'object'
):
def
__init__
(
self
,
canvas
,
x
=
0
,
y
=
0
,
fill
=
'red'
,
text
=
'object'
):
...
@@ -44,12 +69,10 @@ class Object:
...
@@ -44,12 +69,10 @@ class Object:
return
str
(
self
.
group
)
return
str
(
self
.
group
)
def
createitems
(
self
,
fill
,
text
):
def
createitems
(
self
,
fill
,
text
):
self
.
__oval
=
Oval
(
self
.
canvas
,
self
.
__oval
=
self
.
canvas
.
create_oval
(
self
.
x
-
20
,
self
.
y
-
10
,
self
.
x
-
20
,
self
.
y
-
10
,
self
.
x
+
20
,
self
.
y
+
10
,
self
.
x
+
20
,
self
.
y
+
20
,
fill
=
fill
,
width
=
3
)
fill
=
fill
,
width
=
3
)
self
.
group
.
addtag_withtag
(
self
.
__oval
)
self
.
group
.
addtag_withtag
(
self
.
__oval
)
self
.
__text
=
CanvasText
(
self
.
canvas
,
self
.
__text
=
self
.
canvas
.
create_text
(
self
.
x
,
self
.
y
,
text
=
text
)
self
.
x
,
self
.
y
,
text
=
text
)
self
.
group
.
addtag_withtag
(
self
.
__text
)
self
.
group
.
addtag_withtag
(
self
.
__text
)
def
moveby
(
self
,
dx
,
dy
):
def
moveby
(
self
,
dx
,
dy
):
...
@@ -75,18 +98,15 @@ class Object:
...
@@ -75,18 +98,15 @@ class Object:
class
Bottom
(
Object
):
class
Bottom
(
Object
):
"""An object to serve as the bottom of a pile."""
"""An object to serve as the bottom of a pile."""
def
createitems
(
self
,
*
args
):
def
createitems
(
self
,
*
args
):
self
.
__oval
=
Oval
(
self
.
canvas
,
self
.
__oval
=
self
.
canvas
.
create_oval
(
self
.
x
-
20
,
self
.
y
-
10
,
self
.
x
-
20
,
self
.
y
-
10
,
self
.
x
+
20
,
self
.
y
+
10
,
self
.
x
+
20
,
self
.
y
+
10
,
fill
=
'gray'
,
outline
=
''
)
fill
=
'gray'
,
outline
=
''
)
self
.
group
.
addtag_withtag
(
self
.
__oval
)
self
.
group
.
addtag_withtag
(
self
.
__oval
)
class
Pile
:
class
Pile
:
"""A group of graphical objects."""
"""A group of graphical objects."""
def
__init__
(
self
,
canvas
,
x
,
y
,
tag
=
None
):
def
__init__
(
self
,
canvas
,
x
,
y
,
tag
=
None
):
...
...
Demo/tkinter/guido/dialog.py
View file @
856023a0
...
@@ -24,8 +24,7 @@ def dialog(master, title, text, bitmap, default, *args):
...
@@ -24,8 +24,7 @@ def dialog(master, title, text, bitmap, default, *args):
# 2. Fill the top part with the bitmap and message.
# 2. Fill the top part with the bitmap and message.
msg
=
Message
(
top
,
width
=
'3i'
,
text
=
text
,
msg
=
Message
(
top
,
width
=
'3i'
,
text
=
text
)
font
=
'-Adobe-Times-Medium-R-Normal-*-180-*'
)
msg
.
pack
(
side
=
RIGHT
,
expand
=
1
,
fill
=
BOTH
,
padx
=
'3m'
,
pady
=
'3m'
)
msg
.
pack
(
side
=
RIGHT
,
expand
=
1
,
fill
=
BOTH
,
padx
=
'3m'
,
pady
=
'3m'
)
if
bitmap
:
if
bitmap
:
bm
=
Label
(
top
,
bitmap
=
bitmap
)
bm
=
Label
(
top
,
bitmap
=
bitmap
)
...
...
Demo/tkinter/guido/electrons.py
View file @
856023a0
...
@@ -62,11 +62,11 @@ class Electrons:
...
@@ -62,11 +62,11 @@ class Electrons:
# Main program
# Main program
def
main
():
def
main
():
import
sys
,
string
import
sys
# First argument is number of electrons, default 30
# First argument is number of electrons, default 30
if
sys
.
argv
[
1
:]:
if
sys
.
argv
[
1
:]:
n
=
string
.
atoi
(
sys
.
argv
[
1
])
n
=
int
(
sys
.
argv
[
1
])
else
:
else
:
n
=
30
n
=
30
...
...
Demo/tkinter/guido/hanoi.py
View file @
856023a0
...
@@ -125,11 +125,11 @@ class Tkhanoi:
...
@@ -125,11 +125,11 @@ class Tkhanoi:
# Main program
# Main program
def
main
():
def
main
():
import
sys
,
string
import
sys
# First argument is number of pegs, default 4
# First argument is number of pegs, default 4
if
sys
.
argv
[
1
:]:
if
sys
.
argv
[
1
:]:
n
=
string
.
atoi
(
sys
.
argv
[
1
])
n
=
int
(
sys
.
argv
[
1
])
else
:
else
:
n
=
4
n
=
4
...
...
Demo/tkinter/guido/listtree.py
View file @
856023a0
# List a remote app's widget tree (names and classes only)
# List a remote app's widget tree (names and classes only)
import
sys
import
sys
import
string
from
tkinter
import
*
from
tkinter
import
*
...
@@ -13,8 +12,6 @@ def listtree(master, app):
...
@@ -13,8 +12,6 @@ def listtree(master, app):
def
listnodes
(
list
,
app
,
widget
,
level
):
def
listnodes
(
list
,
app
,
widget
,
level
):
klass
=
list
.
send
(
app
,
'winfo'
,
'class'
,
widget
)
klass
=
list
.
send
(
app
,
'winfo'
,
'class'
,
widget
)
## i = string.rindex(widget, '.')
## list.insert(END, '%s%s (%s)' % ((level-1)*'. ', widget[i:], klass))
list
.
insert
(
END
,
'%s (%s)'
%
(
widget
,
klass
))
list
.
insert
(
END
,
'%s (%s)'
%
(
widget
,
klass
))
children
=
list
.
tk
.
splitlist
(
children
=
list
.
tk
.
splitlist
(
list
.
send
(
app
,
'winfo'
,
'children'
,
widget
))
list
.
send
(
app
,
'winfo'
,
'children'
,
widget
))
...
...
Demo/tkinter/guido/mbox.py
View file @
856023a0
...
@@ -3,17 +3,15 @@
...
@@ -3,17 +3,15 @@
# Scan MH folder, display results in window
# Scan MH folder, display results in window
import
os
import
os
import
sys
import
re
import
re
import
sys
import
getopt
import
getopt
import
string
import
mailbox
import
mhlib
from
tkinter
import
*
from
tkinter
import
*
from
dialog
import
dialog
from
dialog
import
dialog
mailbox
=
os
.
environ
[
'HOME'
]
+
'/Mail'
MBOXPATH
=
os
.
environ
[
'HOME'
]
+
'/Mail'
def
main
():
def
main
():
global
root
,
tk
,
top
,
mid
,
bot
global
root
,
tk
,
top
,
mid
,
bot
...
@@ -38,8 +36,8 @@ def main():
...
@@ -38,8 +36,8 @@ def main():
# Initialize MH
# Initialize MH
mh
=
m
hlib
.
MH
(
)
mh
=
m
ailbox
.
MH
(
MBOXPATH
)
mhf
=
mh
.
open
folder
(
folder
)
mhf
=
mh
.
get_
folder
(
folder
)
# Build widget hierarchy
# Build widget hierarchy
...
@@ -171,7 +169,7 @@ def open_folder(e=None):
...
@@ -171,7 +169,7 @@ def open_folder(e=None):
return
return
i
=
sel
[
0
]
i
=
sel
[
0
]
folder
=
folderbox
.
get
(
i
)
folder
=
folderbox
.
get
(
i
)
mhf
=
mh
.
open
folder
(
folder
)
mhf
=
mh
.
get_
folder
(
folder
)
rescan
()
rescan
()
def
open_message
(
e
=
None
):
def
open_message
(
e
=
None
):
...
@@ -189,9 +187,10 @@ def open_message(e=None):
...
@@ -189,9 +187,10 @@ def open_message(e=None):
tk
.
call
(
'update'
,
'idletasks'
)
tk
.
call
(
'update'
,
'idletasks'
)
i
=
sel
[
0
]
i
=
sel
[
0
]
line
=
scanbox
.
get
(
i
)
line
=
scanbox
.
get
(
i
)
if
scanparser
.
match
(
line
)
>=
0
:
m
=
scanparser
.
match
(
line
)
num
=
string
.
atoi
(
scanparser
.
group
(
1
))
if
m
:
m
=
mhf
.
openmessage
(
num
)
num
=
int
(
m
.
group
(
1
))
m
=
mhf
.
get_message
(
num
)
if
viewer
:
viewer
.
destroy
()
if
viewer
:
viewer
.
destroy
()
from
MimeViewer
import
MimeViewer
from
MimeViewer
import
MimeViewer
viewer
=
MimeViewer
(
bot
,
'+%s/%d'
%
(
folder
,
num
),
m
)
viewer
=
MimeViewer
(
bot
,
'+%s/%d'
%
(
folder
,
num
),
m
)
...
@@ -212,9 +211,11 @@ def remove_message(e=None):
...
@@ -212,9 +211,11 @@ def remove_message(e=None):
todo
=
[]
todo
=
[]
for
i
in
sel
:
for
i
in
sel
:
line
=
scanbox
.
get
(
i
)
line
=
scanbox
.
get
(
i
)
if
scanparser
.
match
(
line
)
>=
0
:
m
=
scanparser
.
match
(
line
)
todo
.
append
(
string
.
atoi
(
scanparser
.
group
(
1
)))
if
m
:
mhf
.
removemessages
(
todo
)
toremove
=
int
(
m
.
group
(
1
))
todo
.
append
(
toremove
)
mhf
.
remove
(
toremove
)
rescan
()
rescan
()
fixfocus
(
min
(
todo
),
itop
)
fixfocus
(
min
(
todo
),
itop
)
...
@@ -240,12 +241,13 @@ def refile_message(e=None):
...
@@ -240,12 +241,13 @@ def refile_message(e=None):
todo
=
[]
todo
=
[]
for
i
in
sel
:
for
i
in
sel
:
line
=
scanbox
.
get
(
i
)
line
=
scanbox
.
get
(
i
)
if
scanparser
.
match
(
line
)
>=
0
:
m
=
scanparser
.
match
(
line
)
todo
.
append
(
string
.
atoi
(
scanparser
.
group
(
1
)))
if
m
:
todo
.
append
(
int
(
m
.
group
(
1
)))
if
lastrefile
!=
refileto
or
not
tofolder
:
if
lastrefile
!=
refileto
or
not
tofolder
:
lastrefile
=
refileto
lastrefile
=
refileto
tofolder
=
None
tofolder
=
None
tofolder
=
mh
.
open
folder
(
lastrefile
)
tofolder
=
mh
.
get_
folder
(
lastrefile
)
mhf
.
refilemessages
(
todo
,
tofolder
)
mhf
.
refilemessages
(
todo
,
tofolder
)
rescan
()
rescan
()
fixfocus
(
min
(
todo
),
itop
)
fixfocus
(
min
(
todo
),
itop
)
...
@@ -254,18 +256,18 @@ def fixfocus(near, itop):
...
@@ -254,18 +256,18 @@ def fixfocus(near, itop):
n
=
scanbox
.
size
()
n
=
scanbox
.
size
()
for
i
in
range
(
n
):
for
i
in
range
(
n
):
line
=
scanbox
.
get
(
repr
(
i
))
line
=
scanbox
.
get
(
repr
(
i
))
if
scanparser
.
match
(
line
)
>=
0
:
m
=
scanparser
.
match
(
line
)
num
=
string
.
atoi
(
scanparser
.
group
(
1
))
if
m
:
num
=
int
(
m
.
group
(
1
))
if
num
>=
near
:
if
num
>=
near
:
break
break
else
:
else
:
i
=
'end'
i
=
'end'
scanbox
.
select_from
(
i
)
scanbox
.
yview
(
itop
)
scanbox
.
yview
(
itop
)
def
setfolders
():
def
setfolders
():
folderbox
.
delete
(
0
,
'end'
)
folderbox
.
delete
(
0
,
'end'
)
for
fn
in
mh
.
list
all
folders
():
for
fn
in
mh
.
list
_
folders
():
folderbox
.
insert
(
'end'
,
fn
)
folderbox
.
insert
(
'end'
,
fn
)
def
rescan
():
def
rescan
():
...
@@ -278,6 +280,7 @@ def rescan():
...
@@ -278,6 +280,7 @@ def rescan():
scanbox
.
insert
(
'end'
,
line
)
scanbox
.
insert
(
'end'
,
line
)
def
scanfolder
(
folder
=
'inbox'
,
sequence
=
'all'
):
def
scanfolder
(
folder
=
'inbox'
,
sequence
=
'all'
):
return
[
line
[:
-
1
]
for
line
in
os
.
popen
(
'scan +%s %s'
%
(
folder
,
sequence
),
'r'
).
readlines
()]
return
[
line
[:
-
1
]
for
line
in
os
.
popen
(
'scan +%s %s'
%
(
folder
,
sequence
),
'r'
).
readlines
()]
main
()
main
()
Demo/tkinter/guido/rmt.py
View file @
856023a0
...
@@ -28,7 +28,7 @@ s = Scrollbar(f, relief=FLAT)
...
@@ -28,7 +28,7 @@ s = Scrollbar(f, relief=FLAT)
s
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
s
.
pack
(
side
=
RIGHT
,
fill
=
Y
)
t
=
Text
(
f
,
relief
=
RAISED
,
borderwidth
=
2
,
yscrollcommand
=
s
.
set
,
setgrid
=
1
)
t
=
Text
(
f
,
relief
=
RAISED
,
borderwidth
=
2
,
yscrollcommand
=
s
.
set
,
setgrid
=
1
)
t
.
pack
(
side
=
LEFT
,
fill
=
BOTH
,
expand
=
1
)
t
.
pack
(
side
=
LEFT
,
fill
=
BOTH
,
expand
=
1
)
t
.
tag_config
(
'bold'
,
font
=
'-Adobe-Courier-Bold-R-Normal-*-120-*'
)
t
.
tag_config
(
'bold'
)
s
[
'command'
]
=
t
.
yview
s
[
'command'
]
=
t
.
yview
root
.
title
(
'Tk Remote Controller'
)
root
.
title
(
'Tk Remote Controller'
)
...
...
Demo/tkinter/guido/solitaire.py
View file @
856023a0
...
@@ -22,20 +22,10 @@ know!
...
@@ -22,20 +22,10 @@ know!
# Imports
# Imports
import
math
import
random
import
random
from
tkinter
import
*
from
tkinter
import
*
from
Canvas
import
Rectangle
,
CanvasText
,
Group
,
Window
from
canvasevents
import
Group
# Fix a bug in Canvas.Group as distributed in Python 1.4. The
# distributed bind() method is broken. Rather than asking you to fix
# the source, we fix it here by deriving a subclass:
class
Group
(
Group
):
def
bind
(
self
,
sequence
=
None
,
command
=
None
):
return
self
.
canvas
.
tag_bind
(
self
.
id
,
sequence
,
command
)
# Constants determining the size and lay-out of cards and stacks. We
# Constants determining the size and lay-out of cards and stacks. We
...
@@ -165,20 +155,22 @@ class Card:
...
@@ -165,20 +155,22 @@ class Card:
self
.
face_shown
=
0
self
.
face_shown
=
0
self
.
x
=
self
.
y
=
0
self
.
x
=
self
.
y
=
0
self
.
canvas
=
canvas
self
.
group
=
Group
(
canvas
)
self
.
group
=
Group
(
canvas
)
text
=
"%s %s"
%
(
VALNAMES
[
value
],
suit
)
text
=
"%s %s"
%
(
VALNAMES
[
value
],
suit
)
self
.
__text
=
CanvasText
(
canvas
,
CARDWIDTH
//
2
,
0
,
self
.
__text
=
canvas
.
create_text
(
CARDWIDTH
//
2
,
0
,
anchor
=
N
,
anchor
=
N
,
fill
=
self
.
color
,
text
=
text
)
fill
=
self
.
color
,
text
=
text
)
self
.
group
.
addtag_withtag
(
self
.
__text
)
self
.
group
.
addtag_withtag
(
self
.
__text
)
self
.
__rect
=
Rectangle
(
canvas
,
0
,
0
,
CARDWIDTH
,
CARDHEIGHT
,
self
.
__rect
=
canvas
.
create_rectangle
(
0
,
0
,
CARDWIDTH
,
CARDHEIGHT
,
outline
=
'black'
,
fill
=
'white'
)
outline
=
'black'
,
fill
=
'white'
)
self
.
group
.
addtag_withtag
(
self
.
__rect
)
self
.
group
.
addtag_withtag
(
self
.
__rect
)
self
.
__back
=
Rectangle
(
canvas
,
MARGIN
,
MARGIN
,
self
.
__back
=
canvas
.
create_rectangle
(
MARGIN
,
MARGIN
,
CARDWIDTH
-
MARGIN
,
CARDHEIGHT
-
MARGIN
,
CARDWIDTH
-
MARGIN
,
outline
=
'black'
,
fill
=
'blue'
)
CARDHEIGHT
-
MARGIN
,
outline
=
'black'
,
fill
=
'blue'
)
self
.
group
.
addtag_withtag
(
self
.
__back
)
self
.
group
.
addtag_withtag
(
self
.
__back
)
def
__repr__
(
self
):
def
__repr__
(
self
):
...
@@ -202,15 +194,15 @@ class Card:
...
@@ -202,15 +194,15 @@ class Card:
def
showface
(
self
):
def
showface
(
self
):
"""Turn the card's face up."""
"""Turn the card's face up."""
self
.
tkraise
()
self
.
tkraise
()
self
.
__rect
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
self
.
__rect
)
self
.
__text
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
self
.
__text
)
self
.
face_shown
=
1
self
.
face_shown
=
1
def
showback
(
self
):
def
showback
(
self
):
"""Turn the card's face down."""
"""Turn the card's face down."""
self
.
tkraise
()
self
.
tkraise
()
self
.
__rect
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
self
.
__rect
)
self
.
__back
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
self
.
__back
)
self
.
face_shown
=
0
self
.
face_shown
=
0
...
@@ -400,10 +392,9 @@ class Deck(Stack):
...
@@ -400,10 +392,9 @@ class Deck(Stack):
"""
"""
def
makebottom
(
self
):
def
makebottom
(
self
):
bottom
=
Rectangle
(
self
.
game
.
canvas
,
bottom
=
self
.
game
.
canvas
.
create_rectangle
(
self
.
x
,
self
.
y
,
self
.
x
,
self
.
y
,
self
.
x
+
CARDWIDTH
,
self
.
y
+
CARDHEIGHT
,
outline
=
'black'
,
self
.
x
+
CARDWIDTH
,
self
.
y
+
CARDHEIGHT
,
fill
=
BACKGROUND
)
outline
=
'black'
,
fill
=
BACKGROUND
)
self
.
group
.
addtag_withtag
(
bottom
)
self
.
group
.
addtag_withtag
(
bottom
)
def
fill
(
self
):
def
fill
(
self
):
...
@@ -435,7 +426,7 @@ class Deck(Stack):
...
@@ -435,7 +426,7 @@ class Deck(Stack):
def
randperm
(
n
):
def
randperm
(
n
):
"""Function returning a random permutation of range(n)."""
"""Function returning a random permutation of range(n)."""
r
=
range
(
n
)
r
=
list
(
range
(
n
)
)
x
=
[]
x
=
[]
while
r
:
while
r
:
i
=
random
.
choice
(
r
)
i
=
random
.
choice
(
r
)
...
@@ -478,10 +469,8 @@ class OpenStack(Stack):
...
@@ -478,10 +469,8 @@ class OpenStack(Stack):
class
SuitStack
(
OpenStack
):
class
SuitStack
(
OpenStack
):
def
makebottom
(
self
):
def
makebottom
(
self
):
bottom
=
Rectangle
(
self
.
game
.
canvas
,
bottom
=
self
.
game
.
canvas
.
create_rectangle
(
self
.
x
,
self
.
y
,
self
.
x
,
self
.
y
,
self
.
x
+
CARDWIDTH
,
self
.
y
+
CARDHEIGHT
,
outline
=
'black'
,
fill
=
''
)
self
.
x
+
CARDWIDTH
,
self
.
y
+
CARDHEIGHT
,
outline
=
'black'
,
fill
=
''
)
def
userclickhandler
(
self
):
def
userclickhandler
(
self
):
pass
pass
...
@@ -540,8 +529,8 @@ class Solitaire:
...
@@ -540,8 +529,8 @@ class Solitaire:
background
=
BACKGROUND
,
background
=
BACKGROUND
,
activebackground
=
"green"
,
activebackground
=
"green"
,
command
=
self
.
deal
)
command
=
self
.
deal
)
Window
(
self
.
canvas
,
MARGIN
,
3
*
YSPACING
+
20
,
self
.
canvas
.
create_window
(
MARGIN
,
3
*
YSPACING
+
20
,
window
=
self
.
dealbutton
,
anchor
=
SW
)
window
=
self
.
dealbutton
,
anchor
=
SW
)
x
=
MARGIN
x
=
MARGIN
y
=
MARGIN
y
=
MARGIN
...
...
Demo/tkinter/guido/sortvisu.py
View file @
856023a0
...
@@ -20,7 +20,6 @@ stand-alone application.
...
@@ -20,7 +20,6 @@ stand-alone application.
from
tkinter
import
*
from
tkinter
import
*
from
Canvas
import
Line
,
Rectangle
import
random
import
random
...
@@ -31,6 +30,9 @@ WIDTH = 6
...
@@ -31,6 +30,9 @@ WIDTH = 6
class
Array
:
class
Array
:
class
Cancelled
(
BaseException
):
pass
def
__init__
(
self
,
master
,
data
=
None
):
def
__init__
(
self
,
master
,
data
=
None
):
self
.
master
=
master
self
.
master
=
master
self
.
frame
=
Frame
(
self
.
master
)
self
.
frame
=
Frame
(
self
.
master
)
...
@@ -41,9 +43,9 @@ class Array:
...
@@ -41,9 +43,9 @@ class Array:
self
.
canvas
.
pack
()
self
.
canvas
.
pack
()
self
.
report
=
Label
(
self
.
frame
)
self
.
report
=
Label
(
self
.
frame
)
self
.
report
.
pack
()
self
.
report
.
pack
()
self
.
left
=
Line
(
self
.
canvas
,
0
,
0
,
0
,
0
)
self
.
left
=
self
.
canvas
.
create_line
(
0
,
0
,
0
,
0
)
self
.
right
=
Line
(
self
.
canvas
,
0
,
0
,
0
,
0
)
self
.
right
=
self
.
canvas
.
create_line
(
0
,
0
,
0
,
0
)
self
.
pivot
=
Line
(
self
.
canvas
,
0
,
0
,
0
,
0
)
self
.
pivot
=
self
.
canvas
.
create_line
(
0
,
0
,
0
,
0
)
self
.
items
=
[]
self
.
items
=
[]
self
.
size
=
self
.
maxvalue
=
0
self
.
size
=
self
.
maxvalue
=
0
if
data
:
if
data
:
...
@@ -82,8 +84,6 @@ class Array:
...
@@ -82,8 +84,6 @@ class Array:
if
self
.
in_mainloop
:
if
self
.
in_mainloop
:
self
.
master
.
quit
()
self
.
master
.
quit
()
Cancelled
=
"Array.Cancelled"
# Exception
def
wait
(
self
,
msecs
):
def
wait
(
self
,
msecs
):
if
self
.
speed
==
"fastest"
:
if
self
.
speed
==
"fastest"
:
msecs
=
0
msecs
=
0
...
@@ -110,15 +110,15 @@ class Array:
...
@@ -110,15 +110,15 @@ class Array:
for
i
in
range
(
self
.
size
):
for
i
in
range
(
self
.
size
):
item
=
self
.
items
[
i
]
item
=
self
.
items
[
i
]
if
first
<=
i
<
last
:
if
first
<=
i
<
last
:
item
.
item
.
config
(
fill
=
'red'
)
self
.
canvas
.
itemconfig
(
item
,
fill
=
'red'
)
else
:
else
:
item
.
item
.
config
(
fill
=
'orange'
)
self
.
canvas
.
itemconfig
(
item
,
fill
=
'orange'
)
self
.
hide_left_right_pivot
()
self
.
hide_left_right_pivot
()
def
hide_partition
(
self
):
def
hide_partition
(
self
):
for
i
in
range
(
self
.
size
):
for
i
in
range
(
self
.
size
):
item
=
self
.
items
[
i
]
item
=
self
.
items
[
i
]
item
.
item
.
config
(
fill
=
'red'
)
self
.
canvas
.
itemconfig
(
item
,
fill
=
'red'
)
self
.
hide_left_right_pivot
()
self
.
hide_left_right_pivot
()
def
show_left
(
self
,
left
):
def
show_left
(
self
,
left
):
...
@@ -127,7 +127,7 @@ class Array:
...
@@ -127,7 +127,7 @@ class Array:
return
return
x1
,
y1
,
x2
,
y2
=
self
.
items
[
left
].
position
()
x1
,
y1
,
x2
,
y2
=
self
.
items
[
left
].
position
()
## top, bot = HIRO
## top, bot = HIRO
self
.
left
.
coords
([(
x1
-
2
,
0
),
(
x1
-
2
,
9999
)]
)
self
.
canvas
.
coords
(
self
.
left
,
(
x1
-
2
,
0
,
x1
-
2
,
9999
)
)
self
.
master
.
update
()
self
.
master
.
update
()
def
show_right
(
self
,
right
):
def
show_right
(
self
,
right
):
...
@@ -135,7 +135,7 @@ class Array:
...
@@ -135,7 +135,7 @@ class Array:
self
.
hide_right
()
self
.
hide_right
()
return
return
x1
,
y1
,
x2
,
y2
=
self
.
items
[
right
].
position
()
x1
,
y1
,
x2
,
y2
=
self
.
items
[
right
].
position
()
self
.
right
.
coords
(((
x2
+
2
,
0
),
(
x2
+
2
,
9999
)
))
self
.
canvas
.
coords
(
self
.
right
,
(
x2
+
2
,
0
,
x2
+
2
,
9999
))
self
.
master
.
update
()
self
.
master
.
update
()
def
hide_left_right_pivot
(
self
):
def
hide_left_right_pivot
(
self
):
...
@@ -144,17 +144,17 @@ class Array:
...
@@ -144,17 +144,17 @@ class Array:
self
.
hide_pivot
()
self
.
hide_pivot
()
def
hide_left
(
self
):
def
hide_left
(
self
):
self
.
left
.
coords
(((
0
,
0
),
(
0
,
0
)
))
self
.
canvas
.
coords
(
self
.
left
,
(
0
,
0
,
0
,
0
))
def
hide_right
(
self
):
def
hide_right
(
self
):
self
.
right
.
coords
(((
0
,
0
),
(
0
,
0
)
))
self
.
canvas
.
coords
(
self
.
right
,
(
0
,
0
,
0
,
0
))
def
show_pivot
(
self
,
pivot
):
def
show_pivot
(
self
,
pivot
):
x1
,
y1
,
x2
,
y2
=
self
.
items
[
pivot
].
position
()
x1
,
y1
,
x2
,
y2
=
self
.
items
[
pivot
].
position
()
self
.
pivot
.
coords
(((
0
,
y1
-
2
),
(
9999
,
y1
-
2
)
))
self
.
canvas
.
coords
(
self
.
pivot
,
(
0
,
y1
-
2
,
9999
,
y1
-
2
))
def
hide_pivot
(
self
):
def
hide_pivot
(
self
):
self
.
pivot
.
coords
(((
0
,
0
),
(
0
,
0
)
))
self
.
canvas
.
coords
(
self
.
pivot
,
(
0
,
0
,
0
,
0
))
def
swap
(
self
,
i
,
j
):
def
swap
(
self
,
i
,
j
):
if
i
==
j
:
return
if
i
==
j
:
return
...
@@ -199,12 +199,13 @@ class ArrayItem:
...
@@ -199,12 +199,13 @@ class ArrayItem:
self
.
array
=
array
self
.
array
=
array
self
.
index
=
index
self
.
index
=
index
self
.
value
=
value
self
.
value
=
value
self
.
canvas
=
array
.
canvas
x1
,
y1
,
x2
,
y2
=
self
.
position
()
x1
,
y1
,
x2
,
y2
=
self
.
position
()
self
.
item
=
Rectangle
(
array
.
canvas
,
x1
,
y1
,
x2
,
y2
,
self
.
item
=
array
.
canvas
.
create_rectangle
(
x1
,
y1
,
x2
,
y2
,
fill
=
'red'
,
outline
=
'black'
,
width
=
1
)
fill
=
'red'
,
outline
=
'black'
,
width
=
1
)
self
.
item
.
bind
(
'<Button-1>'
,
self
.
mouse_down
)
array
.
canvas
.
tag_bind
(
self
.
item
,
'<Button-1>'
,
self
.
mouse_down
)
self
.
item
.
bind
(
'<Button1-Motion>'
,
self
.
mouse_move
)
array
.
canvas
.
tag_bind
(
self
.
item
,
'<Button1-Motion>'
,
self
.
mouse_move
)
self
.
item
.
bind
(
'<ButtonRelease-1>'
,
self
.
mouse_up
)
array
.
canvas
.
tag_bind
(
self
.
item
,
'<ButtonRelease-1>'
,
self
.
mouse_up
)
def
delete
(
self
):
def
delete
(
self
):
item
=
self
.
item
item
=
self
.
item
...
@@ -235,7 +236,7 @@ class ArrayItem:
...
@@ -235,7 +236,7 @@ class ArrayItem:
self
.
array
.
items
[
here
],
self
.
array
.
items
[
i
]
=
other
,
self
self
.
array
.
items
[
here
],
self
.
array
.
items
[
i
]
=
other
,
self
self
.
index
=
i
self
.
index
=
i
x1
,
y1
,
x2
,
y2
=
self
.
position
()
x1
,
y1
,
x2
,
y2
=
self
.
position
()
self
.
item
.
coords
(((
x1
,
y1
),
(
x2
,
y2
)
))
self
.
canvas
.
coords
(
self
.
item
,
(
x1
,
y1
,
x2
,
y2
))
other
.
setindex
(
here
)
other
.
setindex
(
here
)
def
setindex
(
self
,
index
):
def
setindex
(
self
,
index
):
...
@@ -249,7 +250,7 @@ class ArrayItem:
...
@@ -249,7 +250,7 @@ class ArrayItem:
trajectory
=
interpolate
(
oldpts
,
newpts
,
nsteps
)
trajectory
=
interpolate
(
oldpts
,
newpts
,
nsteps
)
self
.
item
.
tkraise
()
self
.
item
.
tkraise
()
for
pts
in
trajectory
:
for
pts
in
trajectory
:
self
.
item
.
coords
((
pts
[:
2
],
pts
[
2
:])
)
self
.
canvas
.
coords
(
self
.
item
,
pts
)
self
.
array
.
wait
(
50
)
self
.
array
.
wait
(
50
)
def
swapwith
(
self
,
other
):
def
swapwith
(
self
,
other
):
...
@@ -262,61 +263,63 @@ class ArrayItem:
...
@@ -262,61 +263,63 @@ class ArrayItem:
self
.
index
,
other
.
index
=
other
.
index
,
self
.
index
self
.
index
,
other
.
index
=
other
.
index
,
self
.
index
mynewpts
=
self
.
position
()
mynewpts
=
self
.
position
()
othernewpts
=
other
.
position
()
othernewpts
=
other
.
position
()
myfill
=
self
.
item
[
'fill'
]
myfill
=
self
.
canvas
.
itemcget
(
self
.
item
,
'fill'
)
otherfill
=
other
.
item
[
'fill'
]
otherfill
=
self
.
canvas
.
itemcget
(
other
.
item
,
'fill'
)
self
.
item
.
config
(
fill
=
'green'
)
self
.
canvas
.
itemconfig
(
self
.
item
,
fill
=
'green'
)
other
.
item
.
config
(
fill
=
'yellow'
)
self
.
canvas
.
itemconfig
(
other
.
item
,
fill
=
'yellow'
)
self
.
array
.
master
.
update
()
self
.
array
.
master
.
update
()
if
self
.
array
.
speed
==
"single-step"
:
if
self
.
array
.
speed
==
"single-step"
:
self
.
item
.
coords
((
mynewpts
[:
2
],
mynewpts
[
2
:])
)
self
.
canvas
.
coords
(
self
.
item
,
mynewpts
)
other
.
item
.
coords
((
othernewpts
[:
2
],
othernewpts
[
2
:])
)
self
.
canvas
.
coords
(
other
.
item
,
othernewpts
)
self
.
array
.
master
.
update
()
self
.
array
.
master
.
update
()
self
.
item
.
config
(
fill
=
myfill
)
self
.
canvas
.
itemconfig
(
self
.
item
,
fill
=
myfill
)
other
.
item
.
config
(
fill
=
otherfill
)
self
.
canvas
.
itemconfig
(
other
.
item
,
fill
=
otherfill
)
self
.
array
.
wait
(
0
)
self
.
array
.
wait
(
0
)
return
return
mytrajectory
=
interpolate
(
myoldpts
,
mynewpts
,
nsteps
)
mytrajectory
=
interpolate
(
myoldpts
,
mynewpts
,
nsteps
)
othertrajectory
=
interpolate
(
otheroldpts
,
othernewpts
,
nsteps
)
othertrajectory
=
interpolate
(
otheroldpts
,
othernewpts
,
nsteps
)
if
self
.
value
>
other
.
value
:
if
self
.
value
>
other
.
value
:
self
.
item
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
self
.
item
)
other
.
item
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
other
.
item
)
else
:
else
:
other
.
item
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
other
.
item
)
self
.
item
.
tkraise
(
)
self
.
canvas
.
tag_raise
(
self
.
item
)
try
:
try
:
for
i
in
range
(
len
(
mytrajectory
)):
for
i
in
range
(
len
(
mytrajectory
)):
mypts
=
mytrajectory
[
i
]
mypts
=
mytrajectory
[
i
]
otherpts
=
othertrajectory
[
i
]
otherpts
=
othertrajectory
[
i
]
self
.
item
.
coords
((
mypts
[:
2
],
mypts
[
2
:])
)
self
.
canvas
.
coords
(
self
.
item
,
mypts
)
other
.
item
.
coords
((
otherpts
[:
2
],
otherpts
[
2
:])
)
self
.
canvas
.
coords
(
other
.
item
,
otherpts
)
self
.
array
.
wait
(
50
)
self
.
array
.
wait
(
50
)
finally
:
finally
:
mypts
=
mytrajectory
[
-
1
]
mypts
=
mytrajectory
[
-
1
]
otherpts
=
othertrajectory
[
-
1
]
otherpts
=
othertrajectory
[
-
1
]
self
.
item
.
coords
((
mypts
[:
2
],
mypts
[
2
:])
)
self
.
canvas
.
coords
(
self
.
item
,
mypts
)
other
.
item
.
coords
((
otherpts
[:
2
],
otherpts
[
2
:])
)
self
.
canvas
.
coords
(
other
.
item
,
otherpts
)
self
.
item
.
config
(
fill
=
myfill
)
self
.
canvas
.
itemconfig
(
self
.
item
,
fill
=
myfill
)
other
.
item
.
config
(
fill
=
otherfill
)
self
.
canvas
.
itemconfig
(
other
.
item
,
fill
=
otherfill
)
def
compareto
(
self
,
other
):
def
compareto
(
self
,
other
):
myfill
=
self
.
item
[
'fill'
]
myfill
=
self
.
canvas
.
itemcget
(
self
.
item
,
'fill'
)
otherfill
=
other
.
item
[
'fill'
]
otherfill
=
self
.
canvas
.
itemcget
(
other
.
item
,
'fill'
)
outcome
=
cmp
(
self
.
value
,
other
.
value
)
if
self
.
value
<
other
.
value
:
if
outcome
<
0
:
myflash
=
'white'
myflash
=
'white'
otherflash
=
'black'
otherflash
=
'black'
elif
outcome
>
0
:
outcome
=
-
1
elif
self
.
value
>
other
.
value
:
myflash
=
'black'
myflash
=
'black'
otherflash
=
'white'
otherflash
=
'white'
outcome
=
1
else
:
else
:
myflash
=
otherflash
=
'grey'
myflash
=
otherflash
=
'grey'
outcome
=
0
try
:
try
:
self
.
item
.
config
(
fill
=
myflash
)
self
.
canvas
.
itemconfig
(
self
.
item
,
fill
=
myflash
)
other
.
item
.
config
(
fill
=
otherflash
)
self
.
canvas
.
itemconfig
(
other
.
item
,
fill
=
otherflash
)
self
.
array
.
wait
(
500
)
self
.
array
.
wait
(
500
)
finally
:
finally
:
self
.
item
.
config
(
fill
=
myfill
)
self
.
canvas
.
itemconfig
(
self
.
item
,
fill
=
myfill
)
other
.
item
.
config
(
fill
=
otherfill
)
self
.
canvas
.
itemconfig
(
other
.
item
,
fill
=
otherfill
)
return
outcome
return
outcome
def
position
(
self
):
def
position
(
self
):
...
@@ -429,7 +432,7 @@ def quicksort(array):
...
@@ -429,7 +432,7 @@ def quicksort(array):
j
=
j
-
1
j
=
j
-
1
continue
continue
array
.
message
(
"Choosing pivot"
)
array
.
message
(
"Choosing pivot"
)
j
,
i
,
k
=
first
,
(
first
+
last
)
//
2
,
last
-
1
j
,
i
,
k
=
first
,
(
first
+
last
)
//
2
,
last
-
1
if
array
.
compare
(
k
,
i
)
<
0
:
if
array
.
compare
(
k
,
i
)
<
0
:
array
.
swap
(
k
,
i
)
array
.
swap
(
k
,
i
)
if
array
.
compare
(
k
,
j
)
<
0
:
if
array
.
compare
(
k
,
j
)
<
0
:
...
@@ -519,7 +522,7 @@ class SortDemo:
...
@@ -519,7 +522,7 @@ class SortDemo:
self
.
v_size
=
MyIntVar
(
self
.
master
,
self
)
self
.
v_size
=
MyIntVar
(
self
.
master
,
self
)
self
.
v_size
.
set
(
size
)
self
.
v_size
.
set
(
size
)
sizes
=
[
1
,
2
,
3
,
4
]
+
range
(
5
,
55
,
5
)
sizes
=
[
1
,
2
,
3
,
4
]
+
list
(
range
(
5
,
55
,
5
)
)
if
self
.
size
not
in
sizes
:
if
self
.
size
not
in
sizes
:
sizes
.
append
(
self
.
size
)
sizes
.
append
(
self
.
size
)
sizes
.
sort
()
sizes
.
sort
()
...
...
Demo/tkinter/guido/svkill.py
View file @
856023a0
...
@@ -7,8 +7,6 @@ from tkinter import *
...
@@ -7,8 +7,6 @@ from tkinter import *
if
TkVersion
<
4.0
:
if
TkVersion
<
4.0
:
raise
ImportError
(
"This version of svkill requires Tk 4.0 or later"
)
raise
ImportError
(
"This version of svkill requires Tk 4.0 or later"
)
from
string
import
splitfields
from
string
import
split
import
subprocess
import
subprocess
import
os
import
os
...
@@ -40,14 +38,14 @@ class Kill(Frame):
...
@@ -40,14 +38,14 @@ class Kill(Frame):
]
]
def
kill
(
self
,
selected
):
def
kill
(
self
,
selected
):
c
=
self
.
format_list
[
self
.
format
.
get
()][
2
]
c
=
self
.
format_list
[
self
.
format
.
get
()][
2
]
pid
=
s
plit
(
selected
)[
c
]
pid
=
s
elected
.
split
(
)[
c
]
os
.
system
(
'kill -9 '
+
pid
)
os
.
system
(
'kill -9 '
+
pid
)
self
.
do_update
()
self
.
do_update
()
def
do_update
(
self
):
def
do_update
(
self
):
format
=
self
.
format_list
[
self
.
format
.
get
()][
1
]
format
=
self
.
format_list
[
self
.
format
.
get
()][
1
]
view
=
self
.
view_list
[
self
.
view
.
get
()][
1
]
view
=
self
.
view_list
[
self
.
view
.
get
()][
1
]
s
=
subprocess
.
getoutput
(
'ps %s %s'
%
(
view
,
format
))
s
=
subprocess
.
getoutput
(
'ps %s %s'
%
(
view
,
format
))
list
=
s
plitfields
(
s
,
'
\
n
'
)
list
=
s
.
split
(
'
\
n
'
)
self
.
header
.
set
(
list
[
0
]
+
' '
)
self
.
header
.
set
(
list
[
0
]
+
' '
)
del
list
[
0
]
del
list
[
0
]
self
.
frame
.
list
.
delete
(
0
,
AtEnd
())
self
.
frame
.
list
.
delete
(
0
,
AtEnd
())
...
@@ -97,14 +95,12 @@ class Kill(Frame):
...
@@ -97,14 +95,12 @@ class Kill(Frame):
self
.
header
=
StringVar
(
self
)
self
.
header
=
StringVar
(
self
)
self
.
frame
.
label
=
Label
(
self
.
frame
.
label
=
Label
(
self
.
frame
,
relief
=
FLAT
,
anchor
=
NW
,
borderwidth
=
0
,
self
.
frame
,
relief
=
FLAT
,
anchor
=
NW
,
borderwidth
=
0
,
font
=
'*-Courier-Bold-R-Normal-*-120-*'
,
textvariable
=
self
.
header
)
textvariable
=
self
.
header
)
self
.
frame
.
label
.
pack
(
fill
=
Y
,
anchor
=
W
)
self
.
frame
.
label
.
pack
(
fill
=
Y
,
anchor
=
W
)
self
.
frame
.
vscroll
=
Scrollbar
(
self
.
frame
,
orient
=
VERTICAL
)
self
.
frame
.
vscroll
=
Scrollbar
(
self
.
frame
,
orient
=
VERTICAL
)
self
.
frame
.
list
=
Listbox
(
self
.
frame
.
list
=
Listbox
(
self
.
frame
,
self
.
frame
,
relief
=
SUNKEN
,
relief
=
SUNKEN
,
font
=
'*-Courier-Medium-R-Normal-*-120-*'
,
width
=
40
,
height
=
10
,
width
=
40
,
height
=
10
,
selectbackground
=
'#eed5b7'
,
selectbackground
=
'#eed5b7'
,
selectborderwidth
=
0
,
selectborderwidth
=
0
,
...
...
Demo/tkinter/guido/tkman.py
View file @
856023a0
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
# Tk man page browser -- currently only shows the Tcl/Tk man pages
# Tk man page browser -- currently only shows the Tcl/Tk man pages
import
sys
import
os
import
os
import
string
import
re
import
re
import
sys
from
tkinter
import
*
from
tkinter
import
*
from
ManPage
import
ManPage
from
ManPage
import
ManPage
MANNDIRLIST
=
[
'/depot/sundry/man/mann'
,
'/usr/local/man/mann'
]
MANNDIRLIST
=
[
'/depot/sundry/man/mann'
,
'/usr/local/man/mann'
]
...
@@ -221,9 +221,9 @@ class SelectionBox:
...
@@ -221,9 +221,9 @@ class SelectionBox:
print
(
'Regex error:'
,
msg
)
print
(
'Regex error:'
,
msg
)
return
return
here
=
self
.
text
.
index
(
AtInsert
())
here
=
self
.
text
.
index
(
AtInsert
())
lineno
=
string
.
atoi
(
here
[:
string
.
find
(
here
,
'.'
)])
lineno
=
int
(
here
[:
here
.
find
(
'.'
)])
end
=
self
.
text
.
index
(
AtEnd
())
end
=
self
.
text
.
index
(
AtEnd
())
endlineno
=
string
.
atoi
(
end
[:
string
.
find
(
end
,
'.'
)])
endlineno
=
int
(
end
[:
end
.
find
(
'.'
)])
wraplineno
=
lineno
wraplineno
=
lineno
found
=
0
found
=
0
while
1
:
while
1
:
...
@@ -237,9 +237,9 @@ class SelectionBox:
...
@@ -237,9 +237,9 @@ class SelectionBox:
line
=
self
.
text
.
get
(
'%d.0 linestart'
%
lineno
,
line
=
self
.
text
.
get
(
'%d.0 linestart'
%
lineno
,
'%d.0 lineend'
%
lineno
)
'%d.0 lineend'
%
lineno
)
i
=
prog
.
search
(
line
)
i
=
prog
.
search
(
line
)
if
i
>=
0
:
if
i
:
found
=
1
found
=
1
n
=
max
(
1
,
len
(
prog
.
group
(
0
)))
n
=
max
(
1
,
len
(
i
.
group
(
0
)))
try
:
try
:
self
.
text
.
tag_remove
(
'sel'
,
self
.
text
.
tag_remove
(
'sel'
,
AtSelFirst
(),
AtSelFirst
(),
...
@@ -247,10 +247,10 @@ class SelectionBox:
...
@@ -247,10 +247,10 @@ class SelectionBox:
except
TclError
:
except
TclError
:
pass
pass
self
.
text
.
tag_add
(
'sel'
,
self
.
text
.
tag_add
(
'sel'
,
'%d.%d'
%
(
lineno
,
i
),
'%d.%d'
%
(
lineno
,
i
.
start
()
),
'%d.%d'
%
(
lineno
,
i
+
n
))
'%d.%d'
%
(
lineno
,
i
.
start
()
+
n
))
self
.
text
.
mark_set
(
AtInsert
(),
self
.
text
.
mark_set
(
AtInsert
(),
'%d.%d'
%
(
lineno
,
i
))
'%d.%d'
%
(
lineno
,
i
.
start
()
))
self
.
text
.
yview_pickplace
(
AtInsert
())
self
.
text
.
yview_pickplace
(
AtInsert
())
break
break
if
not
found
:
if
not
found
:
...
...
Demo/tkinter/matt/bind-w-mult-calls-p-type.py
View file @
856023a0
from
tkinter
import
*
from
tkinter
import
*
import
string
# This program shows how to use a simple type-in box
# This program shows how to use a simple type-in box
...
...
Demo/tkinter/matt/entry-with-shared-variable.py
View file @
856023a0
from
tkinter
import
*
from
tkinter
import
*
import
string
# This program shows how to make a typein box shadow a program variable.
# This program shows how to make a typein box shadow a program variable.
...
@@ -35,7 +34,7 @@ class App(Frame):
...
@@ -35,7 +34,7 @@ class App(Frame):
# because it's being looked at by the entry widget, changing
# because it's being looked at by the entry widget, changing
# the variable changes the entry widget display automatically.
# the variable changes the entry widget display automatically.
# the strange get/set operators are clunky, true...
# the strange get/set operators are clunky, true...
str
=
s
tring
.
upper
(
self
.
contents
.
get
()
)
str
=
s
elf
.
contents
.
get
().
upper
(
)
self
.
contents
.
set
(
str
)
self
.
contents
.
set
(
str
)
def
print_contents
(
self
,
event
):
def
print_contents
(
self
,
event
):
...
...
Demo/tkinter/matt/pong-demo-1.py
View file @
856023a0
from
tkinter
import
*
from
tkinter
import
*
import
string
class
Pong
(
Frame
):
class
Pong
(
Frame
):
def
createWidgets
(
self
):
def
createWidgets
(
self
):
...
...
Demo/tkinter/matt/printing-coords-of-items.py
View file @
856023a0
...
@@ -35,7 +35,7 @@ class Test(Frame):
...
@@ -35,7 +35,7 @@ class Test(Frame):
# the "current" tag is applied to the object the cursor is over.
# the "current" tag is applied to the object the cursor is over.
# this happens automatically.
# this happens automatically.
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"red"
)
self
.
draw
.
itemconfig
(
CURRENT
,
fill
=
"red"
)
print
(
self
.
draw
.
coords
(
CURRENT
))
print
(
list
(
self
.
draw
.
coords
(
CURRENT
)
))
def
mouseLeave
(
self
,
event
):
def
mouseLeave
(
self
,
event
):
# the "current" tag is applied to the object the cursor is over.
# the "current" tag is applied to the object the cursor is over.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment