%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core22/current/lib/python3/dist-packages/urwid/__pycache__/
Upload File :
Create Path :
Current File : //snap/core22/current/lib/python3/dist-packages/urwid/__pycache__/wimp.cpython-310.pyc

o

��o_�U�@s0ddlmZmZddlmZmZmZmZmZddl	m
Z
ddlmZddl
mZmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�ded�e�Z!Gdd�de�Z"dd�Z#e$dkr�e#�dSdS)�)�division�print_function)�Text�
WidgetWrap�delegate_to_widget_mixin�BOX�FLOW)�CompositeCanvas)�connect_signal)�Columns�Overlay)�is_mouse_press)�calc_coords)�disconnect_signal)�python3_repr)�WidgetDecoration)�ACTIVATEc@s8eZdZdZdZd
dd�Zddd�Zdd	�Zd
d�ZdS)�SelectableIconFTrcCs|j�|�||_dS)a�
        :param text: markup for this widget; see :class:`Text` for
                     description of text markup
        :param cursor_position: position the cursor will appear in the
                                text when this widget is in focus

        This is a text widget that is selectable.  A cursor
        displayed at a fixed location in the text when in focus.
        This widget has no special handling of keyboard or mouse input.
        N)�_SelectableIcon__super�__init__�_cursor_position)�self�text�cursor_position�r�,/usr/lib/python3/dist-packages/urwid/wimp.pyr's
zSelectableIcon.__init__cCs*|j�||�}|rt|�}|�|�|_|S)a�
        Render the text content of this widget with a cursor when
        in focus.

        >>> si = SelectableIcon(u"[!]")
        >>> si
        <SelectableIcon selectable flow widget '[!]'>
        >>> si.render((4,), focus=True).cursor
        (0, 0)
        >>> si = SelectableIcon("((*))", 2)
        >>> si.render((8,), focus=True).cursor
        (2, 0)
        >>> si.render((2,), focus=True).cursor
        (0, 1)
        )r�renderr	�get_cursor_coords�cursor)r�size�focus�crrrr5s
zSelectableIcon.rendercCsL|jt|j�kr
dS|\}|�|�}t|j||j�\}}||kr"dS||fS)z�
        Return the position of the cursor if visible.  This method
        is required for widgets that display a cursor.
        N)r�lenr�get_line_translationr)rr�maxcol�trans�x�yrrrrLs
z SelectableIcon.get_cursor_coordscCs|S)zn
        No keys are handled by this widget.  This method is
        required for selectable widgets.
        r�rr�keyrrr�keypress\szSelectableIcon.keypressN)r�F)	�__name__�
__module__�__qualname__�ignore_focus�_selectablerrrr*rrrrr$s

rc@seZdZdS)�
CheckBoxErrorN)r,r-r.rrrrr1csr1c@s�eZdZdd�Zedd�edd�edd�d�ZdZd	d
gZ		d"d
d�Zdd�Z	dd�Z
dd�Zdd�Ze
e�Zd#dd�Zdd�Ze
ee�Zdd�Zdd�Zd d!�ZdS)$�CheckBoxcC�
ttg�S�N��	frozensetr�rrrr�sizingg�
zCheckBox.sizingz[X]�z[ ]z[#]�TF�mixed��change�
postchangeFNcCsd|j�d�td�|_||_d|_|rtd|d�|jd<|r&t|d||�|�	|�|�
|�dS)a�
        :param label: markup for check box label
        :param state: False, True or "mixed"
        :param has_mixed: True if "mixed" is a state to cycle through
        :param on_state_change: shorthand for connect_signal()
                                function call for a single callback
        :param user_data: user_data for on_state_change

        Signals supported: ``'change'``, ``"postchange"``

        Register signal handler with::

          urwid.connect_signal(check_box, 'change', callback, user_data)

        where callback is callback(check_box, new_state [,user_data])
        Unregister signal handlers with::

          urwid.disconnect_signal(check_box, 'change', callback, user_data)

        >>> CheckBox(u"Confirm")
        <CheckBox selectable flow widget 'Confirm' state=False>
        >>> CheckBox(u"Yogourt", "mixed", True)
        <CheckBox selectable flow widget 'Yogourt' state='mixed'>
        >>> cb = CheckBox(u"Extra onions", True)
        >>> cb
        <CheckBox selectable flow widget 'Extra onions' state=True>
        >>> cb.render((20,), focus=True).text # ... = b in Python 3
        [...'[X] Extra onions    ']
        N�z[%s]r:Tr>)�_CheckBox__superrr�_label�	has_mixed�_stater�statesr
�	set_label�	set_state)r�label�staterC�on_state_change�	user_data�checked_symbolrrrrus

