Team Ai
Datasetpublic

codekingpro/portable-devtools

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

2��jT���SSKJr SSKrSSKJrJrJr SSKJr SSK	J3r4Jr SSKJ
r
 SSKJrJrJrJrJr \R((aSS	KJr "S5S\5rSr"S
S\5r"SS\\S9rSSjr"SS\5rSSjrg)�)�annotationsN)�
CanvasCombine�CompositeCanvas�SolidCanvas)�get_encoding_mode�)�BAR_SYMBOLS�Sizing)�Text)�Widget�WidgetError�6WidgetMeta�nocache_widget_render�nocache_widget_render_instance)�Literalc�,^�\rSrSrSrU4SjrSrU=r$)�BarGraphMeta�z�7Detect subclass get_data() method and dynamic change to8get_data() method and disable caching in these cases.9 10This is for backwards compatibility only, new programs11should use set_data() instead of overriding get_data().12c�>�[TU]XU5 SU;a![U5UlURUl[
S[5Ulg)N�get_datac��UR$�N)�	_get_data��selfs �\D:\code\apps\devtools\python\user_packages\Python313\site-packages\urwid/widget/bar_graph.py�<lambda>�'BarGraphMeta.__init__.<locals>.<lambda>!s��T�^�^�)�super�__init__r�renderrr�property�nocache_bargraph_get_data)�cls�name�bases�d�	__class__s    �rr!�BarGraphMeta.__init__sB���	����a�(���?�.�s�3�C�J��L�L�C�M�� ;�=V�W��r�)�__name__�13__module__�__qualname__�__firstlineno__�__doc__r!�__static_attributes__�
__classcell__�r)s@rrrs����X�Xrrc�0�[U5UlXlg)za14Disable caching on this bargraph because get_data_fn needs15to be polled to get the latest data.16N)rr"r)r�get_data_fns  rr$r$$s��171��6�D�K� �Nrc��\rSrSrSrg)�
BarGraphError�-r+N)r,r-r.r/r1r+rrr7r7-s��rr7c��^�\rSrSr\"\R/5rSr\	RSSrSrSSU4Sjjjr
SSjrSSSjjrSS	jrSS18jrSSjrSSjrSS
jrSSjrSSjrSrSSSjjrSrU=r$)�BarGraph�1TN�u_⎺⎻─⎼⎽c�>�[TU]5 URXU5 UR/SS5 UR	S5 g)z}19Create a bar graph with the passed display characteristics.20see set_segment_attributes for a description of the parameters.21rN)r r!�set_segment_attributes�set_data�
set_bar_width)r�attlist�hatt�sattr)s    �rr!�BarGraph.__init__9s>���22	�����#�#�G�4�8��
�
�b�!�T�"����4� rc���/Ul/Ul[U5S:a[SU<35e[U5S:a[S5eUH�n[	U[235(d8URR
U5 URR
S5 MPUupVURR
U5 URR
U5 M� /UlUcURS/nO[	U[5(dU/nX lUc0nUR5H�nUuup�n[	U[5(aU[U5:�a[SU<35e[	U	[5(aU	[U5:�a[S	U<35eX�::dMx[S24USU	S35e X0lg![a.n25[SU<35RU26R5U27eSn28A29ff=f)
a30:param attlist: list containing display attribute or31                (display attribute, character) tuple for background,32                first segment, and optionally following segments.33                ie. len(attlist) == num segments+134                character defaults to ' ' if not specified.35:param hatt: list containing attributes for horizontal lines. First36             element is for lines on background, second is for lines37             on first segment, third is for lines on second segment38             etc.39:param satt: dictionary containing attributes for smoothed40             transitions of bars in UTF-8 display mode. The values41             are in the form:42 43               (fg,bg) : attr44 45             fg and bg are integers where 0 is the graph background,46             1 is the first segment, 2 is the second, ...47             fg > bg in all values.  attr is an attribute with a48             foreground corresponding to fg and a background49             corresponding to bg.50 51If satt is not None and the bar graph is being displayed in52a terminal using the UTF-8 encoding then the character cell53that is shared between the segments specified will be smoothed54with using the UTF-8 vertical eighth characters.55 56eg: set_segment_attributes( ['no', ('unsure',"?"), 'yes'] )57will use the attribute 'no' for the background (the area from58the top of the graph to the top of the bar), question marks59with the attribute 'unsure' will be used for the topmost60segment of the bar, and the attribute 'yes' will be used for61the bottom segment of the bar.62�z3attlist must include at least background and seg1: z must at least specify bg and fg!� Nrzsatt not in (fg,bg:attr) form: zfg not valid integer: zbg not valid integer: zfg (z) not > bg (�))�attr�char�lenr7�63isinstance�tuple�appendrB�list�items�64ValueError�with_traceback�
__traceback__�intrC)rrArBrC�arI�ch�i�fg�bg�excs           rr>�BarGraph.set_segment_attributesCs���F��	���	��w�<�!���"U�V]�U`� a�b�b��w�<�!��� B�C�C��A��a��'�'��	�	� � ��#��	�	� � ��%�����	�	� � ��&��	�	� � ��$����	��<��I�I�a�L�>�D��D�$�'�'��6�D��	��<��D�����A�
x�!"����$��b�#�&�&�"��G��*<�#�&<�R�F�$C�D�D��b�#�&�&�"��G��*<�#�&<�R�F�$C�D�D��x�#�d�2�$�l�2�$�a�$@�A�A���	���
x�#�&E�a�U�$K�L�[�[�\_�\m�\m�n�tw�w��
x�s�)F8�865G0�)G+�+G0c�V�Ub
[USSSS9nXU4UlUR5 g)a�66Store bar data, bargraph top and horizontal line positions.67 68bardata -- a list of bar values.69top -- maximum value for segments within bardata70hlines -- None or a bar value marking horizontal line positions71 72bar values are [ segment1, segment2, ... ] lists where top is73the maximal value corresponding to the top of the bar graph and74segment1, segment2, ... are the values for the top of each75segment of this bar.  Simple bar graphs will only have one76segment in each bar value.77 78Eg: if top is 100 and there is a bar value of [ 80, 30 ] then79the top of this bar will be at 80% of full height of the graph80and it will have a second segment that starts at 30%.81NT��reverse)�sorted�data�_invalidate)r�bardata�top�hliness    rr?�BarGraph.set_data�s2��$���F�1�I�t�4�F��&�(��	����rc��Uup#URupEnURX#4U5n[U5[U5:�aUS[U5XV4$XEU4$)z�82Return (bardata, top, hlines)83 84This function is called by render to retrieve the data for85the graph. It may be overloaded to create a dynamic bar graph.86 87This implementation will truncate the bardata list returned88if not all bars will fit within maxcol.89N)r`�calculate_bar_widthsrK)r�size�maxcol�maxrowrbrcrd�widthss        rr�BarGraph._get_data�s`�� ���#�y�y���f��*�*�F�+;�W�E���w�<�#�f�+�%��=�S��[�)�3�6�6��V�#�#rc�X�UbUS::a[U5eXlUR5 g)zz90Set a preferred bar width for calculate_bar_widths to use.91 92width -- width of bar or None for automatic width adjustment93Nr)rQ�	bar_widthra)r�widths  rr@�BarGraph.set_bar_width�s,�����!���U�#�#������rc�H�Uup4URb/UR/[[U5X0R-5-$[U5U:�aS/U-$/nUn[U5nUH7n[[	U5U-S-5n	URU	5 Xi-nUS-nM9 U$)z�94Return a list of bar widths, one for each bar in data.95 96If self.bar_width is None this implementation will stretch97the bars across the available space specified by maxcol.98r��?)rn�minrKrT�floatrN)99rrhrbri�_maxrowrk�grow�remain�_row�ws100          rrg�BarGraph.calculate_bar_widths�s���!����>�>�%��N�N�#�c�#�g�,��.�.�8P�&Q�Q�Q��w�<�6�!��3��<�������W����D��E�$�K�&�(�3�.�/�A��M�M�!���I�D��a�K�F�	�101�
rc��g�z102Return False.103Fr+rs r�104selectable�BarGraph.selectable����rc�B�UR=(a
 [5S:H$)N�utf8)rCrrs r�use_smoothed�BarGraph.use_smoothed�s���y�y�:�.�0�F�:�:rc��Uup#URX#45upEnURX#4U5nUR5(a![XEXsS-5nUR	U5nO[XEXs5nU(aURX�Xc5nU$)z105Calculate display data.106r<)rrgr��calculate_bargraph_display�smooth_display�hlines_display)	rrhrirjrbrcrdrk�disps	         r�calculate_display�BarGraph.calculate_display�s��� ���#�}�}�f�-=�>���f��*�*�F�+;�W�E�������-�g�F�Q�J�O�D��&�&�t�,�D�.�g�F�K�D���&�&�t�&�A�D��rc�^�TR5(aSn/SQnOSnS/nUVs/sH#n[X'-1075U-U-U-108=nS:�dM!UPM% n	n/n109SnU	H?n[U5nX�:XaMX�-110n
UHup�X�:dMU111RX�45  O UnMA U4Sjn/nSnSnUH�unnU[	U1125:�aURUU45 M*UU-nU[	U1135:asU114USU:agU115Uup�UU-116S:�aURUU-117U45 URSU"UU545 US-nUS-
nU[	U1185:aU119USU:aMgUU:dM�URUU-120U45 UnM� U$s snf)z�121Add hlines to display structure represented as bar_type tuple122values:123(bg, 0-5)124bg is the segment that has the hline on it1250-5 is the hline graphic to use where 0 is a regular underscore126and 1-5 are the UTF-8 horizontal scan line characters.127r))g�������?r)g�������?rF)g333333�?�)g�������?�)��?�rr)r�r�����c��>�/nUH[up4[U[5(a/[TR5U:�aUR	X14U45 MIUR	X445 M] U$r)rLrTrKrBrN)�row�chnum�rout�bar_typerors     �r�fill_row�)BarGraph.hlines_display.<locals>.fill_row!s]����D�#&����h��,�,��T�Y�Y��(�1J��K�K�(�!2�E� :�;�����X�-�.�	$'�128�Krr)r�rtrTrNrK)rr�rcrdrj�shiftr�r�h�rh�rhl�hrows�last_irW�f�splr�r��o�k�rnum�y_countr��	end_blocks`                      rr��BarGraph.hlines_display�s����������F��A��F���A�129"�Y�6�a�E�#�'�N�V�,C�c�,I�F�,R�&R�b�WX�%X�r�6��Y������B��B��A��{����A��130���7��L�L�!��,�� ��F��	�
��
���� �L�G�S��C��J�����'�3��(���w��I��c�%�j�.�U�1�X�a�[�9�%<� ��8����t�8�a�<��H�H�a�$�h��_�-����!�X�c�5�1�2�3��1�u���Q���
�c�%�j�.�U�1�X�a�[�9�%<��i�����)�d�*�C�0�1� ��!�"���]Zs� F�Fc�^^^^	�/mSmUU4Sjm	SUU	4SjjnUH�up4T(a.[ST-131U5nU"XT5 X5-nTU-
mTS-mU(dM:TS:wa[eUS:�a'TRUS-S-U45 US-nU(dMsTRX445 UmM� TVVs/sHupdUS-U4PM snn$s snnf)z�132smooth (col, row*8) display into (col, row) display using133UTF vertical eighth characters represented as bar_type134tuple values:135( fg, bg, 1-7 )136where fg is the lower segment, bg is the upper segment and1371-7 is the vertical eighth character to use.138rc�>�Xsup#upEX#4XE4:XaX#4SS4$[X55nS=pxX5:�aX#U-1394nOXS:�aXEU-1404n[U[5(aX&4Xx4$XB4T141R;aT	S:aXF4Xx4$X&4Xx4$XBST	-1424U4Xx4$)Nr�r<)rsrLrMrC)rU�b�bt1�w1�bt2�w2�wmin�l1�l2r�rs         ��r�seg_combine�,BarGraph.smooth_display.<locals>.seg_combineLs����#$� �I�S�y���y�S�I�%��y�$��,�,��r�;�D��N�B��w���7�^������7�^���#�u�%�%��{�B�*�*��z����*��q�5��;��.�.��{�B�*�*��q�1�u�%�t�,�b�4�4rc�t>�T	Sup#USSnUSSn/nU(a�T143"URS5URS55uupVpxU(aUSSU:XaXTSSU-4US'OURXV45 U(aU/UQnU(aU/UQnU(aM�U(a[U5eX -U4T	S'g)Nr�rr)�poprNr7)�countr��o_count�o_row�widget_list�btryr�r�r�r�s         ��r�row_combine_last�1BarGraph.smooth_display.<locals>.row_combine_last^s�����r�U�N�G��a�&�C��!�H�E��K��"-�e�i�i��l�C�G�G�A�J�"G������;�r�?�1�#5��#;�')�r�?�1�+=��+A�&B�K��O��&�&��w�/���L�%�L�E���*��*�C��#��#�E�*�*��_�k�2�A�b�Err<�)r�rT)rsr7rN)144rr�r�r�r�r��yr�r�r�s145`      @@@rr��BarGraph.smooth_display@s����
��
��	5�$	3�	3�,!�L�G���A��E�7�+�� ��,�� ���U�146���Q������A�v�#�#���{����'�Q�,��*�C�0�1��1�����
�H�H�g�^�$��A�%!�&/0�0�a�(�1��a���
�a�0�0��0s�+Cc�V�Uup4URX445n/nUH�upx/n	UH�up�[U147[5(a][U1485S:Xa(U149up�nURX�4nUR150UU-nOGU151up�URU
nURUU-nO!URU152nURU153U-nU	RUU45 M� [U	5RU45nUR5S:wa[S5eUUSS4/U--
nGM [U5nU$)z154Render BarGraph.155r�rzInvalid characters in BarGraph!NF)r�rLrMrKrC�eighthsrBrdrIrJrNrr"�rowsr7r)rrh�focusrirjr��combinelistr�r�r�r�rorXrYr�rU�t�c�canvs                   rr"�BarGraph.render�s<�� ����%�%�v�&6�7���� �L�G��K�#&����h��.�.��8�}��)�$,�	��� �I�I�b�f�-�� �L�L��O�e�3��!)��� �I�I�b�M�� �K�K��N�U�2���	�	�(�+�A��	�	�(�+�e�3�A��"�"�A�q�6�*�$'� �[�!�(�(�&��3�A��v�v�x�1�}�#�$E�F�F��Q��e�,�-��7�7�K�+!�.�[�)���r)rIrnrJr`rBrC)NN)�return�Noner�rcrtr�r�)rh�tuple[int, int])roz156int | None�r�zLiteral[False])r��bool)rcrTrjrT�F)rhr�r�r�r�r)r,r-r.r/�	frozensetr157�BOX�_sizing�ignore_focusr	�VERTICALr�rdr!r>r?rr@rgr}r�r�r�r�r"r1r2r3s@rr:r:1s{��������%�G��L��"�"�2�A�&�G�
�F�!�!�F�P�0$�&	��2�;��(G�RG1�R � rr:)�	metaclassc���[U5[U5:wa[e[U5nS/U-nU4SSjjnSnSnUHsn	X(n158U159S:aMUn[X�U5n[	[U	5S-160SS5H0n
X�nX�:�aM[US5nX�:dM!UnU"U
S-X~U1615 M2 Xz-
nUS-
nMu /nSnSU4/nUGH�nUcUS-
nMU(aUR
UU45 SnSnUUunnSn/nUGH7unnnUUU-:�a0UR
UU45 US-
nUU-
nUUunnUUU-:�aM0UU:XaUR
UUU-16245 O5UU-163S:�aUR
UUU-16445 UR
UUU-16545 UU:Xa
[U5n O�UUU-:�aUS-
nUU-
nUUunnUUU-:�aMUU:waUU-U-166nUnM�USunnUUU-U-167-
nUU4US'US-
nUU-
nUU:Xa O2U[U5:�a[[UU455eUUunnGM: U[U5:aUUU4/UUS-SQ-
nUnUS-
nGM� U(aUR
UU45 U$)aT168Calculate a rendering of the bar graph described by data, bar_widths169and height.170 171bardata -- bar information with same structure as BarGraph.data172top -- maximal value for bardata segments173bar_widths -- list of integer column widths for each bar174maxrow -- rows for display of bargraph175 176Returns a structure as follows:177  [ ( y_count, [ ( bar_type, width), ... ] ), ... ]178 179The outer tuples represent a set of identical rows. y_count is180the number of rows in this set, the list contains the data to be181displayed in the row repeated through the set.182 183The inner tuple describes a run of width characters of bar_type.184bar_type is an integer starting from 0 for the background, 1 for185the 1st segment, 2 for the 2nd segment etc..186 187This function should complete in approximately O(n+m) time, where188n is the number of bars displayed and m is the number of rows.189Nc���XB(a;XBSupVnXq:�aXa:�aXBS	O*XVU4XBS'O XP:XaXq:XaXVXs-4XBS'gO	XBc/XB'XBRXX-45 g)Nr�)rN)�seg_num�colr�ror��last_seg�last_col�last_ends        r�add_segment�/calculate_bargraph_display.<locals>.add_segment�s����9�+/�9�R�=�(�H���~��?��	�"�
�%-��$=�D�I�b�M��$���!)�X�5E� F��	�"�
���
�Y�
��D�I��	���'���4�5rrrr�)190r�rTr�rTr�rTrorTr�r�)	rKr7�sum�scale_bar_values�range�maxrNrQ�repr)rbrc�191bar_widthsrjrir�r�r��barnum�barro�tallest�segmentsr��s�rowsetsr��lastr�rW�la�lnr�r�r��start�end�oa�ons                             rr�r��s��2�7�|�s�:��&���
��_�F�
�6�F�?�D�GK�
6��C�
�F����"���1�9����#�C�f�5���s�3�x�!�|�R��,�A���A��{���A�q�	�A��{����A��E�3�5�1�-�	����!���%�,�G��G�
��K�=�D�
���9��q�L�G����N�N�G�T�?�+��G�
���a����B�
����#$��G�U�C��!�b�&�.����"�b��"��Q����R����a����B�	�!�b�&�.��W�}����"�c�A�g��'��1�9�q�=��H�H�b�%�!�)�_�-����'�3��;�/�0��f�}���I�����R��-��Q����R����a����B���R��-�192�W�}���V�c�\������r�U�F�B���!�b�&�3�,��B���F�A�b�E�
��F�A�
��G�A��F�{���C��I�~� ��r�6�l�!3�4�4��!�W�F�B��S$%�V
�s�4�y�=�
�2�r�(�+�T�!�a�%�'�]�+�+�A����1���u�x�������'��Nrc�^�\rSrSr\"\R/5rSU4SjjrSSjr	SSjr193S	S194SjjrSrU=r
$)�GraphVScalei:c�D>�[TU]5 URX5 g)a%195GraphVScale( [(label1 position, label1 markup),...], top )196label position -- 0 < position < top for the y position197label markup -- text markup for this label198top -- top y position199 200This widget is a vertical scale for the BarGraph widget that201can correspond to the BarGraph's horizontal lines202N)r r!�	set_scale)r�labelsrcr)s   �rr!�GraphVScale.__init__=s���	�������v�#rc���[USSSS9n/Ul/UlUHDup4URRU5 URR[	U55 MF X lg)z�203set_scale( [(label1 position, label1 markup),...], top )204label position -- 0 < position < top for the y position205label markup -- text markup for this label206top -- top y position207NTr])r_�pos�txtrNrrc)rr�rcr��markups     rr��GraphVScale.set_scaleJsY����q�	�4�0���������I�A��H�H�O�O�A���H�H�O�O�D��L�)� ��rc��gr|r+rs rr}�GraphVScale.selectable[rrc���Uup4[URURU5n/nSn[XPR5Hvup�US-nX�:�a OiX�:aMU	RU45n208X�:�a!X�-209n[
U2105n211U212RUS5 XzR5-
nURU213SS45 Mx U(d[SUSUS5$[U5nXG-214(aURSXG-2155 U$)z216Render GraphVScale.217rrNFrG)r�r�rc�zipr�r"r�pad_trim_top_bottomr�rNrr)
rrhr�rirj�plr�r��pr�r��run�canvass
             rr"�GraphVScale.renderas��� ���
�d�h�h����&�
9��������H�H�%�D�A�
��F�A��{���x�����&��#�A��x��h��#�A�&���%�%�c�1�-��F�F�H��D�����4��/�0�&���s�D��G�T�!�W�5�5��{�+���=��&�&�q�&�-�8��
r)r�rcr�r�r�r�)rhr�r�r�r�zSolidCanvas | CompositeCanvas)r,r-r.r/r�r218r�r�r!r�r}r"r1r2r3s@rr�r�:sM��������%�G�$��"�� �� �� �219'�	 � rr�c	�l�UVs/sH"o2[[U5U-U-S-5-220PM$ sn$s snf)zB221Return a list of bar values aliased to integer values of maxrow.222rr)rTrt)r�rcrj�vs    rr�r��s9��BE�E��A�S��q��F�*�S�0�3�6�7�7��E�E��Es�)1)rcrtr��	list[int]rjrT)rcrtrjrTr�r)�223__future__r�typing�urwid.canvasrrr�224urwid.utilr�	constantsr	r225�textr�widgetrr
rrr�
TYPE_CHECKING�typing_extensionsrrr$r7r:r�r�r�r+rr�<module>rsx��"�
�D�D�(�*��j�j�	���)�X�:�X�(!�	�K�	�x�v��x�vK�\G�&�G�TFr
codekingpro/portable-devtools · Team Ai