%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2318/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2318/lib/python3/dist-packages/urwid/__pycache__/container.cpython-38.pyc

U

��dZ2L�@s�ddlmZmZddlmZmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZddlmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0Gd	d
�d
e1�Z2Gdd�de1�Z3Gd
d�de4�Z5Gdd�dee2e3�Z6Gdd�de4�Z7Gdd�dee2e3�Z8Gdd�de4�Z9Gdd�dee2�Z:Gdd�de4�Z;Gdd�dee2e3�Z<Gdd�de4�Z=Gdd �d ee2e3�Z>d!d"�Z?e@d#k�r�e?�d$S)%�)�division�print_function)�chain�repeat)�xrange)�is_mouse_press)�Widget�Divider�FLOW�FIXED�PACK�BOX�
WidgetWrap�GIVEN�WEIGHT�LEFT�RIGHT�RELATIVE�TOP�BOTTOM�CLIP�RELATIVE_100)�Padding�Filler�calculate_left_right_padding�calculate_top_bottom_filler�normalize_align�normalize_width�normalize_valign�normalize_height�simplify_align�simplify_width�simplify_valign�simplify_height)�
MonitoredList�MonitoredFocusList)�CompositeCanvas�
CanvasOverlay�
CanvasCombine�SolidCanvas�
CanvasJoinc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�WidgetContainerMixinzQ
    Mixin class for widget containers implementing common container methods
    cCs|j|djS)aG
        Container short-cut for self.contents[position][0].base_widget
        which means "give me the child widget at position without any
        widget decorations".

        This allows for concise traversal of nested container widgets
        such as:

            my_widget[position0][position1][position2] ...
        r)�contents�base_widget��selfZposition�r0�1/usr/lib/python3/dist-packages/urwid/container.py�__getitem__+sz WidgetContainerMixin.__getitem__cCsDg}|}z
|j}Wntk
r*|YSX|�|�|jj}qdS)z�
        Return the .focus_position values starting from this container
        and proceeding along each child widget until reaching a leaf
        (non-container) widget.
        N)�focus_position�
IndexError�append�focusr-)r/�out�w�pr0r0r1�get_focus_path8s


z#WidgetContainerMixin.get_focus_pathcCs*|}|D]}||jkr||_|jj}qdS)a�
        Set the .focus_position property starting from this container
        widget and proceeding along newly focused child widgets.  Any
        failed assignment due do incompatible position types or invalid
        positions will raise an IndexError.

        This method may be used to restore a particular widget to the
        focus by passing in the value returned from an earlier call to
        get_focus_path().

        positions -- sequence of positions
        N)r3r6r-)r/Z	positionsr8r9r0r0r1�set_focus_pathHs


z#WidgetContainerMixin.set_focus_pathcCs,g}|}|jj}|dkr|S|�|�qdS)aW
        Return the .focus values starting from this container
        and proceeding along each child widget until reaching a leaf
        (non-container) widget.

        Note that the list does not contain the topmost container widget
        (i.e., on which this method is called), but does include the
        lowest leaf widget.
        N)r-r6r5)r/r7r8r0r0r1�get_focus_widgets[s
z&WidgetContainerMixin.get_focus_widgetsN)�__name__�
__module__�__qualname__�__doc__r2r:r;r<r0r0r0r1r+'s

r+c@s eZdZdZdd�Zdd�ZdS)� WidgetContainerListContentsMixinzs
    Mixin class for widget containers whose positions are indexes into
    a list available as self.contents.
    cCsttt|j���S)z`
        Return an iterable of positions for this container from first
        to last.
        ��iterr�lenr,�r/r0r0r1�__iter__rsz)WidgetContainerListContentsMixin.__iter__cCsttt|j�ddd��S)z`
        Return an iterable of positions for this container from last
        to first.
        ����rBrEr0r0r1�__reversed__ysz-WidgetContainerListContentsMixin.__reversed__N)r=r>r?r@rFrIr0r0r0r1rAmsrAc@seZdZdS)�
GridFlowErrorN�r=r>r?r0r0r0r1rJ�srJc@s<eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
ee	dd�Zdd�Zdd�Z
e
ee
dd�Zdd�Zdd�Ze
eedd�Zedfdd�Zdd�Zdd �Ze
ed!d�Zd"d#�Ze
eed$d�Zd%d&�Zd'd(�Ze
eed)d�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd?d3d4�Z d@d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$d=d>�Z%dS)A�GridFlowz�
    The GridFlow widget is a flow widget that renders all the widgets it
    contains the same width and it arranges them from left to right and top to
    bottom.
    cCs
ttg�S�N)�	frozensetr
rEr0r0r1�sizing�szGridFlow.sizingcs�t�fdd�|D���_�j��j��j��fdd���j��j���_|�_|�_	|�_
d�_�j�
d���|�t|�f�dS)a�
        :param cells: list of flow widgets to display
        :param cell_width: column width for each cell
        :param h_sep: blank columns between each cell horizontally
        :param v_sep: blank rows between cells vertically
            (if more than one row is required to display all the cells)
        :param align: horizontal alignment of cells, one of\:
            'left', 'center', 'right', ('relative', percentage 0=left 100=right)
        csg|]}|t�ff�qSr0�r)�.0r8)�
cell_widthr0r1�
<listcomp>�sz%GridFlow.__init__.<locals>.<listcomp>cs���SrM��_invalidate��frEr0r1�<lambda>��z#GridFlow.__init__.<locals>.<lambda>N)r%�	_contents�set_modified_callbackrU�set_focus_changed_callback�set_validate_contents_modified�_contents_modified�_cell_width�h_sep�v_sep�align�
_cache_maxcol�_GridFlow__super�__init__�get_display_widgetrD)r/�cellsrRr`rarbr0)rRr/r1re�s
�
zGridFlow.__init__cCsd|_|j��dSrM)rcrdrUrEr0r0r1rU�szGridFlow._invalidatec
CsR|D]H}z|\}\}}|tkr"t�Wqttfk
rJtd|f��YqXqdS�Nzadded content invalid %r)r�
ValueError�	TypeErrorrJ�r/�slc�	new_items�itemr8�t�nr0r0r1r^�szGridFlow._contents_modifiedcs0tdd��jD�����fdd�}��|��S)Ncss|]\}}|VqdSrMr0�rQr8ror0r0r1�	<genexpr>�sz&GridFlow._get_cells.<locals>.<genexpr>cs����dSrM)�
_set_cellsr0�Zmlr/r0r1�
user_modified�sz*GridFlow._get_cells.<locals>.user_modified�r$r,r[�r/rur0rtr1�
_get_cells�s
zGridFlow._get_cellscs0�j}�fdd�|D��_|t|�kr,|�_dS)Ncsg|]}|t�jff�qSr0)rr_)rQ�newrEr0r1rS�sz'GridFlow._set_cells.<locals>.<listcomp>)r3r,rD�r/Zwidgetsr3r0rEr1rs�s
�zGridFlow._set_cellsz�
        A list of the widgets in this GridFlow

        .. note:: only for backwards compatibility. You should use the new
            use the new standard container property :attr:`contents` to modify
            GridFlow contents.
        ��doccCs|jSrM)r_rEr0r0r1�_get_cell_width�szGridFlow._get_cell_widthcs,|j}�fdd�|jD�|_||_�|_dS)Ncsg|]\}}|t�ff�qSr0rP�rQr8�options��widthr0r1rS�sz,GridFlow._set_cell_width.<locals>.<listcomp>)r3r,r_)r/r�r3r0r�r1�_set_cell_width�s
�zGridFlow._set_cell_widthzg
        The width of each cell in the GridFlow. Setting this value affects
        all cells.
        cCs|jSrM�rZrEr0r0r1�
_get_contents�szGridFlow._get_contentscCs||jdd�<dSrMr��r/�cr0r0r1�
_set_contents�szGridFlow._set_contentsa�
        The contents of this GridFlow as a list of (widget, options)
        tuples.

        options is currently a tuple in the form `('fixed', number)`.
        number is the number of screen columns to allocate to this cell.
        'fixed' is the only type accepted at this time.

        This list may be modified like a normal list and the GridFlow
        widget will update automatically.

        .. seealso:: Create new options tuples with the :meth:`options` method.
        NcCs,|tkrtd|f��|dkr$|j}||fS)z�
        Return a new options tuple for use in a GridFlow's .contents list.

        width_type -- 'given' is the only value accepted
        width_amount -- None to use the default cell_width for this GridFlow
        �invalid width_type: %rN)rrJr_)r/�
width_type�width_amountr0r0r1r�s
zGridFlow.optionscCst|t�r|�|�S|�|�S)a7
        Set the cell in focus, for backwards compatibility.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.

        :param cell: contained element to focus
        :type cell: Widget or int
        )�
isinstance�int�_set_focus_position�_set_focus_cell)r/�cellr0r0r1�	set_focus�s


zGridFlow.set_focuscCs|js
dS|j|jdS)z�
        Return the widget in focus, for backwards compatibility.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus` to get the focus.
        Nr�r,r3rEr0r0r1�	get_focusszGridFlow.get_focusz8the child widget in focus or None when GridFlow is emptycCs>t|j�D] \}\}}||kr
