)L i@KddlmZddlmZddlmZmZddlmZddl m Z ddl m Z m Z ddlmZmZmZmZdd lmZmZdd lmZmZmZd gZd ZGd d e Zy)) annotations)Point) FilterOrBool to_filter)KeyBindingsBase) MouseEvent) Container ScrollOffsets) AnyDimension Dimensionsum_layout_dimensions to_dimension) MouseHandler MouseHandlers)CharScreen WritePositionScrollablePanei'c PeZdZdZdddeddddddf ddZddZddZdd Zdd Z dd Z dd Z dd Z ddZ ddZddZd dZd!dZ d"dZ d#dZy)$raK Container widget that exposes a larger virtual screen to its content and displays it in a vertical scrollbale region. Typically this is wrapped in a large `HSplit` container. Make sure in that case to not specify a `height` dimension of the `HSplit`, so that it will scale according to the content. .. note:: If you want to display a completion menu for widgets in this `ScrollablePane`, then it's still a good practice to use a `FloatContainer` with a `CompletionsMenu` in a `Float` at the top-level of the layout hierarchy, rather then nesting a `FloatContainer` in this `ScrollablePane`. (Otherwise, it's possible that the completion menu is clipped.) :param content: The content container. :param scrolloffset: Try to keep the cursor within this distance from the top/bottom (left/right offset is not used). :param keep_cursor_visible: When `True`, automatically scroll the pane so that the cursor (of the focused window) is always visible. :param keep_focused_window_visible: When `True`, automatically scroll the pane so that the focused window is visible, or as much visible as possible if it doesn't completely fit the screen. :param max_available_height: Always constraint the height to this amount for performance reasons. :param width: When given, use this width instead of looking at the children. :param height: When given, use this height instead of looking at the children. :param show_scrollbar: When `True` display a scrollbar on the right. NT^vc ||_|xs tdd|_t||_t||_||_||_||_t||_ t| |_ | |_ | |_ d|_ y)Nr )topbottomr)contentr scroll_offsetsrkeep_cursor_visiblekeep_focused_window_visiblemax_available_heightwidthheightshow_scrollbardisplay_arrowsup_arrow_symboldown_arrow_symbolvertical_scroll) selfrrrrr r!r"r#r$r%r&s k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/layout/scrollable_pane.py__init__zScrollablePane.__init__4s ,N !A0N#,-@#A +45P+Q($8!  '7'7.!2 c"d|jdS)NzScrollablePane()rr(s r)__repr__zScrollablePane.__repr__Ps  022r+c8|jjyN)rresetr/s r)r3zScrollablePane.resetSs r+c|jt|jS|jj|}|j r t t jd|gS|S)Nr )r!rrpreferred_widthr#rr exact)r(max_available_width content_widths r)r5zScrollablePane.preferred_widthVs_ :: ! + + 445HI     ()//!*>r+c|j}|r|jdz }n |j}|jj||jj } t | |j} t| |j} ttd|} |j| _ tdd|| } t} |jj| | | |||| jddlm} | j$j&} | j(|}|j+|j| || j,j/||j3|| |||j5|| |||j6}|j8}t |j||z|_t |j||jz|_|j;|| || jrd|_ | j,j=D]\}}d|j>cxkr|jks&n)|j@|jBcxkr|j|j@zks`nctE|j>|z|jB|z|j@z |j,|<| jFj=D]V\}}|jItE|j>|z|jB|z|j@z ||jF|<X|r|jK|| |y y #t0$rYwxYw) z Render scrollable pane content. This works by rendering on an off-screen canvas, and copying over the visible region. r  )charstyle) default_charr)xposyposr!r")get_appTxyN)&r#r!rr<r r;maxr"r:rr show_cursorrrwrite_to_screendraw_all_floatsprompt_toolkit.applicationrElayoutcurrent_window"visible_windows_to_write_positions_make_window_visiblecursor_positionsgetKeyError_copy_over_screen_copy_over_mouse_handlersrDrC_copy_over_write_positionsitemsrGr'rHrmenu_positions_clip_point_to_visible_area_draw_scrollbar)r(screenmouse_handlerswrite_position parent_styleerase_bgz_indexr# virtual_widthvirtual_height temp_screentemp_write_positiontemp_mouse_handlersrEfocused_windowvisible_win_write_posrDrCwindowpoints r)rKzScrollablePane.write_to_screenss2,,. *0014M*00M66 444 )  ^^-B-BC^T-F-FG$C|*LM "("4"4 +- ,o $$         ##% 7 ))88 $/$R$R% !  % %%%%,,00@   v{NMR && / """"6<< )=> FMM4.2G2G+GH  '' ^L  " "!%F )99??A MFEUWW3~333((77? ''$*>*>>?38ggn$9M9M(M3''/ )77==? MFE,0,L,L$%''D.4;O;O*OP-F ! !& )      i   sM M'&M'c"|j|jkr|j|j}|j|jkr|j|j}|j|j|j zk\r,|j|j|j zdz }|j|j|j zk\r,|j|j|j zdz }|S)zV Ensure that the cursor and menu positions always are always reported )rG)rHr )rGrC_replacerHrDr!r")r(rjr^s r)rZz*ScrollablePane._clip_point_to_visible_areas 77^(( (NN^%8%8N9E 77^(( (NN^%8%8N9E 77n))N,@,@@ @NN^%8%8>;O;O%ORS%SNTE 77n))N,A,AA ANN^%8%8>;P;P%PST%TNUE r+cv|j}|j}t|jD]}|j||j z}|j||z} |j ||j z} |j ||z} t|D]} || | | |z<| | vs| | | | |z<y)zU Copy over visible screen content and "zero width escape sequences". N)rDrCranger" data_bufferr'zero_width_escapes) r(r\rdr^rbrDrCrHtemp_rowrowtemp_zero_width_escapesrprGs r)rUz ScrollablePane._copy_over_screens""""~,,- NA"..q43G3G/GHH$$QX.C&1&D&DD(((' #"(!:!:1t8!D =) N ( AH //3J13M&q4x0  N Nr+c@ |j|j i d fd }|j}|j}t|jD]G}||vs||j z} ||z} t|D]} | | vs|| | | | z<Iy)z Copy over mouse handlers from virtual screen to real screen. Note: we take `virtual_width` because we don't want to copy over mouse handlers that we possibly have behind the scrollbar. c4vrdfd }|<S)z:Wrap mouse handler. Translate coordinates in `MouseEvent`.ctt|jjz |jjj zz |j |j|j}|y)NrF)position event_typebutton modifiers) rrrwrGrHr'rxryrz)event new_eventhandlerr(rCrDs r) new_handlerzYScrollablePane._copy_over_mouse_handlers..wrap_mouse_handler..new_handler.sg *!&#nn..5#nn..1E1EEL"$)#3#3$||"'//!II&r+)r{rreturnNone)r}r~mouse_handler_wrappersr(rCrDs` r)wrap_mouse_handlerzDScrollablePane._copy_over_mouse_handlers..wrap_mouse_handler*s.44 ' '3>&w/)'2 2r+N)r}rrr)rDrCr]rnr"r')r(r]rfr^rbrmouse_handlers_dicttemp_mouse_handlers_dictrHtemp_mouse_row mouse_rowrGrrCrDs` @@@r)rVz(ScrollablePane._copy_over_mouse_handlerss""""DF 3 3(-;;#6#E#E ~,,- TA,,!9!d>R>R:R!S/D9 }-TAN*.@PQAR.S !d(+T  Tr+c&|j}|j}|jjD]\\}}t |j|z|j|z|j z |j |j|j|<^y)z3 Copy over window write positions. )rCrDr"r!N)rDrCrPrXrr'r"r!)r(r\rdr^rDrCwin write_poss r)rWz)ScrollablePane._copy_over_write_positionsIs """")LLRRT NC=J^^d*^^d*T-A-AA!''oo >F 5 5c : r+c6|jjSr2)ris_modalr/s r)rzScrollablePane.is_modal\s||$$&&r+c6|jjSr2)rget_key_bindingsr/s r)rzScrollablePane.get_key_bindings_s||,,..r+c|jgSr2r.r/s r) get_childrenzScrollablePane.get_childrenbs ~r+czd}||z }|jrh|f|j}|j|z dz|jz}|j|jz } t ||}t dt || }|jrx|j|kr)|j|jz|z } |j} n(|j} |j|jz|z } t || }t || }||kDr|}|j|kDr||_ |j|kr||_ yy)a Scroll the scrollable pane, so that this window becomes visible. :param visible_height: Height of this `ScrollablePane` that is rendered. :param virtual_height: Height of the virtual, temp screen. :param visible_win_write_pos: `WritePosition` of the nested window on the temp screen. :param cursor_position: The location of the cursor position of this window on the temp screen. rNr ) rrrHrrrIr:rr"rDr') r(visible_heightrcrhcursor_position min_scroll max_scrolloffsetscpos_min_scrollcpos_max_scrollwindow_min_scrollwindow_max_scrolls r)rQz#ScrollablePane._make_window_visibleesb& #n4  # # %*--#%%6:W^^K #2"3"3gkk"A _=  C O$DE  + + -%++~=)..+223$%" %:$>$>!%:$>$>!)..+223$%" Z):;JZ):;J  "#J   * ,#-D   * ,#-D  -r+c |j}|j}|r|dz} |jt|z }|jt|z }t t |t d||zt ||zd fd }|j|jzdz } |j} |j} |r!t|jd| | | <| dz } d} d} d}d}t|D]D}d }||r||dzs|}n|}n||dzr| }n| }td || | | <| dz } F|rt|jd| | | <y y #t$rYy wxYw) z Draw the scrollbar on the screen. Note: There is some code duplication with the `ScrollbarMargin` implementation. r c*|cxkxrzkScS)z/True if we should display a button on this row.r)rrscrollbar_height scrollbar_tops r)is_scroll_buttonz8ScrollablePane._draw_scrollbar..is_scroll_buttons$O}?O/OOOOOr+zclass:scrollbar.arrowzclass:scrollbar.backgroundz*class:scrollbar.background,scrollbar.startzclass:scrollbar.buttonz$class:scrollbar.button,scrollbar.endr?N)rrintrbool)r"r$floatr'rr:rIrCr!rDrorr%rnr&ZeroDivisionError)r(r^content_heightr\ window_heightr$fraction_visiblefraction_aboverrCrDroscrollbar_backgroundscrollbar_background_startscrollbar_buttonscrollbar_button_endirArrs @@r)r[zScrollablePane._draw_scrollbars'-- ,,.  Q M7 -44u^7LL !11E.4IIN"M3q-:J*J#KL    >?M  P"&&)=)==AD!&&D ,,K*.((*A+ D!$' $@ )U &7 #I =) #A&+AE2!5 0'A. : 4*.sE*: D!$' ! &*.**,C+ D!$'Y!   sA E E+*E+)rr rzScrollOffsets | Nonerrrrr rr!r r"r r#rr$rr%strr&rrr)rr)rr)r7rrr )r!rr rrr )r\rr]rr^rr_rr`rraz int | Nonerr)rjrr^rrr) r\rrdrr^rrbrrr) r]rrfrr^rrbrrr)r\rrdrr^rrr)rr)rzKeyBindingsBase | None)rzlist[Container]) rrrcrrhrrz Point | Nonerr)r^rrrr\rrr)__name__ __module__ __qualname____doc__MAX_AVAILABLE_HEIGHTr*r0r3r5r<rKrZrUrVrWrrrrQr[rr+r)rrs7F04,048$8"#'+'+"!$!!-!* ! &2 ! " !!!%!%!!! !83  ?uu&u& u  u  uu un,9 "NNN& N  N  N61T%1T+1T& 1T  1T  1Tf+1CP &'/@.@.@. - @. & @.  @.DG+G=@GJPG Gr+N) __future__rprompt_toolkit.data_structuresrprompt_toolkit.filtersrrprompt_toolkit.key_bindingrprompt_toolkit.mouse_eventsr containersr r r=r r rrr]rrr\rrr__all__rrrr+r)rsD"0:620SS7//  [Y[r+