aboutsummaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2014-07-23 15:01:07 -0400
committerTerry Jan Reedy <tjreedy@udel.edu>2014-07-23 15:01:07 -0400
commite2fbf4facaeddeb4748163fa1b9d81e2fbc0451f (patch)
treea91d496c88ffa10ab18231b28350ea46c968cb25 /Demo
parent85b5b739997607459b786ede746c167cbabd1405 (diff)
downloadplatform_external_python_cpython2-e2fbf4facaeddeb4748163fa1b9d81e2fbc0451f.tar.gz
platform_external_python_cpython2-e2fbf4facaeddeb4748163fa1b9d81e2fbc0451f.tar.bz2
platform_external_python_cpython2-e2fbf4facaeddeb4748163fa1b9d81e2fbc0451f.zip
Issue #21597: Turtledemo text pane can now be widened to view or copy complete
lines or narrowed for small screens. Issie #19132: Turtledemo buttons no longer disappear when window is shrun. Patch mostly by Lita Cho (21597) using idea from patch by Jan Kanis (18132).
Diffstat (limited to 'Demo')
-rwxr-xr-xDemo/turtle/turtleDemo.py167
1 files changed, 92 insertions, 75 deletions
diff --git a/Demo/turtle/turtleDemo.py b/Demo/turtle/turtleDemo.py
index 88b9b201b9..ff0bbdf354 100755
--- a/Demo/turtle/turtleDemo.py
+++ b/Demo/turtle/turtleDemo.py
@@ -58,83 +58,95 @@ def showAboutTurtle():
class DemoWindow(object):
- def __init__(self, filename=None): #, root=None):
+ def __init__(self, filename=None):
self.root = root = turtle._root = Tk()
+ root.title('Python turtle-graphics examples')
root.wm_protocol("WM_DELETE_WINDOW", self._destroy)
- #################
- self.mBar = Frame(root, relief=RAISED, borderwidth=2)
- self.mBar.pack(fill=X)
+ root.grid_rowconfigure(1, weight=1)
+ root.grid_columnconfigure(0, weight=1)
+ root.grid_columnconfigure(1, minsize=90, weight=1)
+ root.grid_columnconfigure(2, minsize=90, weight=1)
+ root.grid_columnconfigure(3, minsize=90, weight=1)
+ self.mBar = Frame(root, relief=RAISED, borderwidth=2)
self.ExamplesBtn = self.makeLoadDemoMenu()
self.OptionsBtn = self.makeHelpMenu()
- self.mBar.tk_menuBar(self.ExamplesBtn, self.OptionsBtn) #, QuitBtn)
+ self.mBar.tk_menuBar(self.ExamplesBtn, self.OptionsBtn)
+ self.mBar.grid(row=0, columnspan=4, sticky='news')
+
+ pane = PanedWindow(orient=HORIZONTAL, sashwidth=5,
+ sashrelief=SOLID, bg='#ddd')
+ pane.add(self.makeTextFrame(pane))
+ pane.add(self.makeGraphFrame(pane))
+ pane.grid(row=1, columnspan=4, sticky='news')
+
+ self.output_lbl = Label(root, height= 1, text=" --- ", bg="#ddf",
+ font=("Arial", 16, 'normal'), borderwidth=2,
+ relief=RIDGE)
+ self.start_btn = Button(root, text=" START ", font=btnfont,
+ fg="white", disabledforeground = "#fed",
+ command=self.startDemo)
+ self.stop_btn = Button(root, text=" STOP ", font=btnfont,
+ fg="white", disabledforeground = "#fed",
+ command=self.stopIt)
+ self.clear_btn = Button(root, text=" CLEAR ", font=btnfont,
+ fg="white", disabledforeground="#fed",
+ command = self.clearCanvas)
+ self.output_lbl.grid(row=2, column=0, sticky='news', padx=(0,5))
+ self.start_btn.grid(row=2, column=1, sticky='ew')
+ self.stop_btn.grid(row=2, column=2, sticky='ew')
+ self.clear_btn.grid(row=2, column=3, sticky='ew')
+
+ Percolator(self.text).insertfilter(ColorDelegator())
+ self.dirty = False
+ self.exitflag = False
+ if filename:
+ self.loadfile(filename)
+ self.configGUI(NORMAL, DISABLED, DISABLED, DISABLED,
+ "Choose example from menu", "black")
+ self.state = STARTUP
- root.title('Python turtle-graphics examples')
- #################
- self.left_frame = left_frame = Frame(root)
- self.text_frame = text_frame = Frame(left_frame)
- self.vbar = vbar =Scrollbar(text_frame, name='vbar')
- self.text = text = Text(text_frame,
- name='text', padx=5, wrap='none',
- width=45)
+
+ 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)
+
+ def makeTextFrame(self, root):
+ self.text_frame = text_frame = Frame(root)
+ self.text = text = Text(text_frame, name='text', padx=5,
+ wrap='none', width=45)
+
+ self.vbar = vbar = Scrollbar(text_frame, name='vbar')
vbar['command'] = text.yview
vbar.pack(side=LEFT, fill=Y)
- #####################
- self.hbar = hbar =Scrollbar(text_frame, name='hbar', orient=HORIZONTAL)
+ self.hbar = hbar = Scrollbar(text_frame, name='hbar', orient=HORIZONTAL)
hbar['command'] = text.xview
hbar.pack(side=BOTTOM, fill=X)
- #####################
+
+ text['font'] = txtfont
text['yscrollcommand'] = vbar.set
- text.config(font=txtfont)
- text.config(xscrollcommand=hbar.set)
- text.pack(side=LEFT, fill=Y, expand=1)
- #####################
- self.output_lbl = Label(left_frame, height= 1,text=" --- ", bg = "#ddf",
- font = ("Arial", 16, 'normal'))
- self.output_lbl.pack(side=BOTTOM, expand=0, fill=X)
- #####################
- text_frame.pack(side=LEFT, fill=BOTH, expand=0)
- left_frame.pack(side=LEFT, fill=BOTH, expand=0)
- self.graph_frame = g_frame = Frame(root)
-
- turtle._Screen._root = g_frame
- turtle._Screen._canvas = turtle.ScrolledCanvas(g_frame, 800, 600, 1000, 800)
- #xturtle.Screen._canvas.pack(expand=1, fill="both")
+ text['xscrollcommand'] = hbar.set
+ text.pack(side=LEFT, fill=BOTH, expand=1)
+ return text_frame
+
+ def makeGraphFrame(self, root):
+ turtle._Screen._root = root
+ self.canvwidth = 1000
+ self.canvheight = 800
+ 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
- #xturtle.RawTurtle.canvases = [self.scanvas]
turtle.RawTurtle.screens = [_s_]
-
- self.scanvas.pack(side=TOP, fill=BOTH, expand=1)
-
- self.btn_frame = btn_frame = Frame(g_frame, height=100)
- self.start_btn = Button(btn_frame, text=" START ", font=btnfont, fg = "white",
- disabledforeground = "#fed", command=self.startDemo)
- self.start_btn.pack(side=LEFT, fill=X, expand=1)
- self.stop_btn = Button(btn_frame, text=" STOP ", font=btnfont, fg = "white",
- disabledforeground = "#fed", command = self.stopIt)
- self.stop_btn.pack(side=LEFT, fill=X, expand=1)
- self.clear_btn = Button(btn_frame, text=" CLEAR ", font=btnfont, fg = "white",
- disabledforeground = "#fed", command = self.clearCanvas)
- self.clear_btn.pack(side=LEFT, fill=X, expand=1)
-
- self.btn_frame.pack(side=TOP, fill=BOTH, expand=0)
- self.graph_frame.pack(side=TOP, fill=BOTH, expand=1)
-
- Percolator(text).insertfilter(ColorDelegator())
- self.dirty = False
- self.exitflag = False
- if filename:
- self.loadfile(filename)
- self.configGUI(NORMAL, DISABLED, DISABLED, DISABLED,
- "Choose example from menu", "black")
- self.state = STARTUP
-
- def _destroy(self):
- self.root.destroy()
- sys.exit()
+ return canvas
def configGUI(self, menu, start, stop, clear, txt="", color="blue"):
self.ExamplesBtn.config(state=menu)
@@ -160,9 +172,9 @@ class DemoWindow(object):
self.output_lbl.config(text=txt, fg=color)
-
def makeLoadDemoMenu(self):
- CmdBtn = Menubutton(self.mBar, text='Examples', underline=0, font=menufont)
+ CmdBtn = Menubutton(self.mBar, text='Examples',
+ underline=0, font=menufont)
CmdBtn.pack(side=LEFT, padx="2m")
CmdBtn.menu = Menu(CmdBtn)
@@ -172,17 +184,18 @@ class DemoWindow(object):
self.loadfile(x)
return emit
if isinstance(entry,str):
- CmdBtn.menu.add_command(label=entry[6:-3], underline=0, font=menufont,
+ CmdBtn.menu.add_command(label=entry[6:-3], underline=0,
+ font=menufont,
command=loadexample(entry))
else:
_dir, entries = entry[0], entry[1:]
CmdBtn.menu.choices = Menu(CmdBtn.menu)
for e in entries:
- CmdBtn.menu.choices.add_command(label=e[6:-3], underline=0, font=menufont,
- command = loadexample(os.path.join(_dir,e)))
-
- CmdBtn.menu.add_cascade(label=_dir[6:],
- menu = CmdBtn.menu.choices, font=menufont )
+ CmdBtn.menu.choices.add_command(
+ label=e[6:-3], underline=0, font=menufont,
+ command = loadexample(os.path.join(_dir,e)))
+ CmdBtn.menu.add_cascade(
+ label=_dir[6:], menu = CmdBtn.menu.choices, font=menufont)
CmdBtn['menu'] = CmdBtn.menu
return CmdBtn
@@ -193,9 +206,12 @@ class DemoWindow(object):
CmdBtn.pack(side=LEFT, padx='2m')
CmdBtn.menu = Menu(CmdBtn)
- CmdBtn.menu.add_command(label='About turtle.py', font=menufont, command=showAboutTurtle)
- CmdBtn.menu.add_command(label='turtleDemo - Help', font=menufont, command=showDemoHelp)
- CmdBtn.menu.add_command(label='About turtleDemo', font=menufont, command=showAboutDemo)
+ CmdBtn.menu.add_command(label='About turtle.py', font=menufont,
+ command=showAboutTurtle)
+ CmdBtn.menu.add_command(label='turtleDemo - Help', font=menufont,
+ command=showDemoHelp)
+ CmdBtn.menu.add_command(label='About turtleDemo', font=menufont,
+ command=showAboutDemo)
CmdBtn['menu'] = CmdBtn.menu
return CmdBtn
@@ -203,7 +219,6 @@ class DemoWindow(object):
def refreshCanvas(self):
if not self.dirty: return
self.screen.clear()
- #self.screen.mode("standard")
self.dirty=False
def loadfile(self,filename):
@@ -262,10 +277,12 @@ class DemoWindow(object):
self.configGUI(NORMAL, NORMAL, DISABLED, DISABLED,
"STOPPED!", "red")
turtle.TurtleScreen._RUNNING = False
- #print "stopIT: exitflag = True"
else:
turtle.TurtleScreen._RUNNING = False
- #print "stopIt: exitflag = False"
+
+ def _destroy(self):
+ self.root.destroy()
+ sys.exit()
if __name__ == '__main__':
demo = DemoWindow()