HOME


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

K��^5Q�@sNdZddlZddlZddlZe�d�Zdd�Zdd�Zeej	j
���D]&\ZZ
e
dd	ejfkrFe
ej	ed
<qFej	��Zded<ded<Gd
d�dej�ZGdd�dej�ZGdd�dej�ZGdd�d�ZGdd�dee�ZGdd�dee�ZGdd�de�ZeZeZGdd�dej�Zd$dd�dd �Ze�d!�ZGd"d#�d#ej�Z e ZdS)%a"Extended versions of urwid containers.

This module provides versions of urwid's Columns, Pile and ListBox
containers. It adds support for tab-cycling, callbacks on
gaining/losing focus and scrollbars on listboxes.

 1. Tab-cycling

Tab advances to the next selectable item and wraps when it gets to the
end of the screen. Shift tab goes the other way. In addition, an
unhandled "enter" key also advances to the next selectable item.

 2. Callbacks when a widget gains/loses focus

Define lost_focus or gained_focus callbacks on widgets and they'll be
called when the widget gains or loses focus.

 3. Scrollbars on ListBoxes.

All ListBoxes in subiquity gain a scrollbar when their contents don't
entirely fit on screen. The implementation assumes that there are not
too many elements in the ListBox.
�Nzsubiquitycore.ui.containercCs,|dkrdSt|j|d�}|dk	r(|�dS�N)�getattr�base_widget)�wZmethname�m�r�2/usr/share/subiquity/subiquitycore/ui/container.py�_maybe_callas
r	cCs,t|�D]\}}||kr|��rdSqdS�NTF)�	enumerate�
selectable)Zwidgets�	cur_focus�irrrr�_has_other_selectableisr�next selectable�prev selectable� no wrapZenterz
enter no wrapc@s8eZdZeZdd�Zdd�Zdd�Zdd�Zd	d
�Z	dS)�TabCyclingPilecCs"|jD]\}}|��rdSqdSr
)�contentsr)�selfr�_rrrr|szTabCyclingPile.selectablecCs>t|j�D].\}\}}|��r
|�|�t|d�dSq
dS�z6Select first selectable child (possibily recursively).�_select_first_selectableN�rrr�	set_focusr	�rrr�orrrr�s


z'TabCyclingPile._select_first_selectablecCsFttt|j���D].\}\}}|��r|�|�t|d�dSqdS�z5Select last selectable child (possibily recursively).�_select_last_selectableN��reversed�listrrrrr	rrrrr�s


z&TabCyclingPile._select_last_selectablecCsdd�|jD�S)NcSsg|]\}}|�qSrr)�.0rrrrr�
<listcomp>�sz+TabCyclingPile._widgets.<locals>.<listcomp>)�	_contents�rrrr�_widgets�szTabCyclingPile._widgetscCs�|js
|S|}|�d�s>|j|dkr>t|��|j�r>|d7}d}t|�dkr\|j|dd�}|j}|��r�|�	||d|�}|j
�||�}|j|dkr�|S|j|dk�r|jd	}t|j
|d�|�D].\}\}	}
|	��r�|�|�t|	d
�dSq�|�d��s|��|S|j|dk�r�|j
d|j�}ttt|���D]2\}\}	}
|	���r@|�|�t|	d�dS�q@|�d��s�|��|S|j|d
k�r�tt|d	dd��}d}
ntt|d	t|j���}d
}
|�s�|j|dd�}|D]�}|j|d���s�q�|�|�||_t|j
|
�t|j
d��s6dS||}|j|d
k�rdtt|d	dd��}ntt|��}|D]0}|�	||d|�}|j�||j|��rt�q��qtdS|S)zjPass the keypress to the widget in focus.
        Unhandled 'up' and 'down' keys may cause a focus change.r�rrN�T)�focus)�	cursor upzcursor downrrr�rrrr*���r�move_cursor_to_coords)r�endswith�_command_maprr&�focus_position�lenZ
