%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core18/current/usr/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core18/current/usr/lib/python3/dist-packages/urwid/__pycache__/decoration.cpython-36.pyc

3

��dZ���@s�ddlmZmZddlmZddlmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZddlmZddlmZmZddlmZmZmZmZGdd�de�ZGd	d
�d
ed�e�Z Gdd
�d
e�Z!Gdd�ded�e�Z"Gdd�de"�Z#Gdd�de$�Z%Gdd�de�Z&Gdd�de$�Z'Gdd�de�Z(Gdd�de$�Z)Gdd�de�Z*Gdd�de�Z+d d!�Z,d"d#�Z-d$d%�Z.d&d'�Z/d(d)�Z0d*d+�Z1d,d-�Z2d.d/�Z3d0d1�Z4d2d3�Z5d4d5�Z6e7d6k�r�e6�d7S)8�)�division�print_function)�	int_scale)�Widget�WidgetError�BOX�FLOW�LEFT�CENTER�RIGHT�PACK�CLIP�GIVEN�RELATIVE�RELATIVE_100�TOP�MIDDLE�BOTTOM�delegate_to_widget_mixin)�remove_defaults)�CompositeCanvas�SolidCanvas)�Divider�Edit�Text�	SolidFillc@sZeZdZdZdd�Zdd�Zdd�Zdd	�Zeee�Z	d
d�Z
ee
�Zdd
�Zdd�Z
dS)�WidgetDecorationa
    original_widget -- the widget being decorated

    This is a base class for decoration widgets, widgets
    that contain one or more widgets and only ever have
    a single focus.  This type of widget will affect the
    display or behaviour of the original_widget but it is
    not part of determining a chain of focus.

    Don't actually do this -- use a WidgetDecoration subclass
    instead, these are not real widgets:

    >>> WidgetDecoration(Text(u"hi"))
    <WidgetDecoration flow widget <Text flow widget 'hi'>>
    cCs
||_dS)N)�_original_widget)�self�original_widget�r �2/usr/lib/python3/dist-packages/urwid/decoration.py�__init__1szWidgetDecoration.__init__cCs|jj�t|j�gS)N)Z_WidgetDecoration__super�_repr_words�reprr)rr r r!r#3szWidgetDecoration._repr_wordscCs|jS)N)r)rr r r!�_get_original_widget6sz%WidgetDecoration._get_original_widgetcCs||_|j�dS)N)r�_invalidate)rrr r r!�_set_original_widget8sz%WidgetDecoration._set_original_widgetcCs|}xt|d�r|j}qW|S)a�
        Return the widget without decorations.  If there is only one
        Decoration then this is the same as original_widget.

        >>> t = Text('hello')
        >>> wd1 = WidgetDecoration(t)
        >>> wd2 = WidgetDecoration(wd1)
        >>> wd3 = WidgetDecoration(wd2)
        >>> wd3.original_widget is wd2
        True
        >>> wd3.base_widget is t
        True
        r)�hasattrr)r�wr r r!�_get_base_widget=s