||_dSq
td|f��dS)Nz)Widget not found in GridFlow contents: %r)�	enumerater,r3ri)r/r��ir8rr0r0r1r�
s
zGridFlow._set_focus_cellaF
        The widget in focus, for backwards compatibility.

        .. note:: only for backwards compatibility. You should use the new
            use the new standard container property :attr:`focus` to get the
            widget in focus and :attr:`focus_position` to get/set the cell in
            focus by index.
        cCs|jstd��|jjS)zd
        Return the index of the widget in focus or None if this GridFlow is
        empty.
        z$No focus_position, GridFlow is empty�r,r4r6rEr0r0r1�_get_focus_positionszGridFlow._get_focus_positionc	CsRz|dks|t|j�krt�Wn&ttfk
rDtd|f��YnX||j_dS)�f
        Set the widget in focus.

        position -- index of child widget to be made focus
        rz'No GridFlow child widget at position %sN�rDr,r4rjr6r.r0r0r1r�$szGridFlow._set_focus_positionz�
        index of child widget in focus. Raises :exc:`IndexError` if read when
        GridFlow is empty, or when set to an invalid index.
        cCs.|\}|j|kr|jS||_|�|�|_|jS)z�
        Arrange the cells into columns (and possibly a pile) for
        display, input or to calculate rows, and update the display
        widget.
        )rc�_w�generate_display_widget)r/�size�maxcolr0r0r1rf5s
zGridFlow.get_display_widgetc
Cst|\}t�}|js|S|jdkr,|jd|_d}tg�}d}t|j�D�]\}\}\}	}
|dksl|||
kr�|jr�|j�||��f�tg|j	�}d}t
||j�}||_|j�||��f�|j�||�t
|
�f�||jks�|s�|��r�t|j�d|_d}||jk�rt|j�d|_tdd�|jD��|j	t|j�}|
|k�rN||_||j	|_qF|j�rp|jdd�=|S)zC
        Actually generate display widget (ignoring cache)
        rGNrFTcss|]}|ddVqdS)rGNr0)rQ�xr0r0r1rrisz3GridFlow.generate_display_widget.<locals>.<genexpr>)r	r,ra�top�Piler�r5r�Columnsr`rrb�first_positionrr3�
selectablerD�sumZoriginal_widgetr�)
r/r�r�Zdividerr�r9Z
used_spacer�r8r�r�Zcolumn_focusedZpadr0r0r1r�EsJ

���
z GridFlow.generate_display_widgetcCs8|jj}|sdS|j}|jr$|j}nd}|j||_dS)zK
        Set the focus to the item in focus in the display widget.
        Nr)r�r6r-r3r�)r/Z
pile_focusr�Zcol_focus_positionr0r0r1�_set_focus_from_display_widgetxs
z'GridFlow._set_focus_from_display_widgetcCs,|�|�|j�||�}|dkr(|��|S)z_
        Pass keypress to display widget for handling.
        Captures focus changes.
        N)rfrd�keypressr��r/r��keyr0r0r1r��s

zGridFlow.keypressFcCs|�|�|jj||d�S)N�r6)rfrd�rows�r/r�r6r0r0r1r��s
z
GridFlow.rowscCs|�|�|j�||�SrM)rfrd�renderr�r0r0r1r��s
zGridFlow.rendercCs|�|�|j�|�S)zGet cursor from display widget.)rfrd�get_cursor_coords�r/r�r0r0r1r��s
zGridFlow.get_cursor_coordscCs&|�|�|j�|||�}|��|S)z/Set the widget in focus based on the col + row.)rfrd�move_cursor_to_coordsr�)r/r��col�row�rvalr0r0r1r��s
zGridFlow.move_cursor_to_coordscCs,|�|�|j�||||||�|��dS)NT)rfrd�mouse_eventr�)r/r��event�buttonr�r�r6r0r0r1r��s
zGridFlow.mouse_eventcCs|�|�|j�|�S)z$Return pref col from display widget.)rfrd�get_pref_colr�r0r0r1r��s
zGridFlow.get_pref_col)F)F)&r=r>r?r@rOrerUr^rxrs�propertyrgr}r�rRr�r�r,rrr�r�r6r�Z
focus_cellr�r�r3rfr�r�r�r�r�r�r�r�r�r0r0r0r1rL�sF	

�	3

rLc@seZdZdS)�OverlayErrorNrKr0r0r0r1r��sr�c@s�eZdZdZdZeeg�Zede	dddde
de	ddddfZd+dd�Zd,dd	�Z
d-d
d�Zdd
�Zdd�Zdd�Zeedd�Zdd�Zdd�Zeeedd�Zdd�Zdd�Zdd�Zeedd�Zd d!�Zd"d#�Zd$d%�Zd.d'd(�Zd)d*�ZdS)/�OverlayzN
    Overlay contains two box widgets and renders one on top of the other
    TN�drc

Cs6|j��||_||_|�|||||||	|
||�
dS)a�
        :param top_w: a flow, box or fixed widget to overlay "on top"
        :type top_w: Widget
        :param bottom_w: a box widget to appear "below" previous widget
        :type bottom_w: Widget
        :param align: alignment, one of ``'left'``, ``'center'``, ``'right'`` or
            (``'relative'``, *percentage* 0=left 100=right)
        :type align: str
        :param width: width type, one of:

            ``'pack'``
              if *top_w* is a fixed widget
            *given width*
              integer number of columns wide
            (``'relative'``, *percentage of total width*)
              make *top_w* width related to container width

        :param valign: alignment mode, one of ``'top'``, ``'middle'``, ``'bottom'`` or
            (``'relative'``, *percentage* 0=top 100=bottom)
        :param height: one of:

            ``'pack'``
              if *top_w* is a flow or fixed widget
            *given height*
              integer number of rows high
            (``'relative'``, *percentage of total height*)
              make *top_w* height related to container height
        :param min_width: the minimum number of columns for *top_w* when width
            is not fixed
        :type min_width: int
        :param min_height: minimum number of rows for *top_w* when height
            is not fixed
        :type min_height: int
        :param left: a fixed number of columns to add on the left
        :type left: int
        :param right: a fixed number of columns to add on the right
        :type right: int
        :param top: a fixed number of rows to add on the top
        :type top: int
        :param bottom: a fixed number of rows to add on the bottom
        :type bottom: int

        Overlay widgets behave similarly to :class:`Padding` and :class:`Filler`
        widgets when determining the size and position of *top_w*. *bottom_w* is
        always rendered the full size available "below" *top_w*.
        N)Z_Overlay__superre�top_w�bottom_w�set_overlay_parameters)
r/r�r�rbr��valign�height�	min_width�
min_height�left�rightr��bottomr0r0r1re�s0
�zOverlay.__init__cCs |||||	|||||||
|
|fS)an
        Return a new options tuple for use in this Overlay's .contents mapping.

        This is the common container API to create options for replacing the
        top widget of this Overlay.  It is provided for completeness
        but is not necessarily the easiest way to change the overlay parameters.
        See also :meth:`.set_overlay_parameters`
        r0)r/�
align_type�align_amountr�r��valign_type�
valign_amount�height_type�
height_amountr�r�r�r�r�r�r0r0r1rs�zOverlay.optionscCs�t|t�r<|ddkr$|d}t}n|ddkr<|d}t}t|t�rx|ddkr`|d}t}n|ddkrx|d}t}t|t�r�|ddkr�|d}	t}n|ddkr�|d}
t}t|t�r�|ddkr�|d}
t}n|ddkr�|d}	t}|dkr�t}|dk�r
t}t|t	�\}}t
|t	�\}
}t|t	�\}}t|t	�\}}|t
tfk�rTd}|j|�|||
||||||||||	|
�f|jd<dS)z�
        Adjust the overlay size and position parameters.

        See :class:`__init__() <Overlay>` for a description of the parameters.
        rz
