a  ze:@sdZddlZddlZddlTddlmZmZddlmZddl m Z ddl mZ ddl Z ejejeZejdkZd Zd Zd Zd Zd ZddefZdZgdZdZdZgdZ ddZ!defde fde jffZ"Gddde#Z$ddZ%e&dkre%dS)a ---------------------------------------------- turtleDemo - Help ---------------------------------------------- This document has two sections: (1) How to use the demo viewer (2) How to add your own demos to the demo repository (1) How to use the demo viewer. Select a demoscript from the example menu. The (syntax colored) source code appears in the left source code window. IT CANNOT BE EDITED, but ONLY VIEWED! The demo viewer windows can be resized. The divider between text and canvas can be moved by grabbing it with the mouse. The text font size can be changed from the menu and with Control/Command '-'/'+'. It can also be changed on most systems with Control-mousewheel when the mouse is over the text. Press START button to start the demo. Stop execution by pressing the STOP button. Clear screen by pressing the CLEAR button. Restart by pressing the START button again. SPECIAL demos, such as clock.py are those which run EVENTDRIVEN. Press START button to start the demo. - Until the EVENTLOOP is entered everything works as in an ordinary demo script. - When the EVENTLOOP is entered, you control the application by using the mouse and/or keys (or it's controlled by some timer events) To stop it you can and must press the STOP button. While the EVENTLOOP is running, the examples menu is disabled. - Only after having pressed the STOP button, you may restart it or choose another example script. * * * * * * * * In some rare situations there may occur interferences/conflicts between events concerning the demo script and those concerning the demo-viewer. (They run in the same process.) Strange behaviour may be the consequence and in the worst case you must close and restart the viewer. * * * * * * * * (2) How to add your own demos to the demo repository - 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(). - The code must contain a main() function which will be executed by the viewer (see provided example scripts). It may return a string which will be displayed in the Label below the source code window (when execution has finished.) - In order to run mydemo.py by itself, such as during development, add the following at the end of the file: 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.) N)*)ColorDelegator color_config) Percolator) view_text)__doc__darwinArial )rrZbold)zLucida Console normald)  r rcCsddttDS)NcSs.g|]&}|dr|ddkr|ddqS)z.pyr_N)endswith).0entryr"G/opt/bitninja-python-dojo/embedded/lib/python3.9/turtledemo/__main__.py usz%getExampleEntries..)oslistdirdemo_dirr"r"r"r#getExampleEntriestsr(zTurtledemo helpzAbout turtledemozAbout turtle modulec@seZdZd(ddZddZddZdd Zd d Zd)d d Zd*ddZ ddZ d+ddZ ddZ ddZ ddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS), DemoWindowNc Cst|_}t_|d|d|jtrbddl}|j ddddd t ddg|j |j d |jdd d |jdd d |jd d d d |jdd d d |jdd d d t|tdd|_|jj||jddd|jj||jddd|jj||jddd|j|d<ttdtdd}|||||||jddddt|d ddddtd|_ trt!|d t"d!|j#d"|_$t!|d#t"d!|j%d"|_&t!|d$t"d!|j'd"|_(nHt!|d t"d%d&|j#d'|_$t!|d#t"d%d&|j%d'|_&t!|d$t"d%d&|j'd'|_(|j jd ddd(d)|j$jd d d*d+|j&jd dd*d+|j(jd dd*d+t)|j*+t,d,|_-d,|_.|rx|/||0t1t1t1d-d.t2|_3dS)/NzPython turtle-graphics examplesZWM_DELETE_WINDOWrZ osascriptz-ez tell application "System Events"z>set frontmost of the first process whose unix id is {} to truezend tell)stderrstdoutr )weightZ)Zminsizer,r r )relief borderwidthZExamples)menulabel underlineZFontsizeZHelpr0r z#ddd)orientZ sashwidthZ sashreliefbgr news)rowZ columnspanstickyz --- z#ddf)rr)Zheighttextr4fontr/r.z START z#00cc22)r9r:fgcommandz STOP z CLEAR Zwhitez#fed)r9r:r;Zdisabledforegroundr<)rr )r6columnr7padxZew)r6r=r7FzChoose example from menublack)4ZTkrootturtle_roottitleZ wm_protocol_destroyr subprocessrunformatr%getpidDEVNULLZgrid_rowconfigureZgrid_columnconfigureMenuZRAISEDZmBarZ add_cascademakeLoadDemoMenu makeFontMenu makeHelpMenuZ PanedWindow HORIZONTALZSOLIDadd makeTextFramemakeGraphFrameZgridZLabelZRIDGE output_lblZButtonbtnfont startDemo start_btnstopItstop_btn clearCanvas clear_btnrr9Z insertfilterrdirtyexitflagloadfile configGUIDISABLEDSTARTUPstate)selffilenamer@rEZpaner"r"r#__init__s       zDemoWindow.__init__cCsP|j}|j}|jd|j||j|jd|j||jdS)Ng?)_canvasZ winfo_widthZ winfo_heightZ xview_moveto canvwidthZ yview_moveto canvheight)raeventZcwidthZcheightr"r"r#onResizes  zDemoWindow.onResizecCs6t||_}t|ddddd|_}t|t|dd|_}|j|d<|jt t d t|d t d |_ }|j |d<|jttd |j|d <|j|d <tt|d<trdnd}|d||j|d||j|d||j|d||j|d|j|d|j|d|j|jt tdd|S)Nr9r Znone-)namer>wrapwidthvbar)rjr<)sidefillhbar)rjr3ZyscrollcommandZxscrollcommandr:ZCommandZControlz <%s-minus>z<%s-underscore>z <%s-equal>z <%s-plus>zzzr )rnroexpand)ZFrame text_frameTextr9rZ ScrollbarrmZyviewpackZLEFTYrNrpZxviewZBOTTOMXsettupletxtfontrZbind_all decrease_size increase_sizebindupdate_mousewheelZBOTH)rar@rrr9rmrpZshortcutr"r"r#rPs0       zDemoWindow.makeTextFramecCs|tj_d|_d|_t|dd|j|jtj_|_}||j d|j d|jd<t |_ }tj ||j|j|_|gtj_|S)Nii iXz rr/)rAZ_ScreenrBrerfZScrolledCanvasrdZ adjustScrollsZ _rootwindowr|rhZScreenscreen TurtleScreenrcscanvasZ RawTurtleZscreens)rar@ZcanvasZ_s_r"r"r#rQs  zDemoWindow.makeGraphFramecCs(|td<tt|jd<d||jd<dS)Nr r:z Font size %dr9)ryrxr9rR)rasizer"r"r# set_txtsizeszDemoWindow.set_txtsizecCs|ttddtdSNr break)rmaxryMINIMUM_FONT_SIZEradummyr"r"r#rzszDemoWindow.decrease_sizecCs|ttddtdSr)rminryMAXIMUM_FONT_SIZErr"r"r#r{szDemoWindow.increase_sizecCs$|jdkt kr|S|SdS)Nr)Zdeltarrzr{)rargr"r"r#r} szDemoWindow.update_mousewheelbluecCstr0|jj|d|jj|d|jj|dnT|jj||tkrDdndd|jj||tkr`dndd|jj||tkr|dndd|jj||ddS)N)r`z#d00z#fca)r`r4)r9r;)rrUconfigrWrYNORMALrR)rastartstopclearZtxtZcolorr"r"r#r]szDemoWindow.configGUIcs:t|}tD]&}|ffdd }|j|dt|dq|S)Ncs|dSN)r\)r!rar"r#load&sz)DemoWindow.makeLoadDemoMenu..loadrr1r2r:r<)rJr( add_commandmenufont)ramasterr0r!rr"rr#rK"s zDemoWindow.makeLoadDemoMenucsht|}|jdjtd|jdjtd|tD]*}|ffdd }|jt|dt|dq8|S)NzDecrease (C-'-'))r1r<r:zIncrease (C-'+')cs|dSr)r)rrr"r#resize5sz'DemoWindow.makeFontMenu..resizerr)rJrrzrr{Z add_separator font_sizesstr)rarr0rrr"rr#rL,s   zDemoWindow.makeFontMenucs<t|}tD]*\}}||ffdd }|j|t|dq |S)Ncstj||dSr)rr@) help_label help_filerr"r#show?sz%DemoWindow.makeHelpMenu..show)r1r:r<)rJ help_entriesrr)rarr0rrrr"rr#rM;s  zDemoWindow.makeHelpMenucCs|jr|jd|_dSNF)rZr~rrr"r"r# refreshCanvasDs zDemoWindow.refreshCanvascCs|dtj_d|}t|tj||_t|jj d}| }Wdn1sX0Y|j dd|j d||j|d|tttddt|_dS) NFz turtledemo.rz1.0endz# - a Python turtle graphics examplezPress start buttonred)rXrAr_RUNNING __import__sysmodulesmoduleopen__file__readr9deleteinsertr@rCr]rr^READYr`)rarbmodnamefcharsr"r"r#r\Is & zDemoWindow.loadfilecCs|d|_dtj_|tttdd|j |j dt |_ z$|j }|dkr`t|_ nt|_ Wn.tjy|jdurYdSt|_ d}Yn0|j tkr|ttt|n"|j tkrd|_|tttdddS) NTzdemo running...r?ZstandardZ EVENTLOOPzstopped!zuse mouse/keys or STOPr)rrZrArrr]r^rr~rmodeRUNNINGr`rmain EVENTDRIVENDONEZ Terminatorr@r[)raresultr"r"r#rTXs8           zDemoWindow.startDemocCs4||jd|jjdd|tttdS)Nallr)Zcursor)rr~_deleterrr]rr^rr"r"r#rXus zDemoWindow.clearCanvascCs2|jr&|d|_|tttdddtj_dS)NFzSTOPPED!r)r[rXr]rr^rArrrr"r"r#rV{s zDemoWindow.stopItcCsdtj_|jd|_dSr)rArrr@Zdestroyrr"r"r#rDs zDemoWindow._destroy)N)N)N)rr)__name__ __module__ __qualname__rcrhrPrQrrzr{r}r]rKrLrMrr\rTrXrVrDr"r"r"r#r)s$ L     r)cCst}|jdSr)r)r@Zmainloop)demor"r"r#rsr__main__)'rrr%tkinterZidlelib.colorizerrrZidlelib.percolatorrZidlelib.textviewrZ turtledemoZabout_turtledemorApathdirnameabspathrr'platformrr_rrrrrrrSryrrrr(robjectr)rrr"r"r"r#s@U