z!WidgetDecoration._get_base_widgetcCs
|jj�S)N)r�
selectable)rr r r!r+RszWidgetDecoration.selectablecCs
|jj�S)N)r�sizing)rr r r!r,UszWidgetDecoration.sizingN)�__name__�
__module__�__qualname__�__doc__r"r#r%r'�propertyrr*Zbase_widgetr+r,r r r r!r!s
rc@seZdZdZdS)�WidgetPlaceholdera�
    This is a do-nothing decoration widget that can be used for swapping
    between widgets without modifying the container of this widget.

    This can be useful for making an interface with a number of distinct
    pages or for showing and hiding menu or status bars.

    The widget displayed is stored as the self.original_widget property and
    can be changed by assigning a new widget to it.
    N)r-r.r/r0r r r r!r2Ysr2rc@seZdZdS)�AttrMapErrorN)r-r.r/r r r r!r3hsr3c@s`eZdZdZddd�Zdd�Zdd�Zd	d
�Zeee�Z	dd�Z
d
d�Zee
e�Zddd�Z
dS)�AttrMapz�
    AttrMap is a decoration that maps one set of attributes to another.
    This object will pass all function calls and variable references to the
    wrapped widget.
    NcCsd|jj|�t|�tkr(|jd|i�n
|j|�|dk	rVt|�tkrV|jd|i�n
|j|�dS)a�
        :param w: widget to wrap (stored as self.original_widget)
        :type w: widget

        :param attr_map: attribute to apply to *w*, or dict of old display
            attribute: new display attribute mappings
        :type attr_map: display attribute or dict

        :param focus_map: attribute to apply when in focus or dict of
            old display attribute: new display attribute mappings;
            if ``None`` use *attr*
        :type focus_map: display attribute or dict

        >>> AttrMap(Divider(u"!"), 'bright')
        <AttrMap flow widget <Divider flow widget '!'> attr_map={None: 'bright'}>
        >>> AttrMap(Edit(), 'notfocus', 'focus')
        <AttrMap selectable flow widget <Edit selectable flow widget '' edit_pos=0> attr_map={None: 'notfocus'} focus_map={None: 'focus'}>
        >>> size = (5,)
        >>> am = AttrMap(Text(u"hi"), 'greeting', 'fgreet')
        >>> next(am.render(size, focus=False).content()) # ... = b in Python 3
        [('greeting', None, ...'hi   ')]
        >>> next(am.render(size, focus=True).content())
        [('fgreet', None, ...'hi   ')]
        >>> am2 = AttrMap(Text(('word', u"hi")), {'word':'greeting', None:'bg'})
        >>> am2
        <AttrMap flow widget <Text flow widget 'hi'> attr_map={'word': 'greeting', None: 'bg'}>
        >>> next(am2.render(size).content())
        [('greeting', None, ...'hi'), ('bg', None, ...'   ')]
        N)�_AttrMap__superr"�type�dict�set_attr_map�
set_focus_map)rr)�attr_map�	focus_mapr r r!r"qs
zAttrMap.__init__cCs,t|jj�|jd�}|jdk	r(|j|d<|S)N)r:r;)r7r5�_repr_attrs�	_attr_map�
_focus_map)r�dr r r!r<�s

zAttrMap._repr_attrscCs
t|j�S)N)r7r=)rr r r!�get_attr_map�szAttrMap.get_attr_mapcCsHx4|j�D](\}}|js"|jr
td||f��q
W||_|j�dS)a�
        Set the attribute mapping dictionary {from_attr: to_attr, ...}

        Note this function does not accept a single attribute the way the
        constructor does.  You must specify {None: attribute} instead.

        >>> w = AttrMap(Text(u"hi"), None)
        >>> w.set_attr_map({'a':'b'})
        >>> w
        <AttrMap flow widget <Text flow widget 'hi'> attr_map={'a': 'b'}>
        z@%r:%r attribute mapping is invalid.  Attributes must be hashableN)�items�__hash__r3r=r&)rr:�	from_attr�to_attrr r r!r8�szAttrMap.set_attr_mapcCs|jrt|j�SdS)N)r>r7)rr r r!�
get_focus_map�szAttrMap.get_focus_mapcCsP|dk	r>x4|j�D](\}}|js*|jrtd||f��qW||_|j�dS)az
        Set the focus attribute mapping dictionary
        {from_attr: to_attr, ...}

        If None this widget will use the attr mapping instead (no change
        when in focus).

        Note this function does not accept a single attribute the way the
        constructor does.  You must specify {None: attribute} instead.

        >>> w = AttrMap(Text(u"hi"), {})
        >>> w.set_focus_map({'a':'b'})
        >>> w
        <AttrMap flow widget <Text flow widget 'hi'> attr_map={} focus_map={'a': 'b'}>
        >>> w.set_focus_map(None)
        >>> w
        <AttrMap flow widget <Text flow widget 'hi'> attr_map={}>
        Nz@%r:%r attribute mapping is invalid.  Attributes must be hashable)rArBr3r>r&)rr;rCrDr r r!r9�szAttrMap.set_focus_mapFcCs@|j}|r|jdk	r|j}|jj||d�}t|�}|j|�|S)zK
        Render wrapped widget and apply attribute. Return canvas.
        N)�focus)r=r>r�renderrZfill_attr_apply)r�sizerFr:�canvr r r!rG�s
zAttrMap.render)N)F)r-r.r/r0r"r<r@r8r1r:rEr9r;rGr r r r!r4ks
*

r4c@sxeZdZddd�Zdd�ZejZejZ	e
ee	�Zdd�Zdd	�Z
e
ee
�Zd
d�Zdd
�Ze
ee�Zdd�Zdd�ZdS)�AttrWrapNcCs|jj|||�dS)a�
        w -- widget to wrap (stored as self.original_widget)
        attr -- attribute to apply to w
        focus_attr -- attribute to apply when in focus, if None use attr

        This widget is a special case of the new AttrMap widget, and it
        will pass all function calls and variable references to the wrapped
        widget.  This class is maintained for backwards compatibility only,
        new code should use AttrMap instead.

        >>> AttrWrap(Divider(u"!"), 'bright')
        <AttrWrap flow widget <Divider flow widget '!'> attr='bright'>
        >>> AttrWrap(Edit(), 'notfocus', 'focus')
        <AttrWrap selectable flow widget <Edit selectable flow widget '' edit_pos=0> attr='notfocus' focus_attr='focus'>
        >>> size = (5,)
        >>> aw = AttrWrap(Text(u"hi"), 'greeting', 'fgreet')
        >>> next(aw.render(size, focus=False).content())
        [('greeting', None, ...'hi   ')]
        >>> next(aw.render(size, focus=True).content())
        [('fgreet', None, ...'hi   ')]
        N)�_AttrWrap__superr")rr)�attr�
focus_attrr r r!r"�szAttrWrap.__init__cCs@t|jj�|jd�}|d=d|kr(|d=|jdk	r<|j|d<|S)N)rLr:r;rM)r7rKr<rLrM)rr?r r r!r<s

zAttrWrap._repr_attrscCs
|jdS)N)r:)rr r r!�get_attrszAttrWrap.get_attrcCs|jd|i�dS)z�
        Set the attribute to apply to the wrapped widget

        >> w = AttrWrap(Divider("-"), None)
        >> w.set_attr('new_attr')
        >> w
        <AttrWrap flow widget <Divider flow widget '-'> attr='new_attr'>
        N)r8)rrLr r r!�set_attrs	zAttrWrap.set_attrcCs|j}|r|dSdS)N)r;)rr;r r r!�get_focus_attrszAttrWrap.get_focus_attrcCs|jd|i�dS)a�
        Set the attribute to apply to the wapped widget when it is in
        focus

        If None this widget will use the attr instead (no change when in
        focus).

        >> w = AttrWrap(Divider("-"), 'old')
        >> w.set_focus_attr('new_attr')
        >> w
        <AttrWrap flow widget <Divider flow widget '-'> attr='old' focus_attr='new_attr'>
        >> w.set_focus_attr(None)
        >> w
        <AttrWrap flow widget <Divider flow widget '-'> attr='old'>
        N)r9)rrMr r r!�set_focus_attr#szAttrWrap.set_focus_attrcCst|j|�S)z�
        Call getattr on wrapped widget.  This has been the longstanding
        behaviour of AttrWrap, but is discouraged.  New code should be
        using AttrMap and .base_widget or .original_widget instead.
        )�getattrr)r�namer r r!�__getattr__6szAttrWrap.__getattr__cCs
|jj�S)N)rr,)rr r r!r,?szAttrWrap.sizing)N)r-r.r/r"r<rr%Zget_wr'Zset_wr1r)rNrOrLrPrQrMrTr,r r r r!rJ�s




	rJc@seZdZdS)�BoxAdapterErrorN)r-r.r/r r r r!rUCsrUc@s�eZdZdZdgZdd�Zdd�Zeej	ej
�Zdd�Zdd
d�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zddd�Zdd�ZdS)�
BoxAdapterzM
    Adapter for using a box widget where a flow widget would usually go
    �rowscCs8t|d�r"t|j�kr"td|��tj||�||_dS)aa
        Create a flow widget that contains a box widget

        :param box_widget: box widget to wrap
        :type box_widget: Widget
        :param height: number of rows for box widget
        :type height: int

        >>> BoxAdapter(SolidFill(u"x"), 5) # 5-rows of x's
        <BoxAdapter flow widget <SolidFill box widget 'x'> height=5>
        r,z%r is not a box widgetN)r(rr,rUrr"�height)r�
box_widgetrXr r r!r"Ls
zBoxAdapter.__init__cCst|jj�|jd�S)N)rX)r7Z_BoxAdapter__superr<rX)rr r r!r<_szBoxAdapter._repr_attrscCs
ttg�S)N)�setr)rr r r!r,fszBoxAdapter.sizingFcCs|jS)z�
        Return the predetermined height (behave like a flow widget)

        >>> BoxAdapter(SolidFill(u"x"), 5).rows((20,))
        5
        )rX)rrHrFr r r!rWiszBoxAdapter.rowscCs(|\}t|jd�sdS|jj||jf�S)N�get_cursor_coords)r(rr[rX)rrH�maxcolr r r!r[tszBoxAdapter.get_cursor_coordscCs(|\}t|jd�sdS|jj||jf�S)N�get_pref_col)r(rr]rX)rrHr\r r r!r]zszBoxAdapter.get_pref_colcCs|\}|jj||jf|�S)N)r�keypressrX)rrH�keyr\r r r!r^�szBoxAdapter.keypresscCs,|\}t|jd�sdS|jj||jf||�S)N�move_cursor_to_coordsT)r(rr`rX)rrH�col�rowr\r r r!r`�s
z BoxAdapter.move_cursor_to_coordscCs2|\}t|jd�sdS|jj||jf|||||�S)N�mouse_eventF)r(rrcrX)rrH�event�buttonrarbrFr\r r r!rc�s
zBoxAdapter.mouse_eventcCs&|\}|jj||jf|�}t|�}|S)N)rrGrXr)rrHrFr\rIr r r!rG�szBoxAdapter.rendercCst|j|�S)z+
        Pass calls to box widget.
        )rRrY)rrSr r r!rT�szBoxAdapter.__getattr__N)F)F)r-r.r/r0�no_cacher"r<r1rr%r'rYr,rWr[r]r^r`rcrGrTr r r r!rVFs

