
    jj5                   (   d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZ ddlmZmZmZmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZmZ ej<                  rd dlmZm Z  d dl!m"Z"m#Z# d dlm$Z$m%Z% dZ& ejN                  d      Z( ejN                  d      Z) G d de*      Z+ejX                   G d dejZ                               Z.ejX                   G d dejZ                               Z/ G d dej`                        Z1 G d dee(   e1      Z2 G d de1ee(         Z3 G d  d!e*      Z4 G d" d#ejj                        Z6 G d$ d%ejj                        Z7 G d& d'ejj                        Z8 G d( d)ejj                        Z9 G d* d+ee      Z:y),    )annotationsN)IterableSized)suppress)signals)CanvasCombineSolidCanvas   )SizingVAlign
WHSettingsnormalize_valign)WidgetContainerMixin)calculate_top_bottom_filler)MonitoredFocusListMonitoredList)Widgetnocache_widget_render_instance)CallableHashable)LiteralSelf)CanvasCompositeCanvas)
ListBoxListBoxError
ListWalkerListWalkerErrorSimpleFocusListWalkerSimpleListWalkerVisibleInfoVisibleInfoFillItemVisibleInfoMiddleVisibleInfoTopBottom_T_Kc                      e Zd Zy)r   N__name__
__module____qualname__     ]/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/listbox.pyr   r   >       r-   r   c                  0    e Zd ZdZddZddZd	dZd	dZy)
ScrollSupportingBodyzProtocol for ListWalkers.c                     y Nr,   selfs    r.   	get_focuszScrollSupportingBody.get_focusF       r-   c                     y r3   r,   r5   positions     r.   	set_focuszScrollSupportingBody.set_focusH   r7   r-   c                     y r3   r,   r9   s     r.   get_nextzScrollSupportingBody.get_nextJ   r7   r-   c                     y r3   r,   r9   s     r.   get_prevzScrollSupportingBody.get_prevL   r7   r-   N)returnztuple[Widget, _K])r:   r&   r@   None)r:   r&   r@   z%tuple[Widget, _K] | tuple[None, None])r)   r*   r+   __doc__r6   r;   r=   r?   r,   r-   r.   r1   r1   B   s    #12RRr-   r1   c                      e Zd ZdZddZy)EstimatedSizedzWidget can estimate it's size.

    PEP 424 defines API for memory-efficiency.
    For the ListBox it's a sign of the limited body length.
    The main use-case is lazy-load, where real length calculation is expensive.
    c                     y r3   r,   r4   s    r.   __length_hint__zEstimatedSized.__length_hint__X   r7   r-   N)r@   int)r)   r*   r+   rB   rF   r,   r-   r.   rD   rD   O   s     *r-   rD   c                  8    e Zd ZU dgZded<   d	dZd Zd Zd Zy)
r   modifiedztyping.ClassVar[list[str]]r   c                0    t        j                  | d       y )NrI   )r   emit_signalr4   s    r.   	_modifiedzListWalker._modified_   s    D*-r-   c                ^    	 | j                   }| |   |fS # t        t        t        f$ r Y yw xY w)z
        This default implementation relies on a focus attribute and a
        __getitem__() method defined in a subclass.

        Override and don't call this method if these are not defined.
        NN)focus
IndexErrorKeyError	TypeError)r5   rO   s     r.   r6   zListWalker.get_focusb   s8    	JJE;%%Hi0 		s    ,,c                ^    	 | j                  |      }| |   |fS # t        t        f$ r Y yw xY w)z
        This default implementation relies on a next_position() method and a
        __getitem__() method defined in a subclass.

        Override and don't call this method if these are not defined.
        rN   )next_positionrP   rQ   r9   s     r.   r=   zListWalker.get_nexto   =    	))(3H>8++H% 		    ,,c                ^    	 | j                  |      }| |   |fS # t        t        f$ r Y yw xY w)z
        This default implementation relies on a prev_position() method and a
        __getitem__() method defined in a subclass.

        Override and don't call this method if these are not defined.
        rN   )prev_positionrP   rQ   r9   s     r.   r?   zListWalker.get_prev|   rU   rV   Nr@   rA   )	r)   r*   r+   r   __annotations__rL   r6   r=   r?   r,   r-   r.   r   r   [   s#    +5,G'6.r-   r   )	metaclassc                  Z    e Zd Zd
ddZedd       ZddZddZddZddZ	ddZ
d
ddZy	)r    c                    t        |t              st        d|      t        j                  | |       d| _        || _        y)a  
        contents -- list to copy into this object

        wrap_around -- if true, jumps to beginning/end of list on move

        This class inherits :class:`MonitoredList` which means
        it can be treated as a list.

        Changes made to this object (when it is treated as a list) are
        detected automatically and will cause ListBox objects using
        this list walker to be updated.
        z2SimpleListWalker expecting list like object, got: r   N)
isinstancer   r   r   __init__rO   wrap_aroundr5   contentsr`   s      r.   r_   zSimpleListWalker.__init__   sB     (H-!$VW_Vb"cddtX.
&r-   c                    | S )z_
        Return self.

        Provides compatibility with old SimpleListWalker class.
        r,   r4   s    r.   rb   zSimpleListWalker.contents   s	     r-   c                    | j                   t        |       k\  rt        dt        |       dz
        | _         t        j	                  |        y )Nr   r
   )rO   lenmaxr   rL   r4   s    r.   rL   zSimpleListWalker._modified   s6    ::T"QD	A.DJT"r-   c                    t        d      )z
        This function inherited from MonitoredList is not implemented in SimpleListWalker.

        Use connect_signal(list_walker, "modified", ...) instead.
        9Use connect_signal(list_walker, "modified", ...) instead.NotImplementedErrorr5   callbacks     r.   set_modified_callbackz&SimpleListWalker.set_modified_callback   s     ""]^^r-   c                z    d|cxk  rt        |       k  sn t        d|       || _        | j                          y)Set focus position.r   zNo widget at position N)re   rP   rO   rL   r9   s     r.   r;   zSimpleListWalker.set_focus   s9     H(s4y(5hZ@AA
r-   c                T    t        |       dz
  |k  r| j                  ryt        |dz   S z3
        Return position after start_from.
        r
   r   re   r`   rP   r9   s     r.   rT   zSimpleListWalker.next_position   0     t9q=H$!|r-   c                V    |dk  r | j                   rt        |       dz
  S t        |dz
  S z4
        Return position before start_from.
        r   r
   r`   re   rP   r9   s     r.   rX   zSimpleListWalker.prev_position   2     q=4y1}$!|r-   c                `    |rt        t        |       dz
  dd      S t        t        |             S zI
        Optional method for returning an iterable of positions.
        r
   rangere   r5   reverses     r.   	positionszSimpleListWalker.positions   -     TQB//SYr-   NFrb   zIterable[_T]r`   boolr@   rA   r@   r   rY   )rl   zCallable[[], typing.Any]r@   typing.NoReturnr:   rG   r@   rA   r:   rG   r@   rG   r~   r   r@   zIterable[int])r)   r*   r+   r_   propertyrb   rL   rm   r;   rT   rX   r   r,   r-   r.   r    r       s:    '&  #
