Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
edit.cpython-313.pyc359 linesDownload Raw Back to __pycache__
1�

2��j\���SSKJr SSKrSSKrSSKJr SSKJr SSKJ	r	 SSK3Jr SSKJ
r
JrJr SSKJr S	S4KJrJrJr S	SKJrJr \R2(aSSKJr SS
KJr SSKJr "SS\5r"SS\5r "SS\ 5r!g)�)�annotationsN)�text_layout)�CompositeCanvas)�Command)�remove_defaults)�is_wide_char�move_next_char�move_prev_char)�decompose_tagmarkup�)�Align�Sizing�WrapMode)�Text�	TextError)�Hashable)�Literal)�5TextCanvasc��\rSrSrSrg)�	EditError��N)�__name__�6__module__�__qualname__�__firstlineno__�__static_attributes__r��WD:\code\apps\devtools\python\user_packages\Python313\site-packages\urwid/widget/edit.pyrrs��rrc	�X^�\rSrSr%Sr\"\R/5rSr	Sr7SS/rS\S'S(S	jr
S8S9S\R\R"SSSS4	S)U4SjjjrS*U4S
jjrS+U4SjjrS,SjrS-SjrS.SjrS/Sjr\S0Sj5rS1Sjr\"S\SS9rS2SjrS3SjrS0Sjr\"\\SS9r S3Sjr!S4Sjr"S5Sjr#S6Sjr$S7S jr%S8S!jr&S9S"jr'S:S;U4S#jjjr(S<S=U4S$jjjr)S>S%jr*S?S&jr+S'r,U=r-$)@�Edit�a�10Text editing widget implements cursor movement, text insertion and11deletion.  A caption may prefix the editing area.  Uses text class12for text layout.13 14Users of this class may listen for ``"change"`` or ``"postchange"``15events.  See :func:``connect_signal``.16 17* ``"change"`` is sent just before the value of edit_text changes.18  It receives the new text as an argument.  Note that ``"change"`` cannot19  change the text in question as edit_text changes the text afterwards.20* ``"postchange"`` is sent after the value of edit_text changes.21  It receives the old value of the text as an argument and thus is22  appropriate for changing the text.  It is possible for a ``"postchange"``23  event handler to get into a loop of changing the text and then being24  called when the event is re-emitted.  It is up to the event25  handler to guard against this case (for instance, by not changing the26  text if it is signaled for text that it has already changed once).27TF�change�28postchangeztyping.ClassVar[list[str]]�signalsc�n�[US5=(d# [U5S:H=(a [U5S:�$)z�29Filter for text that may be entered into this widget by the user30 31:param ch: character to be inserted32:type ch: str33 34This implementation returns True for all printable characters.35rr� )r�len�ord��self�chs  r�36valid_char�Edit.valid_char7s+���B��"�F�s�2�w�!�|�'E��B��2�
�Fr�Nc37�*>�[T38U]SXEU5 X0lX`lSUl[U5uUlUlSUlSUl	URU5 Uc[U5nURU5 URU	5 SUlg)a39:param caption: markup for caption preceding edit_text, see40                :class:`Text` for description of text markup.41:type caption: text markup42:param edit_text: initial text for editing, type (bytes or unicode)43                  must match the text in the caption44:type edit_text: bytes or unicode45:param multiline: True: 'enter' inserts newline  False: return it46:type multiline: bool47:param align: typically 'left', 'center' or 'right'48:type align: text alignment mode49:param wrap: typically 'space', 'any' or 'clip'50:type wrap: text wrapping mode51:param allow_tab: True: 'tab' inserts 1-8 spaces  False: return it52:type allow_tab: bool53:param edit_pos: initial position for cursor, None:end of edit_text54:type edit_pos: int55:param layout: defaults to a shared :class:`StandardTextLayout` instance56:type layout: text layout instance57:param mask: hide text entered with this character, None:disable mask58:type mask: bytes or unicode59 60>>> Edit()61<Edit selectable flow widget '' edit_pos=0>62>>> Edit("Y/n? ", "yes")63<Edit selectable flow widget 'yes' caption='Y/n? ' edit_pos=3>64>>> Edit("Name ", "Smith", edit_pos=1)65<Edit selectable flow widget 'Smith' caption='Name ' edit_pos=1>66>>> Edit("", "3.14", align="right")67<Edit selectable flow widget '3.14' align='right' edit_pos=4>68r/rNF)�super�__init__�	multiline�	allow_tab�	_edit_posr�_caption�_attrib�69_edit_text�	highlight�
set_edit_textr(�set_edit_pos�set_mask�_shift_view_to_cursor)r+�caption�	edit_textr3�align�wrapr4�edit_pos�layout�mask�	__class__s          �rr2�
Edit.__init__Bs����X	����U�&�1�"��"�����&9�'�&B�#��
�t�|����15������9�%����9�~�H����(�#��
�
�d��%*��"rc��>�[TU]5SS[UR5/-SUR<3/[UR5--S/URSL--$)N�����zcaption=r3T)r1�_repr_words�reprr8r6�boolr3)r+rEs �rrI�Edit._repr_words|sn����G��!�#�2�&��D�O�O�$�%�
&��$�-�-�*�+�,�t�D�M�M�/B�B�
C��m�t�~�~��5�6�
7�	70rc�t>�0[TU]5ESUR0En[U[R715$)NrB)r1�_repr_attrsr5rr!r2)r+�attrsrEs  �rrN�Edit._repr_attrs�s1���E�5�7�&�(�E�*�d�n�n�E���u�d�m�m�4�4rc���URc%URUR-UR4$URUR[	UR5--UR4$)a�72Returns ``(text, display attributes)``. See :meth:`Text.get_text`73for details.74 75Text returned includes the caption and edit_text, possibly masked.76 77>>> Edit("What? ", "oh, nothing.").get_text()78('What? oh, nothing.', [])79>>> Edit(("bright", "user@host:~$ "), "ls").get_text()80('user@host:~$ ls', [('bright', 13)])81>>> Edit("password:", "seekrit", mask="*").get_text()82('password:*******', [])83)�_maskr6r8r7r(�r+s r�get_text�
Edit.get_text�sT���:�:���=�=�4�?�?�2�D�L�L�@�@��}�}��84�85�S����-A� A�B�D�L�L�P�Prc�V�[US5(dUS:XaSUlg[S5e)z�86Not supported by Edit widget.87 88>>> Edit().set_text("test")89Traceback (most recent call last):90EditError: set_text() not supported.  Use set_caption() or set_edit_text() instead.91�_textr/NzHset_text() not supported.  Use set_caption() or set_edit_text() instead.)�hasattrrWr)r+�markups  r�set_text�
Edit.set_text�s-���t�W�%�%�&�B�,��D�J���b�c�crc�^�UunURup4XB:waURU45S$U$)a�92Return the preferred column for the cursor, or the93current cursor x value.  May also return ``'left'`` or ``'right'``94to indicate the leftmost or rightmost column available.95 96This method is used internally and by other widgets when97moving the cursor up or down between widgets so that the98column selected is one that the user would expect.99 100>>> size = (10,)101>>> Edit().get_pref_col(size)1020103>>> e = Edit("", "word")104>>> e.get_pref_col(size)1054106>>> e.keypress(size, "left")107>>> e.get_pref_col(size)1083109>>> e.keypress(size, "end")110>>> e.get_pref_col(size)111<Align.RIGHT: 'right'>112>>> e = Edit("", "2\nwords")113>>> e.keypress(size, "left")114>>> e.keypress(size, "up")115>>> e.get_pref_col(size)1164117>>> e.keypress(size, "left")118>>> e.get_pref_col(size)1190120r)�pref_col_maxcol�get_cursor_coords)r+�size�maxcol�pref_col�then_maxcols     r�get_pref_col�Edit.get_pref_col�s<��>�	�� $� 4� 4���� ��)�)�6�)�4�Q�7�7��rc�T�[U5uUlUlUR5 g)a�121Set the caption markup for this widget.122 123:param caption: markup for caption preceding edit_text, see124                :meth:`Text.__init__` for description of text markup.125 126>>> e = Edit("")127>>> e.set_caption("cap1")128>>> print(e.caption)129cap1130>>> e.set_caption(("bold", "cap2"))131>>> print(e.caption)132cap2133>>> e.attrib134[('bold', 4)]135>>> e.caption = "cap3"  # not supported because caption stores text but set_caption() takes markup136Traceback (most recent call last):137AttributeError: can't set attribute138N)rr6r7�_invalidate)r+r>s  r�set_caption�Edit.set_caption�s#��(':�'�&B�#��
�t�|����rc��UR$)z;139Read-only property returning the caption for this widget.140)r6rSs rr>�Edit.caption�s��141�}�}�rc��[[US5[UR55nSUlSUlXlUR5 g)a9142Set the cursor position with a self.edit_text offset.143Clips pos to [0, len(edit_text)].144 145:param pos: cursor position146:type pos: int147 148>>> e = Edit("", "word")149>>> e.edit_pos1504151>>> e.set_edit_pos(2)152>>> e.edit_pos1532154>>> e.edit_pos = -1  # Urwid 0.9.9 or later155>>> e.edit_pos1560157>>> e.edit_pos = 20158>>> e.edit_pos1594160rN�NN)�min�maxr(r8r9r]r5rf)r+�poss  rr;�Edit.set_edit_pos�s?��*�#�c�1�+�s�4�?�?�3�4�����)��������rc��UR$�N)r5rSs r�<lambda>�
Edit.<lambda>s��T�^�^rzI161        Property controlling the edit position for this widget.162        )�docc�0�XlUR5 g)z�163Set the character for masking text away.164 165:param mask: hide text entered with this character, None:disable mask166:type mask: bytes or unicode167N)rRrf)r+rDs  rr<�
Edit.set_masks���168����rc��URU5nSUlURSU5 URnXl[	UR169[
U55UlURSU5 UR5 g)am170Set the edit text for this widget.171 172:param text: text for editing, type (bytes or unicode)173             must match the text in the caption174:type text: bytes or unicode175 176>>> e = Edit()177>>> e.set_edit_text("yes")178>>> print(e.edit_text)179yes180>>> e181<Edit selectable flow widget 'yes' edit_pos=0>182>>> e.edit_text = "no"  # Urwid 0.9.9 or later183>>> print(e.edit_text)184no185Nr#r$)�_normalize_to_captionr9�_emitr8rmrBr(rf)r+�text�old_texts   rr:�Edit.set_edit_text sg��$�)�)�$�/������186�187�8�T�"��?�?�����D�M�M�3�t�9�5��
��188�189�<��*����rc��UR$)z�190Return the edit text for this widget.191 192>>> e = Edit("What? ", "oh, nothing.")193>>> print(e.get_edit_text())194oh, nothing.195>>> print(e.edit_text)196oh, nothing.197)r8rSs r�
get_edit_text�Edit.get_edit_text<s�����rzE198        Property controlling the edit text for this widget.199        c��URU5nURU5up#URU5 URU5 SUlg)a�200Insert text at the cursor position and update cursor.201This method is used by the keypress() method when inserting202one or more characters into edit_text.203 204:param text: text for inserting, type (bytes or unicode)205             must match the text in the caption206:type text: bytes or unicode207 208>>> e = Edit("", "42")209>>> e.insert_text(".5")210>>> e211<Edit selectable flow widget '42.5' edit_pos=4>212>>> e.set_edit_pos(2)213>>> e.insert_text("a")214>>> print(e.edit_text)21542a.5216N)ry�insert_text_resultr:r;r9)r+r{�result_text�217result_poss    r�insert_text�Edit.insert_textPsJ��&�)�)�$�/��"&�"9�"9�$�"?������;�'����*�%���rc��[U[5n[UR[5nX#:XaU$U(aURS5$UR	S5$)zIReturn text converted to the same type as self.caption (bytes or unicode)�ascii)�218isinstance�strr6�encode�decode)r+r{�tu�cus    rry�Edit._normalize_to_captionisI��
��c�
"��
��
�
�s�
+��
�8��K�
��;�;�w�'�'��{�{�7�#�#rc��URU5nUR(a2URup#URSUURUSpTXE-nUnOURnURnUSUU-XgS-nU[U5-
nXg4$![[2194a?n[
[URXa455RUR5UeSnAff=f)z�220Return result of insert_text(text) without actually performing the221insertion.  Handy for pre-validation.222 223:param text: text for inserting, type (bytes or unicode)224             must match the text in the caption225:type text: bytes or unicode226N)ryr9r?rB�227IndexError�	TypeError�228ValueErrorrJ�with_traceback�
__traceback__r()	r+r{�start�stop�btext�etextr�r��excs	         rr��Edit.insert_text_resultss����)�)�$�/���>�>��.�.�K�E��>�>�&�5�1�4�>�>�$�%�3H�5��-�K��J��.�.�K����J�	s�%�k�z�2�T�9�K��<T�T�K�	�c�$�i��229��(�(��	�I�&�	s��T�4�>�>�;�"E�F�G�V�V�WZ�Wh�Wh�i�or�r��	s�s�.
B�C�:C�Cc��URnURU5(aW[U[5(a0[UR[5(dURS5nUR
U5 gUS:Xa8UR(a'SSURS--230-nUR
U5 gUS:Xa%UR(aSnUR
U5 gURU[R:Xa1US:XaU$[URSU5nURU5 gURU[R:XaWU[!UR5:�aU$[#URU[!UR55nURU5 gURU[R$[R&1;aSUlUR+U5upEUR-U5nUc[/U5eURU[R$:XaUS	-nOUS	-
nUR1XU5(dU$gUS231:Xa�SUlUR55(diUS:XaU$[URSU5nUR7URSUURURS-5 URU5 ggUS:Xa�SUlUR55(d~U[!UR5:�aU$[#URU[!UR55nUR7URSURURUS-5 ggURU[R8[R:1;a�SUlSUlUR+U5upEURU[R8:Xa"UR1U[<RU5 gUR1U[<RU5 gU$)
aQ232Handle editing keystrokes, return others.233 234>>> e, size = Edit(), (20,)235>>> e.keypress(size, "x")236>>> e.keypress(size, "left")237>>> e.keypress(size, "1")238>>> print(e.edit_text)2391x240>>> e.keypress(size, "backspace")241>>> e.keypress(size, "end")242>>> e.keypress(size, "2")243>>> print(e.edit_text)244x2245>>> e.keypress(size, "shift f1")246'shift f1'247zutf-8N�tab� ��enter�248rr�	backspacerl�delete)rBr-r�r�r6r�r�r4r3�_command_mapr�LEFTr249r?r;�RIGHTr(r	�UP�DOWNr9r^rcr��move_cursor_to_coordsr]�_delete_highlightedr:�MAX_LEFT�	MAX_RIGHTr
)r+r_�keyro�_x�yras       r�keypress�
Edit.keypress�s���,�m�m���?�?�3����#�s�#�#�J�t�}�}�c�,J�,J��j�j��)�����S�!���%�<�D�N�N���d�m�m�a�/�0�1�C����S�!���'�>�d�n�n��C����S�!�����S�!�W�\�\�1��a�x��250� �����C�8�C����c�"�����S�!�W�]�]�2��c�$�.�.�)�)��251� �����c�$�.�.�6I�J�C����c�"�����S�!�g�j�j�'�,�,�%?�?�!�D�N��*�*�4�0�E�B��(�(��.�H��� ��*�*�252� � ��%����3��Q����Q����-�-�d�a�@�@��253���+��#-�D� ��+�+�-�-��!�8��J�$�T�^�^�Q��<���"�"�4�>�>�$�3�#7�$�.�.�����:Y�#Y�Z��!�!�#�&����(�?�#-�D� ��+�+�-�-��#�d�n�n�-�-��J�$�T�^�^�S�#�d�n�n�:M�N���"�"�4�>�>�/�D�M�M�#B�T�^�^�TW�TX�EY�#Y�Z������S�!�g�&6�&6��8I�8I�%J�J�!�D�N�#-�D� ��*�*�4�0�E�B�� � ��%��)9�)9�9��*�*�4����Q�?���*�*�4����a�@���254rc��UunURU5nURUS5upgX7:dU[U5:�ag[R"UR5SXRU5n[
[U[UR5-255S5[UR55n	X�l256X$4UlUR5 g)a=257Set the cursor position with (x,y) coordinates.258Returns True if move succeeded, False otherwise.259 260>>> size = (10,)261>>> e = Edit("", "edit\ntext")262>>> e.move_cursor_to_coords(size, 5, 0)263True264>>> e.edit_pos2654266>>> e.move_cursor_to_coords(size, 5, 3)267False268>>> e.move_cursor_to_coords(size, 0, 1)269True270>>> e.edit_pos2715272rFT)
�get_line_translation�position_coordsr(r�calc_posrTrmrnr>r?rBr]rf)273r+r_�xr�r`�trans�_top_x�top_yro�e_poss274          rr��Edit.move_cursor_to_coords�s���.�	���)�)�&�1���,�,�V�Q�7�
���9��S��Z����"�"�4�=�=�?�1�#5�u��C���C��c�$�,�,�/�/��3�S����5H�I���
� �y�������rc�4�US:XaURXU5$g)z�275Move the cursor to the location clicked for button 1.276 277>>> size = (20,)278>>> e = Edit("", "words here")279>>> e.mouse_event(size, "mouse press", 1, 2, 0, True)280True281>>> e.edit_pos2822283rF)r�)r+r_�event�button�col�row�focuss       r�mouse_event�Edit.mouse_event!s!��&�Q�;��-�-�d��=�=�rc��UR(dgURupURSUURUSpCURX4-5 XlSUlg)zU284Delete all highlighted text and update cursor position, if any285text is highlighted.286FNT)r9r?r:rB)r+r�r�r�r�s     rr��Edit._delete_highlighted8sU��287�~�~���n�n����~�~�f�u�-�t�~�~�d�e�/D�u����5�=�)��
����rc�>�[U5Ul[TU]
X5nU(a![	U5nURU5UlU$)z�288Render edit widget and return canvas.  Include cursor when in289focus.290 291>>> edit = Edit("? ", "yes")292>>> c = edit.render((10,), focus=True)293>>> c.text294[b'? yes     ']295>>> c.cursor296(5, 0)297)rKr=r1�renderrr^�cursor)r+r_r��canvrEs    �rr��Edit.renderFsE��� &*�%�[��"�-2�W�^�D�-H���"�4�(�D��0�0��6�D�K��rc�>�[TU]X5nUR(dU$UR5upE[R298"XCUR[UR5-5upgUS:a)/USUQ[R"X7U*5/QX7S-SQ$Xa:�a./USUQ[R"X7Xa-299S-*5/QX7S-SQ$U$)Nrr)300r1r�r=rTr�calc_coordsrBr(r>�301shift_line)	r+r`�tar�r{�_ignorer�r�rEs	        �rr��Edit.get_line_translationcs����302��,�V�8���)�)��L��
�
��
���&�&�t�D�M�M�C����DU�4U�V����q�5���r�����(�(���A�2�6�7���1�u�w���
�
�;���r�����(�(���Q�Z�!�^�3D�E�F���1�u�w���
��rc�N�UunSUlURX R5$)zs303Return the (*x*, *y*) coordinates of cursor within widget.304 305>>> Edit("? ", "yes").get_cursor_coords((10,))306(5, 0)307T)r=r�rB)r+r_r`s   rr^�Edit.get_cursor_coords~s(���	��%)��"��#�#�F�M�M�:�:rc��U[UR5-nURU5n[R"UR5SXC5upVXV4$)zB308Return (*x*, *y*) coordinates for an offset into self.edit_text.309r)r(r>r�rr�rT)r+r`ro�pr�r�r�s       rr��Edit.position_coords�sM��310
�#�d�l�l�#�#���)�)�&�1���&�&�t�}�}��q�'9�5�D����t�r)r7r6r5r8rRr=rWr4rBr9r3r]�r,r��returnrK)r>�=str | tuple[Hashable, str] | list[str | tuple[Hashable, str]]r?r�r3rKr@z*Literal['left', 'center', 'right'] | AlignrAz6Literal['space', 'any', 'clip', 'ellipsis'] | WrapModer4rKrBz311int | NonerCztext_layout.TextLayoutrD�312str | Noner��None)r�z	list[str])r�zdict[str, typing.Any])r�z.tuple[str | bytes, list[tuple[Hashable, int]]])rYr�r�r�)r_�313tuple[int]r��int)r>r�r�r�)r�r�)ror�r�r�)rDr�r�r�)r{r�r�r�)r{�str | bytesr�r�)r{r�r�ztuple[str | bytes, int]�r_r�r�r�r�r�)r_r�r�z&int | Literal[Align.LEFT, Align.RIGHT]r�r�r�rK)r_r�r�r�r�r�r�r�r�r�r�rKr�zbool | None)r�rK)F)r_r�r�rKr�zTextCanvas | CompositeCanvasrr)r`r�r�z5tuple[str | bytes, list[tuple[Hashable, int]]] | Noner�zAlist[list[tuple[int, int, int | bytes] | tuple[int, int | None]]])r_r�r��tuple[int, int])r`r�ror�r�r�).rrrr�__doc__�	frozensetr�FLOW�_sizing�_selectable�ignore_focusr%�__annotations__r-r
r�r�SPACEr2rIrNrTrZrcrg�propertyr>r;rBr<r:rr?r�ryr�r�r�r�r�r�r�r^r�r�
__classcell__�rEs@rr!r!s_����(����
�&�G��K��L�+3�\�*B�G�
'�B�	G�RT���<A�J�J�GO�~�~��#�)-��8+�N�8+��8+��	8+�314:�8+�E�
8+��8+��8+�'�8+��8+�315�8+�8+�t316�5�Q�(d�$$�L�.�����6�#��
��H�	��8317����
��I��2$�)�:k��k��k�318�	k�Z"��"�2�"��	"�319320�"�H������	�321���
���322��.�"������323&�	��@EI����
B��324K�	��6325;��rr!c�d^�\rSrSrSrSSjrS	S326U4SjjjrSU4SjjrSSjrSr	U=r327$)
�IntEditi�zEdit widget for integer valuesc�R�[U5S:H=(a U[R;$)z!328Return true for decimal digits.329r)r(�string�digitsr*s  rr-�IntEdit.valid_char�s ���2�w�!�|�3��f�m�m� 3�3rc�F>�Ub[U5nOSn[TU]	X5 g)z330caption -- caption markup331default -- default edit value332 333>>> IntEdit("", 42)334<IntEdit selectable flow widget '42' edit_pos=2>335Nr/)r�r1r2)r+r>�default�valrEs    �rr2�IntEdit.__init__�s&������g�,�C��C�
����&rc�>>�[TU]X5=n(aU$URS:�atURSSS:XaaUR	URS-3365 URURSS5 URS:�aURSSS:XaMag)z�337Handle editing keystrokes.  Remove leading zeros.338 339>>> e, size = IntEdit("", 5002), (10,)340>>> e.keypress(size, "home")341>>> e.keypress(size, "delete")342>>> print(e.edit_text)343002344>>> e.keypress(size, "end")345>>> print(e.edit_text)3462347rNr�0)r1r�rBr?r;r:)r+r_r��	unhandledrEs    �rr��IntEdit.keypress�s����"��(��3�3�9�3����m�m�a��D�N�N�2�A�$6�#�$=����d�m�m�a�/�0����t�~�~�a�b�1�2��m�m�a��D�N�N�2�A�$6�#�$=�rc�P�UR(a[UR5$g)z�348Return the numeric value of self.edit_text.349 350>>> e, size = IntEdit(), (10,)351>>> e.keypress(size, "5")352>>> e.keypress(size, "1")353>>> e.value() == 51354True355r)r?r�rSs r�value�
IntEdit.value�s���>�>��t�~�~�&�&�rrr�)r/N)r�zint | str | Noner�r�r�)r�r�)rrrrr�r-r2r�r�rr�r�s@rr�r��s@���(�4�'�'������356�	�6
�
rr�)"�357__future__rr��typing�urwidr�urwid.canvasr�urwid.command_mapr�urwid.split_reprr�urwid.str_utilrr	r358�359urwid.utilr�	constantsr
rrr{rr�
TYPE_CHECKING�collections.abcr�typing_extensionsrrrr!r�rrr�<module>rse��"�
�
��(�%�,�G�G�*�.�.�!�	���(�)�'�	�	�	�v	�4�v	�r?�d�?r
codekingpro/portable-devtools · Team Ai