[Python-checkins] [3.11] Rewrite the turtledemo makeGraphFrame method (GH-104224) (#104238)
terryjreedy
webhook-mailer at python.org
Sat May 6 11:31:35 EDT 2023
https://github.com/python/cpython/commit/10ee19b7371e333f1e22c9471b61954485f2268c
commit: 10ee19b7371e333f1e22c9471b61954485f2268c
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: terryjreedy <tjreedy at udel.edu>
date: 2023-05-06T15:31:28Z
summary:
[3.11] Rewrite the turtledemo makeGraphFrame method (GH-104224) (#104238)
Rewrite the turtledemo makeGraphFrame method (GH-104224)
Replace `self._canvas` and `self.scanvas`, both bound to `canvas`,
with `self.canvas, which is accessed in other methods.
Replace `_s_` with `screen` and `_s_._canvas` with `canvas`.
Add a comment explaining the unorthodox use of
function turtle.Screen and singleton class turtle._Screen.
(cherry picked from commit 96f95df48e41ccf984de1ee1312c81809fd9e876)
Co-authored-by: Terry Jan Reedy <tjreedy at udel.edu>
files:
M Lib/turtledemo/__main__.py
diff --git a/Lib/turtledemo/__main__.py b/Lib/turtledemo/__main__.py
index caea022da4a6..f6c9d6aa6f9a 100755
--- a/Lib/turtledemo/__main__.py
+++ b/Lib/turtledemo/__main__.py
@@ -203,10 +203,10 @@ def __init__(self, filename=None):
def onResize(self, event):
- cwidth = self._canvas.winfo_width()
- cheight = self._canvas.winfo_height()
- self._canvas.xview_moveto(0.5*(self.canvwidth-cwidth)/self.canvwidth)
- self._canvas.yview_moveto(0.5*(self.canvheight-cheight)/self.canvheight)
+ cwidth = self.canvas.winfo_width()
+ cheight = self.canvas.winfo_height()
+ self.canvas.xview_moveto(0.5*(self.canvwidth-cwidth)/self.canvwidth)
+ self.canvas.yview_moveto(0.5*(self.canvheight-cheight)/self.canvheight)
def makeTextFrame(self, root):
self.text_frame = text_frame = Frame(root)
@@ -237,19 +237,23 @@ def makeTextFrame(self, root):
return text_frame
def makeGraphFrame(self, root):
+ # t._Screen is a singleton class instantiated or retrieved
+ # by calling Screen. Since tdemo canvas needs a different
+ # configuration, we manually set class attributes before
+ # calling Screen and manually call superclass init after.
turtle._Screen._root = root
+
self.canvwidth = 1000
self.canvheight = 800
- turtle._Screen._canvas = self._canvas = canvas = turtle.ScrolledCanvas(
+ turtle._Screen._canvas = self.canvas = canvas = turtle.ScrolledCanvas(
root, 800, 600, self.canvwidth, self.canvheight)
canvas.adjustScrolls()
canvas._rootwindow.bind('<Configure>', self.onResize)
canvas._canvas['borderwidth'] = 0
- self.screen = _s_ = turtle.Screen()
- turtle.TurtleScreen.__init__(_s_, _s_._canvas)
- self.scanvas = _s_._canvas
- turtle.RawTurtle.screens = [_s_]
+ self.screen = screen = turtle.Screen()
+ turtle.TurtleScreen.__init__(screen, canvas)
+ turtle.RawTurtle.screens = [screen]
return canvas
def set_txtsize(self, size):
@@ -373,7 +377,7 @@ def startDemo(self):
def clearCanvas(self):
self.refreshCanvas()
self.screen._delete("all")
- self.scanvas.config(cursor="")
+ self.canvas.config(cursor="")
self.configGUI(NORMAL, DISABLED, DISABLED)
def stopIt(self):
More information about the Python-checkins
mailing list