fixed leftrGzfixed rightz	fixed topzfixed bottomN)r��tuplerrrrrrrr�rrrrr�rr,)r/rbr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0r0r1r�sl	




�zOverlay.set_overlay_parameterscCs
|j��S)zReturn selectable from top_w.)r�r�rEr0r0r1r�LszOverlay.selectablecCs"|j�|j|f|�|d���|�S)zPass keypress to top_w.T)r�r��
top_w_size�calculate_padding_fillerr�r0r0r1r�Ps

��zOverlay.keypresscCs|jS)zH
        Currently self.top_w is always the focus of an Overlay
        )r�rEr0r0r1�
_get_focusUszOverlay._get_focusz1the top widget in this overlay is always in focusr{cCsdS)zF
        Return the top widget position (currently always 1).
        rGr0rEr0r0r1r�]szOverlay._get_focus_positioncCs|dkrtd|f��dS)z�
        Set the widget in focus.  Currently only position 0 is accepted.

        position -- index of child widget to be made focus
        rGzGOverlay widget focus_position currently must always be set to 1, not %sN)r4r.r0r0r1r�bs�zOverlay._set_focus_positionz2index of child widget in focus, currently always 1csG�fdd�dt�}|�S)Ncs eZdZdd�Z�jZ�jZdS)z*Overlay._contents.<locals>.OverlayContentscSsdS)N�r0��
inner_selfr0r0r1�__len__psz2Overlay._contents.<locals>.OverlayContents.__len__N)r=r>r?r��_contents__getitem__r2�_contents__setitem__�__setitem__r0rEr0r1�OverlayContentsosr���object)r/r�r0rEr1rZnszOverlay._contentscCsp|dkr|j|jfS|dkr^|j|j|j|j|j|j|j|j	|j
|j|j|j
|j|j|jffStd|f��dS)NrrG�#Overlay.contents has no position %r)r��_DEFAULT_BOTTOM_OPTIONSr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r4)r/�indexr0r0r1r�us,��zOverlay._contents__getitem__cCsvz|\}}Wn&ttfk
r2td|f��YnX|dkr`||jkrVtd|jf��||_�n
|dk�r\z$|\}}}}}	}
}}}
}}}}}Wn&ttfk
r�td|f��YnXtt||�t�\}}tt||�t�\}}t	t
||
�t�\}}tt||�t�\}}||_
||_||_||_||_|
|_||_||_|
|_||_||_||_|	|_||_ntd|f��|��dS)N�added content invalid: %rrz bottom_options must be set to %rrGztop_options is invalid: %rr�)rirjr�r�r�rr rr!rr"rr#r�r�r�r�r�r�r�r�r�r�r�r�r�r�r4rU)r/r��value�value_w�
value_optionsr�r�r�r�r�r�r�r�r�r�r�r�r�r�Zvalign_amounr0r0r1r��s~
�

�
�������zOverlay._contents__setitem__a-
        a list-like object similar to::

            [(bottom_w, bottom_options)),
             (top_w, top_options)]

        This object may be used to read or update top and bottom widgets and
        top widgets's options, but no widgets may be added or removed.

        `top_options` takes the form
        `(align_type, align_amount, width_type, width_amount, min_width, left,
        right, valign_type, valign_amount, height_type, height_amount,
        min_height, top, bottom)`

        bottom_options is always
        `('left', None, 'relative', 100, None, 0, 0,
        'top', None, 'relative', 100, None, 0, 0)`
        which means that bottom widget always covers the full area of the Overlay.
        writing a different value for `bottom_options` raises an
        :exc:`OverlayError`.
        c
Cspt|jd�sdS|\}}|�|d�\}}}}|j�||||||f�\}}	|	|kr`|d}	|||	|fS)z(Return cursor coords from top_w, if any.r�NTrG)�hasattrr�r�r�)
r/r�r��maxrowr�r�r�r�r��yr0r0r1r��s��zOverlay.get_cursor_coordsc	CsN|\}}d}|jtkrZ|jjd|d�\}}|s6td��t||j|jt|d|j	|j
�\}}n(t||j|j|j|j|j|j	|j
�\}}|r�t
||j|jt|d|j|j�\}	}
||	|
|kr�||	|}
n||jtk�r|jj|f|d�}t
||j|jt|d|j|j�\}	}
||k�rB||}
n(t
||j|j|j|j|j|j|j�\}	}
|||	|
fS)z1Return (padding left, right, filler top, bottom).Nr0r�zfixed widget must have a height)r�rr��packr�rr�r�rr�r�r�r�rr�r�rr�r�r�r�r�r�)r/r�r6r�r�r�r�r�r�r�r�r0r0r1r��sv
�
���

�z Overlay.calculate_padding_fillercCsP|jtkrdS|\}}|jtkr8|jtkr8|||fS||||||fS)z!Return the size to pass to top_w.r0)r�rr�)r/r�r�r�r�r�r�r�r0r0r1r��s
zOverlay.top_w_sizeFc		Cs�|�||�\}}}}|j�|�}|��r0|��s8t|�S|j�|�|||||�|�}t|�}|dksl|dkr�|�t	d|�t	d|��|dks�|dkr�|�
t	d|�t	d|��t||||�S)z#Render top_w overlayed on bottom_w.r)r�r�r��colsr�r&r�r��pad_trim_left_right�min�pad_trim_top_bottomr')	r/r�r6r�r�r�r�Zbottom_cZtop_cr0r0r1r�s ��zOverlay.renderc
	Cs�t|jd�sdS|�||�\}}}	}
