JL i-YdZddlmZmZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZGddeZGd d eZGd d eZGd deZGddeZGddeZGddeZGddeZGddeZGddeZ GddeZ!GddeZ"Gdd Z#Gd!d"Z$Gd#d$Z%Gd%d&Z&Gd'd(e Z'd)Z(e)d*k(re(y+y+),a8 Tools for graphically displaying and interacting with the objects and processing classes defined by the Toolkit. These tools are primarily intended to help students visualize the objects that they create. The graphical tools are typically built using "canvas widgets", each of which encapsulates the graphical elements and bindings used to display a complex object on a Tkinter ``Canvas``. For example, NLTK defines canvas widgets for displaying trees and directed graphs, as well as a number of simpler widgets. These canvas widgets make it easier to build new graphical tools and demos. See the class documentation for ``CanvasWidget`` for more information. The ``nltk.draw`` module defines the abstract ``CanvasWidget`` base class, and a number of simple canvas widgets. The remaining canvas widgets are defined by submodules, such as ``nltk.draw.tree``. The ``nltk.draw`` module also defines ``CanvasFrame``, which encapsulates a ``Canvas`` and its scrollbars. It uses a ``ScrollWatcherWidget`` to ensure that all canvas widgets contained on its canvas are within the scroll region. Acknowledgements: Many of the ideas behind the canvas widget system are derived from ``CLIG``, a Tk-based grapher for linguistic data structures. For more information, see the CLIG homepage (http://www.ags.uni-sb.de/~konrad/clig.html). )ABCMetaabstractmethod)RAISEDButtonCanvasEntryFrameLabelMenu Menubutton Scrollbar StringVarTextTkToplevelWidget)asksaveasfilename)in_idleceZdZdZd%dZdZdZdZdZdZ d Z d Z d&d Z d Z d ZdZdZdZdZdZdZdZdZd'dZdZd'dZdZdZdZdZdZdZdZ d Z!d!Z"e#d"Z$d#Z%d$Z&y)( CanvasWidgeta- A collection of graphical elements and bindings used to display a complex object on a Tkinter ``Canvas``. A canvas widget is responsible for managing the ``Canvas`` tags and callback bindings necessary to display and interact with the object. Canvas widgets are often organized into hierarchies, where parent canvas widgets control aspects of their child widgets. Each canvas widget is bound to a single ``Canvas``. This ``Canvas`` is specified as the first argument to the ``CanvasWidget``'s constructor. Attributes. Each canvas widget can support a variety of "attributes", which control how the canvas widget is displayed. Some typical examples attributes are ``color``, ``font``, and ``radius``. Each attribute has a default value. This default value can be overridden in the constructor, using keyword arguments of the form ``attribute=value``: >>> from nltk.draw.util import TextWidget >>> cn = TextWidget(Canvas(), 'test', color='red') # doctest: +SKIP Attribute values can also be changed after a canvas widget has been constructed, using the ``__setitem__`` operator: >>> cn['font'] = 'times' # doctest: +SKIP The current value of an attribute value can be queried using the ``__getitem__`` operator: >>> cn['color'] # doctest: +SKIP 'red' For a list of the attributes supported by a type of canvas widget, see its class documentation. Interaction. The attribute ``'draggable'`` controls whether the user can drag a canvas widget around the canvas. By default, canvas widgets are not draggable. ``CanvasWidget`` provides callback support for two types of user interaction: clicking and dragging. The method ``bind_click`` registers a callback function that is called whenever the canvas widget is clicked. The method ``bind_drag`` registers a callback function that is called after the canvas widget is dragged. If the user clicks or drags a canvas widget with no registered callback function, then the interaction event will propagate to its parent. For each canvas widget, only one callback function may be registered for an interaction event. Callback functions can be deregistered with the ``unbind_click`` and ``unbind_drag`` methods. Subclassing. ``CanvasWidget`` is an abstract class. Subclasses are required to implement the following methods: - ``__init__``: Builds a new canvas widget. It must perform the following three tasks (in order): - Create any new graphical elements. - Call ``_add_child_widget`` on each child widget. - Call the ``CanvasWidget`` constructor. - ``_tags``: Returns a list of the canvas tags for all graphical elements managed by this canvas widget, not including graphical elements managed by its child widgets. - ``_manage``: Arranges the child widgets of this canvas widget. This is typically only called when the canvas widget is created. - ``_update``: Update this canvas widget in response to a change in a single child. For a ``CanvasWidget`` with no child widgets, the default definitions for ``_manage`` and ``_update`` may be used. If a subclass defines any attributes, then it should implement ``__getitem__`` and ``__setitem__``. If either of these methods is called with an unknown attribute, then they should propagate the request to ``CanvasWidget``. Most subclasses implement a number of additional methods that modify the ``CanvasWidget`` in some way. These methods must call ``parent.update(self)`` after making any changes to the canvas widget's graphical elements. The canvas widget must also call ``parent.update(self)`` after changing any attribute value that affects the shape or position of the canvas widget's graphical elements. :type __canvas: Tkinter.Canvas :ivar __canvas: This ``CanvasWidget``'s canvas. :type __parent: CanvasWidget or None :ivar __parent: This ``CanvasWidget``'s hierarchical parent widget. :type __children: list(CanvasWidget) :ivar __children: This ``CanvasWidget``'s hierarchical child widgets. :type __updating: bool :ivar __updating: Is this canvas widget currently performing an update? If it is, then it will ignore any new update requests from child widgets. :type __draggable: bool :ivar __draggable: Is this canvas widget draggable? :type __press: event :ivar __press: The ButtonPress event that we're currently handling. :type __drag_x: int :ivar __drag_x: Where it's been moved to (to find dx) :type __drag_y: int :ivar __drag_y: Where it's been moved to (to find dy) :type __callbacks: dictionary :ivar __callbacks: Registered callbacks. Currently, four keys are used: ``1``, ``2``, ``3``, and ``'drag'``. The values are callback functions. Each callback function takes a single argument, which is the ``CanvasWidget`` that triggered the callback. Nc |jtk(r tdt|ts td||_||_t|dsg|_d|_ d|_ d|_ dx|_ |_ i|_d|_t!|j#D] \}}|||< |j%|j'D]w}|j j)|d|j*|j j)|d|j*|j j)|d|j*yy) a Create a new canvas widget. This constructor should only be called by subclass constructors; and it should be called only "after" the subclass has constructed all graphical canvas objects and registered all child widgets. :param canvas: This canvas widget's canvas. :type canvas: Tkinter.Canvas :param parent: This canvas widget's hierarchical parent. :type parent: CanvasWidget :param attribs: The new canvas widget's attributes. z&CanvasWidget is an abstract base classzExpected a canvas!_CanvasWidget__childrenrN) __class__r TypeError isinstancer_CanvasWidget__canvas_CanvasWidget__parenthasattrr_CanvasWidget__hidden_CanvasWidget__updating_CanvasWidget__press_CanvasWidget__drag_x_CanvasWidget__drag_y_CanvasWidget__callbacks_CanvasWidget__draggablelistitems_manage_tagstag_bind_CanvasWidget__press_cb)selfcanvasparentattribsattrvaluetags T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/draw/util.py__init__zCanvasWidget.__init__s+ >>\ )DE E&&)01 1  t67 DO  ())    0 KD%DJ  ::< LC MM " "3(94?? K MM " "3(94?? K MM " "3(94?? K Lc|jryt|jdk(r td|jj |jS)a :return: A bounding box for this ``CanvasWidget``. The bounding box is a tuple of four coordinates, *(xmin, ymin, xmax, ymax)*, for a rectangle which encloses all of the canvas widget's graphical elements. Bounding box coordinates are specified with respect to the coordinate space of the ``Canvas``. :rtype: tuple(int, int, int, int) )rrrrrNo tags)r"lentags ValueErrorrbboxr/s r6r>zCanvasWidget.bboxsI == tyy{ q Y' '!t}}!!499;//r8ct|jdk(r td|jj|j}|d|dz S)z :return: The width of this canvas widget's bounding box, in its ``Canvas``'s coordinate space. :rtype: int rr:r;r<r=rr>r/r>s r6widthzCanvasWidget.widthQ tyy{ q Y' '!t}}!!499;/Awa  r8ct|jdk(r td|jj|j}|d|dz S)z :return: The height of this canvas widget's bounding box, in its ``Canvas``'s coordinate space. :rtype: int rr:rBrCs r6heightzCanvasWidget.heightrEr8c|jS)z :return: The hierarchical parent of this canvas widget. ``self`` is considered a subpart of its parent for purposes of user interaction. :rtype: CanvasWidget or None )r r?s r6r1zCanvasWidget.parents}}r8c|jS)z :return: A list of the hierarchical children of this canvas widget. These children are considered part of ``self`` for purposes of user interaction. :rtype: list of CanvasWidget )rr?s r6 child_widgetszCanvasWidget.child_widgetssr8c|jS)zi :return: The canvas that this canvas widget is bound to. :rtype: Tkinter.Canvas )rr?s r6r0zCanvasWidget.canvas! }}r8c||cxk(rdk(ry|jD]}|jj|||!|jr|jj |yy)a Move this canvas widget by a given distance. In particular, shift the canvas widget right by ``dx`` pixels, and down by ``dy`` pixels. Both ``dx`` and ``dy`` may be negative, resulting in leftward or upward movement. :type dx: int :param dx: The number of pixels to move this canvas widget rightwards. :type dy: int :param dy: The number of pixels to move this canvas widget downwards. :rtype: None rN)r<rmover update)r/dxdyr5s r6rPzCanvasWidget.move(s` =q=  99; ,C MM  sB + , == MM  & r8cH|j\}}}}|dk(r|j||z ||z |dk(r!|j||dz z |dz z ||z |dk(r|j||z ||z |dk(r!|j||z ||dz z |dz z |dk(r|j||z ||z |dk(r!|j||dz z |dz z ||z |dk(r|j||z ||z |d k(r"|j||z ||dz z |dz z y y ) a% Move this canvas widget to the given location. In particular, shift the canvas widget such that the corner or side of the bounding box specified by ``anchor`` is at location (``x``, ``y``). :param x,y: The location that the canvas widget should be moved to. :param anchor: The corner or side of the canvas widget that should be moved to the specified location. ``'N'`` specifies the top center; ``'NE'`` specifies the top right corner; etc. NWNrANEESESSWWN)r>rP)r/xyanchorx1y1x2y2s r6movetozCanvasWidget.moveto>s8BB T> IIa"fa"f % S= IIa"q&j26)1r6 2 T> IIa"fa"f % S= IIa"fa"q&j261 2 T> IIa"fa"f % S= IIa"q&j26)1r6 2 T> IIa"fa"f % S= IIa"fa"q&j261 2 r8c|j|jjy|jD]V}|jj |d|jj |d|jj |dX|jj |jd|_y)a Remove this ``CanvasWidget`` from its ``Canvas``. After a ``CanvasWidget`` has been destroyed, it should not be accessed. Note that you only need to destroy a top-level ``CanvasWidget``; its child widgets will be destroyed automatically. If you destroy a non-top-level ``CanvasWidget``, then the entire top-level widget will be destroyed. :raise ValueError: if this ``CanvasWidget`` has a parent. :rtype: None Nrrr)r destroyr<r tag_unbinddeleter/r5s r6rfzCanvasWidget.destroy^s == $ MM ! ! # 99; =C MM $ $S*; < MM $ $S*; < MM $ $S*; < =  diik* r8c|js |jry|jryd|_|j||jr|jj |d|_y)a Update the graphical display of this canvas widget, and all of its ancestors, in response to a change in one of this canvas widget's children. :param child: The child widget that changed. :type child: CanvasWidget NrHr)r"r#_updater rQr/childs r6rQzCanvasWidget.updatewsY ==ENN  ??  U == MM  &r8c|jry|jD]}|j|jy)z^ Arrange this canvas widget and all of its descendants. :rtype: None N)r"rmanager+rls r6rozCanvasWidget.manages3 == __ E LLN  r8c|j tdg}||jz }|jD]}||j z }|S)z :return: a list of the canvas tags for all graphical elements managed by this canvas widget, including graphical elements managed by its child widgets. :rtype: list of int z+Attempt to access a destroyed canvas widget)rr=r,rr<)r/r<rms r6r<zCanvasWidget.tagssW == JK K  __ !E EJJL D ! r8c8|dk(r||_ytd|z)z Set the value of the attribute ``attr`` to ``value``. See the class documentation for a list of attributes supported by this canvas widget. :rtype: None draggableUnknown attribute %rNr(r=r/r3r4s r6 __setitem__zCanvasWidget.__setitem__s% ; $D 3d:; ;r8c@|dk(r |jStd|z)z :return: the value of the attribute ``attr``. See the class documentation for a list of attributes supported by this canvas widget. :rtype: (any) rrrsrtr/r3s r6 __getitem__zCanvasWidget.__getitem__s) ; ## #3d:; ;r8c4d|jjzS)z] :return: a string representation of this canvas widget. :rtype: str z<%s>)r__name__r?s r6__repr__zCanvasWidget.__repr__s ////r8cvd|_|jD]}|jj|d!y)zL Temporarily hide this canvas widget. :rtype: None rHhiddenstateNr"r<r itemconfigris r6hidezCanvasWidget.hide7  99; :C MM $ $S $ 9 :r8cvd|_|jD]}|jj|d!y)zD Show a hidden canvas widget. :rtype: None rnormalrNrris r6showzCanvasWidget.showrr8c|jS)zU :return: True if this canvas widget is hidden. :rtype: bool )r"r?s r6r~zCanvasWidget.hiddenrNr8c"||j|<y)aF Register a new callback that will be called whenever this ``CanvasWidget`` is clicked on. :type callback: function :param callback: The callback function that will be called whenever this ``CanvasWidget`` is clicked. This function will be called with this ``CanvasWidget`` as its argument. :type button: int :param button: Which button the user should use to click on this ``CanvasWidget``. Typically, this should be 1 (left button), 3 (right button), or 2 (middle button). Nr')r/callbackbuttons r6 bind_clickzCanvasWidget.bind_clicks$, r8c0d|_||jd<y)a Register a new callback that will be called after this ``CanvasWidget`` is dragged. This implicitly makes this ``CanvasWidget`` draggable. :type callback: function :param callback: The callback function that will be called whenever this ``CanvasWidget`` is clicked. This function will be called with this ``CanvasWidget`` as its argument. rHdragN)r(r')r/rs r6 bind_dragzCanvasWidget.bind_drags#+ r8c. |j|=y#YyxYw)a. Remove a callback that was registered with ``bind_click``. :type button: int :param button: Which button the user should use to click on this ``CanvasWidget``. Typically, this should be 1 (left button), 3 (right button), or 2 (middle button). Nr)r/rs r6 unbind_clickzCanvasWidget.unbind_click s   (   c. |jd=y#YyxYw)zK Remove a callback that was registered with ``bind_drag``. rNrr?s r6 unbind_dragzCanvasWidget.unbind_drags   (  rc|jjds6|jjds|jjdry|jjd||_|jdk(r.|}|*|dr|j |n|j }|*|jjd|jz|jy) a Handle a button-press event: - record the button press event in ``self.__press`` - register a button-release callback. - if this CanvasWidget or any of its ancestors are draggable, then register the appropriate motion callback. zzzNrHrr)rbindunbindr$num_CanvasWidget__start_dragr1_CanvasWidget__release_cb)r/eventwidgets r6 __press_cbzCanvasWidget.__press_cb%s MM  2 3}}!!"56}}!!"56  Z(  99>F$+&''. $ /%));T=N=NOr8c|jjd|j|j|_|j |_y)z| Begin dragging this object: - register a motion callback - record the drag coordinates rN)rr_CanvasWidget__motion_cbr]r%r^r&r/rs r6 __start_dragzCanvasWidget.__start_dragIs4 :t'7'78  r8c|j|j|jz |j|jz |j|_|j|_y)z Handle a motion event: - move this object to the new location - record the new drag coordinates N)rPr]r%r^r&rs r6 __motion_cbzCanvasWidget.__motion_cbSsB %''DMM)577T]]+BC  r8c|jjd|jz|jjd|j|jjz dkrt |j |jj z t |j|jjz zdkr|jrc|jdk(rT|j|jj |jz |jj|jz |j|jd|_y|jdk(r|jd|_y)z Handle a release callback: - unregister motion & button release callbacks. - decide whether they clicked, dragged, or cancelled - call the appropriate handler. rrdrHN)rrrtimer$absr]r^r(rPr%r&_CanvasWidget__click_CanvasWidget__dragrs r6 __release_cbzCanvasWidget.__release_cb]s  1EII=> Z( JJ** *S 0EGGdllnn,-EGGdllnn4L0MMPQQEIIN LLNNT]]2DLLNNT]]4R LL # YY!^ KKM r8c|jr(d|jvr|jd} ||yy|j|jj yy#td|zYyxYw)z If this ``CanvasWidget`` has a drag callback, then call it; otherwise, find the closest ancestor with a drag callback, and call it. If no ancestors have a drag callback, do nothing. rzError in drag callback for %rN)r(r'printr r)r/cbs r6__dragzCanvasWidget.__dragxst   )))%%f-BtH* ]] & MM "'B9D@As AA/c||jvr|j|}||y|j|jj|yy)z If this ``CanvasWidget`` has a drag callback, then call it; otherwise, find the closest ancestor with a click callback, and call it. If no ancestors have a click callback, do nothing. N)r'r r)r/rrs r6__clickzCanvasWidget.__clicksL T%% %!!&)B tH]] & MM ! !& )'r8ct|dsg|_|jt|d||_|jj |y)a Register a hierarchical child widget. The child will be considered part of this canvas widget for purposes of user interaction. ``_add_child_widget`` has two direct effects: - It sets ``child``'s parent to this canvas widget. - It adds ``child`` to the list of canvas widgets returned by the ``child_widgets`` member function. :param child: The new child widget. ``child`` must not already have a parent. :type child: CanvasWidget rNz already has a parent)r!rr r=appendrls r6_add_child_widgetzCanvasWidget._add_child_widgetsLt67 DO >> %w&;<= = u%r8cH|jj|d|_y)a Remove a hierarchical child widget. This child will no longer be considered part of this canvas widget for purposes of user interaction. ``_add_child_widget`` has two direct effects: - It sets ``child``'s parent to None. - It removes ``child`` from the list of canvas widgets returned by the ``child_widgets`` member function. :param child: The child widget to remove. ``child`` must be a child of this canvas widget. :type child: CanvasWidget N)rremover rls r6_remove_child_widgetz!CanvasWidget._remove_child_widgets u%r8cy)z :return: a list of canvas tags for all graphical elements managed by this canvas widget, not including graphical elements managed by its child widgets. :rtype: list of int Nr?s r6r,zCanvasWidget._tagsr8cy)a Arrange the child widgets of this canvas widget. This method is called when the canvas widget is initially created. It is also called if the user calls the ``manage`` method on this canvas widget or any of its ancestors. :rtype: None Nrr?s r6r+zCanvasWidget._managerr8cy)z Update this canvas widget in response to a change in one of its children. :param child: The child that changed. :type child: CanvasWidget :rtype: None Nrrls r6rkzCanvasWidget._updaterr8N)rU)rH)'r{ __module__ __qualname____doc__r7r>rDrIr1rLr0rPrdrfrQror<rvryr|rrr~rrrrr.rrrrrrrrr,r+rkrr8r6rr>sqf2Lp 0 ! !',3@26   < <0::, , "PH  6# *(&((    r8r) metaclassc:eZdZdZdZdZdZdZdZdZ dZ y ) TextWidgeta A canvas widget that displays a single string of text. Attributes: - ``color``: the color of the text. - ``font``: the font used to display the text. - ``justify``: justification for multi-line texts. Valid values are ``left``, ``center``, and ``right``. - ``width``: the width of the text. If the text is wider than this width, it will be line-wrapped at whitespace. - ``draggable``: whether the text can be dragged by the user. c r||_|jdd||_tj||fi|y)a  Create a new text widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :type text: str :param text: The string of text to display. :param attribs: The new canvas widget's attributes. rHtextN)_text create_text_tagrr7)r/r0rr2s r6r7zTextWidget.__init__s9 &&q!$&7 dF6g6r8c|dvr4|dk(rd}|jj|j||iytj |||y)N)colorfontjustifyrDrfill)r0rrrrvrus r6rvzTextWidget.__setitem__sG 8 8w KKM $ $TYYu >  $ $T4 7r8c|dk(r3t|jj|j|S|dvr1|dk(rd}|jj|j|Stj ||S)NrD)rrrrr)intr0itemcgetrrryrxs r6ryzTextWidget.__getitem__ sp 7?t{{}--dii>? ? 1 1w;;=))$))T: :++D$7 7r8c|jgSrrr?s r6r,zTextWidget._tags {r8cV|jj|jdS)zV :return: The text displayed by this text widget. :rtype: str TEXT)r0rrr?s r6rzTextWidget.texts! {{}%%dii88r8c|jj|j||j |jj |yy)z Change the text that is displayed by this text widget. :type text: str :param text: The string of text to display. :rtype: None rN)r0rrr1rQ)r/rs r6set_textzTextWidget.set_textsF    6 ;;= $ KKM  & %r8c d|jzS)Nz [Text: %r])rr?s r6r|zTextWidget.__repr__+sdjj((r8N) r{rrrr7rvryr,rrr|rr8r6rrs*  7889 ')r8rceZdZdZidddddddd d d d d dddddddddddddedddddd d!d"d#d$d%iZd&Zd'Zd(Zd)Z e d,d*Z y+)- SymbolWidgeta A canvas widget that displays special symbols, such as the negation sign and the exists operator. Symbols are specified by name. Currently, the following symbol names are defined: ``neg``, ``disj``, ``conj``, ``lambda``, ``merge``, ``forall``, ``exists``, ``subseteq``, ``subset``, ``notsubset``, ``emptyset``, ``imp``, ``rightarrow``, ``equal``, ``notequal``, ``epsilon``. Attributes: - ``color``: the color of the text. - ``draggable``: whether the text can be dragged by the user. :cvar SYMBOLS: A dictionary mapping from symbols to the character in the ``symbol`` font used to render them. negØdisjÚconjÙlambdalmergeÄforall"exists$subseteqÍsubsetÌ notsubsetËemptysetÆimpÞ rightarrowequal=notequal¹ intersectionÇunionÈepsilonec `d|d<tj||dfi||j|y)a Create a new symbol widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :type symbol: str :param symbol: The name of the symbol to display. :param attribs: The new canvas widget's attributes. symbolrN)rr7 set_symbol)r/r0rr2s r6r7zSymbolWidget.__init__Vs0#D&"88 r8c|jS)zz :return: the name of the symbol that is displayed by this symbol widget. :rtype: str _symbolr?s r6rzSymbolWidget.symbolds ||r8c|tjvrtd|z||_|j tj|y)z Change the symbol that is displayed by this symbol widget. :type symbol: str :param symbol: The name of the symbol to display. zUnknown symbol: %sN)rSYMBOLSr=r r)r/rs r6rzSymbolWidget.set_symbollsA -- -1F:; ;  l**623r8c d|jzS)Nz [Symbol: %r]rr?s r6r|zSymbolWidget.__repr__xs ,,r8ct}|fd}|jd|t|d|jj dt |d| fdd }|j d t ||j }|j|d <|j dd|jdd| ftdD]}|dvrttjjD]*\}}|t|k(s|j!dd|zn|j!dd|z|j!ddt|zd|j#y)z Open a new Tkinter window that displays the entire alphabet for the symbol font. This is useful for constructing the ``SymbolWidget.SYMBOLS`` dictionary. c$|jyr)rf)rtops r6rfz)SymbolWidget.symbolsheet..destroys KKMr8qQuitrcommandbottomside helvetica)rrDrIleftryscrollcommandrightr^rrr)r)r endz%-10s z%-10d z[%s] N)rrrrfpackrr yviewset tag_configranger)rr r*chrinsertmainloop)sizerrfrsbikvs r6 symbolsheetzSymbolWidget.symbolsheet{sHd  gs5:::IC{TE2"RH v  sDJJ /!#  W3' 4%'89s  $ $T4 7r8c|dk(r |jS|dk(r3t|jj|j|S|dvr*|jj|j|St j ||S)NrGrDrH)rBfloatr0rrDrryrxs r6ryzBoxWidget.__getitem__sv 8 <<  W_// 4@A A 1 1;;=))$))T: :++D$7 7r8c|j\}}}}|j|ddz z}|jj|j||z ||z ||z||zy)NrDrA)r>rBr0coordsrD)r/rmr`rarbrcrGs r6rkzBoxWidget._updates` ::<RRW  11  IIrF{BKfb6k r8c|jgSr)rDr?s r6r,zBoxWidget._tags rr8N r{rrrr7rvryrkr,rr8r6r@r@s! I"88 r8r@c2eZdZdZdZdZdZdZdZdZ y) OvalWidgeta A canvas widget that places a oval around a child widget. Attributes: - ``fill``: The color used to fill the interior of the oval. - ``outline``: The color used to draw the outline of the oval. - ``width``: The width of the outline of the oval. - ``margin``: The number of pixels space left between the child and the oval. - ``draggable``: whether the text can be dragged by the user. - ``double``: If true, then a double-oval is drawn. c n||_d|_|jdddd|_|j dd|_|j dd|_|j r|jdddd|_nd|_|j|jtj|||fi|y)a: Create a new oval widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :param child: The child widget. ``child`` must not have a parent. :type child: CanvasWidget :param attribs: The new canvas widget's attributes. rHcircleFdoubleN) r4rB create_oval_ovalpop_circle_double_oval2rEr2r7r5s r6r7zOvalWidget.__init__s  ''1a3 {{8U3 {{8U3 << ,,Q1a8DKDK$((vuHHr8c d|j}|dk(r||_y|dk(r|dk(r|j|j|j\}}}}|ddz}|j ||z ||z ||z||z|j |jd|j |jd|_|j|j|dk(r0|j#|j|jd|_yyy|d vr|j|j||i|j#|d k7r|j|j||i|j3|d k7r-|jj|j||iyyytj|||y) NrGrTTrDrArI)rIrDFrHr) r0rBrZr>rVrUrrErhrrrv) r/r3r4cr`rarbrcws r6rvzOvalWidget.__setitem__6s KKM 8  DL X }!4!" !3BBMA%mmFFFFJJtzz9=**TZZ9 ,  DKK(~$++"9%" #:~1 1 LLdE] 3{{&46> T[[4-8{{&46> ((tUmD,:&  $ $T4 7r8cB|dk(r |jS|dk(r|jduS|dk(r3t|jj |j |S|dvr*|jj |j |St j||S)NrGrTrDrH)rBrYrKr0rrVrryrxs r6ryzOvalWidget.__getitem__Ts 8 <<  X <rBrXrrr0rMrVrZ)r/rmRr`rarbrcrGrRrSr^r]rrrbots r6rkzOvalWidget._updatecs    ::<RR <<b\3rBw<BBw"WMR!VQaZBb"WMR!VQaZBB!a%L2Q</145sBGq=))2Q<"A,.!34CbA &&  JJv sV|UV^S6\  ;; " KKM  v !f q "f q   #r8cd|j |jgS|j|jgSr)rZrVr?s r6r,zOvalWidget._tagss+ ;; JJ< JJ , ,r8N) r{rrrr7rvryr`rkr,rr8r6rQrQs) I.8< 8 E@-r8rQc.eZdZdZdZdZdZdZdZy) ParenWidgeta A canvas widget that places a pair of parenthases around a child widget. Attributes: - ``color``: The color used to draw the parenthases. - ``width``: The width of the parenthases. - ``draggable``: whether the text can be dragged by the user. c ||_|jddddddd|_|jddddddd|_t j |||fi|y)aA Create a new parenthasis widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :param child: The child widget. ``child`` must not have a parent. :type child: CanvasWidget :param attribs: The new canvas widget's attributes. rHarcZ)stylestartextentiN)r4 create_arc_oparen_cparenr2r7r5s r6r7zParenWidget.__init__sf ((Aq!5SV(W ((Aq!5TW(X ((vuHHr8c|dk(rW|jj|j||jj|j|y|dk(rW|jj|j||jj|j|ytj |||y)NrrIrDrD)r0rrnrorrvrus r6rvzParenWidget.__setitem__s 7? KKM $ $T\\5 $ A KKM $ $T\\5 $ A W_ KKM $ $T\\ $ ? KKM $ $T\\ $ ?  $ $T4 7r8c|dk(r*|jj|jdS|dk(r*|jj|jdStj ||SNrrIrD)r0rrnrryrxs r6ryzParenWidget.__getitem__] 7?;;=))$,, B B W_;;=))$,,@ @++D$7 7r8c|j\}}}}t||z dz d}|jj|j||z |||z||jj|j ||z |||z|y)N)r>maxr0rMrnror/rmr`rarbrcrDs r6rkzParenWidget._updatesz ::<RRR"WM1% T\\2:r2:rJ T\\2:r2:rJr8c2|j|jgSr)rnror?s r6r,zParenWidget._tags dll++r8NrOrr8r6reres"I 88K ,r8rec.eZdZdZdZdZdZdZdZy) BracketWidgeta A canvas widget that places a pair of brackets around a child widget. Attributes: - ``color``: The color used to draw the brackets. - ``width``: The width of the brackets. - ``draggable``: whether the text can be dragged by the user. c ||_|jdddddddd|_|jdddddddd|_t j |||fi|y)a= Create a new bracket widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :param child: The child widget. ``child`` must not have a parent. :type child: CanvasWidget :param attribs: The new canvas widget's attributes. rHN)r4 create_line_obrack_cbrackr2r7r5s r6r7zBracketWidget.__init__sb ))!Q1aAqA ))!Q1aAqA ((vuHHr8c|dk(rW|jj|j||jj|j|y|dk(rW|jj|j||jj|j|ytj |||y)NrrrDrr)r0rrrrrvrus r6rvzBracketWidget.__setitem__s 7? KKM $ $T\\ $ > KKM $ $T\\ $ > W_ KKM $ $T\\ $ ? KKM $ $T\\ $ ?  $ $T4 7r8c|dk(r*|jj|jdS|dk(r*|jj|jdStj ||Srt)r0rrrryrxs r6ryzBracketWidget.__getitem__rur8c .|j\}}}}t||z dz d}|jj|j||||z |||z ||| |jj|j ||||z|||z||| y)NrA)r>ryr0rMrrrzs r6rkzBracketWidget._updates ::<RRR"WM1%  LL"b"u*b"u*b"b   LL"b"u*b"u*b"b r8c2|j|jgSr)rrr?s r6r,zBracketWidget._tagsr|r8NrOrr8r6r~r~s!I 88 ,r8r~cjeZdZdZdZdZdZdZdZdZ dZ d Z e jZd Zd Zd Zy )SequenceWidgeta A canvas widget that keeps a list of canvas widgets in a horizontal line. Attributes: - ``align``: The vertical alignment of the children. Possible values are ``'top'``, ``'center'``, and ``'bottom'``. By default, children are center-aligned. - ``space``: The amount of horizontal space to place between children. By default, one pixel of space is used. - ``ordered``: If true, then keep the children in their original order. cd|_d|_d|_t||_|D]}|j |t j||fi|y)aj Create a new sequence widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :param children: The widgets that should be aligned horizontally. Each child must not have a parent. :type children: list(CanvasWidget) :param attribs: The new canvas widget's attributes. centerrHFN_align_space_orderedr) _childrenrrr7r/r0childrenr2rms r6r7zSequenceWidget.__init__ V   h *E  " "5 ) *dF6g6r8c|dk(r|dvrtd|z||_y|dk(r||_y|dk(r||_ytj |||y)Nalign)rrrBad alignment: %rspaceorderedr=rrrrrvrus r6rvzSequenceWidget.__setitem__Y 7?77 !4u!<==DK W_DK Y !DM  $ $T4 7r8c|dk(r |jS|dk(r |jS|dk(r |jStj ||SNrrrrrrrryrxs r6ryzSequenceWidget.__getitem__*I 7?;;  W_;;  Y == ++D$7 7r8cgSrrr?s r6r,zSequenceWidget._tags4 r8cv|jdk(r|S|jdk(r|S|jdk(r||zdz Sy)NrrrrAr)r/rrbs r6_yalignzSequenceWidget._yalign7sC ;;% J ;;( "J ;;( "#I? " #r8c |j\}}}}|j||}|jD]<}|j\}} } } |jd||j| | z >|jrNt |jdkDr4|jj |} ||jz} t| dzt |jD]a}|j|j\}} } } | |kDs+|j|j| |z d| | |z |jzz } c||jz } t| dz ddD]a}|j|j\}} } } | | ks+|j|j| | z d| | |z |jzz} cyyyNrrH) r>rrrPrr;indexrr&)r/rmrrrrbr^r\r`rarbrcrr]r,s r6rkzSequenceWidget._update?s"'**,sE3 LLc " 0A vvx RR FF1a$,,r2.. / 0 ==S014NN((/E #A519c$..&9: /#'>>!#4#9#9#; RRr6NN1%**1r615b4;;..A  / t{{"A519b"- /#'>>!#4#9#9#; RRr6NN1%**1r615b4;;..A  /5=r8c <t|jdk(ry|jd}|j\}}}}|j||}|jj |}||j z}t |dzt|jD]n} |j| j\} } } } |j| j|| z ||j| | z || | z |j zz }p||j z }t |dz ddD]n} |j| j\} } } } |j| j|| z ||j| | z || | z |j zz}pyr)r;rr>rrrr&rP)r/rmrrrrbr^rr]r,r`rarbrcs r6r+zSequenceWidget._manageXs t~~ ! # q!#(**,sE3 LLc "$$U+ DKK uqy#dnn"56 'A#~~a0557 RR NN1  " "1r61t||B/C+C D b4;;& &A ' 4;; uqy"b) 'A#~~a0557 RR NN1  " "1r61t||B/C+C D b4;;& &A 'r8c>dt|jddzdzS)Nz [Sequence: rHrr<reprrr?s r6r|zSequenceWidget.__repr__qs"tDNN3Ab99C??r8c|jj|}||j|<|j||j||j |ya Replace the child canvas widget ``oldchild`` with ``newchild``. ``newchild`` must not have a parent. ``oldchild``'s parent will be set to None. :type oldchild: CanvasWidget :param oldchild: The child canvas widget to remove. :type newchild: CanvasWidget :param newchild: The canvas widget that should replace ``oldchild``. NrrrrrQr/oldchildnewchildrs r6 replace_childzSequenceWidget.replace_childwN$$X. (u !!(+ x( Hr8c|jj|}|j|=|j|t|jdkDr|j |jdyyz Remove the given child canvas widget. ``child``'s parent will be set to None. :type child: CanvasWidget :param child: The child canvas widget to remove. rNrrrr;rQr/rmrs r6 remove_childzSequenceWidget.remove_child]$$U+ NN5 ! !!%( t~~  " KKq) * #r8c^|jj|||j|ya Insert a child canvas widget before a given index. :type child: CanvasWidget :param child: The canvas widget that should be inserted. :type index: int :param index: The index where the child widget should be inserted. In particular, the index of ``child`` will be ``index``; and the index of any children whose indices were greater than equal to ``index`` before ``child`` was inserted will be incremented by one. Nrr(rr/rrms r6 insert_childzSequenceWidget.insert_child& eU+ u%r8N)r{rrrr7rvryr,rrkr+r|rrLrrrrrr8r6rrsL 7& 88#/2'2@))H$ +&r8rcjeZdZdZdZdZdZdZdZdZ dZ d Z e jZd Zd Zd Zy ) StackWidgeta A canvas widget that keeps a list of canvas widgets in a vertical line. Attributes: - ``align``: The horizontal alignment of the children. Possible values are ``'left'``, ``'center'``, and ``'right'``. By default, children are center-aligned. - ``space``: The amount of vertical space to place between children. By default, one pixel of space is used. - ``ordered``: If true, then keep the children in their original order. cd|_d|_d|_t||_|D]}|j |t j||fi|y)ae Create a new stack widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :param children: The widgets that should be aligned vertically. Each child must not have a parent. :type children: list(CanvasWidget) :param attribs: The new canvas widget's attributes. rrHFNrrs r6r7zStackWidget.__init__rr8c|dk(r|dvrtd|z||_y|dk(r||_y|dk(r||_ytj |||y)Nr)rrrrrrrrus r6rvzStackWidget.__setitem__rr8c|dk(r |jS|dk(r |jS|dk(r |jStj ||Srrrxs r6ryzStackWidget.__getitem__rr8cgSrrr?s r6r,zStackWidget._tagsrr8cv|jdk(r|S|jdk(r|S|jdk(r||zdz Sy)NrrrrAr)r/rrs r6_xalignzStackWidget._xalignsD ;;& K ;;' !L ;;( "5LA% % #r8c|j\}}}}|j||}|jD]<}|j\}} } } |j||j|| z d>|jrNt |jdkDr4|jj |} ||jz} t| dzt |jD]a}|j|j\}} } } | | kDs+|j|jd| | z | | | z |jzz } c||jz } t| dz ddD]a}|j|j\}} } } | | ks+|j|jd| | z | | | z |jzz} cyyyr) r>rrrPrr;rrr&)r/rmrrrrbr]r\r`rarbrcrr^r,s r6rkzStackWidget._updates"'**,sE3 LLu % 0A vvx RR FF1t||B++Q / 0 ==S014NN((/Edkk!A519c$..&9: /#'>>!#4#9#9#; RRr6NN1%**1a"f5b4;;..A  / dkk!A519b"- /#'>>!#4#9#9#; RRr6NN1%**1a"f5b4;;..A  /5=r8c<t|jdk(ry|jd}|j\}}}}|j||}|jj |}||j z}t |dzt|jD]n} |j| j\} } } } |j| j||j| | z || z || | z |j zz }p||j z }t |dz ddD]n} |j| j\} } } } |j| j||j| | z || z || | z |j zz}pyr)r;rr>rrrr&rP)r/rmrrrrbr]rr^r,r`rarbrcs r6r+zStackWidget._manages t~~ ! # q!#(**,sE3 LLu %$$U+ $++ uqy#dnn"56 'A#~~a0557 RR NN1  " "1t||B';#;QV D b4;;& &A ' $++ uqy"b) 'A#~~a0557 RR NN1  " "1t||B';#;QV D b4;;& &A 'r8c>dt|jddzdzS)Nz[Stack: rHrr<rr?s r6r|zStackWidget.__repr__s"D0266<r0rMr)r/rDr`rarbrcs r6 set_widthzSpaceWidget.set_widthss< 99;RR TYYBU B?r8c|j\}}}}|jj|j|||||zy)z Change the height of this space widget. :param height: The new height. :type height: int :rtype: None Nr)r/rIr`rarbrcs r6 set_heightzSpaceWidget.set_height~s< 99;RR TYYBBK@r8c|jgSrrr?s r6r,zSpaceWidget._tagsrr8cy)Nz[Space]rr?s r6r|zSpaceWidget.__repr__sr8N) r{rrrr7rrr,r|rr8r6rrTs"7* @ Ar8rc4eZdZdZdZdZdZdZdZdZ y) ScrollWatcherWidgeta  A special canvas widget that adjusts its ``Canvas``'s scrollregion to always include the bounding boxes of all of its children. The scroll-watcher widget will only increase the size of the ``Canvas``'s scrollregion; it will never decrease it. cb|D]}|j|tj||fi|y)a Create a new scroll-watcher widget. :type canvas: Tkinter.Canvas :param canvas: This canvas widget's canvas. :type children: list(CanvasWidget) :param children: The canvas widgets watched by the scroll-watcher. The scroll-watcher will ensure that these canvas widgets are always contained in their canvas's scrollregion. :param attribs: The new canvas widget's attributes. N)rrr7rs r6r7zScrollWatcherWidget.__init__s6 *E  " "5 ) *dF6g6r8cH|j||j|y)a0 Add a new canvas widget to the scroll-watcher. The scroll-watcher will ensure that the new canvas widget is always contained in its canvas's scrollregion. :param canvaswidget: The new canvas widget. :type canvaswidget: CanvasWidget :rtype: None N)rrQr/ canvaswidgets r6 add_childzScrollWatcherWidget.add_childs |, L!r8c&|j|y)aA Remove a canvas widget from the scroll-watcher. The scroll-watcher will no longer ensure that the new canvas widget is always contained in its canvas's scrollregion. :param canvaswidget: The canvas widget to remove. :type canvaswidget: CanvasWidget :rtype: None N)rrs r6rz ScrollWatcherWidget.remove_childs !!,/r8cgSrrr?s r6r,zScrollWatcherWidget._tagsrr8c$|jyr)_adjust_scrollregionrls r6rkzScrollWatcherWidget._updates !!#r8c |j}|j}|djDcgc] }t|}}t |dk7ry|d|dks!|d|dks|d|dkDs |d|dkDrOdt |d|dt |d|dt |d|dt |d|dfz}||d<yycc}w) z Adjust the scrollregion of this scroll-watcher's ``Canvas`` to include the bounding boxes of all of its children. scrollregionrxNrrHrArGz %d %d %d %d)r>r0splitrr;minry)r/r>r0nrs r6rz(ScrollWatcherWidget._adjust_scrollregions yy{(.~(>(D(D(FG1AG G |  !  Gl1o %Awa(Awa(Awa((DG\!_-DG\!_-DG\!_-DG\!_- ,L &2F> ")HsCN) r{rrrr7rrr,rkrrr8r6rrs%7" " 0$2r8rcbeZdZdZddZdZddZdZdZddZ d Z d Z d Z ifd Z d ZdZy) CanvasFrameaS A ``Tkinter`` frame containing a canvas and scrollbars. ``CanvasFrame`` uses a ``ScrollWatcherWidget`` to ensure that all of the canvas widgets contained on its canvas are within its scrollregion. In order for ``CanvasFrame`` to make these checks, all canvas widgets must be registered with ``add_widget`` when they are added to the canvas; and destroyed with ``destroy_widget`` when they are no longer needed. If a ``CanvasFrame`` is created with no parent, then it will create its own main window, including a "Done" button and a "Print" button. Nc |t_jjdjjdfdjjdjjjdjn|_t jx_}t|fi|x_}tj d}tj d }|j|d <|j|d <|j|d <|j|d <|jd d|jdd|jddddj|d|d}||d<t|_|$jddj#yy)a Create a new ``CanvasFrame``. :type parent: Tkinter.BaseWidget or Tkinter.Tk :param parent: The parent ``Tkinter`` widget. If no parent is specified, then ``CanvasFrame`` will create a new main window. :param kw: Keyword arguments for the new ``Canvas``. See the documentation for ``Tkinter.Canvas`` for more information. NNLTKz c$jSr) print_to_file)rr/s r6z&CanvasFrame.__init__..st7I7I7Kr8z horizontalorientverticalrxscrollcommandrr^r)rrr]rrHbothrexpandrrz 0 0 {} {}rDrIrrr)r_parenttitlerrfr _framer_canvasr xviewr#r$r"formatr_scrollwatcher _init_menubar)r/r1kwframer0 xscrollbar yscrollbarrs` r6r7zCanvasFrame.__init__s >4DL LL  v & LL  m-K L LL  mT\\ : LL  mT\\ :!DL$DLL11 e &u 3 33 vt{{<@ t{{:> & 9 & 9#->> #->> Sw/Sx0 16 7#))&/6(;KL !-~1&9 > IIQVI ,     r8c$t|j}t|d}|jdd|jd|jdd|jd|j d d| |jj | y) Nr)tearoffzPrint to PostscriptzCtrl-p)label underliner acceleratorExitrHzCtrl-xFile)rr menu)r )r r add_commandrrf add_cascadeconfig)r/menubarfilemenus r6rzCanvasFrame._init_menubar"st||$+'&&  At||   &AHE )r8c ^|ddg}t|d}|sy|j\}}}}|jj|||dz|dz|dz|dzdd}|j d d }t |d 5}|j |jd dddy#1swYyxYw) a Print the contents of this ``CanvasFrame`` to a postscript file. If no filename is given, then prompt the user for one. :param filename: The name of the file to print the tree to. :type filename: str :rtype: None N)zPostscript files.ps)z All files*r) filetypesdefaultextensionrAr)r]r^rDrI pagewidth pageheightpagexpageyz 0 scalefont z 9 scalefont wbutf8)rrr postscriptreplaceopenwriteencode) r/filenameftypesx0y0r]hrfs r6rzCanvasFrame.print_to_file3s  13EFF(6ERH**,RA\\,,a%q5!e1u-   ''I (D ! /Q GGJ%%f- . / / /s 9!B##B,c|jdj\}}}}t|t|t|t|fS)z :return: The current scroll region for the canvas managed by this ``CanvasFrame``. :rtype: 4-tuple of int r)rrr)r/r`rarbrcs r6rzCanvasFrame.scrollregionQsC  <<7==?RRBR#b'3r733r8c|jS)ze :return: The canvas managed by this ``CanvasFrame``. :rtype: Tkinter.Canvas )rr?s r6r0zCanvasFrame.canvasZs ||r8c|||j|||\}}|j\}}}}|j||z ||z |jj |y)ad Register a canvas widget with this ``CanvasFrame``. The ``CanvasFrame`` will ensure that this canvas widget is always within the ``Canvas``'s scrollregion. If no coordinates are given for the canvas widget, then the ``CanvasFrame`` will attempt to find a clear area of the canvas for it. :type canvaswidget: CanvasWidget :param canvaswidget: The new canvas widget. ``canvaswidget`` must have been created on this ``CanvasFrame``'s canvas. :type x: int :param x: The initial x coordinate for the upper left hand corner of ``canvaswidget``, in the canvas's coordinate space. :type y: int :param y: The initial y coordinate for the upper left hand corner of ``canvaswidget``, in the canvas's coordinate space. N) _find_roomr>rPrr)r/rr]r^r`rarbrcs r6 add_widgetzCanvasFrame.add_widgetasj( 9 __\1a8FQ(,,.RR!b&!b&) %%l3r8c |j\}}}}|j}|j} |||z k\ry| ||z k\ry|j\} } } } |j || z dz || z dz |_|}t ||| z t ||z | z dz D]8}|jj|dz |dz ||zdz|| zdzr4||fcS|_|}t |||z t ||z |z dz D]8}|jj|dz |dz ||zdz|| zdzr4||fcSt ||| z t ||z | z dz D]a}t |||z t ||z |z dz D]:}|jj|dz |dz ||zdz|| zdzr4||fccScy)z9 Try to find a space for a given widget. )rr2r r) rrDrIr>rPr&rrfind_overlapping)r/r desired_x desired_yrrrrbr]r'r`rarbrcr]r^s r6r,zCanvasFrame._find_rooms#'"3"3"5sE3 LLN MMO   s ";;=RR D2INC"HrM2  A3acCi!mr-A)BC "||44E1q5!a%!)QUQYq6M  "  A4C1AR0G,HI "||44E1q5!a%!)QUQYq6M  " sC!GS#)a-2)=%>? "A4C1AR0G,HI "||44E1q5!a%!)QUQYq6M  " " r8cF|j||jy)z Remove a canvas widget from this ``CanvasFrame``. This deregisters the canvas widget, and destroys it. N) remove_widgetrfrs r6destroy_widgetzCanvasFrame.destroy_widgets <(r8c:|jj|yr)rrrs r6r4zCanvasFrame.remove_widgets ((6r8c >|jj|fi|y)zv Pack this ``CanvasFrame``. See the documentation for ``Tkinter.Pack`` for more information. N)rr"r/cnfrs r6r"zCanvasFrame.packs  ##r8c`|jy|jjd|_y)z Destroy this ``CanvasFrame``. If this ``CanvasFrame`` created a top-level window, then this will close that window. N)rrfr/rs r6rfzCanvasFrame.destroys( <<    r8cRtry|jj|i|y)z Enter the Tkinter mainloop. This function must be called if this frame is created from a non-interactive program (e.g. from a secript); otherwise, the frame will close as soon as the script completes. N)rrr)r/argskwargss r6r)zCanvasFrame.mainloops% 9  t.v.r8rNN)r{rrrr7rrrr0r-r,r5r4r"rfr)rr8r6rrsJ +!Z*"/<44<'R7$ /r8rc*eZdZdZddZdZdZdZy)ShowTextz A ``Tkinter`` window used to display a text. ``ShowText`` is typically used by graphical tools to display help text, or similar information. Nc `|||j|||\}}|tx|_}nt|x|_}|j |t |d|j }|jdt|} | jddt| d } | jd d t| fd ||d|} | jd|d| d<| jddd| j| d<| j| d<|jd|j |jd|j |jd|j |jd|j |jd|j | jy)NOkrrrrHrrrrrr^rword)wraprDrIr!disabledrr)rrrrrrr]r\)find_dimentionsr_toprrrrfr"r r rr(r#r$rfocus) r/rootrrrDrItextbox_optionsrbtbf scrollbartextboxs r6r7zShowText.__init__sp =FN"224GOUF < d "DI&tn ,DI % 3T4<< 8 HCj 'c*5 G#.sWuVWWud#% & 8&}} )$-MM ! dll# dll# dll# T\\* T\\* r8c|jd}|td|D}t|d}d}|D]B}t||kDr-|d|j d}||d}|dz }t||kDr-|dz }Dt|d}||fS)N c32K|]}t|ywr)r;).0lines r6 z+ShowText.find_dimentions..s73t97sPr rH)rryrr;rfind)r/rrDrIlinesmaxwidthrWbrks r6rJzShowText.find_dimentionss 4  =777H"%E Dd)e#6El((-CDz! d)e# aKF   VRvr8c`|jy|jjd|_yrrKrfr;s r6rfzShowText.destroy& 99    r8cRtry|jj|i|y)z Enter the Tkinter mainloop. This function must be called if this window is created from a non-interactive program (e.g. from a secript); otherwise, the window will close as soon as the script completes. N)rrKr)r=s r6r)zShowText.mainloops% 9  D+F+r8r@)r{rrrr7rJrfr)rr8r6rBrBs !F$ ,r8rBc8eZdZdZ d dZdZdZdZdZdZ y) EntryDialogz# A dialog box for entering Nc||_||_||_tt dt |dzdz }t ||_|r|jj|t|j}|jddddd|r!t|| }|jd d d t|| |_ |jjddd|jjd|t|jdd} | jdddt|j} | jddddt| d|j d} | jddt| d|j"dd} | jddt| d|j$d} | jd|jj'd |j"|jj'd!|j |jj'd"|j |jj)y)#NrrGrArHrrr )rrpadxpadyipadyrrr])rr_rgrrr])rrrgrsunken) borderwidthrelief)rrirg)rrrgrhCancelr)rrrDr)rrgrDactive)rrrDdefaultrApplyrrHrrI)r_original_text _set_callbackrryr;rrKrr r"r r_entryr(r_cancel_ok_applyrrL) r/r1 original_text instructions set_callbackrrD entryframerdividerbuttonsrOs r6r7zEntryDialog.__init__/s +)CC .2Q678V$  IIOOE "499% qvAARH j|4A FFcF 3Je4  "5 1m, qB #QR 0 " ACaa 8 74<z N) r _callbacks_marks_init_itemframecopy _textwidgetr _keypress _buttonpress_itemsr$)r/r1r*optionss r6r7zColorizedList.__init__s}   W\\^, lDNN; ot/@/@A  r8cy)z Set up any colortags that will be used by this colorized list. E.g.: textwidget.tag_config('terminal', foreground='black') Nr)r/ textwidgetrs r6_init_colortagszColorizedList._init_colortagsrr8cy)a Return a list of (text, colortag) tuples that make up the colorized representation of the item. Colorized representations may not span multiple lines. I.e., the text strings returned may not contain newline characters. Nrr/items r6 _item_reprzColorizedList._item_reprrr8NcB||jddS|j|S)zF :return: A list of the items contained by this list. N)r)r/rs r6rzColorizedList.gets& =;;q> !;;u% %r8c:t|}|j|k(ryt||_d|jd<|jjdd|D]_}|j |D]-\}}d|vsJd|jj d||/|jj dda|jjdd|jj d dd |jd<|jjy) zB Modify the list of items contained by this list. Nrr1.0r!rTz!item repr may not contain newlinez end-1charr(rG) r)rrrhrr(mark_setrclear)r/r*rrcolortags r6r$zColorizedList.sets U  ;;%  5k $,! u- 1D"&//$"7 ?h4'L)LL'  ''tX> ?    # #E4 0  1  U3 !!(E2$.! r8c"|8|jj|jjdddy|jj |}|j|=d|dzzd|dzz}}|jjd||y)z Remove highlighting from the given item; or from every item, if no item is given. :raise ValueError: If ``item`` is not contained in the list. :raise KeyError: If ``item`` is not marked. N highlightr end+1char%d.0rHrA)rrr tag_removerrr/rrrkr!s r6unmarkzColorizedList.unmarks < KK       ' ' UK HKK%%d+E D!"eai0&EAI2FCU    ' ' UC @r8cd|j|<|jj|}d|dzzd|dzz}}|jj d||y)zp Highlight the given item. :raise ValueError: If ``item`` is not contained in the list. rHrrArN)rrrrtag_addrs r6markzColorizedList.marksY  D !!$'%!),f .B   eS9r8cF|j|j|y)z Remove any current highlighting, and mark the given item. :raise ValueError: If ``item`` is not contained in the list. N)rrrs r6markonlyzColorizedList.markonlys  $r8c||jj|}|jjd|dzzy)z Adjust the view such that the given item is visible. If the item is already visible, then do nothing. rrHN)rrrsee)r/rrs r6viewzColorizedList.views5  !!$' Vuqy12r8c~|dk(rgd}n |dk(rgd}n|g}|D]!}d|jj|i|<#y)a Register a callback function with the list. This function will be called whenever the given event occurs. :param event: The event that will trigger the callback function. Valid events are: click1, click2, click3, space, return, select, up, down, next, prior, move :param func: The function that should be called when the event occurs. ``func`` will be called with a single item as its argument. (The item selected or the item moved to). selectclick1rreturnrPupdownnextpriorrHN)r setdefaultr/rfunceventsrs r6 add_callbackzColorizedList.add_callback sN H 2F f_4FWF 8A67DOO & &q" -d 3 8r8c|$t|jj}n|dk(rgd}n |dk(rgd}n|g}|D]#}||j|= |j||=%y#Y+xYw)z Deregister a callback function. If ``func`` is none, then all callbacks are removed for the given event. NrrrPr)r)rkeysrs r6remove_callbackzColorizedList.remove_callback s =$//..01F h 2F f_4FWF A|OOA&*40   s A''A+c >|jj|fi|yr) _itemframer"r8s r6r"zColorizedList.pack; sS'B'r8c >|jj|g|yr)rgridr8s r6rzColorizedList.grid? sS&2&r8c8|jjyr)rrLr?s r6rLzColorizedList.focusC s  r8c*t|j|_|jddt |jfi||_t |jdd|_|j j|jj|jj|j j|jjdd |j jd d d |j jdddd|j|j ||j jdd|j jddddd |j jddy)N backgroundz#e0e0e0rr) takefocusr)rrrr^rrHrrrrz#e0ffff1raised)rborderrlselr) foreground)rrrr )r rrrrrr _textscrollrr$r#r"r%rrE)r/rs r6rzColorizedList._init_itemframeK s\ - <3;7;$T__*U t/?/?/C/CD (8(8(>(>? 75 QV&A ## Ic( $  T--w7 ##Eb#9 ## bRa $  "";6r8c||jvryd|cxkrt|jkrnn|j|}nd}t|j|j D] }|| y)Nr)rr;rr)r)r/ritemnumrcb_funcs r6_fire_callbackzColorizedList._fire_callbackd sg  '   *#dkk* *;;w'DDDOOE2779: G DM r8cd|j|jfz}|jj|}t |j dddz }|j d|jz|y)Nz@%d,%d.rrHzclick%d)r]r^rrrrrr)r/rclickloc insert_pointrs r6rzColorizedList._buttonpressn sguww00''--h7 l((-a01A5 I 17;r8cP|jdk(s|jdk(rf|jjd}t|j dddz }|j |jj |y|jdk(rd}n7|jd k(rd }n%|jd k(rd }n|jd k(rd}ny|jjdd|z|jjd|jjddd|jjddd|jjd}t|j dddz }|j |jj |y)NReturnrr(rrrHDownz+1lineUpz-1lineNextz+10linesPriorz-10linescontinuerrrzinsert linestartzinsert lineendbreak) keysymrrrrrlowerrrrr)r/rrrdeltas r6rzColorizedList._keypresst sk <<8 #u||w'>++11(;L,,,S1!459G    2 2 4g >  \\V #E \\T !E \\V #E \\W $E !!(Hu,<= X& ##E5+>   (:r)r _callbackr _variabler;r$rrQrr7 widgetNamer _menu_wmenuname_valuesadd)r/mastervaluesrvariablerr4s r6r7zMutableOptionMenu.__init__ s Y/   "%.K/ v;? LL #$"#   'flB7)$VQ7     E HHUO zzV r8c|jvry|ffd }jj||jj|y)Nc(j|yr)r$)r4r/s r6r$z"MutableOptionMenu.add..set s HHUOr8)rr)rrrr)r/r4r$s` r6rzMutableOptionMenu.add sE DLL   UC8 E"r8cv|jj||jr|j|yyr)rr$r)r/r4s r6r$zMutableOptionMenu.set s, 5! >> NN5 ! r8c|jj|}|j|=|jj||yr)rrrrh)r/r4r,s r6rzMutableOptionMenu.remove s5 LL  u % LLO !Qr8cP|dk(r |jStj||S)Nr )_MutableOptionMenu__menurryr=s r6ryzMutableOptionMenu.__getitem__ s& 6>;; !!$--r8c<tj|d|_y)z,Destroy this widget and the associated menu.N)r rfrr?s r6rfzMutableOptionMenu.destroy s4  r8N) r{rrr7rr$rryrfrr8r6rr s "<#"  . r8rc 2d}d}tddd}|j}t|dd}t|d dd }t||d }t|ddd }t ||d }t ||dddd} t |t|dt|dt|dt|dt|dt|dt|d} t|dd} t|| || || d } t|ddd } t || | }t||dd}|j|dd| j||j||j||j||j||jy )!zC A simple demonstration showing how to use canvas widgets. c.ddlm}d|ddz|d<y)Nrrandintz#00%04d'rrandomrcwrs r6rzdemo..fill s"D!116 r8c.ddlm}d|ddz|d<y)Nrrz#ff%04drrrrs r6rzdemo..color s"'!T"227 r8r i,) closeenoughrDrIz hiya thererH)rrzo o || ___ Ur)rrrredrqz o o || \___/)rcyanrG)rrrrDrGrr]rzy: rr^rr)rztry clicking and dragginggreen4)rrD<N)rr0rrQrer@rrrrr~r-rr))rrcfr\ct3ct2coctcprequationrcstack prompt_msgcszzs r6demor s 2 3 3s ;B A Q  2C Q,8 LC AsE *B A)Q IB Q% (B 1bv!B GB Q!1cQ!1e1cQ #1c H 1b !E BUB IF '1hJ 6: .B q"HA 6BMM"b"MM$MM%MM$NN5NN5KKMr8__main__N)*rabcrrtkinterrrrrr r r r r rrrrrtkinter.filedialogr nltk.utilrrrrr2r@rQrer~rrrrrrBrerrrr{rr8r6rs48( 1a  Wa  RE)E)Pj:jZ7,l7,t8'8vv-(v-r4,)4,n8,+8,vi&\i&Xi&,i&X9,9xN2,N2li/i/bK,K,fIIbSSv< <H0h zFr8