_ r-   r    c                  @    e Zd Zdd	dZd
dZddZddZddZdddZy)r   c                z    t        |t              st        d|      t        j                  | |       || _        y)a8  
        contents -- list to copy into this object

        wrap_around -- if true, jumps to beginning/end of list on move

        This class inherits :class:`MonitoredList` which means
        it can be treated as a list.

        Changes made to this object (when it is treated as a list) are
        detected automatically and will cause ListBox objects using
        this list walker to be updated.

        Also, items added or removed before the widget in focus with
        normal list methods will cause the focus to be updated
        intelligently.
        z6SimpleFocusListWalker expecting iterable object, got: N)r^   r   r   r   r_   r`   ra   s      r.   r_   zSimpleFocusListWalker.__init__   s;    " (H-!$Z[cZf"ghh##D(3&r-   c                    t        d      )z
        This function inherited from MonitoredList is not
        implemented in SimpleFocusListWalker.

        Use connect_signal(list_walker, "modified", ...) instead.
        rh   ri   rk   s     r.   rm   z+SimpleFocusListWalker.set_modified_callback   s     ""]^^r-   c                2    || _         | j                          y)ro   N)rO   rL   r9   s     r.   r;   zSimpleFocusListWalker.set_focus   s    
r-   c                T    t        |       dz
  |k  r| j                  ryt        |dz   S rq   rr   r9   s     r.   rT   z#SimpleFocusListWalker.next_position   rs   r-   c                V    |dk  r | j                   rt        |       dz
  S t        |dz
  S ru   rv   r9   s     r.   rX   z#SimpleFocusListWalker.prev_position	  rw   r-   c                `    |rt        t        |       dz
  dd      S t        t        |             S ry   r{   r}   s     r.   r   zSimpleFocusListWalker.positions  r   r-   Nr   r   )rl   z
typing.Anyr@   r   r   r   r   )	r)   r*   r+   r_   rm   r;   rT   rX   r   r,   r-   r.   r   r      s!    ',_
 r-   r   c                      e Zd Zy)r   Nr(   r,   r-   r.   r   r     r/   r-   r   c                  D    e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   y)r#   "Named tuple for ListBox internals.rG   offsetr   focus_widgetr   	focus_pos
focus_rowsz#tuple[int, int] | tuple[int] | NonecursorNr)   r*   r+   rB   rZ   r,   r-   r.   r#   r#      s!    ,KO//r-   r#   c                  0    e Zd ZU dZded<   ded<   ded<   y)	r"   r   r   widgetr   r:   rG   rowsNr   r,   r-   r.   r"   r"   *  s    ,N
Ir-   r"   c                  D    e Zd ZU dZded<   ded<   e	 	 	 	 	 	 dd       Zy)	r$   r   rG   trimzlist[VisibleInfoFillItem]fillc           	     H     | ||D cg c]
  }t        |  c}      S c c}w )zDConstruct from not typed data.

        Useful for overridden cases.)r   r   )r"   )clsr   r   items       r.   from_raw_dataz"VisibleInfoTopBottom.from_raw_data8  s%     4#P4$7$>#PQQ#Ps   
N)r   rG   r   z&Iterable[tuple[Widget, Hashable, int]]r@   r   )r)   r*   r+   rB   rZ   classmethodr   r,   r-   r.   r$   r$   2  sC    ,
I
##RR 5R 
	R Rr-   r$   c                  N    e Zd ZU ded<   ded<   ded<   e	 	 	 	 	 	 	 	 dd       Zy)	r!   r#   middler$   topbottomc                d     | t        | t        j                  | t        j                  |       S )zMConstruct from not typed data.

        Useful for overridden cases.
        )r   r   r   )r#   r$   r   )r   r   r   r   s       r.   r   zVisibleInfo.from_raw_dataI  s5     $f-$22C8'55v>
 	
r-   N)r   zFtuple[int, Widget, Hashable, int, tuple[int, int] | tuple[int] | None]r   2tuple[int, Iterable[tuple[Widget, Hashable, int]]]r   r   r@   r   )r)   r*   r+   rZ   r   r   r,   r-   r.   r!   r!   D  sN    	  
V
 @
 C	

 

 
r-   r!   c                  ^    e Zd ZdZdZ eej                  g      Zd/ fdZ	e
d0d       Zej                  d1d       Ze
d2d       Ze
d2d       Z	 d3	 	 	 	 	 d4dZd5d	Zd6d7d
Zd6d7dZd3d8dZd3d9dZd3d9dZ	 d3	 	 	 	 	 d:dZd;dZ	 	 d<dZd=d>dZd Ze
d?d       Zd Z e
eed      Zd Zd Ze
d        Z d Z!d@dZ"d@dZ#d@dZ$dAdZ%dBd Z&	 	 	 	 dC	 	 	 	 	 	 	 	 	 	 	 dDd!Z'dEd"Z(dBd#Z)	 	 	 	 	 	 dFd$Z*dBd%Z+dBd&Z,dGd'Z-dGd(Z.dGd)Z/dGd*Z0	 	 	 	 	 	 	 	 	 	 	 	 dHd+Z1d3dId,Z2d- Z3d. Z4 xZ5S )Jr   z,
    Vertically stacked list of widgets
    Tc                    t         |           t        |dd      r|| _        nt	        |      | _        | j                  | _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        y)z
        :param body: a ListWalker subclass such as :class:`SimpleFocusListWalker`
            that contains widgets to be displayed inside the list box
        :type body: ListWalker
        r6   Nr   r   r
   leftfirst selectable)r   r   )superr_   getattr_bodyr    bodyoffset_rowsinset_fractionpref_colset_focus_pendingset_focus_valign_pending_rows_max_cached_rendered_size)r5   r   	__class__s     r.   r_   zListBox.__init__c  s}     	4d+%)DJ)$/DJJJ	  %  "4 )-% !""r-   c                    | j                   S )z
        a ListWalker subclass such as :class:`SimpleFocusListWalker` that contains
        widgets to be displayed inside the list box
        )r   r4   s    r.   r   zListBox.body  s     zzr-   c                   t        t              5  t        j                  | j                  d| j
                         d d d        t        |dd       r|| _        nt        |      | _        	 t        j                  | j                  d| j
                         | j                          y # 1 sw Y   kxY w# t        $ r t        |       | _        Y 8w xY w)NrI   r6   )r   AttributeErrorr   disconnect_signalr   _invalidater   r    connect_signal	NameErrorr   render)r5   r   s     r.   r   zListBox.body  s    n% 	P%%djj*d>N>NO	P 4d+DJ)$/DJ	?""4::z4;K;KL 		P 	P  	? 9>DK		?s   ,B&*+B2 &B/2CCc                    t        | j                  t              r| j                  j                  S t	        | j                  j
                  j                   d      )Nz is not Sized)r^   r   r   __len__r   r   r)   r4   s    r.   r   zListBox.__len__  sC    djj%(::%%%

 4 4 = =>mLMMr-   c                     t         j                  t        t        f      r fdS t	         j                  j
                  j                   d      )Nc                 B    t        j                   j                        S r3   )operatorlength_hintr   r4   s   r.   <lambda>z)ListBox.__length_hint__.<locals>.<lambda>  s    8//

