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
7d96270d
Commit
7d96270d
authored
Feb 22, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6639: Module-level turtle functions no longer raise TclError after
closing the window.
parent
faa02376
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
34 deletions
+39
-34
Demo/turtle/turtleDemo.py
Demo/turtle/turtleDemo.py
+4
-0
Lib/lib-tk/turtle.py
Lib/lib-tk/turtle.py
+32
-34
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Demo/turtle/turtleDemo.py
View file @
7d96270d
...
@@ -231,6 +231,8 @@ class DemoWindow(object):
...
@@ -231,6 +231,8 @@ class DemoWindow(object):
else
:
else
:
self
.
state
=
DONE
self
.
state
=
DONE
except
turtle
.
Terminator
:
except
turtle
.
Terminator
:
if
self
.
root
is
None
:
return
self
.
state
=
DONE
self
.
state
=
DONE
result
=
"stopped!"
result
=
"stopped!"
if
self
.
state
==
DONE
:
if
self
.
state
==
DONE
:
...
@@ -257,7 +259,9 @@ class DemoWindow(object):
...
@@ -257,7 +259,9 @@ class DemoWindow(object):
turtle
.
TurtleScreen
.
_RUNNING
=
False
turtle
.
TurtleScreen
.
_RUNNING
=
False
def
_destroy
(
self
):
def
_destroy
(
self
):
turtle
.
TurtleScreen
.
_RUNNING
=
False
self
.
root
.
destroy
()
self
.
root
.
destroy
()
self
.
root
=
None
#sys.exit()
#sys.exit()
def
main
():
def
main
():
...
...
Lib/lib-tk/turtle.py
View file @
7d96270d
...
@@ -1235,7 +1235,7 @@ class TurtleScreen(TurtleScreenBase):
...
@@ -1235,7 +1235,7 @@ class TurtleScreen(TurtleScreenBase):
def
_incrementudc
(
self
):
def
_incrementudc
(
self
):
"""Increment update counter."""
"""Increment update counter."""
if
not
TurtleScreen
.
_RUNNING
:
if
not
TurtleScreen
.
_RUNNING
:
TurtleScreen
.
_RUNN
N
ING
=
True
TurtleScreen
.
_RUNNING
=
True
raise
Terminator
raise
Terminator
if
self
.
_tracing
>
0
:
if
self
.
_tracing
>
0
:
self
.
_updatecounter
+=
1
self
.
_updatecounter
+=
1
...
@@ -3644,7 +3644,7 @@ class _Screen(TurtleScreen):
...
@@ -3644,7 +3644,7 @@ class _Screen(TurtleScreen):
Turtle
.
_screen
=
None
Turtle
.
_screen
=
None
_Screen
.
_root
=
None
_Screen
.
_root
=
None
_Screen
.
_canvas
=
None
_Screen
.
_canvas
=
None
TurtleScreen
.
_RUNNING
=
Tru
e
TurtleScreen
.
_RUNNING
=
Fals
e
root
.
destroy
()
root
.
destroy
()
def
bye
(
self
):
def
bye
(
self
):
...
@@ -3685,7 +3685,6 @@ class _Screen(TurtleScreen):
...
@@ -3685,7 +3685,6 @@ class _Screen(TurtleScreen):
except
AttributeError
:
except
AttributeError
:
exit
(
0
)
exit
(
0
)
class
Turtle
(
RawTurtle
):
class
Turtle
(
RawTurtle
):
"""RawTurtle auto-creating (scrolled) canvas.
"""RawTurtle auto-creating (scrolled) canvas.
...
@@ -3708,18 +3707,6 @@ class Turtle(RawTurtle):
...
@@ -3708,18 +3707,6 @@ class Turtle(RawTurtle):
Pen
=
Turtle
Pen
=
Turtle
def
_getpen
():
"""Create the 'anonymous' turtle if not already present."""
if
Turtle
.
_pen
is
None
:
Turtle
.
_pen
=
Turtle
()
return
Turtle
.
_pen
def
_getscreen
():
"""Create a TurtleScreen if not already present."""
if
Turtle
.
_screen
is
None
:
Turtle
.
_screen
=
Screen
()
return
Turtle
.
_screen
def
write_docstringdict
(
filename
=
"turtle_docstringdict"
):
def
write_docstringdict
(
filename
=
"turtle_docstringdict"
):
"""Create and write docstring-dictionary to file.
"""Create and write docstring-dictionary to file.
...
@@ -3847,30 +3834,41 @@ def _screen_docrevise(docstr):
...
@@ -3847,30 +3834,41 @@ def _screen_docrevise(docstr):
## as functions. So we can enhance, change, add, delete methods to these
## as functions. So we can enhance, change, add, delete methods to these
## classes and do not need to change anything here.
## classes and do not need to change anything here.
__func_body
=
"""
\
def {name}{paramslist}:
if {obj} is None:
if not TurtleScreen._RUNNING:
TurtleScreen._RUNNING = True
raise Terminator
{obj} = {init}
try:
return {obj}.{name}{argslist}
except TK.TclError:
if not TurtleScreen._RUNNING:
TurtleScreen._RUNNING = True
raise Terminator
raise
"""
for
methodname
in
_tg_screen_functions
:
def
_make_global_funcs
(
functions
,
cls
,
obj
,
init
,
docrevise
):
pl1
,
pl2
=
getmethparlist
(
eval
(
'_Screen.'
+
methodname
))
for
methodname
in
functions
:
method
=
getattr
(
cls
,
methodname
)
pl1
,
pl2
=
getmethparlist
(
method
)
if
pl1
==
""
:
if
pl1
==
""
:
print
">>>>>>"
,
pl1
,
pl2
print
">>>>>>"
,
pl1
,
pl2
continue
continue
defstr
=
(
"def %(key)s%(pl1)s: return _getscreen().%(key)s%(pl2)s"
%
defstr
=
__func_body
.
format
(
obj
=
obj
,
init
=
init
,
name
=
methodname
,
{
'key'
:
methodname
,
'pl1'
:
pl1
,
'pl2'
:
pl2
}
)
paramslist
=
pl1
,
argslist
=
pl2
)
exec
defstr
exec
defstr
in
globals
()
eval
(
methodname
).
__doc__
=
_screen_docrevise
(
eval
(
'_Screen.'
+
methodname
)
.
__doc__
)
globals
()[
methodname
].
__doc__
=
docrevise
(
method
.
__doc__
)
for
methodname
in
_tg_turtle_functions
:
_make_global_funcs
(
_tg_screen_functions
,
_Screen
,
pl1
,
pl2
=
getmethparlist
(
eval
(
'Turtle.'
+
methodname
))
'Turtle._screen'
,
'Screen()'
,
_screen_docrevise
)
if
pl1
==
""
:
_make_global_funcs
(
_tg_turtle_functions
,
Turtle
,
print
">>>>>>"
,
pl1
,
pl2
'Turtle._pen'
,
'Turtle()'
,
_turtle_docrevise
)
continue
defstr
=
(
"def %(key)s%(pl1)s: return _getpen().%(key)s%(pl2)s"
%
{
'key'
:
methodname
,
'pl1'
:
pl1
,
'pl2'
:
pl2
})
exec
defstr
eval
(
methodname
).
__doc__
=
_turtle_docrevise
(
eval
(
'Turtle.'
+
methodname
).
__doc__
)
done
=
mainloop
=
TK
.
mainloop
done
=
mainloop
=
TK
.
mainloop
del
pl1
,
pl2
,
defstr
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
def
switchpen
():
def
switchpen
():
...
...
Misc/NEWS
View file @
7d96270d
...
@@ -116,6 +116,9 @@ Documentation
...
@@ -116,6 +116,9 @@ Documentation
Tools
/
Demos
Tools
/
Demos
-----------
-----------
-
Issue
#
6639
:
Module
-
level
turtle
functions
no
longer
raise
TclError
after
closing
the
window
.
-
Issue
#
22314
:
pydoc
now
works
when
the
LINES
environment
variable
is
set
.
-
Issue
#
22314
:
pydoc
now
works
when
the
LINES
environment
variable
is
set
.
-
Issue
#
18905
:
"pydoc -p 0"
now
outputs
actually
used
port
.
Based
on
patch
by
-
Issue
#
18905
:
"pydoc -p 0"
now
outputs
actually
used
port
.
Based
on
patch
by
...
...
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