HOME


Mini Shell 1.0
DIR: /snap/core20/current/usr/share/subiquity/subiquitycore/ui/__pycache__/
Upload File :
Current File : //snap/core20/current/usr/share/subiquity/subiquitycore/ui/__pycache__/utils.cpython-38.pyc
U

K��^w%�@svdZddlmZddlZddlmZmZmZmZm	Z
mZmZm
Z
mZddlmZddlmZmZddlmZddlmZdd	lmZe�d
�Zdd�ZeGd
d�d��Z	edddddddddddddddddd d!d"d#d$g�Zd%d&�ZeGd'd(�d(��Z d)d*�eedg�BD�Z!d+d,�Z"d-d.�Z#d/d0�Z$d@d3d4�Z%Gd5d6�d6e
�Z&Gd7d8�d8e�Z'dAd:d;�Z(d<d=�Z)Gd>d?�d?e�Z*dS)Bz UI utilities �)�
partialmethodN)	�ACTIVATE�AttrMap�CompositeCanvas�connect_signal�Padding�SelectableIcon�Text�WidgetDecoration�
WidgetDisable)�	other_btn)�ListBox�Pile)�Stretchy)�TableRow)�widget_widthzsubiquitycore.ui.utilsc
Cs�d}td|�D]�}t|d�|�tt|d��t|d�|�tt|d��t|d�|�ttd||d	��t|d
�|�ttdd|fd��t|d
�|�ttdd|fd��t|d�|�ttdd|fd��q|S)aT Decorator for generating useful padding methods

    Loops through and generates methods like:

      Padding.push_1(Widget)

      Sets the left padding attribute by 1

      Padding.pull_24(Widget)

      Sets right padding attribute by 24.

      Padding.center_50(Widget)

      Provides center padding with a relative width of 50
    �d�zpush_{})�leftzpull_{})�rightzfixed_{}�center)�align�width�	min_widthz	center_{}�relative)rrzleft_{}rzright_{}r)�range�setattr�formatr�_Padding)�clsZ
padding_count�i�r!�./usr/share/subiquity/subiquitycore/ui/utils.py�
apply_padders*s4��������r#c@seZdZdZee�ZdS)rau Padding methods

    .. py:meth:: push_X(:class:`urwid.Widget`)

       This method supports padding the left side of the widget
       from 1-99, for example:

       .. code::

          Padding.push_20(Text("This will be indented 20 columns")

    .. py:meth:: pull_X(:class:`urwid.Widget`)

       This method supports padding the right side of the widget
       from 1-99, for example:

       .. code::

          Padding.pull_20(Text("This will be right indented 20 columns")

    .. py:meth:: fixed_X(:class:`urwid.Widget`)

       This method supports padding the widget to a fixed size and
       centering it.
       from 1-99, for example:

       .. code::

          Padding.fixed_20(Text("This will be centered and fixed sized
                                 of 20 columns"))

    .. py:meth:: center_X(:class:`urwid.Widget`)

       This method centers a widget with X being the relative width of
       the widget.

       .. code::

          Padding.center_10(Text("This will be centered with a "
                                 "width of 10 columns"))

    .. py:meth:: left_X(:class:`urwid.Widget`)

       This method aligns a widget left with X being the relative width of
       the widget.

       .. code::

          Padding.left_10(Text("This will be left aligned with a "
                               "width of 10 columns"))

    .. py:meth:: right_X(:class:`urwid.Widget`)

       This method right aligns a widget with X being the relative width of
       the widget.

       .. code::

          Padding.right_10(Text("This will be right aligned with a "
                                "width of 10 columns"))

    N)�__name__�
__module__�__qualname__�__doc__rr	Z
line_breakr!r!r!r"rOs>r�bodyzdanger_button focusZ
danger_buttonzdone_button focusZdone_buttonzframe_button focusZframe_buttonZframe_headerZframe_header_fringeZ
info_error�
info_minorZinfo_primary�menu_button focus�menu_buttonzother_button focusZother_buttonZprogress_completeZprogress_incompletezscrollbar focusZ	scrollbarzstring_input focusZstring_inputc	CsJtD]@}|d}|tkr0t||tt||d��qt||tt|d��q|S)z� Applies AttrMap attributes to Color class

    Eg:

      Color.frame_header(Text("I'm text in the Orange frame header"))
      Color.body(Text("Im text in wrapped with the body color"))
    z focus)�attr_map�	focus_map)r,)�STYLE_NAMESrrr)r�kZkfr!r!r"�apply_style_map�sr0c@seZdZdZdS)�ColoraZ Partial methods for :class:`~subiquity.palette.STYLES`

    .. py:meth:: frame_header(:class:`urwid.Widget`)

       This method colors widget based on the style map used.

       .. code::

          Color.frame_header(Text("This will use foreground and background "
                                  "defined from the STYLES attribute"))

    N)r$r%r&r'r!r!r!r"r1�sr1cCsi|]
}|d�qS)r)r!)�.0r/r!r!r"�
<dictcomp>�sr3cCstt|t��S�N)rr�_disable_everything_map��wr!r!r"�disabled�sr8cCs$t|t�r|j}t|t�r |j}|Sr4)�
isinstancerZoriginal_widgetrr6r!r!r"�
undisabled�s