; r-   z4 is not Sized and do not implement "__length_hint__")r^   r   r   rD   r   r   r)   r4   s   `r.   rF   zListBox.__length_hint__  s@    djj5."9:;;

 4 4 = =>>rsttr-   c           	        |\  }}| j                   s| j                  r| j                  ||f|       | j                  j	                         \  }}|y|}| j                  ||f      \  }}	|r
||k\  r|dz
  }d}
|r0|j                         r |rt        |d      r|j                  |f      }
|
,|
\  }}||z   |	z
  }|dk  r|}	n||k\  r||z
  dz
  }|dk  r| d}}	|	}|j                  |fd      }|}|}g }|}|dkD  rn| j                  j                  |      \  }}|||z  }nH|}|j                  |f      }|r|j                  t        |||             ||kD  r||z
  }n||z  }|dkD  rnt        ||z   |	z
  |z
  d      }|}||z
  |z
  |	z   }g }|dkD  rl| j                  j                  |      \  }}|nK|j                  |f      }|r|j                  t        |||             ||kD  r||z
  }||z  }n||z  }|dkD  rlt        d|      }|dkD  r#|dkD  r||k  r||z  }||z  }d}n||z  }||z  }d}|}|dkD  ro| j                  j                  |      \  }}|nN|j                  |f      }|j                  t        |||             ||kD  r||z
  }||z  }n||z  }||z  }|dkD  rot        t!        ||	z
  ||||
      t#        ||      t#        ||            S )a  
        Returns the widgets that would be displayed in
        the ListBox given the current *size* and *focus*.

        see :meth:`Widget.render` for parameter details

        :returns: (*middle*, *top*, *bottom*) or (``None``, ``None``, ``None``)

        *middle*
            (*row offset*(when +ve) or *inset*(when -ve),
            *focus widget*, *focus position*, *focus rows*,
            *cursor coords* or ``None``)
        *top*
            (*# lines to trim off top*,
            list of (*widget*, *position*, *rows*) tuples above focus in order from bottom to top)
        *bottom*
            (*# lines to trim off bottom*,
            list of (*widget*, *position*, *rows*) tuples below focus in order from top to bottom)
        N)NNNr
   get_cursor_coordsr   T)r   r   _set_focus_completer   r6   get_focus_offset_inset
selectablehasattrr   r   r?   appendr"   rf   r=   r!   r#   r$   )r5   sizerO   maxcolmaxrowr   r   top_posr   
inset_rowsr   _cxcyeffective_cytrim_topr   pos
fill_lines
fill_aboveprevp_rowstrim_bottom
fill_belownext_posn_rowss                            r.   calculate_visiblezListBox.calculate_visible  s   0   !!T%B%B$$ff%5u= #'**"6"6"8i#"&"="=vv>N"OZkV+ 1*K l--/EglTg>h!33VI>FGC+j8La
'$rkAo?/:lAJ !&&y$7
  

1n

++C0ID#|z)GYYy)F!!"5dC"HI
"!J.& J 1n *{2Z?&H!L j(;6C

1n JJ//4MHc]]F9-F!!"5hV"LM
"$z1f$
& J 1n J'
>hlX%J&z)
h&
x'1n

++C0ID#|YYy)F1$VDE
"!J.z)& J6!K 1n kJ6iQ[]cd :6 j9
 	
r-   c                   ddl m} t        | j                  t              st        |  d      t        | j                  t        t        |f      st        |  d      t        | j                  dd      rt        d      y )Nr
   )
TreeWalkerz> body do not implement methods required for scrolling protocolz body is not a Sized, can not estimate it's size and not a TreeWalker.Scroll is not allowed due to risk of infinite cycle of widgets load.r`   FzABody is wrapped around. Scroll position calculation is undefined.)		treetoolsr   r^   r   r1   r   r   rD   r   )r5   r   s     r.   _check_support_scrollingz ListBox._check_support_scrolling5  s}    )$**&:;$'efgg$**unj&IJ& W X 
 4::}e4bcc 5r-   c                   | j                          | j                  sy||| _        | j                  | j                  |      \  }}}|j                  }| j                  d   }|j
                  r|j
                  d   j                  }n|j                  }| j                  j                  |      \  }	}|	6||	j                  |f      z  }| j                  j                  |      \  }	}|	6|S )zCurrent scrolling position.r   rz   )
r   r   r   r   r   r   r:   r   r?   r   )
r5   r   rO   midr   _bottom	start_rowr   r   r   s
             r.   get_scrollposzListBox.get_scrollposD  s    %%'zz"&D 2243F3FNS'HH	$$Q'88((2,''C--CJJ'',	cF9--I

++C0ID#  r-   c                ^   | j                          ||| _        |s| j                  s| j                  d   }d}| j                  j	                         \  }}|r||j                  |f|      z  }| j                  j                  |      \  }}|7||j                  |fd      z  }| j                  j                  |      \  }}|7| j                  j                  |      \  }	}|	7||	j                  |fd      z  }| j                  j                  |      \  }	}|	7|| _        | j                  S )zGScrollable protocol for sized iterable and not wrapped around contents.r   FT)	r   r   r   r   r6   r   r   r?   r=   )
r5   r   rO   colsr   	focused_widxr   r   next_s
             r.   rows_maxzListBox.rows_max_  s.   %%'"&Dt,,&&q)DD!YY002NIs	w66 JJ//4	c&DIItgu55D $

 3 3C 8ID# & "YY//4
