diff options
author | Guido van Rossum <guido@python.org> | 2002-09-23 16:55:05 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-09-23 16:55:05 (GMT) |
commit | fd2ede2aa84e77dac30e297a04fc49dd3bb61c68 (patch) | |
tree | d8cde1e5979253f6af7a80771189f12345955870 /Lib/lib-tk | |
parent | 4299231e685ff2a38677775943ccc7ba2bf66a04 (diff) | |
download | cpython-fd2ede2aa84e77dac30e297a04fc49dd3bb61c68.zip cpython-fd2ede2aa84e77dac30e297a04fc49dd3bb61c68.tar.gz cpython-fd2ede2aa84e77dac30e297a04fc49dd3bb61c68.tar.bz2 |
Add the bulk of SF patch 595111 by Attila Babo.
This adds new methods heading(), setheading(), position(),
window_width(), window_height(), setx(), and sety(), to make this more
functionality-compatible with Logo turtle graphics (Attila's last
words, not mine :-). I had to fix the sety() code which was broken in
Attila's patch.
I'm not adopting the functionality change that Attila claimed was a
bugfix (no output without tracing), because I disagree that it's a
bug.
Diffstat (limited to 'Lib/lib-tk')
-rw-r--r-- | Lib/lib-tk/turtle.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/Lib/lib-tk/turtle.py b/Lib/lib-tk/turtle.py index 1b418eb..d59cd7a 100644 --- a/Lib/lib-tk/turtle.py +++ b/Lib/lib-tk/turtle.py @@ -2,6 +2,7 @@ from math import * # Also for export import Tkinter + class Error(Exception): pass @@ -53,7 +54,6 @@ class RawPen: self._delete_turtle() self._draw_turtle() - def tracer(self, flag): self._tracing = flag if not self._tracing: @@ -118,7 +118,6 @@ class RawPen: self._color = color self._draw_turtle() - def write(self, arg, move=0): x, y = start = self._position x = x-1 # correction -- calibrated for Windows @@ -200,6 +199,40 @@ class RawPen: if self._filling: self._path.append(self._position) self._draw_turtle() + + def heading(self): + return self._angle + + def setheading(self, angle): + self._angle = angle + self._draw_turtle() + + def window_width(self): + width = self._canvas.winfo_width() + if width <= 1: # the window isn't managed by a geometry manager + width = self._canvas['width'] + return width + + def window_height(self): + height = self._canvas.winfo_height() + if height <= 1: # the window isn't managed by a geometry manager + height = self._canvas['height'] + return height + + def position(self): + x0, y0 = self._origin + x1, y1 = self._position + return [x1-x0, -y1+y0] + + def setx(self, xpos): + x0, y0 = self._origin + x1, y1 = self._position + self._goto(x0+xpos, y1) + + def sety(self, ypos): + x0, y0 = self._origin + x1, y1 = self._position + self._goto(x1, y0-ypos) def goto(self, *args): if len(args) == 1: @@ -326,6 +359,13 @@ def write(arg, move=0): _getpen().write(arg, move) def fill(flag): _getpen().fill(flag) def circle(radius, extent=None): _getpen().circle(radius, extent) def goto(*args): apply(_getpen().goto, args) +def heading(): return _getpen().heading() +def setheading(angle): _getpen().setheading(angle) +def position(): return _getpen().position() +def window_width(): return _getpen().window_width() +def window_height(): return _getpen().window_height() +def setx(xpos): _getpen().setx(xpos) +def sety(ypos): _getpen().sety(ypos) def demo(): reset() |