|\}}||ksT|||ksT||	ksT|||
krXdS|j�|�||||	|
�||||||	|�S)z0Pass event to top_w, ignore if outside of top_w.r�F)r�r�r�r�r�)
r/r�r�r�r�r�r6r�r�r�r�r�r�r0r0r1r�s(��
��zOverlay.mouse_event)NNrrrr)NNrrrr)NNrrrr)F) r=r>r?r@�_selectablerNr
�_sizingrrrr�rerr�r�r�r�r�r6r�r�r3rZr�r�r,r�r�r�r�r�r0r0r0r1r��sv
��
:�
�
9�	�
.
'
r�c@seZdZdS)�
FrameErrorNrKr0r0r0r1r�*sr�c@seZdZdZdZeeg�Zd6dd�Zdd�Z	d	d
�Z
ee	e
�Zdd�Z
d
d�Zee
e�Zdd�Zdd�Zeee�Zdd�Zdd�Zdd�Zeedd�Zeeedd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zeed&d�Zd'd(�Zd)d*�Zd7d,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$dS)8�Framea�
    Frame widget is a box widget with optional header and footer
    flow widgets placed above and below the box widget.

    .. note:: The main difference between a Frame and a :class:`Pile` widget
        defined as: `Pile([('pack', header), body, ('pack', footer)])` is that
        the Frame will not automatically change focus up and down in response to
        keystrokes.
    TN�bodycCs&|j��||_||_||_||_dS)au
        :param body: a box widget for the body of the frame
        :type body: Widget
        :param header: a flow widget for above the body (or None)
        :type header: Widget
        :param footer: a flow widget for below the body (or None)
        :type footer: Widget
        :param focus_part:  'header', 'footer' or 'body'
        :type focus_part: str
        N)Z
_Frame__superre�_header�_body�_footer�
focus_part)r/r��header�footerr�r0r0r1re;s

zFrame.__init__cCs|jSrM)r�rEr0r0r1�
get_headerMszFrame.get_headercCs*||_|dkr|jdkrd|_|��dS)Nr�r�)r�r�rU)r/r�r0r0r1�
set_headerOszFrame.set_headercCs|jSrM)r�rEr0r0r1�get_bodyVszFrame.get_bodycCs||_|��dSrM)r�rU)r/r�r0r0r1�set_bodyXszFrame.set_bodycCs|jSrM)r�rEr0r0r1�
get_footer]szFrame.get_footercCs*||_|dkr|jdkrd|_|��dS)Nr�r�)r�r�rU)r/r�r0r0r1�
set_footer_szFrame.set_footercCsZ|dkrtd|f��|dkr(|jdks:|dkrH|jdkrHtd|f��||_|��dS)a(
        Determine which part of the frame is in focus.

        .. note:: included for backwards compatibility. You should rather use
            the container property :attr:`.focus_position` to set this value.

        :param part: 'header', 'footer' or 'body'
        :type part: str
        �r�r�r�zInvalid position for Frame: %sr�Nr�zThis Frame has no %s)r4r�r�r�rU)r/�partr0r0r1r�fs
��zFrame.set_focuscCs|jS)a2
        Return an indicator which part of the frame is in focus

        .. note:: included for backwards compatibility. You should rather use
            the container property :attr:`.focus_position` to get this value.

        :returns: one of 'header', 'footer' or 'body'.
        :rtype: str
        )r�rEr0r0r1r�xs
zFrame.get_focuscCs|j|j|jd�|jS)Nr�)r�r�r�r�rEr0r0r1r��s��zFrame._get_focuszq
        child :class:`Widget` in focus: the body, header or footer widget.
        This is a read-only property.r{z�
        writeable property containing an indicator which part of the frame
        that is in focus: `'body', 'header'` or `'footer'`.
        csG�fdd�dt�}|�S)NcsFeZdZdd�Zdd�Zdd�Zd
dd	�Z�jZ�j	Z
�jZ�j
ZdS)z&Frame._contents.<locals>.FrameContentscSst|���SrM)rD�keysr�r0r0r1r��sz.Frame._contents.<locals>.FrameContents.__len__cs�fdd����D�S)Ncsg|]}|�|f�qSr0r0�rQ�kr�r0r1rS�sz@Frame._contents.<locals>.FrameContents.items.<locals>.<listcomp>�r�r�r0r�r1�items�sz,Frame._contents.<locals>.FrameContents.itemscs�fdd����D�S)Ncsg|]}�|�qSr0r0r�r�r0r1rS�szAFrame._contents.<locals>.FrameContents.values.<locals>.<listcomp>r�r�r0r�r1�values�sz-Frame._contents.<locals>.FrameContents.valuesNc[s\|rBt|dd�}|r,|D]}||||<qn|D]\}}|||<q0|D]}||||<qFdS)Nr�)�getattr)r��E�Fr�r��vr0r0r1�update�s
z-Frame._contents.<locals>.FrameContents.update)N)r=r>r?r�r�r�r�_contents_keysr�r�r2r�r��_contents__delitem__�__delitem__r0rEr0r1�
FrameContents�s
rr�)r/rr0rEr1rZ�szFrame._contentscCs*dg}|jr|�d�|jr&|�d�|S)Nr�r�r�)r�r5r�)r/r�r0r0r1r�s

zFrame._contents_keyscCsT|dkr|jdfS|dkr*|jr*|jdfS|dkrB|jrB|jdfStd|f��dS)Nr�r�r��Frame.contents has no key: %r)r�r�r��KeyError�r/r�r0r0r1r��s


zFrame._contents__getitem__c	Cs�|dkrtd|f��z|\}}|dk	r,t�Wn&ttfk
rTtd|f��YnX|dkrf||_n|dkrv||_n||_dS)N)r�r�r�r	r�r�r�)r
rirjr�r�r�r�)r/r�r�r�r�r0r0r1r��szFrame._contents__setitem__cCsb|dkrtd|f��|dkr(|jdks:|dkrH|jdkrHtd|f��|dkrXd|_nd|_dS)N)r�r�z#Frame.contents can't remove key: %rr�r�r	)r
r�r�r�r�rr0r0r1r�s��zFrame._contents__delitem__a#
        a dict-like object similar to::

            {
                'body': (body_widget, None),
                'header': (header_widget, None),  # if frame has a header
                'footer': (footer_widget, None) # if frame has a footer
            }

        This object may be used to read or update the contents of the Frame.

        The values are similar to the list-like .contents objects used
        in other containers with (:class:`Widget`, options) tuples, but are
        constrained to keys for each of the three usual parts of a Frame.
        When other keys are used a :exc:`KeyError` will be raised.

        Currently all options are `None`, but using the :meth:`options` method
        to create the options value is recommended for forwards
        compatibility.
        cCsdS)z~
        There are currently no options for Frame contents.

        Return None as a placeholder for future options.
        Nr0rEr0r0r1r�sz
Frame.optionsc	CsL|\}}d}}|jr0|j�|f|jdko,|�}|jrP|j�|f|jdkoL|�}|}|jdkr�||krvd|f||ffS||8}||kr�||f||ffSn�|jdkr�||kr�|df||ffS||8}||kr�||f||ffSn`|||k�r<td|d�}||dk�rd|f||ffS||8}td|d�}||f||ffS||f||ffS)a�
        Calculate the number of rows for the header and footer.

        :param size: See :meth:`Widget.render` for details
        :type size: widget size
        :param focus: ``True`` if this widget is in focus
        :type focus: bool
        :returns: `(head rows, foot rows),(orig head, orig foot)`
                  orig head/foot are from rows() calls.
        :rtype: (int, int), (int, int)
        rr�r�rG)r�r�r�r��max)	r/r�r6r�r��frows�hrows�	remainingZrless1r0r0r1�frame_top_bottom�s>
�
�

zFrame.frame_top_bottomFcCs�|\}}|�||f|�\\}}\}}g}	g}
d}|r`||kr`t|jd��||f|oZ|jdk�}n2|r�|j�|f|oz|jdk�}|��|ks�td��|r�|	�|d|jdkf�|
�|j�|||k�r|j�||||f|o�|jdk�}|	�|d|jdkf�|
�|j�d}
|�rF||k�rFt|j	d��||f|�o@|jdk�}
n8|�r~|j	�|f|�od|jdk�}
|
��|k�s~td��|
�r�|	�|
d|jdkf�|
�|j	�t
|	�S)Nr�r�zrows, render mismatchr�r�r�)rrr�r�r�r��AssertionErrorr5r�r�r()r/r�r6r�r��htrim�ftrimrr
�combinelistZ
depends_on�headr�Zfootr0r0r1r�&s`��
�����
��zFrame.rendercCs�|\}}|jdkr:|jdk	r:|j��s*|S|j�|f|�S|jdkrl|jdk	rl|j��s\|S|j�|f|�S|jdkrz|S|}|jdk	r�||j�|f�8}|jdk	r�||j�|f�8}|dkr�|S|j��s�|S|j�||f|�S)z!Pass keypress to widget in focus.r�Nr�r�r)r�r�r�r�r�r�r�)r/r�r�r�r�rr0r0r1r�Ts*