s'EJJw55D!%!4!4S!9JE3 ' %)D!$$$r-   c                    t        | j                  t        t        f      xr( |d   dz  t	        j
                  | j                        k  S )z^Widget require relative scroll due to performance limitations of real lines count calculation.r
      )r^   r   r   rD   r   r   r   )r5   r   rO   s      r.   require_relative_scrollzListBox.require_relative_scroll|  s=    $**un&=>rDGaKRZRfRfgkgpgpRqDqrr-   c                `   | j                          | j                  sy| j                  ||      \  }}}|j                  r|j                  d   j                  }n| j
                  }d}| j                  j                  |      \  }}|&|dz  }| j                  j                  |      \  }}|&|S )Nr   rz   r
   )r   r   r   r   r:   focus_positionr   r?   )	r5   r   rO   _midr   r   	first_posover_widgets	            r.   get_first_visible_poszListBox.get_first_visible_pos  s    %%'zz!33D%@c788--I++I!YY//	:#AID!%!3!3I!>GY # r-   c                    | j                          | j                  sy| j                  ||      \  }}}dt        |j                        z   t        |j                        z   S )Nr
   )r   r   r   re   r   )r5   r   rO   r   r   r   s         r.   get_visible_amountzListBox.get_visible_amount  sR    %%'zz 224?c63sxx= 3v{{#333r-   c                b   |\  }}|| _         | j                  ||f|      \  }}}|t        d||      S |\  }}	}
}}|\  }}|\  }}g }d}|j                          |D ]l  \  }}}|j	                  |f      }||j                         k7  r(t        d|d|d|dd	|j                         dd
	      ||z  }|j                  ||df       n |	j	                  |f|      }|j                         |k7  r(t        d|	d|
d|dd	|j                         dd
	      |j                  }|||k7  rt        d|	d|
d|d|d
	      ||z  }|j                  ||
df       |D ]l  \  }}}|j	                  |f      }||j                         k7  r(t        d|d|d|dd	|j                         dd
	      ||z  }|j                  ||df       n t        |      }|r|j                  |       ||z  }|r|j                  |       ||z  }||kD  rt        d|d|d|d      ||k  r|dk7  rt        d|d|d|d|      |
}|r|d   d   }t        d |D              }| j                  j                  |      \  }}t        |du|du||vf      r|j                  |fd      rt        d|d|d|d|d|d      | j                  j                  |      \  }}||k(  rt        d|d| j                        |}t        |du|du||vf      r|j!                  d||z
         |S )zb
        Render ListBox and return canvas.

        see :meth:`Widget.render` for details
        rO   N r   zWidget z at position z within listbox calculated dz rows but rendered !FzFocus Widget z) within listbox calculated cursor coords z but rendered cursor coords Tz&Listbox contents too long!
Render top=z	, middle=z	, bottom=
z'Listbox contents too short!
Render top=z
Trim bottom=rz   r
   c              3  (   K   | ]
  \  }}}|  y wr3   r,   ).0_r   s      r.   	<genexpr>z!ListBox.render.<locals>.<genexpr>  s     *L91c13*Ls   z4
Not rendered not empty widgets available (first is z with position )zNext position after z3 is invalid (points to itself)
Looks like bug with )r   r   r	   r~   r   r   r   r   r   r   r   trim_end	frozensetr   r=   allpad_trim_top_bottom)r5   r   rO   r   r   r   r   r   _ignorer   r   r   r   r   r   r   r   combinelistr   r   w_posw_rowscanvasfocus_canvasc_cursorfinal_canvas
bottom_posrendered_positionsr   next_next_poss                                 r.   r   zListBox.render  s     ""44ff5EU4SV>sFF33?E<y*f"*"(Z68%/ 		7!FE6]]F9-F&"fZ}UI >117
 ;$$*KKM!#4A7 
 FNDu56		7 $**F9E*B*,/}YM J--7N ;  , 1 1 3A6a9 
  &&&H"4/}YM J;;A* E..6\<  	
L)T:;%/ 		7!FE6]]F9-F&"fZ}UI >117
 ;))/q(9< 
 FNDu56		7 %[1h'HD!!+.KD&=9#	&S\]c\ffhi  &=a"""%	&9VJ O##./3  #J'^A.
!**L*L!L#zz22:>FH$&D($66 ;;y%0&&&)WIfZy
 SNNTZWfgofrrsu  )-

(;(;H(E%},&.xl ;//3zzn>  )) $&D($66, ,,Q>r-   c                    |\  }}| j                  ||fd      \  }}}|y|\  }}}	}
}|sy|\  }}||z  }|dk  s||k\  ry||fS )zB
        See :meth:`Widget.get_cursor_coords` for details
        TNr   )r   )r5   r   r   r   r   _topr   offset_inset_ignore1_ignore2_ignore3r   xys                 r.   r   zListBox.get_cursor_coords  sv       $ 6 67G Ng>=C:h(F1	\q5AK1vr-   c                <    t        |t              \  }}||f| _        y)zSet the focus widget's display offset and inset.

        :param valign: one of: 'top', 'middle', 'bottom' ('relative', percentage 0=top 100=bottom)
        N)r   r   r   )r5   valignvtvas       r.   set_focus_valignzListBox.set_focus_valign)  s      "&,7B(*B%r-   c                    |dvrt        d|      | j                  j                         \  }}|t        d      |||f| _        | j                  j                  |       y)aT  
        Set the focus position and try to keep the old focus in view.

        :param position: a position compatible with :meth:`self._body.set_focus`
        :param coming_from: set to 'above' or 'below' if you know that
                            old position is above or below the new position.
        :type coming_from: str
        >   Nabovebelowzcoming_from value invalid: Nz!Can't set focus, ListBox is empty)r   r   r6   rP   r   r;   )r5   r:   coming_fromr   r   s        r.   r;   zListBox.set_focus4  sj     66!<[OLMM"&**"6"6"8i@AA!,lI!E

X&r-   c                n    t        j                  dt        d       | j                  j	                         S )z
        Return a `(focus widget, focus position)` tuple, for backwards
        compatibility. You may also use the new standard container
        properties :attr:`focus` and :attr:`focus_position` to read these values.
        zonly for backwards compatibility.You may also use the new standard container property `focus` to get the focus and property `focus_position` to read these values.API will be removed in version 5.0.   
stacklevel)warningswarnDeprecationWarningr   r6   r4   s    r.   r6   zListBox.get_focusF  s2     	2 	
 zz##%%r-   c                <    | j                   j                         d   S )z
        the child widget in focus or None when ListBox is empty.

        Return the widget in focus according to our :obj:`list walker <ListWalker>`.
        r   )r   r6   r4   s    r.   rO   zListBox.focusV  s     zz##%a((r-   c                Z    | j                   j                         \  }}|t        d      |S )z
        Return the list walker position of the widget in focus. The type
        of value returned depends on the :obj:`list walker <ListWalker>`.

        z#No focus_position, ListBox is empty)r   r6   rP   )r5   wr   s      r.   _get_focus_positionzListBox._get_focus_position_  s0     %%'39BCC
r-   a  
        the position of child widget in focus. The valid values for this
        position depend on the list walker in use.
        :exc:`IndexError` will be raised by reading this property when the
        ListBox is empty or setting this property to an invalid position.
        )docc                *      G  fdd      } |       S )Nc                  V    e Zd ZW  j                  ZW  j
                  Zd fdZddZy)*ListBox._contents.<locals>.ListBoxContentsc                X    d| j                   j                   ddt        |       ddS )N<z for z at 0xX>)r   r)   id)
inner_selfr5   s    r.   __repr__z3ListBox._contents.<locals>.ListBoxContents.__repr__~  s5    ://889thfRPZ^\]L^^_``r-   c                >    t        j                  dt        d       | S )Nz,ListBox.contents is a property, not a methodr   r-  )r/  r0  r1  )r?  s    r.   __call__z3ListBox._contents.<locals>.ListBoxContents.__call__  s    B& 
 "!r-   N)r@   strr   )r)   r*   r+   _contents__getitem____getitem__r   r@  rB  r4   s   r.   ListBoxContentsr9  w  s$     33KllGa"r-   rF  r,   )r5   rF  s   ` r.   	_contentszListBox._contentsu  s    	" 	"$   r-   c                p   t        | j                  d      r	 | j                  |   d fS | j                  j                         \  }}	 | j                  j                  |       | j                  j                         d   | j                  j                  |       S # t        t        f$ r-}t        d|      j	                  |j
                        |d }~ww xY w# t        t        f$ r-}t        d|      j	                  |j
                        |d }~ww xY w# | j                  j                  |       w xY w)NrE  z ListBox.contents key not found: r   )r   r   rP   rQ   with_traceback__traceback__r6   r;   )r5   keyexc_w	old_focuss        r.   rD  zListBox._contents__getitem__  s   4::}-v

