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
f51531e2
Commit
f51531e2
authored
Jun 22, 2014
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21823: Catch turtle.Terminator exceptions in turtledemo.
Add note to demohelp.txt about doing so.
parent
fabefc3c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
25 deletions
+37
-25
Lib/turtledemo/clock.py
Lib/turtledemo/clock.py
+20
-16
Lib/turtledemo/demohelp.txt
Lib/turtledemo/demohelp.txt
+10
-6
Lib/turtledemo/minimal_hanoi.py
Lib/turtledemo/minimal_hanoi.py
+7
-3
No files found.
Lib/turtledemo/clock.py
View file @
f51531e2
...
...
@@ -11,6 +11,7 @@ and time
------------------------------------
"""
from
turtle
import
*
from
turtle
import
Terminator
# not in __all__
from
datetime
import
datetime
mode
(
"logo"
)
...
...
@@ -102,22 +103,25 @@ def tick():
sekunde
=
t
.
second
+
t
.
microsecond
*
0.000001
minute
=
t
.
minute
+
sekunde
/
60.0
stunde
=
t
.
hour
+
minute
/
60.0
tracer
(
False
)
writer
.
clear
()
writer
.
home
()
writer
.
forward
(
65
)
writer
.
write
(
wochentag
(
t
),
align
=
"center"
,
font
=
(
"Courier"
,
14
,
"bold"
))
writer
.
back
(
150
)
writer
.
write
(
datum
(
t
),
align
=
"center"
,
font
=
(
"Courier"
,
14
,
"bold"
))
writer
.
forward
(
85
)
tracer
(
True
)
second_hand
.
setheading
(
6
*
sekunde
)
minute_hand
.
setheading
(
6
*
minute
)
hour_hand
.
setheading
(
30
*
stunde
)
tracer
(
True
)
ontimer
(
tick
,
100
)
try
:
tracer
(
False
)
# Terminator can occur here
writer
.
clear
()
writer
.
home
()
writer
.
forward
(
65
)
writer
.
write
(
wochentag
(
t
),
align
=
"center"
,
font
=
(
"Courier"
,
14
,
"bold"
))
writer
.
back
(
150
)
writer
.
write
(
datum
(
t
),
align
=
"center"
,
font
=
(
"Courier"
,
14
,
"bold"
))
writer
.
forward
(
85
)
tracer
(
True
)
second_hand
.
setheading
(
6
*
sekunde
)
# or here
minute_hand
.
setheading
(
6
*
minute
)
hour_hand
.
setheading
(
30
*
stunde
)
tracer
(
True
)
ontimer
(
tick
,
100
)
except
Terminator
:
pass
# turtledemo user pressed STOP
def
main
():
tracer
(
False
)
...
...
Lib/turtledemo/demohelp.txt
View file @
f51531e2
...
...
@@ -60,11 +60,15 @@
be executed by the viewer (see provided example scripts)
main() may return a string which will be displayed
in the Label below the source code window (when execution
has finished.)
has finished.)
!! For programs, which are EVENT DRIVEN, main must return
!! the string "EVENTLOOP". This informs the viewer, that the
!! script is still running and must be stopped by the user!
If the demo is EVENT DRIVEN, main must return the string
"EVENTLOOP". This informs the demo viewer that the script is
still running and must be stopped by the user!
If an "EVENTLOOP" demo runs by itself, as with clock, which uses
ontimer, or minimal_hanoi, which loops by recursion, then the
code should catch the turtle.Terminator exception that will be
raised when the user presses the STOP button. (Paint is not such
a demo; it only acts in response to mouse clicks and movements.)
Lib/turtledemo/minimal_hanoi.py
View file @
f51531e2
...
...
@@ -18,6 +18,7 @@ stretched to rectangles by shapesize()
---------------------------------------
"""
from
turtle
import
*
from
turtle
import
Terminator
# not in __all__
class
Disc
(
Turtle
):
def
__init__
(
self
,
n
):
...
...
@@ -50,9 +51,12 @@ def hanoi(n, from_, with_, to_):
def
play
():
onkey
(
None
,
"space"
)
clear
()
hanoi
(
6
,
t1
,
t2
,
t3
)
write
(
"press STOP button to exit"
,
align
=
"center"
,
font
=
(
"Courier"
,
16
,
"bold"
))
try
:
hanoi
(
6
,
t1
,
t2
,
t3
)
write
(
"press STOP button to exit"
,
align
=
"center"
,
font
=
(
"Courier"
,
16
,
"bold"
))
except
Terminator
:
pass
# turtledemo user pressed STOP
def
main
():
global
t1
,
t2
,
t3
...
...
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