zFrame.keypressc
Csf|\}}|�||f|�\\}	}
\}}||	kr�|o8|jdk}t|�r^|dkr^|j��r^|�d�t|jd�sndS|j�|f|||||�S|||
kr�|o�|jdk}t|�r�|dkr�|j��r�|�d�t|jd�s�dS|j�|f|||||||�S|�o|jdk}t|��r.|dk�r.|j	���r.|�d�t|j	d��s@dS|j	�|||	|
f|||||	|�S)zp
        Pass mouse event to appropriate part of frame.
        Focus may be changed on button 1 press.
        r�rGr�Fr�r�)
rr�rr�r�r�r�r�r�r�)
r/r�r�r�r�r�r6r�r�rrrr
r0r0r1r�nsX�

�


�
�zFrame.mouse_eventccs"|jrdVdV|jrdVdS)zT
        Return an iterator over the positions in this Frame top to bottom.
        r�r�r�N)r�r�rEr0r0r1rF�s
zFrame.__iter__ccs"|jrdVdV|jrdVdS)zT
        Return an iterator over the positions in this Frame bottom to top.
        r�r�r�N)r�r�rEr0r0r1rI�s
zFrame.__reversed__)NNr�)F)%r=r>r?r@r�rNr
r�rer�r�r�r�r�r�r�r�r�r�r�r�r�r6r3rZrr�r�rr,rrr�r�r�rFrIr0r0r0r1r�-s>






6
.(
r�c@seZdZdS)�	PileErrorNrKr0r0r0r1r�src@s<eZdZdZeeeg�Zd<dd�Zdd�Z	dd�Z
d	d
�Zee
edd�Z
d
d�Zdd�Zeeedd�Zdd�Zdd�Zeeedd�Zedfdd�Zdd�Zdd�Zdd�Zeed d�Zeeed!d�Zd"d#�Zd$d%�Zeeed&d�Zd'd(�Zd=d)d*�Zd+d,�Z d>d.d/�Z!d0d1�Z"d?d2d3�Z#d4d5�Z$d6d7�Z%d8d9�Z&d:d;�Z'dS)@r�zA
    A pile of widgets stacked vertically from top to bottom
    Nc	sz�j��t��_�j��j��j��fdd���j��j�|}t	|�D�]\}}|}t
|t�s|�j�
|tdff�n�|dttfkr�|\}}�j�
|tdff�n�t|�dkr�|\}}�j�
|t|ff�nj|dtk�r|\}}}�j�
|t|ff�n<|dtk�r0|\}}}�j�
|||ff�ntd|f��|dkrN|��rN|}qN�j�rp|dk	�rp��|�d�_dS)aX
        :param widget_list: child widgets
        :type widget_list: iterable
        :param focus_item: child widget that gets the focus initially.
            Chooses the first selectable widget if unset.
        :type focus_item: Widget or int

        *widget_list* may also contain tuples such as:

        (*given_height*, *widget*)
            always treat *widget* as a box widget and give it *given_height* rows,
            where given_height is an int
        (``'pack'``, *widget*)
            allow *widget* to calculate its own height by calling its :meth:`rows`
            method, ie. treat it as a flow widget.
        (``'weight'``, *weight*, *widget*)
            if the pile is treated as a box widget then treat widget as a box
            widget with a height based on its relative weight value, otherwise
            treat the same as (``'pack'``, *widget*).

        Widgets not in a tuple are the same as (``'weight'``, ``1``, *widget*)`

        .. note:: If the Pile is treated as a box widget there must be at least
            one ``'weight'`` tuple in :attr:`widget_list`.
        cs���SrMrTrVrEr0r1rX�rYzPile.__init__.<locals>.<lambda>rGrNr�z#initial widget list item invalid %r)Z_Pile__superrer%rZr[rUr\r]r^r�r�r�r,r5rr
rrDrrrr�r��pref_col)	r/�widget_list�
focus_itemr��originalr8rWr��_ignorer0rEr1re�s<



�
z
Pile.__init__c
CsX|D]N}z"|\}\}}|tttfkr(t�Wqttfk
rPtd|f��YqXqdS)Nr�)rrrrirjrrkr0r0r1r^�szPile._contents_modifiedcs0tdd��jD�����fdd�}��|��S)Ncss|]\}}|VqdSrMr0rqr0r0r1rr�sz(Pile._get_widget_list.<locals>.<genexpr>cs����dSrM��_set_widget_listr0rtr0r1ru�sz,Pile._get_widget_list.<locals>.user_modifiedrvrwr0rtr1�_get_widget_list�s
zPile._get_widget_listc	CsF|j}dd�t|t|jtdtdff���D�|_|t|�krB||_dS)NcSsg|]\}\}}||f�qSr0r0�rQryr8rr0r0r1rSs
z)Pile._set_widget_list.<locals>.<listcomp>rG�r3�ziprr,rrrDrzr0r0r1r�s��zPile._set_widget_listz�
        A list of the widgets in this Pile

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`contents`.
        r{cs0tdd��jD�����fdd�}��|��S)Ncss.|]&\}\}}tttti�||�|fVqdSrM�rrrr
�get)rQr8rWr�r0r0r1rrs
�z'Pile._get_item_types.<locals>.<genexpr>cs����dSrM)�_set_item_typesr0rtr0r1rusz+Pile._get_item_types.<locals>.user_modifiedrvrwr0rtr1�_get_item_typess�
zPile._get_item_typescCs4|j}dd�t||j�D�|_|t|�kr0||_dS)NcSs4g|],\\}}\}}|tttti�||�|ff�qSr0�rrr
rr#)rQ�new_tZ
new_heightr8rr0r0r1rSs�z(Pile._set_item_types.<locals>.<listcomp>�r3r!r,rD)r/�
item_typesr3r0r0r1r$s
�zPile._set_item_typesz�
        A list of the options values for widgets in this Pile.

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`contents`.
        cCs|jSrMr�rEr0r0r1r�&szPile._get_contentscCs||jdd�<dSrMr�r�r0r0r1r�(szPile._set_contentsa�
        The contents of this Pile as a list of (widget, options) tuples.

        options currently may be one of

        (``'pack'``, ``None``)
            allow widget to calculate its own height by calling its
            :meth:`rows <Widget.rows>` method, i.e. treat it as a flow widget.
        (``'given'``, *n*)
            Always treat widget as a box widget with a given height of *n* rows.
        (``'weight'``, *w*)
            If the Pile itself is treated as a box widget then
            the value *w* will be used as a relative weight for assigning rows
            to this box widget. If the Pile is being treated as a flow
            widget then this is the same as (``'pack'``, ``None``) and the *w*
            value is ignored.

        If the Pile itself is treated as a box widget then at least one
        widget must have a (``'weight'``, *w*) options value, or the Pile will
        not be able to grow to fill the required number of rows.

        This list may be modified like a normal list and the Pile widget
        will updated automatically.

        .. seealso:: Create new options tuples with the :meth:`options` method
        rGcCs2|tkrtdfS|ttfkr*td|f��||fS)a,
        Return a new options tuple for use in a Pile's :attr:`contents` list.

        :param height_type: ``'pack'``, ``'given'`` or ``'weight'``
        :param height_amount: ``None`` for ``'pack'``, a number of rows for
            ``'fixed'`` or a weight value (number) for ``'weight'``
        Nzinvalid height_type: %r)rrrr)r/r�r�r0r0r1rEs
	zPile.optionscCs|j}|dk	o|��S)z,Return True if the focus item is selectable.N�r6r��r/r8r0r0r1r�TszPile.selectablecCsRt|t�r|�|�St|j�D] \}\}}||kr||_dSqtd|f��dS)aT
        Set the item in focus, for backwards compatibility.

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`focus_position`.
            to set the position by integer index instead.

        :param item: element to focus
        :type item: Widget or int
        Nz%Widget not found in Pile contents: %r�r�r�r�r�r,r3ri�r/rnr�r8rr0r0r1r�Ys

zPile.set_focuscCs|js
dS|j|jdS�z�
        Return the widget in focus, for backwards compatibility.  You may
        also use the new standard container property .focus to get the
        child widget in focus.
        Nrr�rEr0r0r1r�lszPile.get_focusz4the child widget in focus or None when Pile is emptyaL
        A property for reading and setting the widget in focus.

        .. note::

            only for backwards compatibility. You should use the new
            standard container properties :attr:`focus` and
            :attr:`focus_position` to get the child widget in focus or modify the
            focus position.
        cCs|jstd��|jjS)z`
        Return the index of the widget in focus or None if this Pile is
        empty.
        z No focus_position, Pile is emptyr�rEr0r0r1r��szPile._get_focus_positionc	CsRz|dks|t|j�krt�Wn&ttfk
