blob: a49720b07124db99d40f41df4b0623f223ed266a [file] [log] [blame]
Martin v. Löwis87184592008-06-04 06:29:55 +00001
2
3 ----------------------------------------------
4
Terry Jan Reedy3fecd482014-06-24 22:21:36 -04005 turtleDemo - Help
Martin v. Löwis87184592008-06-04 06:29:55 +00006
7 ----------------------------------------------
8
9 This document has two sections:
10
11 (1) How to use the demo viewer
12 (2) How to add your own demos to the demo repository
13
14
15 (1) How to use the demo viewer.
16
17 Select a demoscript from the example menu.
Terry Jan Reedy13755382014-10-09 18:44:26 -040018 The (syntax colored) source code appears in the left
Martin v. Löwis87184592008-06-04 06:29:55 +000019 source code window. IT CANNOT BE EDITED, but ONLY VIEWED!
20
21 - Press START button to start the demo.
22 - Stop execution by pressing the STOP button.
23 - Clear screen by pressing the CLEAR button.
24 - Restart by pressing the START button again.
25
26 SPECIAL demos are those which run EVENTDRIVEN.
27 (For example clock.py - or oldTurtleDemo.py which
28 in the end expects a mouse click.):
29
30 Press START button to start the demo.
31
32 - Until the EVENTLOOP is entered everything works
33 as in an ordinary demo script.
34
35 - When the EVENTLOOP is entered, you control the
36 application by using the mouse and/or keys (or it's
37 controlled by some timer events)
38 To stop it you can and must press the STOP button.
39
40 While the EVENTLOOP is running, the examples menu is disabled.
41
42 - Only after having pressed the STOP button, you may
43 restart it or choose another example script.
44
45 * * * * * * * *
46 In some rare situations there may occur interferences/conflicts
47 between events concerning the demo script and those concerning the
48 demo-viewer. (They run in the same process.) Strange behaviour may be
49 the consequence and in the worst case you must close and restart the
50 viewer.
51 * * * * * * * *
52
53
54 (2) How to add your own demos to the demo repository
Terry Jan Reedyf7f746a2014-06-30 16:09:16 -040055 IMPORTANT! When imported, the demo should not modify the system
56 by calling functions in other modules, such as sys, tkinter, or
57 turtle. Global variables should be initialized in main().
Martin v. Löwis87184592008-06-04 06:29:55 +000058
Terry Jan Reedy3fecd482014-06-24 22:21:36 -040059 - The script name must begin with tdemo_ ,
Martin v. Löwis87184592008-06-04 06:29:55 +000060 so it must have the form tdemo_<your-script-name>.py
61
Terry Jan Reedy3fecd482014-06-24 22:21:36 -040062 - The code must contain a main() function which will
63 be executed by the viewer (see provided example scripts).
64 It may return a string which will be displayed in the Label below
65 the source code window (when execution has finished.)
66
67 - In order to run mydemo.py by itself, such as during development,
68 add the following at the end of the file:
Martin v. Löwis87184592008-06-04 06:29:55 +000069
Terry Jan Reedy3fecd482014-06-24 22:21:36 -040070 if __name__ == '__main__':
71 main()
72 mainloop() # keep window
Martin v. Löwis87184592008-06-04 06:29:55 +000073
Terry Jan Reedy3fecd482014-06-24 22:21:36 -040074 python -m turtledemo.mydemo # will then run it
Martin v. Löwis87184592008-06-04 06:29:55 +000075
Terry Jan Reedy3fecd482014-06-24 22:21:36 -040076 - If the demo is EVENT DRIVEN, main must return the string
77 "EVENTLOOP". This informs the demo viewer that the script is
78 still running and must be stopped by the user!
Terry Jan Reedy122df1e2014-06-22 01:18:48 -040079
Terry Jan Reedy3fecd482014-06-24 22:21:36 -040080 If an "EVENTLOOP" demo runs by itself, as with clock, which uses
81 ontimer, or minimal_hanoi, which loops by recursion, then the
82 code should catch the turtle.Terminator exception that will be
83 raised when the user presses the STOP button. (Paint is not such
84 a demo; it only acts in response to mouse clicks and movements.)