3.. 

,,.I	,JJ  %::'')!, JJ  + ) v!A#IJYYZ]ZkZklruuv H% 	r=cWEFUUVYVgVghnqq	r JJ  +s;   B 7C C)(CCD((DDD D5c                "    | j                         S )a  
        An object that allows reading widgets from the ListBox's list
        walker as a `(widget, options)` tuple. `None` is currently the only
        value for options.

        .. warning::

            This object may not be used to set or iterate over contents.

            You must use the list walker stored as
            :attr:`.body` to perform manipulation and iteration, if supported.
        )rG  r4   s    r.   rb   zListBox.contents  s     ~~r-   c                     y)z
        There are currently no options for ListBox contents.

        Return None as a placeholder for future options.
        Nr,   r4   s    r.   optionszListBox.options  r7   r-   c           
        |\  }}| j                   \  }}d| _         d| _        | j                  j                         \  }}|y|j	                  |f|      }	t        |||t        j                  |	ddd      \  }
}| j                  ||f|
       y)zLFinish setting the offset and inset now that we have have a maxcol & maxrow.Nr   )	r   r   r   r6   r   r   r   GIVENshift_focus)r5   r   rO   r   r   r$  r%  r   
_focus_posr   rtop_rbots               r.   _set_focus_valign_completez"ListBox._set_focus_valign_complete  s    ..B(,%!%#'::#7#7#9 j  &E21	
e 	&&)40r-   c                b   |\  }}d| _         d| _        | j                  ||f|      \  }}}|y|\  }}	}
}}|\  }}|\  }}|	j                         ry|r|dd }||z   }|D ]L  \  }}}|j                         r1| j                  j                  |       | j                  ||f|        y||z  }N y)zXChoose the first visible, selectable widget below the current focus as the focus widget.Nr  rz   )r   r   r   r   r   r;   rT  )r5   r   rO   r   r   r   r   r   
row_offsetr   rU  r   _cursor	_trim_top_fill_abover   r   new_row_offsetr   r   r   s                        r.   _set_focus_first_selectablez#ListBox._set_focus_first_selectable  s    (,%!%"44ff5EU4SV>DJA
L*j'!$	;"(Z""$#CRJ#j0!+ 	#FC  "

$$S)  &&!1>Bd"N	#r-   c                n   |\  }}| j                          | j                  dk(  r| j                  ||f|      S | j                  | j	                  ||f|      S | j                  \  }}}d| _        | j
                  j                         \  }}	||	k(  ry| j
                  j                  |       | j                  ||f|      \  }
}}|
y|
\  }}}}}|\  }}|\  }}|}|D ](  \  }}}||z  }||	k(  s| j                  ||f||d        y ||z   }|D ](  \  }}}||	k(  r| j                  ||f||d        y||z  }* | j
                  j                  |	       | j
                  j                         \  }}	|j                  |f|      }|dk(  rd}n|dk(  r||z
  }n||z
  dz  }| j                  ||f|       y)z=Finish setting the position now that we have maxcol & maxrow.r   Nr)  r(  r   r,  )r   r   r_  r   rX  r   r6   r;   r   change_focusr   rT  )r5   r   rO   r   r   r*  _focus_widgetr   _new_focus_widgetr:   r   r   r   focus_offsetr   r[  r\  r   _trim_bottomr   r   r   r   r   r   s                            r.   r   zListBox._set_focus_complete  s   !!%7733VV4DeLL((422FF3CUKK040F0F-]I!% '+jj&:&:&<#8  	

Y'"44ff5EuMV>FLCmY
G #	:#) j", 	GS$dNFh!!66"2CI		 
*", 	GS$h!!66"2CIdNF		 	

X&:://1{{F9e,'!FG#d]Ftm)F&&)62r-   c                :   |\  }}|dk\  r&||k\  rt        d|d|d      || _        d| _        n[| j                  j	                         \  }}|j                  |fd      }||z   dk  rt        d|d|d      d| _        | |f| _        | j                          y)	a  
        Move the location of the current focus relative to the top.
        This is used internally by methods that know the widget's *size*.

        See also :meth:`.set_focus_valign`.

        :param size: see :meth:`Widget.render` for details
        :param offset_inset: either the number of rows between the
            top of the listbox and the start of the focus widget (+ve
            value) or the number of lines of the focus widget hidden off
            the top edge of the listbox (-ve value) or ``0`` if the top edge
            of the focus widget is aligned with the top edge of the
            listbox.
        :type offset_inset: int
        r   Invalid offset_inset: , only z rows in list boxr   T rows in target!N)r   r   r   r   r6   r   r   )r5   r   r  r   r   targetr  tgt_rowss           r.   rT  zListBox.shift_focus  s       1v%"%;L;K7SYR\\m#noo+D"(D"jj224OFG{{F9d3Hh&!+"%;L;K7S[R^^n#opp D$0=(";Dr-   c                   |\  }}| j                   j                         \  }}|yd}t        |d      r|j                  |f      }|3t        |d      r'|j	                  |f      }t        |t              r|\  }}||| _        yy)z+Update self.pref_col from the focus widget.Nget_pref_colr   )r   r6   r   rm  r   r^   tupler   )	r5   r   r   _maxrowr   _old_posr   coords_ys	            r.   update_pref_col_from_focusz"ListBox.update_pref_col_from_focus?  s     !:://1>6>***F95H0C D--vi8F&%(%"$DM  r-   c                    |\  }}|r|d   | _         n| j                  ||f       | j                          | j                  j	                  |       | j                  j                         \  }	}
|	j                  |fd      }||dz
  }d}||z
  }|dk(  r0|	j                         r ||kD  r|||z
  k\  r|}n|||z
  k\  r|}n||z  }|dk(  r0|	j                         r ||k  r|||z
  k\  r|}n|||z
  k\  r|}n||z  }|dk\  r|| _        d| _	        n+||z   dk  rt        d| d	| d
      d| _        | |f| _	        ||y| j                   f}t        |	d      syg }t        |      dk(  r3|\  }|dk(  rt        |      }nf|dk7  rt        d      t        |dd      }nH|\  }}|dk  s||k\  rt        d|d|      |dk(  rt        |dd      }n|dk(  rt        ||      }n|g}|D ]  }|	j                  |f||      s y y)a  
        Change the current focus widget.
        This is used internally by methods that know the widget's *size*.

        See also :meth:`.set_focus`.

        :param size: see :meth:`Widget.render` for details
        :param position: a position compatible with :meth:`self._body.set_focus`
        :param offset_inset: either the number of rows between the
            top of the listbox and the start of the focus widget (+ve
            value) or the number of lines of the focus widget hidden off
            the top edge of the listbox (-ve value) or 0 if the top edge
            of the focus widget is aligned with the top edge of the
            listbox (default if unspecified)
        :type offset_inset: int
        :param coming_from: either 'above', 'below' or unspecified `None`
        :type coming_from: str
        :param cursor_coords: (x, y) tuple indicating the desired
            column and row for the cursor, a (x,) tuple indicating only
            the column for the cursor, or unspecified
        :type cursor_coords: (int, int)
        :param snap_rows: the maximum number of extra rows to scroll
            when trying to "snap" a selectable focus into the view
        :type snap_rows: int
        r   TNr
   r(  r)  r   rg  rh  ri  move_cursor_to_coordszLmust specify coming_from ('above' or 'below') if cursor row is not specifiedrz   z;cursor_coords row outside valid range for target. pref_row:z target_rows:)r   rs  r   r   r;   r6   r   r   r   r   r   r   re   r|   