zCheckBox.__init__cC�|j��t|j�gSr4)rA�_repr_wordsrrHr7rrrrN�s�zCheckBox._repr_wordscCst|j��|jd�S)N)rI)�dictrA�_repr_attrsrIr7rrrrP�s
�zCheckBox._repr_attrscC�|j�|�dS)au
        Change the check box label.

        label -- markup for label.  See Text widget for description
        of text markup.

        >>> cb = CheckBox(u"foo")
        >>> cb
        <CheckBox selectable flow widget 'foo' state=False>
        >>> cb.set_label(('bright_attr', u"bar"))
        >>> cb
        <CheckBox selectable flow widget 'bar' state=False>
        N�rB�set_text�rrHrrrrF�szCheckBox.set_labelcC�|jjS)a>
        Return label text.

        >>> cb = CheckBox(u"Seriously")
        >>> print(cb.get_label())
        Seriously
        >>> print(cb.label)
        Seriously
        >>> cb.set_label([('bright_attr', u"flashy"), u" normal"])
        >>> print(cb.label)  #  only text is returned
        flashy normal
        �rBrr7rrr�	get_label�s
zCheckBox.get_labelTcCs�|j|krdS||jvrtdt|�t|�f��|j}|r'|dur'|�d|�||_td|j|j|f|jg�|_d|j_	|rK|durM|�d|�dSdSdS)a�
        Set the CheckBox state.

        state -- True, False or "mixed"
        do_callback -- False to suppress signal from this change

        >>> changes = []
        >>> def callback_a(cb, state, user_data):
        ...     changes.append("A %r %r" % (state, user_data))
        >>> def callback_b(cb, state):
        ...     changes.append("B %r" % state)
        >>> cb = CheckBox('test', False, False)
        >>> key1 = connect_signal(cb, 'change', callback_a, "user_a")
        >>> key2 = connect_signal(cb, 'change', callback_b)
        >>> cb.set_state(True) # both callbacks will be triggered
        >>> cb.state
        True
        >>> disconnect_signal(cb, 'change', callback_a, "user_a")
        >>> cb.state = False
        >>> cb.state
        False
        >>> cb.set_state(True)
        >>> cb.state
        True
        >>> cb.set_state(False, False) # don't send signal
        >>> changes
        ["A True 'user_a'", 'B True', 'B False', 'B True']
        Nz%s Invalid state: %sr>�fixedrr?)
rDrEr1�repr�_emitr�reserve_columnsrB�_w�	focus_col)rrI�do_callback�	old_staterrrrG�s$

