Mini Shell

Direktori : /usr/lib/python3.6/site-packages/simpleline/render/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/simpleline/render/__pycache__/widgets.cpython-36.pyc

3

<�Zcc9�@s�ddlZddlmZddlmZddlmZddddd	d
dgZGdd�de�Z	Gd
d�de	�Z
Gdd�de
�ZGdd�de	�ZGdd�de	�Z
Gdd
�d
e	�ZGdd	�d	e	�ZdS)�N)�wrap)�_)�
ensure_str�Widget�
TextWidget�SeparatorWidget�EntryWidget�ColumnWidget�CheckboxWidget�CenterWidgetc@s�eZdZddd�Zedd��Zedd��Zdd	�Zed
d��Zdd
�Z	dd�Z
dd�Zedd��Zdd�Z
ddd�Zddd�Zdd�ZdS) rNcCs0g|_|r dd�|jd�D�|_||_d|_dS)adInitializes base Widgets buffer.

        This class can be subclassed to create customized widgets.

        :param max_width: serves as a hint about screen size to write method with default arguments
        :type max_width: int

        :param default: string containing the default content to fill the buffer with
        :type default: string
        cSsg|]}dd�|D��qS)cSsg|]}|�qS�r)�.0�crr�/usr/lib/python3.6/widgets.py�
<listcomp>/sz.Widget.__init__.<locals>.<listcomp>.<listcomp>r)r
�lrrrr/sz#Widget.__init__.<locals>.<listcomp>�
rN)rr)�_buffer�split�
_max_width�_cursor)�selfZ	max_width�defaultrrr�__init__"s
zWidget.__init__cCs
t|j�S)z*The current height of the internal buffer.)�lenr)rrrr�height3sz
Widget.heightcCstjdd�|jd�S)zHThe current width of the internal buffer (id of the first empty column).cSst|t|��S)N)�maxr)Zaccrrrr�<lambda>;szWidget.width.<locals>.<lambda>r)�	functools�reducer)rrrr�width8szWidget.widthcCst�|_d|_dS)z-Clears this widgets buffer and resets cursor.rN)rr)�listrr)rrrr�clear=szWidget.clearcCs|jS)zDReturn a list (rows) of lists (columns) with one character elements.)r)rrrr�contentBszWidget.contentcCs|j�dS)aRedraw the widget's self._buffer.

        :param width: the width of buffer requested by the caller
        :type width: int

        Commonly, call render of child widgets and then draw and write
        methods to copy their contents to self._buffer.
        N)r")rr rrr�renderGs	z
Widget.rendercCsdd�|jD�S)z�Return lines to write out in order to show this widget.

        :return: lines representing this widget
        :rtype: list(str)
        cSsg|]}tdj|���qS)�)�str�join)r
�linerrrrXsz$Widget.get_lines.<locals>.<listcomp>)r)rrrr�	get_linesRszWidget.get_linescCs||f|_dS)z�Set cursor position.

        :param row: row id, starts with 0 at the top of the screen
        :type row: int

        :param col: column id, starts with 0 on the left side of the screen
        :type col: int
        N)r)r�row�colrrr�set_cursor_positionZs	zWidget.set_cursor_positioncCs|jS)N)r)rrrr�cursoresz