rDtd|f��YnX||j_dS)r�rz#No Pile child widget at position %sNr�r.r0r0r1r��szPile._set_focus_positionz�
        index of child widget in focus. Raises :exc:`IndexError` if read when
        Pile is empty, or when set to an invalid index.
        cCs|��sdS|�|�|jS)z4Return the preferred column for the cursor, or None.N)r��_update_pref_col_from_focusrr�r0r0r1r��s
zPile.get_pref_colc	Csd|d}|j|\}\}}|tkr*||fS|tkrZt|�dkrZ|sN|�||�}|||fS|fSdS)zU
        Return a size appropriate for passing to self.contents[i][0].render
        rr�N)r,rrrD�
get_item_rows)	r/r�r�r6�	item_rowsr�r8rWr�r0r0r1�
get_item_size�szPile.get_item_sizec
Cs�d}|d}t|�dkr |d}g}|dkrx|jD]@\}\}}|tkrR|�|�q2|�|j|f|oj|j|kd��q2|Sd}	|jD]�\}\}}|tkr�|j|f|o�|j|kd�}
|�|
�||
8}q�|tkr�|�|�||8}q�|r�|�d�|	|7}	q�|�d�q�|	dk�rtd��|dk�r$d}t|j�D]T\}\}\}}||}|dk�r.t	t
|�||	d�}
|
||<||
8}|	|8}	�q.|S)zb
        Return a list of the number of rows used by each widget
        in self.contents
        Nrr�rGr�z:No weighted widgets found for Pile treated as a box widget��?)rDr,rr5r�rrrr�r��float)
r/r�r6rr��lr8rWr��wtotalr�r�Zlir0r0r1r0�sL�









zPile.get_item_rowsFcCsB|d}d}g}t|j�D]�\}\}\}}	|j|k}
d}|tkrX|j||	f|oP|
d�}nd|tkslt|�dkr�|j|f|oz|
d�}n:|dkr�|�||�}||}|dkr�|j||f|o�|
d�}|r|�|||
f�q|s�t	d|d|dd�dd�St
|�}
t|�dk�r>|d|
��k�r>t|
�}
|
�
d|d|
���|
S)Nrr�rG� �rr�)r�r,rrr�rrDr0r5r)r(r�r&r�)r/r�r6r�r1rr�r8rWr�Z
item_focus�canvr�r7r0r0r1r��s0
  zPile.renderc
Cs�|��sdSt|jd�sdS|j}|j|\}\}}d}|d}|tks\|tkr�t|�dkr�|tkrj|}n|dkr�|j|dd�}||}|j�	||f�}	n|j�	|f�}	|	dkr�dS|	\}
}|dkr�|dkr�|j|dd�}|d|�D]}||7}q�|
|fS)z2Return the cursor coordinates of the focus widget.Nr�rr�Tr�)
r�r�rr3r,rrrDr0r�)
r/r�r�r8rWr�r1r�r��coordsr�r��rr0r0r1r�s2
zPile.get_cursor_coordscCst|�||��SrM)r�r0r�r0r0r1r�&sz	Pile.rowscCsl|js
|Sd}t|�dkr(|j|dd�}|j}|��rf|�||d|�}|j�||�}|j|dkrf|S|j|dkr�t	t
|ddd��}nt	t
|dt|j���}|s�|j|dd�}|D]�}|j|d	��s�q�|�|�||_t|jd
�s�dS||}|j|dk�r t	t
|ddd��}	nt	t
|��}	|	D]0}
|�||d|�}|j
�||j|
��r0�qb�q0dS|S)zjPass the keypress to the widget in focus.
        Unhandled 'up' and 'down' keys may cause a focus change.Nr�Tr�)�	cursor up�cursor downr<rGrHrr�)r,rDr0r3r�r2r6r��_command_map�list�ranger/r�rr�r)r/r�r�r1r��tsize�
