Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/turtledemo/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/turtledemo/__pycache__/__main__.cpython-35.opt-1.pyc



��Yf�7�@s�dZddlZddlZddlTddlmZmZddlmZddl	m
Z
ddlmZddl
Z
ddlZejjejje��ZejdkZd	Zd
ZdZdZd
ZddefZd)ZdddgZdZdZ dddddddddddgZ!dd �Z"d!efd"efd#e
jffZ#Gd$d%�d%e$�Z%d&d'�Z&e'd(kr�e&�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__�darwin������Arial��boldzLucida Console�
�normal��d��	�������cCsdd�tjt�D�S)NcSs?g|]5}|jd�r|ddkr|dd��qS)z.pyr�_Nr���)�endswith)�.0�entry�r#�8/opt/alt/python35/lib64/python3.5/turtledemo/__main__.py�
<listcomp>us	z%getExampleEntries.<locals>.<listcomp>)�os�listdir�demo_dirr#r#r#r$�getExampleEntriestsr)zTurtledemo helpzAbout turtledemozAbout turtle modulec@s�eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zddd
�Zddd�Z	dd�Z
dddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS)(�
DemoWindowNcCs�t�|_}t_|jd�|jd|j�tr�ddl}|j	dddddj
tj��ddgd	|j
d
|j
�}|jddd�|jddd�|jdd
ddd�|jdd
ddd�|jdd
ddd�t|dtdd�|_|jjd|j|j�dddd�|jjd|j|j�dddd�|jjd|j|j�dddd�|j|d<tdtdddtdd�}|j|j|��|j|j|��|jddd d!d"d#�t|d$dd%d&dd'd(d:dddt�|_ t!|d%d,d(t"d-d.d/d0d1|j#�|_$t!|d%d2d(t"d-d.d/d0d1|j%�|_&t!|d%d3d(t"d-d.d/d0d1|j'�|_(|j jddd4dd"d#d5d;�|j$jddd4dd"d6�|j&jddd4dd"d6�|j(jddd4dd"d6�t)|j*�j+t,��d7|_-d7|_.|r�|j/|�|j0t1t1t1d8d9�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�stderr�stdoutZweightr	Zminsize�Zr
rZrelief�borderwidth�menu�labelZExamples�	underlineZFontsizeZHelp�orientZ	sashwidthr
Z
sashrelief�bgz#ddd�rowZ
columnspanrZstickyZnewsZheight�textz --- z#ddf�fontr�rz START �fgZwhiteZdisabledforegroundz#fed�commandz STOP z CLEAR �column�padxZewFzChoose example from menu�black)rr7r)rr
)4ZTk�root�turtle�_root�titleZwm_protocol�_destroyr�
subprocess�Popen�formatr&�getpidZDEVNULLZgrid_rowconfigureZgrid_columnconfigure�MenuZRAISEDZmBarZadd_cascade�makeLoadDemoMenu�makeFontMenu�makeHelpMenuZPanedWindow�
HORIZONTALZSOLID�add�
makeTextFrame�makeGraphFrameZgridZLabelZRIDGE�
output_lblZButton�btnfont�	startDemo�	start_btn�stopIt�stop_btn�clearCanvas�	clear_btnrr5Zinsertfilterr�dirty�exitflag�loadfile�	configGUI�DISABLED�STARTUP�state)�self�filenamer=rB�pZpaner#r#r$�__init__�sn
		



%		

zDemoWindow.__init__cCsf|jj�}|jj�}|jjd|j||j�|jjd|j||j�dS)Ng�?)�_canvasZwinfo_widthZwinfo_heightZxview_moveto�	canvwidthZyview_moveto�
canvheight)r]�eventZcwidthZcheightr#r#r$�onResize�s"zDemoWindow.onResizec
Cs�t|�|_}t|dddddddd�|_}t|�t|dd	�|_}|j|d
<|jdt	dt
�t|dd
dt�|_}|j
|d
<|jdtdt�|j|d<|j|d<tt�|d<tr�dnd}|jd||j�|jd||j�|jd||j�|jd||j�|jd|j�|jd|j�|jd|j�|jdt	dtdd�|S)N�namer5r;r
ZwrapZnone�width�-�vbarr9ZsideZfill�hbarr2ZyscrollcommandZxscrollcommandr6ZCommandZControlz
<%s-minus>z<%s-underscore>z
<%s-equal>z	<%s-plus>z<Control-MouseWheel>z<Control-Button-4>z<Control-Button-5>�expandr	)ZFrame�
text_frameZTextr5rZ	ScrollbarriZyviewZpackZLEFT�YrJrjZxviewZBOTTOM�X�set�tuple�txtfontrZbind_all�
decrease_size�
increase_size�bind�update_mousewheelZBOTH)r]r=rlr5rirjZshortcutr#r#r$rL�s.