rVc@seZdZdS)�PaddingErrorN)r-r.r/r r r r!rg�srgc@s�eZdZeedddfdd�Zdd�Zdd�Zd	d
�Zdd�Z	e
ee	�Zd
d�Zdd�Z
e
ee
�Zd"dd�Zdd�Zd#dd�Zdd�Zdd�Zdd�Zdd�Zd d!�ZdS)$�PaddingNrcCs�|jj|�t|�tkrJ|ddkrJ|ddkr>|d}t}n|d}t}t|�tkr�|ddkr�|ddkrx|d}n|d}t}|dkr�t}||_||_	t
|t�\|_|_
t|t�\|_|_||_dS)a�
        :param w: a box, flow or fixed widget to pad on the left and/or right
            this widget is stored as self.original_widget
        :type w: Widget

        :param align: one of: ``'left'``, ``'center'``, ``'right'``
            (``'relative'``, *percentage* 0=left 100=right)

        :param width: one of:

            *given width*
              integer number of columns for self.original_widget

            ``'pack'``
              try to pack self.original_widget to its ideal size

            (``'relative'``, *percentage of total width*)
              make width depend on the container's width

            ``'clip'``
              to enable clipping mode for a fixed widget

        :param min_width: the minimum number of columns for
            self.original_widget or ``None``
        :type min_width: int

        :param left: a fixed number of columns to pad on the left
        :type left: int

        :param right: a fixed number of columns to pad on the right
        :type right: int

        Clipping Mode: (width= ``'clip'``)
        In clipping mode this padding widget will behave as a flow
        widget and self.original_widget will be treated as a fixed
        widget.  self.original_widget will will be clipped to fit
        the available number of columns.  For example if align is
        ``'left'`` then self.original_widget may be clipped on the right.

        >>> size = (7,)
        >>> def pr(w):
        ...     for t in w.render(size).text:
        ...         print("|%s|" % (t.decode('ascii'),))
        >>> pr(Padding(Text(u"Head"), ('relative', 20), 'pack'))
        | Head  |
        >>> pr(Padding(Divider(u"-"), left=2, right=1))
        |  ---- |
        >>> pr(Padding(Divider(u"*"), 'center', 3))
        |  ***  |
        >>> p=Padding(Text(u"1234"), 'left', 2, None, 1, 1)
        >>> p
        <Padding flow widget <Text flow widget '1234'> left=1 right=1 width=2>
        >>> pr(p)   # align against left
        | 12    |
        | 34    |
        >>> p.align = 'right'
        >>> pr(p)   # align against right
        |    12 |
        |    34 |
        >>> pr(Padding(Text(u"hi\nthere"), 'right', 'pack')) # pack text first
        |  hi   |
        |  there|
        r�
fixed left�fixed right�N)rirj)rirj)�_Padding__superr"r6�tupler	rrr
�left�right�normalize_alignrg�_align_type�
_align_amount�normalize_width�_width_type�
_width_amount�	min_width)rr)�align�widthrvrnror r r!r"�s.A
zPadding.__init__cCs|jtkrttg�S|jj�S)N)rtr
rZrrr,)rr r r!r,s

zPadding.sizingcCs0t|jj�|j|j|j|j|jd�}t|t	j
�S)N)rwrxrnrorv)r7rlr<rwrxrnrorvrrhr")r�attrsr r r!r<	s

zPadding._repr_attrscCst|j|j�S)z7
        Return the padding alignment setting.
        )�simplify_alignrqrr)rr r r!�
_get_alignszPadding._get_aligncCst|t�\|_|_|j�dS)z,
        Set the padding alignment.
        N)rprgrqrrr&)rrwr r r!�
_set_alignszPadding._set_aligncCst|j|j�S)z+
        Return the padding width.
        )�simplify_widthrtru)rr r r!�
_get_width szPadding._get_widthcCst|t�\|_|_|j�dS)z(
        Set the padding width.
        N)rsrgrtrur&)rrxr r r!�
_set_width%szPadding._set_widthFcCs�|j||�\}}|d}|||8}|jtkr>|jjf|�}n|jj|f|dd�|�}|j�dkr�td|d|j��}t|�}|j	|jg�|St|�}|j	|jg�|dks�|dkr�|j
||�|S)Nrrk� )�padding_valuesrtr
rrGZcolsrrWrZset_dependsZpad_trim_left_right)rrHrFrnror\rIr r r!rG.s 
zPadding.renderc	Cs�|d}|jtkrD|jjf|d�\}}t||j|jt|d|j|j�S|jt	kr�t
||j|j|jpfd�}|jj|f|d�\}}t||j|jt||j|j|j�St||j|j|j|j
|j|j|j�S)z|Return the number of columns to pad on the left and right.

        Override this method to define custom padding behaviour.r)rFN)rtr