candidates�jr�Zrowlistr�r0r0r1r�)sJ
�
z
Pile.keypresscCsBt|jd�sdS|j}|�||d�}|j�|�}|dk	r>||_dS)z+Update self.pref_col from the focus widget.r�NT)r�r6r3r2r�r)r/r�r�rArr0r0r1r/Zsz Pile._update_pref_col_from_focuscCs�||_d}d}|�||�}tt|dd�|jD���D]$\}\}}	|||krPq^||7}q4dS|	��sjdSt|	d�r�|�||||�}
|	�|
|||�}|dkr�dS||_	dS)z#Capture pref col and set new focus.Trcss|]\}}|VqdSrMr0r~r0r0r1rrnsz-Pile.move_cursor_to_coords.<locals>.<genexpr>Fr�)
rr0r�r!r,r�r�r2r�r3)r/r�r�r�r6�wrowr1r�r;r8rAr�r0r0r1r�es(�

zPile.move_cursor_to_coordsc
Cs�d}|�||�}tt|dd�|jD���D]$\}	\}
}||
|krFqT||
7}q*dS|o`|j|k}t|�r�|dkr�|��r�|	|_t|d�s�dS|�	||	||�}|�
|||||||�S)ze
        Pass the event to the contained widget.
        May change focus on button 1 press.
        rcss|]\}}|VqdSrMr0r~r0r0r1rr�sz#Pile.mouse_event.<locals>.<genexpr>FrGr�)r0r�r!r,rrr�r3r�r2r�)
r/r�r�r�r�r�r6rDr1r�r;r8rAr0r0r1r��s&�

�zPile.mouse_event)N)N)F)F)(r=r>r?r@rNr
r
r�rer^rrr�rr%r$r)r�r�r,rrr�r�r�r6rr�r�r3r�r2r0r�r�r�r�r/r�r�r0r0r0r1r��sD
<			�
6
 
1r�c@seZdZdS)�ColumnsErrorNrKr0r0r0r1rE�srEc@s�eZdZdZeeeg�ZdIdd�Zdd�Z	d	d
�Z
dd�Zee
ed
d�Z
dd�Zdd�Zeeedd�Zdd�Zdd�Zeeedd�Zdd�Zdd�Zeeedd�Zdd�Zd d!�Zeeed"d�Zedd#fd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z ee d0d�Z!d1d2�Z"d3d4�Z#ee"e#d5d�Z$ee"e#d6d�Z%dJd7d8�Z&dKd9d:�Z'd;d<�Z(d=d>�Z)d?d@�Z*dAdB�Z+dLdCdD�Z,dEdF�Z-dGdH�Z.dS)Mr�zE
    Widgets arranged horizontally in columns from left to right
    rNrGcs��j��t��_�j��j��j��fdd���j��j�t	|pJd�}t
|�D�](\}}|}t|t�s��j
�|td||kff�n�|dttfkr�t}	|\}
}�j
�||	d||kff�n�t|�dkr�|\}}�j
�|t|||kff�nz|dtk�r*t}	|\}
}}�j
�|t|||kff�nB|dtk�r^|\}	}}�j
�||	|||kff�ntd|f��|dkrV|��rV|}qV|�_�j
�r�|dk	�r�|�_|dk�r�d}d�_|�_d�_dS)	aX
        :param widget_list: iterable of flow or box widgets
        :param dividechars: number of blank characters between columns
        :param focus_column: index into widget_list of column in focus,
            if ``None`` the first selectable widget will be chosen.
        :param min_width: minimum width for each column which is not
            calling widget.pack() in *widget_list*.
        :param box_columns: a list of column indexes containing box widgets
            whose height is set to the maximum of the rows
            required by columns not listed in *box_columns*.

        *widget_list* may also contain tuples such as:

        (*given_width*, *widget*)
            make this column *given_width* screen columns wide, where *given_width*
            is an int
        (``'pack'``, *widget*)
            call :meth:`pack() <Widget.pack>` to calculate the width of this column
        (``'weight'``, *weight*, *widget*)
            give this column a relative *weight* (number) to calculate its width from the
            screen columns remaining

        Widgets not in a tuple are the same as (``'weight'``, ``1``, *widget*)

        If the Columns widget is treated as a box widget then all children
        are treated as box widgets, and *box_columns* is ignored.

        If the Columns widget is treated as a flow widget then the rows
        are calculated as the largest rows() returned from all columns
        except the ones listed in *box_columns*.  The box widgets in
        *box_columns* will be displayed with this calculated number of rows,
        filling the full height.
        cs���SrMrTrVrEr0r1rX�rYz"Columns.__init__.<locals>.<lambda>r0rGrNr�z$initial widget list item invalid: %r)�_Columns__superrer%rZr[rUr\r]r^�setr�r�r�r,r5rr
rrDrrrEr��dividecharsr3rr�rc)r/rrHZfocus_columnr��box_columnsr�rr8rWZ_ignoredr�r0rEr1re�sJ#



�
zColumns.__init__c
CsZ|D]P}z$|\}\}}}|tttfkr*t�Wqttfk
rRtd|f��YqXqdSrh)rrrrirjrE)r/rlrmrnr8rorp�br0r0r1r^�szColumns._contents_modifiedcs0tdd��jD�����fdd�}��|��S)Ncss|]\}}|VqdSrMr0rqr0r0r1rr�sz+Columns._get_widget_list.<locals>.<genexpr>cs����dSrMrr0rtr0r1rusz/Columns._get_widget_list.<locals>.user_modifiedrvrwr0rtr1r�s
zColumns._get_widget_listc
CsH|j}dd�t|t|jtdtddff���D�|_|t|�krD||_dS)NcSsg|]\}\}}||f�qSr0r0rr0r0r1rSs
z,Columns._set_widget_list.<locals>.<listcomp>rGFr rzr0r0r1rs��zColumns._set_widget_listz�
        A list of the widgets in this Columns

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`contents`.
        r{cs0tdd��jD�����fdd�}��|��S)Ncss0|](\}\}}}tttti�||�|fVqdSrMr"�rQr8rorprJr0r0r1rrs�z,Columns._get_column_types.<locals>.<genexpr>cs����dSrM)�_set_column_typesr0rtr0r1rusz0Columns._get_column_types.<locals>.user_modifiedrvrwr0rtr1�_get_column_typess�
zColumns._get_column_typescCs4|j}dd�t||j�D�|_|t|�kr0||_dS)NcSs<g|]4\\}}\}\}}}|tttti�||�||ff�qSr0r&)rQr'Znew_nr8rorprJr0r0r1rSs�z-Columns._set_column_types.<locals>.<listcomp>r()r/�column_typesr3r0r0r1rLs
�zColumns._set_column_typesz�
        A list of the old partial options values for widgets in this Pile,
        for backwards compatibility only.  You should use the new standard
        container property .contents to modify Pile contents.
        cs4tdd�t�j�D�����fdd�}��|��S)Ncss$|]\}\}\}}}|r|VqdSrMr0�rQr�r8rorprJr0r0r1rr+sz+Columns._get_box_columns.<locals>.<genexpr>cs����dSrM)�_set_box_columnsr0rtr0r1ru-sz/Columns._get_box_columns.<locals>.user_modified)r$r�r,r[rwr0rtr1�_get_box_columns*s�
zColumns._get_box_columnscs&t����fdd�t|j�D�|_dS)Ncs,g|]$\}\}\}}}||||�kff�qSr0r0rO�rIr0r1rS3s�z,Columns._set_box_columns.<locals>.<listcomp>)rGr�r,)r/rIr0rRr1rP1s
�zColumns._set_box_columnsa
        A list of the indexes of the columns that are to be treated as
        box widgets when the Columns is treated as a flow widget.

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`contents`.
        cCsddl}|�dt�t|jkS�NrzA.has_flow_type is deprecated, read values from .contents instead.)�warnings�warn�DeprecationWarningrrN)r/rTr0r0r1�_get_has_pack_type>s
�zColumns._get_has_pack_typecCsddl}|�dt�dSrS)rTrUrV)r/r�rTr0r0r1�_set_has_pack_typeCs�zColumns._set_has_pack_typezP
        .. deprecated:: 1.0 Read values from :attr:`contents` instead.
        cCs|jSrMr�rEr0r0r1r�KszColumns._get_contentscCs||jdd�<dSrMr�r�r0r0r1r�MszColumns._set_contentsa
        The contents of this Columns as a list of `(widget, options)` tuples.
        This list may be modified like a normal list and the Columns
        widget will update automatically.

        .. seealso:: Create new options tuples with the :meth:`options` method
        FcCs2|tkrd}|tttfkr(td|f��|||fS)a�
        Return a new options tuple for use in a Pile's .contents list.

        This sets an entry's width type: one of the following:

        ``'pack'``
            Call the widget's :meth:`Widget.pack` method to determine how wide
            this column should be. *width_amount* is ignored.
        ``'given'``
            Make column exactly width_amount screen-columns wide.
        ``'weight'``
            Allocate the remaining space to this column by using
            *width_amount* as a weight value.

        :param width_type: ``'pack'``, ``'given'`` or ``'weight'``
        :param width_amount: ``None`` for ``'pack'``, a number of screen columns
            for ``'given'`` or a weight value (number) for ``'weight'``
        :param box_widget: set to `True` if this widget is to be treated as a box
            widget when the Columns widget itself is treated as a flow widget.
        :type box_widget: bool
        Nr�)rrrrE)r/r�r�Z
box_widgetr0r0r1rWs
zColumns.optionscCsd|_|j��dSrM)rcrFrUrEr0r0r1rUsszColumns._invalidatecCs|�|�dS)a4
        Set the column in focus by its index in :attr:`widget_list`.

        :param num: index of focus-to-be entry
        :type num: int

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to set the focus.
        N)r�)r/Znumr0r0r1�set_focus_columnws
zColumns.set_focus_columncCs|jS)z�
        Return the focus column index.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.
        )r3rEr0r0r1�get_focus_column�szColumns.get_focus_columncCsRt|t�r|�|�St|j�D] \}\}}||kr||_dSqtd|f��dS)z�
        Set the item in focus

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.

        :param item: widget or integer indexNz(Widget not found in Columns contents: %rr,r-r0r0r1r��s

zColumns.set_focuscCs|js
dS|j|jdSr.r�rEr0r0r1r��szColumns.get_focusz7the child widget in focus or None when Columns is emptycCs|jstd��|jjS)zc
        Return the index of the widget in focus or None if this Columns is
        empty.
        z#No focus_position, Columns is empty)rr4r,r6rEr0r0r1r��szColumns._get_focus_positionc	CsRz|dks|t|j�krt�Wn&ttfk
rDtd|f��YnX||j_dS)r�rz&No Columns child widget at position %sNr�r.r0r0r1r��szColumns._set_focus_positionz�
        index of child widget in focus. Raises :exc:`IndexError` if read when
        Columns is empty, or when set to an invalid index.
        z�
        A property for reading and setting the index of the column in
        focus.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.
        cCs�|d}||jkr,tdd�|jD��s,|jSg}g}||j}t|j�D]�\}\}\}	}
}|	tkrh|
}n"|	tkr�|�|f|�d}n|j	}|||jkr�||j
kr�q�|�|�|||j8}|	ttfkrH|�|
|f�qHt|�D]J\}}|dkr��q.||||j7}d||<|r�|dd|kr�|d=q�|�r�|��t
dd�|D��}
|t|�|j	}|D]F\}}tt|�||
d�}
t|j	|
�}
|
||<||
8}|
|8}
�qd||_||_|S)zy
        Return a list of column widths.

        0 values in the list mean hide corresponding column completely
        rcss |]\}\}}}|tkVqdSrM)rrKr0r0r1rr�sz(Columns.column_widths.<locals>.<genexpr>rGcss|]\}}|VqdSrMr0)rQ�weightr�r0r0r1rr�sr3)rc�anyr,Z_cache_column_widthsrHr�rrr�r�r3r5�sortr�rDr�r4r)r/r�r6r��widthsZweightedZsharedr�r8ror�rJZstatic_wr6Zgrowr[r0r0r1�
column_widths�sP�

zColumns.column_widthscCsr|�||�}d}t|�dkrrd}tt||j��D]@\}\}\}\}}	}
|
rLq0|j|f|o`|j|kd�}t||�}q0g}tt||j��D]�\}\}\}\}}	}
|dkr�q�|r�|
r�||f}
n|f|dd�}
|j|
|o�|j|kd�}|t|�dkr�||j	7}|�
|||j|k|f�q�|�s<td|d|dd�dd�St|�}|�
�|dk�rn|�d|d|�
��|S)z�
        Render columns and return canvas.

        :param size: see :meth:`Widget.render` for details
        :param focus: ``True`` if this widget is in focus
        :type focus: bool
        NrGr�rr7)rG)r_rDr�r!r,r�r3rr�rHr5r)r*r�r�)r/r�r6r^Z