get_item_rowsrZ
get_item_sizer)�keypressrr$rr	rr r!r�rangeZ_update_pref_col_from_focus�hasattrZ
focus_itemr-Zpref_col)r�size�key�downkeyZ	item_rowsrZtsize�upkey�next_fprr�	positionsZ
candidates�meth�j�rowsZrowlist�rowrrrr2�s��
 






�
zTabCyclingPile.keypressN)
�__name__�
__module__�__qualname__�enter_advancing_command_mapr/rrrr&r2rrrrrysrcs.eZdZd
�fdd�	Zdd�Zdd	�Z�ZS)�OneSelectableColumnsrNr+c	sLt��|||||�d}|jD]\}}|��r|d7}q|dkrHtd��dS)Nrr+z3subiquity only supports one selectable in a Columns)�super�__init__r$r�	Exception)	rZwidget_listZdividecharsZfocus_columnZ	min_widthZbox_columnsZselectablesrr��	__class__rrrE�s�
�zOneSelectableColumns.__init__cCs>t|j�D].\}\}}|��r
|�|�t|d�dSq
dSrrrrrrrs


z-OneSelectableColumns._select_first_selectablecCsFttt|j���D].\}\}}|��r|�|�t|d�dSqdSrrrrrrr
s


z,OneSelectableColumns._select_last_selectable)rNr+N)r?r@rArErr�
__classcell__rrrGrrC�s�rCcsDeZdZeZ�fdd�Zdd�Zdd�Zdd�Z�fd	d
�Z	�Z
S)�TabCyclingListBoxcs*t|dd�dkrt�|�}t��|�dS)N�	get_focus)r�urwid�SimpleFocusListWalkerrDrE)r�bodyrGrrrEs
zTabCyclingListBox.__init__cCs |�|�|�|�|��dSr)r�_invalidate)rrrrr�_set_focus_no_moves

z$TabCyclingListBox._set_focus_no_movecCs:t|j�D]*\}}|��r
|�|�t|d�dSq
dSr)rrNrrPr	�rrrrrrr)s


z*TabCyclingListBox._select_first_selectablecCsBttt|j���D]*\}}|��r|�|�t|d�dSqdSr)r r!rrNrrPr	rQrrrr1s


z)TabCyclingListBox._select_last_selectablec	sH|}|�d�s2|j|dkr2t|j|j�r2|d7}t��||�}||krL|}t|j�dkr^|S|j|dkr�|jd}t|j|d�|�D]*\}}|�	�r�|�
|�t|d�dSq�|�d�s�|��|S|j|dk�r@|jd|j�}t
tt|���D]*\}}|�	�r�|�
|�t|d�dSq�|�d��s<|��|S|SdS)	Nrr'rrr+rrr)r.r/rrNr0rDr2r1rrrr	rr r!r)	rr5r6r7r8r9rrr:rGrrr29s@�





zTabCyclingListBox.keypress)r?r@rArBr/rErPrrr2rIrrrGrrJsrJcs4eZdZ�fdd�Zdd�Zdd�Zdd�Z�ZS)	�FocusTrackingMixincs t�j||�|j�|j�dSr)rDrEr$�set_focus_changed_callback�_focus_changed�r�args�kwrGrrrEaszFocusTrackingMixin.__init__cCs.z
|j}Wntk
rYnXt|d�dS�N�
lost_focus)r)�
IndexErrorr	)rr
rrrrYes

zFocusTrackingMixin.lost_focuscCst|jd�dS�N�gained_focus�r	r)r%rrrr\mszFocusTrackingMixin.gained_focuscCsDz
|j}Wntk
rYnXt|d�t||d�|��dS�NrYr\)r)rZr	rO)r�	new_focusr
rrrrTps