r�pack�calculate_left_right_paddingrqrrrnror�maxrvrru)rrHrFr\rx�ignore�maxwidthr r r!r�Ds&


zPadding.padding_valuesc
Csz|\}|j||�\}}|jtkr@|jj|||f|�\}}|S|jtkr`|jjf|�\}}	|	S|jj|||f|d�S)z0Return the rows needed for self.original_widget.)rF)r�rtrrr�r
rW)
rrHrFr\rnroZpcolsZprowsZfcolsZfrowsr r r!rW\s


zPadding.rowscCs@|d}|j|d�\}}|||f|dd�}|jj||�S)z'Pass keypress to self._original_widget.rTrkN)r�rr^)rrHr_r\rnro�maxvalsr r r!r^iszPadding.keypressc	Cs~t|jd�sdS|j|d�\}}|d}|||f|dd�}|ddkrRdS|jj|�}|dkrjdS|\}}|||fS)zDReturn the (x,y) coordinates of cursor within self._original_widget.r[NTrrk)r(rr�r[)	rrHrnror\r��coords�x�yr r r!r[pszPadding.get_cursor_coordscCs�t|jd�sdS|j|d�\}}|d}|||f|dd�}t|�tkr|||kr\|}n|||krt||d}||8}|jj|||�S)z�Set the cursor position with (x,y) coordinates of self._original_widget.

        Returns True if move succeeded, False otherwise.
        r`TrrkN)r(rr�r6�intr`)rrHr�r�rnror\r�r r r!r`szPadding.move_cursor_to_coordscCstt|jd�sdS|j||�\}}|d}	||ks<||	|kr@dS|	||f|dd�}
|jj|
||||||�S)z=Send mouse event if position is within self._original_widget.rcFrrkN)r(rr�rc)rrHrdrer�r�rFrnror\r�r r r!rc�szPadding.mouse_eventcCsft|jd�sdS|j|d�\}}|d}|||f|dd�}|jj|�}t|�tkrb||S|S)z@Return the preferred column from self._original_widget, or None.r]NTrrk)r(rr�r]r6r�)rrHrnror\r�r�r r r!r]�szPadding.get_pref_col)F)F)r-r.r/r	rr"r,r<r{r|r1rwr~rrxrGr�rWr^r[r`rcr]r r r r!rh�s$_	





