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__/stretchy.cpython-38.pyc
U

K��^b�@sFdZddlZddlmZmZGdd�dejd�ZGdd�dej�ZdS)	aCustom overlay that only takes the space it needs but can still scroll.

There are a couple of dialogs in subiquity that basically have the form:

 +------ dialog title --------+
 |                            |
 | potentially quite long     |
 | block of text that might   |
 | take several lines and so  |
 | need to be scrollable      |
 |                            |
 |  maybe another widget      |
 |                            |
 |       [ OK     ]           |
 |       [ Cancel ]           |
 |                            |
 +----------------------------+

The way urwid works makes doing this nicely hard.  Simply putting the
text in a ListBox "works" but because the listbox is a box widget we
can't let it choose its height: either we'll end up having the text
scrollable in some situations where there is enough space on the
screen to show it all or when the screen is large there will be a
massive ugly space between the text and the following widgets.

Because you can't make a widget that behaves the way we want, this
module gives a way of providing a list of widgets to display in a Pile
and and nominating one of them to be made scrollable. A title, a list
of widgets and index to be scrollable is bundled up into an object
called a "stretchy" but is a bad name but at least easily greppable.
�N)�ListBox�Pilec@s@eZdZddgZdd�Zdd�Zdd�Zed	d
��Zdd�Z	d
S)�Stretchy�opened�closedcCs||_||_||_||_dS)z�
        title: goes in the LineBox
        widgets: list of widgets to put in the pile
        stretchy_index: index into widgets of widget to wrap in ListBox
        focus_index: index into widgets of initial focus
        N)�title�widgets�stretchy_index�focus_index)�selfrrr	r
�r�1/usr/share/subiquity/subiquitycore/ui/stretchy.py�__init__9szStretchy.__init__cCsdS)z1Called when the stretchy is placed on the screen.Nr�rrrr
rEszStretchy.openedcCsdS)z4Called when the stretchy is removed from the screen.Nrrrrr
rIszStretchy.closedcCs|j|jS�N)rr	rrrr
�
stretchy_wLszStretchy.stretchy_wcs0t�|d�fdd��t�|d�fdd��dS)Nrcs
��d�S)Nr)Zenterr��contextrr
�<lambda>Q�z)Stretchy.attach_context.<locals>.<lambda>rcs
��d�S)Nr)�exitrrrr
rRr)�urwidZconnect_signal)rrrrr
�attach_contextPszStretchy.attach_contextN)
�__name__�
__module__�__qualname__Zsignalsrrr�propertyrrrrrr
r5s
r)�	metaclassc@sHeZdZdZeejg�Zdd�Zdd�Z	e
dd��Zdd	�Zd
d�Z
dS)
�StretchyOverlayTc	s�|�_��_t�jg��_��fdd��t�fdd�t�j�D��}�j|_	t
jt
jt
j
t
jt
j|ddd�dddd	��jd
�ddd�dddd	��_dS)Ncs"|�jkrdd�jfSd|fSdS)NZweight��pack)r	�listbox)�i�w)r�stretchyrr
�entry^s
z'StretchyOverlay.__init__.<locals>.entrycsg|]\}}�||��qSrr)�.0r"r#)r%rr
�
<listcomp>esz,StretchyOverlay.__init__.<locals>.<listcomp>�)�left�rightr)�relative�d)�topZbottomZheight)r�)�bottom_wr$rrr!r�	enumeraterr
Zfocus_positionrZFillerZPaddingZLineBoxr�top_w)rr/r$Z
inner_piler)r%rr$r
rYs<�����	�zStretchyOverlay.__init__c
Cs�|\}}t|d�}|d}d}t|jj�D]T\}}	||jjkr@q*tj|	��krf|	�|f|�}
||
7}q*|	�	d|�}||d7}q*||kr�||dfdfS|jj
�|f|�}|||kr�|||fdfS||dfdfSdS)N�P��rrFT)�minr0r$rr	rZFLOWZsizing�rowsr r)
r�size�focusZmaxcolZmaxrowZoutercolZinnercolZ
fixed_rowsr"Zwidgetr6Zw_sizeZstretchy_ideal_rowsrrr
�	_top_sizeus$

zStretchyOverlay._top_sizecCs|jSr)r1rrrr
r8�szStretchyOverlay.focuscCs4|�|d�\}}|p|jj��|jj_|j�||�S)NT)	r9r$rZ
selectabler!Zbase_widget�_selectabler1�keypress)rr7�key�top_sizeZscrollbar_visiblerrr
r;�s�zStretchyOverlay.keypressc	Cs�|j�|d�}|��r|��s(t�|�S|�||�\}}|j�||�}t�|�}|d|dd}|d|dd}t�||||�S)NFrr(r)	r/�renderZcolsr6rZCompositeCanvasr9r1Z
CanvasOverlay)	rr7r8Zbottom_cr=�_Ztop_cr)r-rrr
r>�s

zStretchyOverlay.renderN)rrrr:�	frozensetrZBOXZ_sizingrr9rr8r;r>rrrr
rUs!
r)	�__doc__rZsubiquitycore.ui.containerrrZMetaSignalsrZWidgetrrrrr
�<module>s!