���zCheckBox.set_statecCs|jS)z!Return the state of the checkbox.)rDr7rrr�	get_state�szCheckBox.get_statecCs|j|tkr	|S|��dS)a�
        Toggle state on 'activate' command.

        >>> assert CheckBox._command_map[' '] == 'activate'
        >>> assert CheckBox._command_map['enter'] == 'activate'
        >>> size = (10,)
        >>> cb = CheckBox('press me')
        >>> cb.state
        False
        >>> cb.keypress(size, ' ')
        >>> cb.state
        True
        >>> cb.keypress(size, ' ')
        >>> cb.state
        False
        N)�_command_mapr�toggle_stater(rrrr*szCheckBox.keypresscCs`|jdkr|�d�dS|jdkr"|jr|�d�dS|�d�dS|jdkr.|�d�dSdS)aM
        Cycle to the next valid state.

        >>> cb = CheckBox("3-state", has_mixed=True)
        >>> cb.state
        False
        >>> cb.toggle_state()
        >>> cb.state
        True
        >>> cb.toggle_state()
        >>> cb.state
        'mixed'
        >>> cb.toggle_state()
        >>> cb.state
        False
        FTr<N)rIrGrCr7rrrrbs


�zCheckBox.toggle_statecCs |dkst|�s
dS|��dS)a
        Toggle state on button 1 press.

        >>> size = (20,)
        >>> cb = CheckBox("clickme")
        >>> cb.state
        False
        >>> cb.mouse_event(size, 'mouse press', 1, 2, 0, True)
        True
        >>> cb.state
        True
        r:FT)r
rb�rr�event�buttonr&r'r rrr�mouse_event3s
zCheckBox.mouse_event)FFNNN�T)r,r-r.r8rrEr[�signalsrrNrPrFrW�propertyrHrGr`rIr*rbrfrrrrr2fs,�
�,
2
r2c@sNeZdZedd�edd�edd�d�ZdZ		dd	d
�Zddd
�Zdd�ZdS)�RadioButtonz(X)r:z( )z(#)r;r=�
first TrueNcCs6|dkr|}||_|j�||d||�|�|�dS)a
        :param group: list for radio buttons in same group
        :param label: markup for radio button label
        :param state: False, True, "mixed" or "first True"
        :param on_state_change: shorthand for connect_signal()
                                function call for a single 'change' callback
        :param user_data: user_data for on_state_change

        This function will append the new radio button to group.
        "first True" will set to True if group is empty.

        Signals supported: ``'change'``, ``"postchange"``

        Register signal handler with::

          urwid.connect_signal(radio_button, 'change', callback, user_data)

        where callback is callback(radio_button, new_state [,user_data])
        Unregister signal handlers with::

          urwid.disconnect_signal(radio_button, 'change', callback, user_data)

        >>> bgroup = [] # button group
        >>> b1 = RadioButton(bgroup, u"Agree")
        >>> b2 = RadioButton(bgroup, u"Disagree")
        >>> len(bgroup)
        2
        >>> b1
        <RadioButton selectable flow widget 'Agree' state=True>
        >>> b2
        <RadioButton selectable flow widget 'Disagree' state=False>
        >>> b2.render((15,), focus=True).text # ... = b in Python 3
        [...'( ) Disagree   ']
        rkFN)�group�_RadioButton__superr�append)rrlrHrIrJrKrrrrMs$�zRadioButton.__init__TcCsR|j|krdS|j�||�|durdS|jD]}||urq|jr&|�d�qdS)a�
        Set the RadioButton state.

        state -- True, False or "mixed"

        do_callback -- False to suppress signal from this change

        If state is True all other radio buttons in the same button
        group will be set to False.

        >>> bgroup = [] # button group
        >>> b1 = RadioButton(bgroup, u"Agree")
        >>> b2 = RadioButton(bgroup, u"Disagree")
        >>> b3 = RadioButton(bgroup, u"Unsure")
        >>> b1.state, b2.state, b3.state
        (True, False, False)
        >>> b2.set_state(True)
        >>> b1.state, b2.state, b3.state
        (False, True, False)
        >>> def relabel_button(radio_button, new_state):
        ...     radio_button.set_label(u"Think Harder!")
        >>> key = connect_signal(b3, 'change', relabel_button)
        >>> b3
        <RadioButton selectable flow widget 'Unsure' state=False>
        >>> b3.set_state(True) # this will trigger the callback
        >>> b3
        <RadioButton selectable flow widget 'Think Harder!' state=True>
        NTF)rDrmrGrl)rrIr^�cbrrrrG{s



��zRadioButton.set_statecCs|�d�dS)a�
        Set state to True.

        >>> bgroup = [] # button group
        >>> b1 = RadioButton(bgroup, "Agree")
        >>> b2 = RadioButton(bgroup, "Disagree")
        >>> b1.state, b2.state
        (True, False)
        >>> b2.toggle_state()
        >>> b1.state, b2.state
        (False, True)
        >>> b2.toggle_state()
        >>> b1.state, b2.state
        (False, True)
        TN)rGr7rrrrb�szRadioButton.toggle_state)rkNNrg)	r,r-r.rrEr[rrGrbrrrrrjFs�
�
..rjc@sdeZdZdd�Zed�Zed�ZdgZddd�Zd	d
�Z	dd�Z
d
d�Zee�Z
dd�Zdd�ZdS)�ButtoncCr3r4r5r7rrrr8�r9z
Button.sizing�<�>�clickNcCs\tdd�|_tdd|jf|jdd|jfgdd�}|j�|�|r't|d||�|�|�dS)a�
        :param label: markup for button label
        :param on_press: shorthand for connect_signal()
                         function call for a single callback
        :param user_data: user_data for on_press

        Signals supported: ``'click'``

        Register signal handler with::

          urwid.connect_signal(button, 'click', callback, user_data)

        where callback is callback(button [,user_data])
        Unregister signal handlers with::

          urwid.disconnect_signal(button, 'click', callback, user_data)

        >>> Button(u"Ok")
        <Button selectable flow widget 'Ok'>
        >>> b = Button("Cancel")
        >>> b.render((15,), focus=True).text # ... = b in Python 3
        [...'< Cancel      >']
        r@rrXr:)�dividecharsrsN)	rrBr�button_left�button_right�_Button__superrr
rF)rrH�on_pressrK�colsrrrr�s

��zButton.__init__cCrMr4)rwrNrrHr7rrrrN�s�zButton._repr_wordscCrQ)z�
        Change the button label.

        label -- markup for button label

        >>> b = Button("Ok")
        >>> b.set_label(u"Yup yup")
        >>> b
        <Button selectable flow widget 'Yup yup'>
        NrRrTrrrrF�szButton.set_labelcCrU)z�
        Return label text.

        >>> b = Button(u"Ok")
        >>> print(b.get_label())
        Ok
        >>> print(b.label)
        Ok
        rVr7rrrrW�s