rhc@seZdZdS)�FillerErrorN)r-r.r/r r r r!r��sr�c@s�eZdZeedddfdd�Zdd�Zdd�Zej	Z
ejZe
e
e�Zd	d
�Zdd�Zddd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�FillerNrcCs*|jj|�t|t�r�|ddkrPt|t�s:|ddkrBtd��|d}t}n8|ddkr�t|t�st|ddkr|td��|d}t}t|t�r�|ddkr�|d}t}n|ddkr�|d}t}|dks�|tkr�t	}||_
||_t|t�\|_
|_t|t�\|_|_|jtt	fk�r ||_nd|_dS)a
        :param body: a flow widget or box widget to be filled around (stored
            as self.original_widget)
        :type body: Widget

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

        :param height: one of:

            ``'pack'``
              if body is a flow widget

            *given height*
              integer number of rows for self.original_widget

            (``'relative'``, *percentage of total height*)
              make height depend on container's height

        :param min_height: one of:

            ``None``
              if no minimum or if body is a flow widget

            *minimum height*
              integer number of rows for the widget when height not fixed

        :param top: a fixed number of rows to fill at the top
        :type top: int
        :param bottom: a fixed number of rows to fill at the bottom
        :type bottom: int

        If body is a flow widget then height must be ``'flow'`` and
        *min_height* will be ignored.

        Filler widgets will try to satisfy height argument first by
        reducing the valign amount when necessary.  If height still
        cannot be satisfied it will also be reduced.
        rz	fixed topzfixed bottomz:fixed top height may only be used with fixed bottom valignrkz:fixed bottom height may only be used with fixed top valignN)�_Filler__superr"�
isinstancermr�rrrrr�top�bottom�normalize_valign�valign_type�
valign_amount�normalize_height�height_type�
height_amountr�
min_height)r�body�valignrXr�r�r�r r r!r"�s<*

zFiller.__init__cCs
ttg�S)N)rZr)rr r r!r,sz
Filler.sizingcCs@t|jj�t|j|j�t|j|j�|j	|j
|jd�}t|t
j�S)N)r�rXr�r�r�)r7r�r<�simplify_valignr�r��simplify_heightr�r�r�r�r�rr�r")rryr r r!r<s

zFiller._repr_attrscCs
|jj�S)zReturn selectable from body.)rr+)rr r r!r+szFiller.selectablec	Csf|\}}|jtkrB|jj|f|d�}t||j|jt|d|j|j	�St||j|j|j|j
|j|j|j	�S)z�
        Return the number of rows to pad on the top and bottom.

        Override this method to define custom padding behaviour.
        )rFN)r�rrrW�calculate_top_bottom_fillerr�r�rr�r�r�r�)rrHrFr\�maxrowrXr r r!�
filler_valuess
zFiller.filler_valuesFc
Cs�|\}}|j||�\}}|jtkr4|jj|f|�}n|jj||||f|�}t|�}|r�|j�|kr�|jdk	r�|j\}}	|	|kr�|j|	|d|||�|j�|kr�|jd|�|S|j	||�|S)z:Render self.original_widget with space above and/or below.Nrkr)
r�r�rrrGrrWZcursorZtrimZpad_trim_top_bottom)
rrHrFr\r�r�r�rIZcxZcyr r r!rG+s

z
Filler.rendercCsP|\}}|jtkr"|jj|f|�S|j||fd�\}}|jj||||f|�S)z&Pass keypress to self.original_widget.T)r�rrr^r�)rrHr_r\r�r�r�r r r!r^As

zFiller.keypressc	Cs�|\}}t|jd�sdS|j|d�\}}|jtkrB|jj|f�}n|jj||||f�}|sbdS|\}}||krz|d}|||fS)z6Return cursor coords from self.original_widget if any.r[NTrk)r(rr�r�rr[)	rrHr\r�r�r�r�r�r�r r r!r[Js
zFiller.get_cursor_coordscCs^|\}}t|jd�sdS|jtkr2|jj|f�}n(|j|d�\}}|jj||||f�}|S)z1Return pref_col from self.original_widget if any.r]NT)r(rr�rr]r�)rrHr\r�r�r�r�r r r!r]]s
zFiller.get_pref_colcCs�|\}}t|jd�sdS|j|d�\}}||ks<|||kr@dS|jtkr`|jj|f|||�S|jj||||f|||�S)zPass to self.original_widget.r`TF)r(rr�r�rr`)rrHrarbr\r�r�r�r r r!r`ls

zFiller.move_cursor_to_coordscCs�|\}}t|jd�sdS|j|d�\}	}
||	ks<|||
kr@dS|jtkrf|jj|f|||||	|�S|jj|||	|
f|||||	|�S)zPass to self.original_widget.rcFT)r(rr�r�rrc)rrHrdrerarbrFr\r�r�r�r r r!rc|s