zDemoWindow.makeTextFramecCs�|tj_d|_d|_tj|dd|j|j�tj_|_}|j�|jj	d|j
�d|jd<tj�|_}tj
j||j�|j|_|gtj_|S)Ni�i iXz<Configure>rr.)r>Z_Screenr?rbrcZScrolledCanvasraZ
adjustScrollsZ_rootwindowrtreZScreen�screen�TurtleScreenr`�scanvasZ	RawTurtleZscreens)r]r=ZcanvasZ_s_r#r#r$rM�s		,

zDemoWindow.makeGraphFramecCs2|td<tt�|jd<d||jd<dS)Nr	r6zFont size %dr5)rqrpr5rN)r]�sizer#r#r$�set_txtsize�s
zDemoWindow.set_txtsizecCs"|jttddt��dS)Nr	�break)rz�maxrq�MINIMUM_FONT_SIZE)r]�dummyr#r#r$rr�szDemoWindow.decrease_sizecCs"|jttddt��dS)Nr	r{)rz�minrq�MAXIMUM_FONT_SIZE)r]r~r#r#r$rsszDemoWindow.increase_sizecCs.|jdktkr |j�S|j�SdS)Nr)Zdeltarrrrs)r]rdr#r#r$rus
zDemoWindow.update_mousewheel�ZbluecCs�|jjd|d|tkr$dnd�|jjd|d|tkrOdnd�|jjd|d|tkrzdnd�|jjd|d|�dS)Nr\r3z#d00z#fcar5r8)rQ�config�NORMALrSrUrN)r]�start�stop�clearZtxtZcolorr#r#r$rY
szDemoWindow.configGUIc
s[t|�}xHt�D]=}|�fdd�}|jd|dddtd|�qW|S)Ncs�j|�dS)N)rX)r")r]r#r$�loadsz)DemoWindow.makeLoadDemoMenu.<locals>.loadr0r1rr6r9)rFr)�add_command�menufont)r]�masterr/r"r�r#)r]r$rGszDemoWindow.makeLoadDemoMenuc
s�t|�}|jddd�jdt�|jddd�jdt�|j�xKtD]C}|�fdd�}|jdt|�dd	dtd|�q[W|S)
Nr0zDecrease (C-'-')r9r6zIncrease (C-'+')cs�j|�dS)N)rz)ry)r]r#r$�resize)sz'DemoWindow.makeFontMenu.<locals>.resizer1r)rFr�rrr�rsZ
add_separator�
font_sizes�str)r]r�r/ryr�r#)r]r$rH s

zDemoWindow.makeFontMenucs[t|�}xHtD]@\}}||�fdd�}|jd|dtd|�qW|S)Ncst�j||�dS)N)rr=)�
help_label�	help_file)r]r#r$�show3sz%DemoWindow.makeHelpMenu.<locals>.showr0r6r9)rF�help_entriesr�r�)r]r�r/r�r�r�r#)r]r$rI/s
 zDemoWindow.makeHelpMenucCs#|jr|jj�d|_dS)NF)rVrvr�)r]r#r#r$�
refreshCanvas8s	
zDemoWindow.refreshCanvasc
Cs�|j�dtj_d|}t|�tj||_t|jj	d��}|j
�}WdQRX|jjdd�|jj
d|�|jj|d�|jtttdd�t|_dS)	NFzturtledemo.�rz1.0�endz# - a Python turtle graphics examplezPress start button�red)rTr>rw�_RUNNING�
__import__�sys�modules�module�open�__file__�readr5Zdelete�insertr=r@rYr�rZ�READYr\)r]r^�modname�f�charsr#r#r$rX=s



zDemoWindow.loadfilecCs)|j�d|_dtj_|jtttdd�|jj	�|jj
d�t|_y4|j
j�}|dkr�t|_n	t|_Wn7tjk
r�|jdkr�dSt|_d}YnX|jtkr�|jttt|�n1|jtkr%d|_|jtttdd�dS)	NTzdemo running...r<ZstandardZ	EVENTLOOPzstopped!zuse mouse/keys or STOPr�)r�rVr>rwr�rYrZr�rvr��mode�RUNNINGr\r��main�EVENTDRIVEN�DONEZ
Terminatorr=rW)r]�resultr#r#r$rPLs2
	

	
	
	zDemoWindow.startDemocCsD|j�|jjd�|jjdd�|jttt�dS)N�allZcursorr�)r�rvZ_deleterxr�rYr�rZ)r]r#r#r$rTis
zDemoWindow.clearCanvascCsE|jr5|j�d|_|jtttdd�dtj_dS)NFzSTOPPED!r�)rWrTrYr�rZr>rwr�)r]r#r#r$rRos	
	
zDemoWindow.stopItcCs&dtj_|jj�d|_dS)NF)r>rwr�r=Zdestroy)r]r#r#r$rAws
zDemoWindow._destroy)�__name__�
__module__�__qualname__r`rerLrMrzrrrsrurYrGrHrIr�rXrPrTrRrAr#r#r#r$r*�s$D	
	r*cCst�}|jj�dS)N)r*r=Zmainloop)Zdemor#r#r$r�}s	r��__main__)rrr)(rr�r&ZtkinterZidlelib.ColorDelegatorrrZidlelib.PercolatorrZidlelib.textViewrZ
turtledemoZabout_turtledemor>Ztime�path�dirname�abspathr�r(�platformrr[r�r�r�r�r�r�rOrqr}r�r�r)r��objectr*r�r�r#r#r#r$�<module>Vs<
'		