ValueErrorru  )r5   r   r:   r  r*  cursor_coords	snap_rowsr   r   rj  r  rk  	align_topalign_bottomattempt_rowsr   pref_rowrows                     r.   ra  zListBox.change_focusR  s   D   )!,DM++VV,<=

X&**..0;;y$/
I 	('!f&7&7&9l\>YL<77+lY66(	)'!f&7&7&9lY>VI44(l\99+	) 1+D"(Dh&!+"%;L>QYPZZj#kll D$0=(";D "!]],Mv67}" (KXg%$X')$%stt$Xr26 $1 Xx!|x83"QRZQ]]jksjvw  g%$Xr26'$Xx8 (z 	C++VIxE	r-   c                :   |\  }}| j                   j                         \  }}|j                  |fd      }| j                  }d}|dk(  rP| j                  \  }	}
|	dk  s
|
dk  s|	|
k\  rt        d| j                        ||	z  |
z  }|r||k\  rt        d      ||fS )z2Return (offset rows, inset rows) for focus widget.Tr   zInvalid inset_fraction: z*urwid inset_fraction error (please report))r   r6   r   r   r   r   )r5   r   r   ro  r   _posr   r   r   inumidens              r.   r   zListBox.get_focus_offset_inset  s     !ZZ113d!&&y$7
&&
!,,JD$ax4!8tt|"%=d>Q>Q=T#UVV#d*d2JjJ6"#OPPJ&&r-   c                l   |\  }}| j                   j                         \  }}|y|j                         syt        |d      sy|j	                  |f      }|y|\  }}| j                  ||f      \  }	}
||
k  r| j                  ||f|        y|	|
z
  |z   |k\  r| j                  ||f||z
  dz
         yy)z5Shift the focus widget so that its cursor is visible.Nr   r
   )r   r6   r   r   r   r   rT  )r5   r   r   r   r   r  r   r   r   r   r   s              r.   make_cursor_visiblezListBox.make_cursor_visible  s    !ZZ113d&&(|%89//	:>R"&"="=vv>N"OZ
?ff-u5#b(F2ff-v{Q? 3r-   c                   ddl m} |\  }}| j                  s| j                  r| j	                  ||fd       | j
                  j                         \  }}|S |j                         r)|j                  |f      | j                  ||f       ydfd}| j                     |j                  k(  r || j                  ||f            S | j                     |j                  k(  r || j                  ||f            S | j                     |j                  k(  r || j!                  ||f            S | j                     |j"                  k(  r || j%                  ||f            S | j                     |j&                  k(  r || j)                  ||f            S | j                     |j*                  k(  r || j-                  ||f            S S )a  Move selection through the list elements scrolling when
        necessary. Keystrokes are first passed to widget in focus
        in case that widget can handle them.

        Keystrokes handled by this widget are:
         'up'        up one line (or widget)
         'down'      down one line (or widget)
         'page up'   move cursor up one listbox length (or widget)
         'page down' move cursor down one listbox length (or widget)
        r   )CommandTr  Nc                    | rS y r3   r,   )	unhandledrK  s    r.   
actual_keyz$ListBox.keypress.<locals>.actual_key  s    
r-   )r@   
str | None)urwid.command_mapr  r   r   r   r   r6   r   keypressr  _command_mapUP_keypress_upDOWN_keypress_downPAGE_UP_keypress_page_up	PAGE_DOWN_keypress_page_downMAX_LEFT_keypress_max_left	MAX_RIGHT_keypress_max_right)	r5   r   rK  r  r   r   r   r  r  s	     `      r.   r  zListBox.keypress  s    	.!!T%B%B$$ff%5T$B!ZZ113dJ""$''	37C{((&&)9:	 S!WZZ/d//0@ABBS!W\\1d11662BCDDS!W__4d44ff5EFGGS!W%6%66d667GHIIS!W%5%55d55vv6FGHHS!W%6%66d667GHII
r-   c                    t        t        | j                  j                                     | _        | j                  t        j                         y r3   )nextiterr   r   r   r&  r   TOPr5   r   s     r.   r  zListBox._keypress_max_left,  s3    "4		(;(;(=#>?fjj)r-   c                    t        t        | j                  j                  d                  | _        | j                  t        j                         y )NTr~   )r  r  r   r   r   r&  r   BOTTOMr  s     r.   r  zListBox._keypress_max_right0  s8    "4		(;(;D(;(I#JKfmm,r-   c                ~   |\  }}| j                  ||fd      \  }}}|y|\  }}}	}
}|\  }}|}|	}d }|D ]6  \  }}}||z  }|s|j                         s | j                  ||f||d        y  |dz  }| j                          |dkD  rh| j                  j                  |      \  }}|y|j                  |fd      }||z  }|r'|j                         r| j                  ||f||d       y |dkD  rh|j                         r|dz   |k\  r.|| j                  ||f|       y | j                  ||f||d       y |n|\  }}||z   dz   |k\  r^|9| j                  j                  |      \  }}|y |j                  |fd      }||z  }| k\  r|dz
   }| j                  ||f||d       y | j                  ||f|dz          y )NTr)  r
   r   )r   r   ra  r   r   r?   r   rT  )r5   r   r   r   r   r   r   focus_row_offsetr   r   r  r   r\  r   rZ  r   r   r   _xr!  s                       r.   r  zListBox._keypress_up4  sC   #55vv6FMW>EKB,	7F #	:%
 !+ 	FC$J))+!!66"2CWM	 	a
1n**--c2KFC~;;y$/D$J))+!!66"2CWM 1n &&(,<q,@F,J ~  &&!1:>vv.ZI EB##a'61 >"&**"5"5c":KFC~#!;;y$7D$&J;$&#'!8J!!66"2CWM 	&&)+;a+?@r-   c                l   |\  }}| j                  ||fd      \  }}}|y|\  }}}	}
}|\  }}||
z   }|
}|	}d }|D ]5  \  }}}|r(|j                         r| j                  ||f||d        y ||z  }7 |dz  }| j                          ||k  rg| j                  j                  |      \  }}|y|j                  |f      }|r'|j                         r| j                  ||f||d       y ||z  }||k  rg|j                         r||
z   dz
  dk  r4|| j                  ||f||z
         y | j                  ||f|||z
  d       y |Y|\  }}||z   dz
  dk  rI|!| j                  j                  |      \  }}|y ||z  }||k\  r|dz
  }| j                  ||f||d       y | j                  ||f|dz
         y )NTr(  r
   r   )r   r   ra  r   r   r=   r   rT  )r5   r   r   r   r   r  r   r  r   r   r   r   re  r   rZ  r   r   r   r  r!  s                       r.   r  zListBox._keypress_down}  sO   #55vv6FMf>HNE,	:v#) j%
2
 !+ 	FC))+!!66"2CWM$J	 	a
6!**--c2KFC~;;y)D))+!!66"2CWM$J 6! &&(,<z,IA,MQR,R ~  &&!1:3DEvv.Z$5FP EB##a'!+ >"&**"5"5c":KFC~#$&J'!'!J!!V$	  	&&)+;a+?@r-   c                H   |\  }}| j                  ||fd      \  }}}|y|\  }}}	}
}|\  }}|}|j                         s|}n|	|\  }}| }n
|dk\  rd}n|}||z
  }||z   }d x}}|||	|
fg}|	}|D ]   \  }}}||z  }|j                  ||||f       " t        |      }|| kD  r^| j                  j                  |      \  }}|n=|j                  |f      }||z  }|dkD  r|dz  }|j                  ||||f       || kD  r^|d   \  }}}}|dkD  r$| }|D cg c]  \  }}}}||z   |||f }}}}}|d   \  }}}}||k\  r|d= |dz  }| j                  ||f       t        t        |t        |                  t        t        |dz
  dd            z   } g }!d}"| D ]#  }#||#   \  }}}}|j                         s|s"t        d|       }$||z   dk  r6| j                  ||f||dz
   d| j                  |dz
  f|| |dz
  z
  z
         n$| j                  ||f||d| j                  |$f|       |r%| j                  j                  |d   d         dk(  r	 | j                  ||fd      \  }}}|\  }%}&}'}(})|%||z   kD  r|!j                  |#       |%|k  r|!j                  |#       
|%dk  r|!j                  |#       d}"$ y  |"ry |r5|j                         r%| j                  j                  |d   d         dk(  r	 | D *cg c]	  }*|*|!vs|* }+}*|+| z   D ]H  }#||#   \  }}}}||	k(  r|s||z   dk  r|| |dz
  z
  z  }|dz
   }| j                  ||f||dd |        y  | j                  ||ft        |dz
  |             | j                  ||fd      \  }}}|\  }%}&}}'}(|%|k\  ry |sy |d   \  }&}'}}(| j                  j                  |      \  }}|y |j                  |fd      }| j                  ||f||dz
   d| j                  |dz
  fd       y c c}}}}w c c}*w )NTr   r
   rz   r)  rN   )r   r   r   re   r   r?   r   rs  listr|   rf   ra  r   rT  min),r5   r   r   r   r   r   r   rZ  r   r   r   r   r\  r   topmost_visiblescroll_from_rowr  r!  rx  tr   r   r   snap_region_startrM  _p_radjustror4  prsearch_orderbad_choicescut_off_selectable_chosenir|  act_row_offset_ign1_ign2_ign3_ign4jgood_choicess,                                               r.   r  zListBox._keypress_page_up  s   #55vv6FMW>BH?
L)Z #	: % &&(-OEB bO1_O-O $o5	 %v-
 -10/ ,	:>?!+ 	6FC$JHHj&#t45	6  FI:%**--c2KFC~;;y)D$JA~!Q&!HHj&#t45 I:% "#2
BB> [F=>??MRAq"v+q!Q'?A? "#1
BB!" 	''(89 E"3SV<=UK\_`K`bdfhEi@jj$%! 6	A,-aD)JT$$& 1zk*H j A%!!V$QhK]]D1H-:+$(!;< !!V$]]H- djj11*R.2CDT $(#9#966:JD#Q FC9?6NE5% 
Y 66""1%
*""1% !""1%,-)m6	r %,113

8K8KJWYN[\L]8^bn8n $0Ha1K3GHH, 	A,-aD)JTi j A%zkdQh77	#ax[
vv.Z$PYZ	" 	&&)3vz:+FG  $55vv6FMW390sE5Z' #$R5 uc5jj))#.>{{F9d+VQhK]]D1H%	
  @d Is   P
	PPc           
        |\  }}| j                  ||fd      \  }}}|y|\  }}}	}
}|\  }}||z
  }|j                         s|}n||\  }}|dz   }n
||
k\  r|
}n|}||z
  }| }d x}}|||	|
fg}|	}||
z  }|D ]   \  }}}|j                  ||||f       ||z  }" t        |      }|||z   k  r`| j                  j                  |      \  }}|n?|j                  |f      }|j                  ||||f       ||z  }||k  r|dz  }|||z   k  r`|d   \  }}}}||z   |k  r)|||z   z
  }|D cg c]  \  }}}}||z   |||f }}}}}|d   \  }}}}||z   dk  r|d= |dz  }| j                  ||f       t        t        |t        |                  t        t        |dz
  dd            z   }g } d}!|D ]  }"||"   \  }}}}|j                         s|s!t        ||z
  dz
  |dz
        }#||k\  r1| j                  ||f||dz
  d| j                  df||z   |z
  dz
         n$| j                  ||f||d| j                  |#f|       | j                  ||fd      \  }}}|\  }$}%}&}'}(|$||z
  k  r| j                  |"       |$|kD  r| j                  |"       |$|z   |kD  r| j                  |"       d}! y  |!ry |D )cg c]	  })|)| vs|) }*})|*|z   D ]F  }"||"   \  }}}}||	k(  r|s||k\  r|||z   |z
  dz
  z  }|dz
  }| j                  ||f||dd |        y  | j                  ||ft        d|
z
  |             | j                  ||fd      \  }}}|\  }$}%}}&}'|$|k  ry |sy |d   \  }%}&}}'| j                  j                  |      \  }}|y |j                  |fd      }| j                  ||f||dz
  d| j                  dfd       y c c}}}}w c c})w )NTr
   rz   r   r(  )r   r   r   re   r   r=   r   rs  r  r|   r  ra  r   rT  rf   )+r5   r   r   r   r   r  r   rZ  r   r   r   r   re  r   bottom_edger  r  r!  rx  r  r   r   r   r  rM  r  r  r  r4  r  r  r  r  r  r  r|  r  r  r  r  r  r  r  s+                                              r.   r  zListBox._keypress_page_down  sq   #55vv6FMf>BH?
L)Z#) j z) &&()OEB!eOJ&(O)O  /1	 &%
 )-,+ ,	:>?j 
!+ 	FCHHj&#t45$J	  F6I--**--c2KFC~;;y)DHHj&#t45$JF"!Q&! 6I-- $%R5 
BDv%zD01F=>??MRAq"v+q!Q'?A? $%Q4 
BD!!" 	''(89 E"3SV<=UK\_`K`bdfhEi@jj$%! 2	A,-aD)JT$$& 6J.2D1H=H V#!!V$QJ]]A&&3a7 !!V$]]H- $(#9#966:JD#Q FD&9?6NE5% 
Y 66""1%
*""1% $v-""1%,-)e2	j % $0Ha1K3GHH, 	A,-aD)JTi V#Y/*<q@@	#aZ
vv.Z$PYZ	" 	&&)3q:~z+JK  $55vv6FMf390sE5Z' #$R5 uc5jj))#.>{{F9d+VQJ]]A	
 o @T Is   0O

<	OOc                   ddl m} |\  }}	| j                  ||	fd      \  }
}}|
y|
\  }}}}}|\  }}|\  }}|j                          g ||||f|}| }|D ]  \  }}}||z   |kD  r n||z  } y|xr ||k(  } ||      r*|dk(  r%|j	                         r| j                  ||	f||       t        |d      sKt        j                  |j                  j                   d|j                  j                   d	t        d
       y|j                  |f|||||z
  |      ry ||      r2|dk(  r| j                  ||	f       S |dk(  r| j                  ||	f       S y)zf
        Pass the event to the contained widgets.
        May change focus on button 1 press.
        r   )is_mouse_pressTr  Fr
   mouse_event.z is not subclass of Widgetr,  r-        )
urwid.utilr  r   r~   r   ra  r   r/  r0  r   r*   r)   r1  r  r  r  )r5   r   eventbuttoncolr}  rO   r  r   r   r   r   r   r  r   r   r   r[  r   r   r   w_listwrowr4  r  r  s                             r.   r  zListBox.mouse_eventD  s    	."44ff5ET4RV>@F=y*g"*$R:RiDRzRy & 	Auff}s"FND	
 +!|+% Vq[Q\\^vv.t<q-(MM;;))*!AKK,@,@+AA[\"
 ==&E63d
EJ% {,,ff-=>>>{../?@@@r-   c                   |\  }}g }| j                  ||f|      \  }}}|ddgS |\  }	}
|\  }}|dk(  rQ|\  }}}}}||z  }|D ]  \  }}}||z  } ||k  s| j                  j                  |      dk(  r|j                  d       |	dk(  rH|\  }}}}}|
D ]  \  }}}||z  } | j                  j	                  |      dk(  r|j                  dd       |S )a+  
        Return a list that may contain ``'top'`` and/or ``'bottom'``.

        i.e. this function will return one of: [], [``'top'``],
        [``'bottom'``] or [``'top'``, ``'bottom'``].

        convenience function for checking whether the top and bottom
        of the list are visible
        r  r   r   r   rN   )r   r   r=   r   r?   insert)r5   r   rO   r   r   resultr   r   r   r   r(  r   r)  rZ  rM  r   r   _c_rowss                      r.   ends_visiblezListBox.ends_visible  s"     "44ff5EU4SV>8$$%#U!,2)JCr$J!& #Cd"
#F"tzz':':3'?<'Oh'q=-3*JC!& #Cd"
#zz""3'<7a'r-   c              #  D  K   t        | j                  dd      x}r |       E d{    y| j                  j                         \  }}|y|}	 | | j                  j                  |      \  }}|sn&|}	 | j                  j	                  |      \  }}|sy| &7 ww)a=  
        Return an iterator over the positions in this ListBox.

        If self._body does not implement positions() then iterate
        from the focus widget down to the bottom, then from above
        the focus up to the top.  This is the best we can do with
        a minimal list walker implementation.
        r   N)r   r   r6   r=   r?   r5   positions_fnr   r   r   r4  s         r.   __iter__zListBox.__iter__  s      #4::{DAA<A#~%%"&**"6"6"8iIZZ((-FAs	 
 ZZ((-FAsI	  &s   $B BA8B c              #  H  K   t        | j                  dd      x}r |d      E d{    y| j                  j                         \  }}|y|}	 | j                  j                  |      \  }}|sn| &|}	 | | j                  j	                  |      \  }}|sy&7 ww)a  
        Return a reversed iterator over the positions in this ListBox.

        If :attr:`body` does not implement :meth:`positions` then iterate
        from above the focus widget up to the top, then from the focus
        widget down to the bottom.  Note that this is not actually the
        reverse of what `__iter__()` produces, but this is the best we can
        do with a minimal list walker implementation.
        r   NTr  )r   r   r6   r?   r=   r  s         r.   __reversed__zListBox.__reversed__  s      #4::{DAA<A#D111"&**"6"6"8iZZ((-FAsI	 
 IZZ((-FAs	  2s   &B"B A8B")r   zListWalker | Iterable[Widget]r@   rA   )r@   r   )r   zIterable[Widget] | ListWalkerr@   rA   )r@   zCallable[[], int]r   )r   tuple[int, int]rO   r   r@   z%VisibleInfo | tuple[None, None, None]rY   )NF)r   tuple[int, int] | NonerO   r   r@   rG   )r   r  rO   r   r@   r   )r   r  rO   r   r@   rG   )r   r  rO   r   r@   zCompositeCanvas | SolidCanvas)r   r  r@   r  )r#  zbLiteral['top', 'middle', 'bottom'] | VAlign | tuple[Literal['relative', WHSettings.RELATIVE], int]r3   )r*   Literal['above', 'below'] | Noner@   rA   )r@   zWidget | None)r   r  rO   r   r@   rA   )r   r  r  rG   r@   rA   )r   r  r@   rA   )r   NNN)r   r  r  rG   r*  r  rw  r  rx  z
int | Noner@   rA   )r   r  r@   r  )r   r  rK  rC  r@   r  )r   r  r@   bool | None)r   r  r  rG   r  rG   r}  rG   rO   r   r@   r  )r   r  rO   r   r@   zlist[Literal['top', 'bottom']])6r)   r*   r+   rB   _selectabler  r   BOX_sizingr_   r   r   setterr   rF   r   r   r   r   r   r   r   r   r   r&  r;   r6   rO   r5  r   rG  rD  rb   rQ  rX  r_  r   rT  rs  ra  r   r  r  r  r  r  r  r  r  r  r  r  r  __classcell__)r   s   @r.   r   r   [  st    K%G"#H   
[[ $ N N
 u u E
E
 E
 
/	E
Nd6%:s(4 vv v 
'	vp(	/r	/'$&  ) )	 	N!,,$    12#46p@%. 8<04 $uu 	u
 6u .u u 
un' 288 8 
	8t*-GRM^~@vp99 	9
 9 9 9 
9v!F<r-   r   );
__future__r   r   typingr/  collections.abcr   r   
contextlibr   urwidr   urwid.canvasr   r	   	constantsr   r   r   r   	containerr   fillerr   monitored_listr   r   r   r   r   TYPE_CHECKINGr   r   typing_extensionsr   r   r   r   __all__TypeVarr%   r&   	Exceptionr   runtime_checkableProtocolr1   rD   MetaSignalsr   r    r   r   
NamedTupler#   r"   r$   r!   r   r,   r-   r.   <module>r     sj  * #    +   3 C C + / = :	2/4 V^^DV^^D	i 	 	S6?? 	S 	S *V__ * *,7.. ,^M }R(* M `? J(:2(> ? D	9 	0)) 0&++ R6,, R$
&## 
.Bf* Br-   