box_maxrowr��mcr8rorprJr�r5Zsub_sizer9r0r0r1r�s<&�&
�
 zColumns.rendercs��j�j\}\}}}|��s"dSt|d�s0dS��|�}t|��jkrLdS|�j}t|�dkr||r||�|��|�f�}n|�|f|dd��}|dkr�dS|\}	}
|	t�fdd�|d�j�D��7}	|	|
fS)z4Return the cursor coordinates from the focus widget.Nr�rGcsg|]}|dkr�j|�qSr8)rH)rQZwcrEr0r1rSJs�z-Columns.get_cursor_coords.<locals>.<listcomp>)	r,r3r�r�r_rDr�r�r�)r/r�r8rorprJr^Zcolwr:r�r�r0rEr1r�5s&


�
zColumns.get_cursor_coordscCs�|�|�}d}d}tt||j��D]�\}\}\}	}
||}|	��r�|tkrt|tksZ||krt|dkrt||||	|
f}q�|tkr�||kr�||d||kr�q�||||	|
f}|tkr�||kr�q�||j}q"|dkr�dS|\}}}}	\}}
}t|	d��r�t	|t
��r ttd||�||d�}n|}t
|�dk�rV|�rV|	�|||�|�f||�}n |	�||f|dd�||�}|dk�r�dS||_||_dS)z�
        Choose a selectable column to focus based on the coords.

        see :meth:`Widget.move_cursor_coords` for details
        Nrr�Fr�rGT)r_r�r!r,r�rrrHr�r�r�r�rrDr�r�r3r)r/r�r�r�r^Zbestr�r�r�r8r�endrorprJZmove_xr�r0r0r1r�NsH
  $��
zColumns.move_cursor_to_coordsc	Cs|�|�}d}tt||j��D]�\}	\}
\}\}}
}||krBdS|j|	}||
}||krh||j}q|ot|j|	k}t|�r�|dkr�|��r�|	|_	t
|d�s�dSt|�dkr�|r�|�|||�
|�f||||||�S|�||f|dd�||||||�SdS)z_
        Send event to appropriate column.
        May change focus on button 1 press.
        rFrGr�N)r_r�r!r,rrH�	focus_colrr�r3r�rDr�r�)r/r�r�r�r�r�r6r^r�r�r�r8rorprJrar0r0r1r�}s8
&


��zColumns.mouse_eventc	Cs|�|�}|j|j\}\}}}t|�|jkr2dSd}||j}t|d�r�t|�dkrp|rp|�||�|�f�}n|�|f|dd��}t|t�r�||j	|j
7}|t|d|j��7}|dkr�|j}|dk�r|�
��r|d}||j|j
7}|t|d|j��7}|S)z-Return the pref col from the column in focus.rNr�rGr�)r_r,r3rDr�r�r�r�r�rbrHr�rr�)	r/r�r^r8rorprJr�Zcwidthr0r0r1r��s(



zColumns.get_pref_colcCsb|�||�}d}tt||j��D]<\}\}\}\}}	}
|
r<q t||j|f|oT|j|kd��}q |S)z�
        Return the number of rows required by the columns.
        This only makes sense if :attr:`widget_list` contains flow widgets.

        see :meth:`Widget.rows` for details
        rGr�)r_r�r!r,rr�r3)r/r�r6r^r�r�r`r8rorprJr0r0r1r��s&�zColumns.rowscCs |jdkr|S|�|�}|jt|�kr*|S|j}||}|j|\}\}}}	|j|dkr`d|_t|�dkr�|	r�|�||�|d�f|�}n|�|f|dd�|�}|j|dkr�|S|j|dkr�tt	|ddd��}
ntt	|dt|j���}
|
D]$}|j|d�
��sq�||_dS|S)	z�
        Pass keypress to the focus column.

        :param size: `(maxcol,)` if :attr:`widget_list` contains flow widgets or
            `(maxcol, maxrow)` if it contains box widgets.
        :type size: int, int
        N)r<r=zcursor page upzcursor page downrGT)�cursor leftzcursor rightrcrHr)r3r_rDr,r>rr�r�r?r@r�)r/r�r�r^r�r`r8rorprJrBrCr0r0r1r��s0

zColumns.keypresscCs|j}|dk	o|��S)z0Return the selectable value of the focus column.Nr*r+r0r0r1r��szColumns.selectable)rNrGN)F)F)F)/r=r>r?r@rNr
r
r�rer^rrr�rrMrLrNrQrPrIrWrXZ
has_flow_typer�r�r,rrrUrYrZr�r�r6r�r�r3rbr_r�r�r�r�r�r�r�r�r0r0r0r1r��sX�
M				�
=
//!
*r�cCsddl}|��dS)Nr)�doctestZtestmod)rdr0r0r1�_test�sre�__main__N)AZ
__future__rr�	itertoolsrrZurwid.compatrZ
urwid.utilrZurwid.widgetrr	r
rrr
rrrrrrrrrrZurwid.decorationrrrrrrrrr r!r"r#Zurwid.monitored_listr$r%Zurwid.canvasr&r'r(r)r*r�r+rA�	ExceptionrJrLr�r�r�r�rr�rEr�rer=r0r0r0r1�<module>sHH8F;ls^


Zerion Mini Shell 1.0