zButton.get_labelcCs |j|tkr	|S|�d�dS)aD
        Send 'click' signal on 'activate' command.

        >>> assert Button._command_map[' '] == 'activate'
        >>> assert Button._command_map['enter'] == 'activate'
        >>> size = (15,)
        >>> b = Button(u"Cancel")
        >>> clicked_buttons = []
        >>> def handle_click(button):
        ...     clicked_buttons.append(button.label)
        >>> key = connect_signal(b, 'click', handle_click)
        >>> b.keypress(size, 'enter')
        >>> b.keypress(size, ' ')
        >>> clicked_buttons # ... = u in Python 2
        [...'Cancel', ...'Cancel']
        rsN)rarrZr(rrrr*szButton.keypresscCs"|dkst|�s
dS|�d�dS)a
        Send 'click' signal on button 1 press.

        >>> size = (15,)
        >>> b = Button(u"Ok")
        >>> clicked_buttons = []
        >>> def handle_click(button):
        ...     clicked_buttons.append(button.label)
        >>> key = connect_signal(b, 'click', handle_click)
        >>> b.mouse_event(size, 'mouse press', 1, 4, 0, True)
        True
        >>> b.mouse_event(size, 'mouse press', 2, 4, 0, True) # ignored
        False
        >>> clicked_buttons # ... = u in Python 2
        [...'Ok']
        r:FrsT)r
rZrcrrrrf!s
zButton.mouse_event)NN)r,r-r.r8rrurvrhrrNrFrWrirHr*rfrrrrrp�s
'
rpc@s>eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zddd
�ZdS)�
PopUpLaunchercCs|j�|�d|_dSr4)�_PopUpLauncher__superr�_pop_up_widget�r�original_widgetrrrr;s
zPopUpLauncher.__init__cC�td��)z�
        Subclass must override this method and return a widget
        to be used for the pop-up.  This method is called once each time
        the pop-up is opened.
        �"Subclass must override this method��NotImplementedErrorr7rrr�
create_pop_up?szPopUpLauncher.create_pop_upcCr)z�
        Subclass must override this method and have it return a dict, eg:

        {'left':0, 'top':1, 'overlay_width':30, 'overlay_height':4}

        This method is called each time this widget is rendered.
        r�r�r7rrr�get_pop_up_parametersGsz#PopUpLauncher.get_pop_up_parameterscCs|��|_|��dSr4)r�r|�_invalidater7rrr�open_pop_upQs
zPopUpLauncher.open_pop_upcCsd|_|��dSr4)r|r�r7rrr�close_pop_upUszPopUpLauncher.close_pop_upFcCs8|j�||�}|jrt|�}|j|jfi|����|Sr4)r{rr|r	�
set_pop_upr�)rrr �canvrrrrYs
zPopUpLauncher.renderNr+)	r,r-r.rr�r�r�r�rrrrrrz9s
rz�_original_widgetc@sfeZdZeeg�ZdZdd�Zdd�Zddd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zddd�ZdS)�PopUpTargetTcCs|j�|�d|_|j|_dSr4)�_PopUpTarget__superr�_pop_upr��_current_widgetr}rrrrgszPopUpTarget.__init__c
Cs�|jj||d�}||_|��}|rA|\}}\}}}	|j|kr2||_t||jd|f|d|f|	�|_dS|j�d|f|d|f|	�dSd|_|j|_dS)N�r z
fixed leftz	fixed top)r�r�_cache_original_canvas�
get_pop_upr�rr��set_overlay_parameters)
rrr r��pop_up�left�top�w�
overlay_width�overlay_heightrrr�_update_overlayls&�

��zPopUpTarget._update_overlayFcCs|�||�|jj||d�S)Nr�)r�r�r�rrr rrrr��zPopUpTarget.rendercC�|�|d�|j�|�S�NT)r�r�r�rrrrrr��zPopUpTarget.get_cursor_coordscCr�r�)r�r��get_pref_colr�rrrr��r�zPopUpTarget.get_pref_colcCs|�|d�|j�||�Sr�)r�r�r*r(rrrr*�szPopUpTarget.keypresscCs|�|d�|j�|||�Sr�)r�r��move_cursor_to_coords)rrr&r'rrrr��r�z!PopUpTarget.move_cursor_to_coordscCs"|�||�|j�||||||�Sr4)r�r�rfrcrrrrf�szPopUpTarget.mouse_eventNcCs|�||�|j�|�Sr4)r�r��packr�rrrr��r�zPopUpTarget.packr+)NF)r,r-r.�setr�_sizingr0rr�rrr�r*r�rfr�rrrrr�as

r�cCsddl}|��dS)Nr)�doctest�testmod)r�rrr�_test�sr��__main__N)%�
__future__rr�urwid.widgetrrrrr�urwid.canvasr	�
urwid.signalsr
�urwid.containerrr�
urwid.utilr
�urwid.text_layoutrr�urwid.split_reprr�urwid.decorationr�urwid.command_maprr�	Exceptionr1r2rjrprzr�r�r,rrrr�<module>s2?av}�(:
�

Zerion Mini Shell 1.0