Issue #22065: forward port the changes in c26862955342, update docstring with

changes that were only merged into demohelp.txt, and re-delete demohelp.txt.
This commit is contained in:
Terry Jan Reedy 2014-08-15 00:39:04 -04:00
parent 8544378e59
commit 2d7d661f37

View file

@ -2,9 +2,7 @@
""" """
---------------------------------------------- ----------------------------------------------
turtleDemo - Help
turtledemo - Help
---------------------------------------------- ----------------------------------------------
This document has two sections: This document has two sections:
@ -54,18 +52,34 @@
(2) How to add your own demos to the demo repository (2) How to add your own demos to the demo repository
- place: same directory as turtledemo/__main__.py - Place the file in the same directory as turtledemo/__main__.py
IMPORTANT! When imported, the demo should not modify the system
by calling functions in other modules, such as sys, tkinter, or
turtle. Global variables should be initialized in main().
- requirements on source code: - The code must contain a main() function which will
code must contain a main() function which will be executed by the viewer (see provided example scripts).
be executed by the viewer (see provided example scripts) It may return a string which will be displayed in the Label below
main() may return a string which will be displayed the source code window (when execution has finished.)
in the Label below the source code window (when execution
has finished.)
!! For programs, which are EVENT DRIVEN, main must return - In order to run mydemo.py by itself, such as during development,
!! the string "EVENTLOOP". This informs the viewer, that the add the following at the end of the file:
!! script is still running and must be stopped by the user!
if __name__ == '__main__':
main()
mainloop() # keep window open
python -m turtledemo.mydemo # will then run it
- 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.)
""" """
import sys import sys
import os import os
@ -96,14 +110,11 @@ def getExampleEntries():
return [entry[:-3] for entry in os.listdir(demo_dir) if return [entry[:-3] for entry in os.listdir(demo_dir) if
entry.endswith(".py") and entry[0] != '_'] entry.endswith(".py") and entry[0] != '_']
def showDemoHelp(): help_entries = ( # (help_label, help_doc)
view_text(demo.root, "Help on turtledemo", __doc__) ('Turtledemo help', __doc__),
('About turtledemo', about_turtledemo),
def showAboutDemo(): ('About turtle module', turtle.__doc__),
view_text(demo.root, "About turtledemo", about_turtledemo) )
def showAboutTurtle():
view_text(demo.root, "About the turtle module.", turtle.__doc__)
class DemoWindow(object): class DemoWindow(object):
@ -245,12 +256,10 @@ class DemoWindow(object):
CmdBtn.pack(side=LEFT, padx='2m') CmdBtn.pack(side=LEFT, padx='2m')
CmdBtn.menu = Menu(CmdBtn) CmdBtn.menu = Menu(CmdBtn)
CmdBtn.menu.add_command(label='About turtle.py', font=menufont, for help_label, help_file in help_entries:
command=showAboutTurtle) def show(help_label=help_label, help_file=help_file):
CmdBtn.menu.add_command(label='turtleDemo - Help', font=menufont, view_text(self.root, help_label, help_file)
command=showDemoHelp) CmdBtn.menu.add_command(label=help_label, font=menufont, command=show)
CmdBtn.menu.add_command(label='About turtleDemo', font=menufont,
command=showAboutDemo)
CmdBtn['menu'] = CmdBtn.menu CmdBtn['menu'] = CmdBtn.menu
return CmdBtn return CmdBtn
@ -323,7 +332,6 @@ class DemoWindow(object):
def main(): def main():
global demo
demo = DemoWindow() demo = DemoWindow()
demo.root.mainloop() demo.root.mainloop()