zFiller.mouse_event)F)r-r.r/rrr"r,r<rr%Zget_bodyr'Zset_bodyr1r�r+r�rGr^r[r]r`rcr r r r!r��sQ


	r�c@sHeZdZdZdgZdZdd�Zddd�Zd	d
�Zddd�Z	dd
d�Z
dS)�
WidgetDisablez�
    A decoration widget that disables interaction with the widget it
    wraps.  This widget always passes focus=False to the wrapped widget,
    even if it somehow does become the focus.
    rWTcCsdS)NFr )rr r r!r+�szWidgetDisable.selectableFcCs|jj|d�S)NF)rrW)rrHrFr r r!rW�szWidgetDisable.rowscCs
|jj�S)N)rr,)rr r r!r,�szWidgetDisable.sizingcCs|jj|d�S)NF)rr�)rrHrFr r r!r��szWidgetDisable.packcCs|jj|d�}t|�S)NF)rrGr)rrHrFrIr r r!rG�szWidgetDisable.renderN)F)F)F)r-r.r/r0rfZignore_focusr+rWr,r�rGr r r r!r��s

r�cCsP|tttfkr|dfSt|�tkr>t|�dkr>|dtkr>|S|d|f��dS)zy
    Split align into (align_type, align_amount).  Raise exception err
    if align doesn't match a valid alignment.
    N�rzaalign value %r is not one of 'left', 'center', 'right', ('relative', percentage 0=left 100=right))r	r
rr6rm�lenr)rw�errr r r!rp�s$rpcCs|tkr||fS|S)zc
    Recombine (align_type, align_amount) into an align value.
    Inverse of normalize_align.
    )r)�
align_type�align_amountr r r!rz�srzcCsb|ttfkr|dfSt|�tkr(t|fSt|�tkrPt|�dkrP|dtkrP|S|d|f��dS)zy
    Split width into (width_type, width_amount).  Raise exception err
    if width doesn't match a valid alignment.
    Nr�rzmwidth value %r is not one of fixed number of columns, 'pack', ('relative', percentage of total width), 'clip')r
rr6r�rrmr�r)rxr�r r r!rs�s$rscCs$|ttfkr|S|tkr|S||fS)zc
    Recombine (width_type, width_amount) into an width value.
    Inverse of normalize_width.
    )r
rr)�
width_type�width_amountr r r!r}�s
r}cCsN|tttfkr|dfSt|t�r<t|�dkr<|dtkr<|S|d|f��dS)z{
    Split align into (valign_type, valign_amount).  Raise exception err
    if align doesn't match a valid alignment.
    Nr�rzbvalign value %r is not one of 'top', 'middle', 'bottom', ('relative', percentage 0=left 100=right))rrrr�rmr�r)r�r�r r r!r��sr�cCs|tkr||fS|S)zg
    Recombine (valign_type, valign_amount) into an valign value.
    Inverse of normalize_valign.
    )r)r�r�r r r!r��sr�cCs^|ttfkr|dfSt|t�r:t|�dkr:|dtkr:|St|t�rLt|fS|d|f��dS)zi
    Split height into (height_type, height_amount).  Raise exception err
    if height isn't valid.
    Nr�rzgheight value %r is not one of fixed number of columns, 'pack', ('relative', percentage of total height))rrr�rmr�rr�r)rXr�r r r!r��s
r�cCs$|ttfkr|S|tkr|S||fS)zg
    Recombine (height_type, height_amount) into an height value.
    Inverse of normalize_height.
    )rrr)r�r�r r r!r��s