r:cCs0d}|D]}tt|�|�}qtt|�||dd�S)N�r)rrr)�maxrrr)�buttonsrZbuttonr!r!r"�button_pile�s�r>TFcCs�t|t�rt|�}|r t�|�}|dkr.d}nt|t�r@t|�}g}|dk	rddt|�fdtd�fg}|dtd�fg}|dk	r�|�d|fdtd�fg�t||�}|r�t	|�d|_
tj|dd�S)a_Helper to create a common screen layout.

    The commonest screen layout in subiquity is:

        [ 1 line padding (optional) ]
        excerpt (optional)
        [ 1 line padding ]
        Box widget (usually a ListBox)
        [ 1 line padding ]
        a button_pile
        [ 1 line padding ]

    This helper makes creating this a 1-liner.
    NFZpack���L)r)r9�listr
rZ	center_63r>r	�extendr�lenZfocus_positionZ	center_79)�rowsr=Z
focus_buttonsZexcerptZnarrow_rowsZexcerpt_rowsr(Zpiler!r!r"�screen�s2




�
�
�rFcsHeZdZdZdZd�fdd�	Zdd�Zdd	�Zd
d�Zdd
d�Z	�Z
S)�CursorOverridezKDecoration to override where the cursor goes when a widget is focused.
    Trcst��|�||_dSr4)�super�__init__�cursor_x)�selfr7rJ��	__class__r!r"rIszCursorOverride.__init__cCs
|jdfS)Nr�rJ)rK�sizer!r!r"�get_cursor_coordssz CursorOverride.get_cursor_coordscCs|j�||�Sr4)�_original_widgetrE�rKrO�focusr!r!r"rE"szCursorOverride.rowscCs|j�||�Sr4)rQ�keypressrRr!r!r"rT%szCursorOverride.keypressFcCs*|j�||�}|r&t|�}|�|�|_|Sr4)rQ�renderrrPZcursor)rKrOrS�cr!r!r"rU(s
zCursorOverride.render)r)F)r$r%r&r'Zhas_original_widthrIrPrErTrU�
__classcell__r!r!rLr"rGsrGc@seZdZdZdgZdd�ZdS)�
ClickableIconzLike Button, but simpler. �clickcCs |j|tkr|S|�d�dS)NrY)Z_command_maprZ_emit)rKrO�keyr!r!r"rT5szClickableIcon.keypressN)r$r%r&r'ZsignalsrTr!r!r!r"rX1srXr@cspt|�}t�t�sd�i�t�t�s,d�i�tt||d�����t|d��fdd��t|d��fdd���S)NrN�opencs
����Sr4�Zset_attr_map��menu)�amr-r!r"�<lambda>F�z&make_action_menu_row.<locals>.<lambda>�closecs
����Sr4r\r])r_r,r!r"r`Gra)rr9�dictrrGr)Zcellsr^r,r-rJ�rowr!)r_r,r-r"�make_action_menu_row;s

recCs"|�d�}d�dd�|D����S)Nz

cSsg|]}|�dd��qS)�
� )�replace)r2�pr!r!r"�
<listcomp>Mszrewrap.<locals>.<listcomp>)�split�join�strip)�textZparasr!r!r"�rewrapKs
rocs$eZdZ�fdd�Zdd�Z�ZS)�SomethingFailedcsX||_ttd�|jd�}t|�td�t|�d��td�t|g�g}t��d|dd�dS)NZClose)ZlabelZon_pressr?rfr@�)	�parentr�_rbr	rmr>rHrI)rKrr�msg�stderr�okZwidgetsrLr!r"rIQs��zSomethingFailed.__init__cCs|j��dSr4)rrZremove_overlay)rKZsenderr!r!r"rb`szSomethingFailed.close)r$r%r&rIrbrWr!r!rLr"rpPsrp)NTNF)r+r*r@)+r'�	functoolsrZloggingZurwidrrrrrrrr	r
rZsubiquitycore.ui.buttonsrZsubiquitycore.ui.containerr
rZsubiquitycore.ui.stretchyrZsubiquitycore.ui.tablerZsubiquitycore.ui.widthrZ	getLogger�logr#�setr.r0r1r5r8r:r>rFrGrXrerorpr!r!r!r"�<module>sl,
%E��
-
