11#!/usr/bin/env python3
2+
3+ """
4+ ----------------------------------------------
5+ turtleDemo - Help
6+ ----------------------------------------------
7+
8+ This document has two sections:
9+
10+ (1) How to use the demo viewer
11+ (2) How to add your own demos to the demo repository
12+
13+
14+ (1) How to use the demo viewer.
15+
16+ Select a demoscript from the example menu.
17+ The (syntax coloured) source code appears in the left
18+ source code window. IT CANNOT BE EDITED, but ONLY VIEWED!
19+
20+ - Press START button to start the demo.
21+ - Stop execution by pressing the STOP button.
22+ - Clear screen by pressing the CLEAR button.
23+ - Restart by pressing the START button again.
24+
25+ SPECIAL demos are those which run EVENTDRIVEN.
26+ (For example clock.py - or oldTurtleDemo.py which
27+ in the end expects a mouse click.):
28+
29+ Press START button to start the demo.
30+
31+ - Until the EVENTLOOP is entered everything works
32+ as in an ordinary demo script.
33+
34+ - When the EVENTLOOP is entered, you control the
35+ application by using the mouse and/or keys (or it's
36+ controlled by some timer events)
37+ To stop it you can and must press the STOP button.
38+
39+ While the EVENTLOOP is running, the examples menu is disabled.
40+
41+ - Only after having pressed the STOP button, you may
42+ restart it or choose another example script.
43+
44+ * * * * * * * *
45+ In some rare situations there may occur interferences/conflicts
46+ between events concerning the demo script and those concerning the
47+ demo-viewer. (They run in the same process.) Strange behaviour may be
48+ the consequence and in the worst case you must close and restart the
49+ viewer.
50+ * * * * * * * *
51+
52+
53+ (2) How to add your own demos to the demo repository
54+
55+ - Place the file in the same directory as turtledemo/__main__.py
56+ IMPORTANT! When imported, the demo should not modify the system
57+ by calling functions in other modules, such as sys, tkinter, or
58+ turtle. Global variables should be initialized in main().
59+
60+ - The code must contain a main() function which will
61+ be executed by the viewer (see provided example scripts).
62+ It may return a string which will be displayed in the Label below
63+ the source code window (when execution has finished.)
64+
65+ - In order to run mydemo.py by itself, such as during development,
66+ add the following at the end of the file:
67+
68+ if __name__ == '__main__':
69+ main()
70+ mainloop() # keep window open
71+
72+ python -m turtledemo.mydemo # will then run it
73+
74+ - If the demo is EVENT DRIVEN, main must return the string
75+ "EVENTLOOP". This informs the demo viewer that the script is
76+ still running and must be stopped by the user!
77+
78+ If an "EVENTLOOP" demo runs by itself, as with clock, which uses
79+ ontimer, or minimal_hanoi, which loops by recursion, then the
80+ code should catch the turtle.Terminator exception that will be
81+ raised when the user presses the STOP button. (Paint is not such
82+ a demo; it only acts in response to mouse clicks and movements.)
83+ """
284import sys
385import os
486
587from tkinter import *
688from idlelib .Percolator import Percolator
789from idlelib .ColorDelegator import ColorDelegator
8- from idlelib .textView import view_file # TextViewer
90+ from idlelib .textView import view_text # TextViewer
991from importlib import reload
92+ from turtledemo import __doc__ as about_turtledemo
1093
1194import turtle
1295import time
@@ -27,10 +110,10 @@ def getExampleEntries():
27110 return [entry [:- 3 ] for entry in os .listdir (demo_dir ) if
28111 entry .endswith (".py" ) and entry [0 ] != '_' ]
29112
30- help_entries = ( # (help_label, help_file )
31- ('Turtledemo help' , "demohelp.txt" ),
32- ('About turtledemo' , " about_turtledemo.txt" ),
33- ('About turtle module' , "about_turtle.txt" ),
113+ help_entries = ( # (help_label, help_doc )
114+ ('Turtledemo help' , __doc__ ),
115+ ('About turtledemo' , about_turtledemo ),
116+ ('About turtle module' , turtle . __doc__ ),
34117 )
35118
36119class DemoWindow (object ):
@@ -175,7 +258,7 @@ def makeHelpMenu(self):
175258
176259 for help_label , help_file in help_entries :
177260 def show (help_label = help_label , help_file = help_file ):
178- view_file (self .root , help_label , os . path . join ( demo_dir , help_file ) )
261+ view_text (self .root , help_label , help_file )
179262 CmdBtn .menu .add_command (label = help_label , font = menufont , command = show )
180263
181264 CmdBtn ['menu' ] = CmdBtn .menu
0 commit comments