r�cCs|tkr>t|||d�}t|d|d�}	|dk	rBt|	|�}	n|}	tdtdtdi}
|
j||�}||	||}|td|d|d�7}||	|}|dko�|knr�t||�}
||
8}||
7}n4|dko�|knr�t||�}
||
8}||
7}t|d�}t|d�}||fS)a�
    Return the amount of filler (or clipping) on the top and
    bottom part of maxrow rows to satisfy the following:

    valign_type -- 'top', 'middle', 'bottom', 'relative'
    valign_amount -- a percentage when align_type=='relative'
    height_type -- 'given', 'relative', 'clip'
    height_amount -- a percentage when width_type=='relative'
        otherwise equal to the height of the widget
    min_height -- a desired minimum width for the widget or None
    top -- a fixed number of rows to fill on the top
    bottom -- a fixed number of rows to fill on the bottom

    >>> ctbf = calculate_top_bottom_filler
    >>> ctbf(15, 'top', 0, 'given', 10, None, 2, 0)
    (2, 3)
    >>> ctbf(15, 'relative', 0, 'given', 10, None, 2, 0)
    (2, 3)
    >>> ctbf(15, 'relative', 100, 'given', 10, None, 2, 0)
    (5, 0)
    >>> ctbf(15, 'middle', 0, 'given', 4, None, 2, 0)
    (6, 5)
    >>> ctbf(15, 'middle', 0, 'given', 18, None, 2, 0)
    (0, 0)
    >>> ctbf(20, 'top', 0, 'relative', 60, None, 0, 0)
    (0, 8)
    >>> ctbf(20, 'relative', 30, 'relative', 60, None, 0, 0)
    (2, 6)
    >>> ctbf(20, 'relative', 30, 'relative', 60, 14, 0, 0)
    (2, 4)
    r�erkN�2�d)rr�rrrr�get�min)r�r�r�r�r�r�r�r�Z	maxheightrX�standard_alignmentsr�Zfiller�shiftr r r!r�s,!


r�cCs&|tkr>t|||d�}t|d|d�}	|dk	rBt|	|�}	n|}	tdtdtdi}
|
j||�}||	||}|td|d|d�7}||	|}|dkr�|dkr�t||�}
||
8}||
7}n,|dkr�|dkr�t||�}
||
8}||
7}|tk�r|dk�s
|dk�rt|d�}t|d�}||fS)a
    Return the amount of padding (or clipping) on the left and
    right part of maxcol columns to satisfy the following:

    align_type -- 'left', 'center', 'right', 'relative'
    align_amount -- a percentage when align_type=='relative'
    width_type -- 'fixed', 'relative', 'clip'
    width_amount -- a percentage when width_type=='relative'
        otherwise equal to the width of the widget
    min_width -- a desired minimum width for the widget or None
    left -- a fixed number of columns to pad on the left
    right -- a fixed number of columns to pad on the right

    >>> clrp = calculate_left_right_padding
    >>> clrp(15, 'left', 0, 'given', 10, None, 2, 0)
    (2, 3)
    >>> clrp(15, 'relative', 0, 'given', 10, None, 2, 0)
    (2, 3)
    >>> clrp(15, 'relative', 100, 'given', 10, None, 2, 0)
    (5, 0)
    >>> clrp(15, 'center', 0, 'given', 4, None, 2, 0)
    (6, 5)
    >>> clrp(15, 'left', 0, 'clip', 18, None, 0, 0)
    (0, -3)
    >>> clrp(15, 'right', 0, 'clip', 18, None, 0, -1)
    (-2, -1)
    >>> clrp(15, 'center', 0, 'given', 18, None, 2, 0)
    (0, 0)
    >>> clrp(20, 'left', 0, 'relative', 60, None, 0, 0)
    (0, 8)
    >>> clrp(20, 'relative', 30, 'relative', 60, None, 0, 0)
    (2, 6)
    >>> clrp(20, 'relative', 30, 'relative', 60, 14, 0, 0)
    (2, 4)
    rr�rkNr�r�)	rr�rr	r
rr�r�r
)r\r�r�r�r�rvrnror�rxr�rwZpaddingr�r r r!r�Fs.%


r�cCsddl}|j�dS)Nr)�doctestZtestmod)r�r r r!�_test�sr��__main__N)8Z
__future__rrZ
urwid.utilrZurwid.widgetrrrrr	r
rrr
rrrrrrrZurwid.split_reprrZurwid.canvasrrrrrrrr2r3r4rJ�	ExceptionrUrVrgrhr�r�r�rprzrsr}r�r�r�r�r�r�r�r-r r r r!�<module>sDH8~ZZ
_
		BH


Zerion Mini Shell 1.0