Widget.cursorcCs|jdf|_dS)z6Set the cursor to first column in new line at the end.rN)rr)rrrr�set_endiszWidget.set_endFc	Cs|dkr|jd}|dkr$|jd}|j||jkr`x*t||j|j�D]}|jjt��qJWx�t|||j�D]z}t|j|�}t|j||�}|||kr�|j||||td�7<|j||dd�|j||||�<qrW|�r||j|f|_n||jdf|_dS)a�Copy w widget's content to this widget's buffer at row, col position.

        :param w: widget to take content from
        :type w: class Widget

        :param row: row number to start at (default is at the cursor position)
        :type row: int

        :param col: column number to start at (default is at the cursor position)
        :type col: int

        :param block: when printing newline, start at column col (True) or at column 0 (False)
        :type block: boolean
        Nr�� )rr�ranger�appendr!rr#)	r�wr*r+�block�_irZl_lenZw_lenrrr�drawms 

",zWidget.drawcCs^|sdSt|�}|dkr"|jd}|dkr4|jd}|dkrL|jrL|j|}|}|}|rd|j||�}x�|D]�}	|	dkr�|d7}|r�|}qjd}qj|t|j�kr�x,t|t|j�d�D]}
|jjt��q�W|t|j|�k�r
|j||t|j|�dtd�7<|	|j||<|d7}|dk	rj|||krj|d7}|�rH|}qjd}qjW||f|_dS)a�Emulate the typing machine writing to this widget's buffer.

        :param text: text to type
        :type text: str

        :param row: row number to start at (default is at the cursor position)
        :type row: int

        :param col: column number to start at (default is at the cursor position)
        :type col: int

        :param width: wrap at "col" + "width" column (default is at self._max_width)
        :type width: int

        :param block: when printing newline, start at column col (True) or at column 0 (False)
        :type block: boolean

        :param wordwrap: wrap by words
        :type wordwrap: boolean
        Nrr/rr0)	rrr�_wrap_wordsrrr1r2r!)r�textr*r+r r4�wordwrap�x�y�	characterr5rrr�write�sB



,zWidget.writecCs�g}xr|jd�D]d}g}x2t||�D]$}|j|�t|�|kr$|jd�q$W|rd|ddkrd|j�|jdj|��qWdj|�S)Nrr/r%���)rrr2r�popr')rr8r �linesr(ZsublinesZsublinerrrr7�s
zWidget._wrap_words)NN)NNF)NNNFF)�__name__�
__module__�__qualname__r�propertyrr r"r#r$r)r,r-r.r6r=r7rrrrr s

*
Jcs8eZdZdZ�fdd�Zedd��Z�fdd�Z�ZS)rz$Class to handle wrapped text output.cst�j�||_dS)zE
        :param text: text to format
        :type text: str
        N)�superr�_text)rr8)�	__class__rrr�s
zTextWidget.__init__cCs|jS)zContains text of this widget.)rF)rrrrr8szTextWidget.textcs"t�j|�|j|j|dd�dS)z�Renders the text widget limited to width number of columns.

        Wraps to the next line when the text is longer.

        :param width: maximum width allocated to the string
        :type width: int
        T)r r9N)rEr$r=rF)rr )rGrrr$szTextWidget.render)	rArBrC�__doc__rrDr8r$�
__classcell__rr)rGrr�scs*eZdZdZd�fdd�	Zdd�Z�ZS)rz�This is the easy way how to generate entry items for containers.

    If the numbering in a container is turned on the output looks like:

    N) title
       value

    Without numbering turned on:

    title
    value
    Ncs|j||d�}t�j|�dS)z� Create Entry widget instance.

        :param title: Title of this entry.
        :type title: String.

        :param value: Actual value printed in second line below the title.
        :type value: String.
        )�title�valueN)�_create_textrEr)rrJrKr8)rGrrrs	zEntryWidget.__init__cCs|}|r|d7}||7}|S)Nrr)rrJrK�msgrrrrL+s
zEntryWidget._create_text)N)rArBrCrHrrLrIrr)rGrrscs8eZdZdZd�fdd�	Z�fdd�Zdd	d
�Z�ZS)
rzPrint empty line.r/cst�j�||_dS)z�Construct SeparatorWidget for printing blank lines.

        :param lines: How many lines should be blank.
        :type lines: int greater than 0.
        N)rEr�_lines)rr@)rGrrr8s
zSeparatorWidget.__init__cst�j|�|jd�dS)zRender empty line to the buffer.

        :param width: maximum width allocated to the string
        :type width: int
        r%N)rEr$r=)rr )rGrrr$AszSeparatorWidget.renderNFcCsLx4td|j�D]$}|jjt��|j|d7<qW|j|jdd�dS)zcOptimize write function.

        To print just a blank line we don't need too much logic.
        rr%r/N)r1rNrr2r!r,)rr8r*r+r r4r9�irrrr=JszSeparatorWidget.write)r/)NNNFF)rArBrCrHrr$r=rIrr)rGrr5s		cs,eZdZdZ�fdd�Z�fdd�Z�ZS)rz0Class to handle horizontal centering of content.cst�j�||_dS)zD
        :param w: widget to center
        :type w: Widget
        N)rEr�_w)rr3)rGrrrXs
zCenterWidget.__init__cs8t�j|�|jj|�|j|j||jjdd�dS)z�Render the centered widget to internal buffer.

        :param width: maximum width the widget should use
        :type width: int
        �)r+N)rEr$rPr6r )rr )rGrrr$`szCenterWidget.render)rArBrCrHrr$rIrr)rGrrUscsReZdZdZd�fdd�	Z�fdd�Zedd	��Zed
d��Zedd
��Z	�Z
S)r
zCWidget to show checkbox with (un)checked box, name and description.r:Ncs&t�j�||_||_||_||_dS)ar
        :param key: tick character to be used inside [ ]
        :type key: character

        :param title: the title next to the [ ] box
        :type title: str

        :param text: the description text to be shown on the second row in ()
        :type text: str

        :param completed: is the checkbox ticked or not?
        :type completed: True|False
        N)rEr�_key�_titlerF�
_completed)r�keyrJr8�	completed)rGrrros

zCheckboxWidget.__init__cs�t�j|�|jr|j}nd}td|�}g}|jrH|jtt|j���|jrb|jtd|j��t	d|gf|d|fgd�}|j|�|j
|�dS)z_Render the widget to internal buffer.

        It should be max width characters wide.
        r0z[%s]z(%s)��r/N)rEr$rVrRrrJr2rr8r	r6)rr Z	checkcharZcheckbox�dataZcols)rGrrr$�s
zCheckboxWidget.rendercCs|jS)z4Returns the first line (main title) of the checkbox.)rS)rrrrrJ�szCheckboxWidget.titlecCs|jS)z3Returns the state of the checkbox, checked is True.)rT)rrrrrV�szCheckboxWidget.completedcCs|jS)z3Contains the description text from the second line.)rF)rrrrr8�szCheckboxWidget.text)r:NNN)rArBrCrHrr$rDrJrVr8rIrr)rGrr
ls!cs*eZdZd�fdd�	Z�fdd�Z�ZS)r	rcst�j�||_||_dS)aRCreate text columns

        Deprecated. Please do not use this widget, use containers instead.

        :param columns: list containing (column width, [list of widgets to put into this column])
        :type columns: [(int, [...]), ...]

        :param spacing: number of spaces to use between columns
        :type spacing: int
        N)rEr�_spacing�_columns)r�columnsZspacing)rGrrr�s
zColumnWidget.__init__cs�t�j|�d}xz|jD]p\}}|jd|�|dkrH||jd}d}n|}x$|D]}|j|�|j|dd�qRWt|||j�|j}qWdS)z�Render the widget to it's internal buffer

        :param width: the maximum width the widget can use
        :type width: int

        :return: nothing
        rNr/T)r4)	rEr$r[r,r-r6rr rZ)rr Zcol_posZ	col_widthr+Z
col_max_width�item)rGrrr$�s

zColumnWidget.render)r)rArBrCrr$rIrr)rGrr	�s)r�textwraprZsimpleline.utils.i18nrZsimpleline.utilsr�__all__�objectrrrrrr
r	rrrr�<module>s
V$ H