z!FocusTrackingMixin._focus_changed)r?r@rArErYr\rTrIrrrGrrR_srRc@seZdZdS)�FocusTrackingPileN�r?r@rArrrrr`{sr`c@seZdZdS)�FocusTrackingColumnsNrarrrrrbsrbcs@eZdZ�fdd�Zdd�Zdd�Zdd�Z�fd	d
�Z�ZS)�FocusTrackingListBoxcs&t�j||�|j�|j�d|_dS)NF)rDrErNrSrT�_in_set_focus_completerUrGrrrE�szFocusTrackingListBox.__init__cCs.|js*t|jd�t|j|d�|��dSr^)rdr	r)rNrO)rr_rrrrT�sz#FocusTrackingListBox._focus_changedcCst|jd�dSrXr]r%rrrrY�szFocusTrackingListBox.lost_focuscCst|jd�dSr[r]r%rrrr\�sz!FocusTrackingListBox.gained_focuscs&d|_zt��||�W5d|_XdSr
)rdrD�_set_focus_complete�rr5r)rGrrre�sz(FocusTrackingListBox._set_focus_complete)	r?r@rArErTrYr\rerIrrrGrrc�s
rccsdeZdZe�d�Ze�d�Ze�d�Ze�d�Zdd��fdd�
Z	d	d
�Z
dd�Zdd
d�Z�Z
S)�ScrollBarListBoxu▴u█� u▾F��
always_scrollcs`tdd|jfdd|jfdd|jfdd|jfdd|jfg�}t�|dd�|_||_t	��
|�dS)NZfixedr+�weight�	scrollbarzscrollbar focus)�Pile�top�bg�box�botrL�AttrMap�bar�_always_scrollrDrE)r�lbrjZpilerGrrrE�s




�zScrollBarListBox.__init__cCs |jr
dSt|j�||��dkS)NTr()rtr1�original_widget�ends_visiblerfrrr�_scroll�szScrollBarListBox._scrollcCs2|j}|�|d�s&|dd|df}|�||�S)NTrr+)rvrxr2)rr5r6rurrrr2�szScrollBarListBox.keypresscCs�|j}|�||�r|�||�S|\}}|�|d|f�\}}|�|d|f|�}d}	d}
}|j��\}}
|jD]6}|�|df�}||kr�d}	n|	s�||7}|
|7}
qpd|kr�d}n|||}d|kr�d}n|
||}|jj	j
}|||k�r|dd�}n
|d|�}|j}|dk�r&t�
|d	�}|j}|dk�rBt�
|d	�}||dd�f|j|d|�f|j|f|j|d|�f||dd�fg|jj	jdd�<|�|d|f|�}|j�d|f|�}t�||jd|df|dddfg�SdS)
Nr+FrTrn�bottomZgivenrkrl)rvrx�renderZget_focus_offset_insetrwrNrKr=rsrZoptionsrnrLrrrqrorprZ
CanvasJoinr0)rr5r)ruZmaxcolZmaxrow�offsetZinsetZvisibleZ
seen_focusZheightZheight_before_focusZfocus_widgetZ	focus_posZwidgetr=rnryrZboxoptZ	top_arrowZ	bot_arrowZ	lb_canvasZ
bar_canvasrrrrz�sX





�
�zScrollBarListBox.render)F)r?r@rArLZ	SolidFillrnrprorqrErxr2rzrIrrrGrrg�s



rgFricCsF|dkrg}|t|dd�kr(dkr6nn
t�|�}tt|�|d�S)NrKri)rrLrMrgrc)rNrjrrr�ListBox
s 
�r|z_wrapped_widget.base_widgetc@s<eZdZedd��Zedd��Zedd��Zedd��ZdS)�
OurWidgetWrapcCs
t|�jSr)�get_delegaterr%rrr�<lambda>!�zOurWidgetWrap.<lambda>cCs
t|�jSr)r~rr%rrrr#r�cCs
t|�jSr)r~rYr%rrrr$r�cCs
t|�jSr)r~r\r%rrrr%r�N)r?r@rA�propertyrrrYr\rrrrr}s��r})N)!�__doc__Zlogging�operatorrLZ	getLogger�logr	rr!Zcommand_mapZ_command�itemsr6ZcommandZACTIVATE�copyrBrmrZColumnsrCr|rJrRr`rbrcZWidgetDecorationrg�
attrgetterr~Z
WidgetWrapr}rrrr�<module>'s4

|Lh