+
   ϗ䪖c                   s  a  R) tP0 t R t^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ R	IHt ]! R
R4       ^ RIHt ]P.                  ! R4       ^ RIt^ RIHtHt ]'       d   ^ RIHt ^ RIHtHtHtH t  ]PB                  ! R4      t"Rt#] ^ k Rt$R R lt%R R lt&R R lt'R R lt(](! 4       t) ! R R]PT                  4      t+ ! R R4      t,],! 4       t-] ^k R*R R llt.]/R 8X  Ed   ])P`                  '       g   ]Pb                  ! 4       t2Ml]Pf                  ! ]Ph                  R!7      t5]Pl                  ! R"4      t7]5Pq                  ]74       ]"Ps                  ]Pt                  4       ]"Pw                  ]54        ]Px                  ! ]Pz                  R#4       ]P                  ! R&4      tA]P                  ! ]$]A4       ])P                  e   ]+! ])P                  R'7      tD]P                  ! 4       t#]P                  ! ]P                  ]P                  ]-P                  R4       ]P                  ! ]P                  ]P                  ]-P                  R4        ]#P                  4        R# R# R#   ]P|                   d3    ]"P                  R$4       ]Px                  ! ]Pz                  R%4        ELi ; i  ]M d&    ]"P                  R(4       ]#P                  4         R# i ; i)+z&
A module with utilites to use ollama
)Optional)List)Dict)UnionAny)TYPE_CHECKING)	FrameTypeN)require_versionGLibz2.0)r	   Ollama Pull)Gtk	GTK_MAJOR)r   )	add_childset_border_widthshow_allCompatButtonzibus-typing-boosterc                0    V ^8  d   QhR\         R\         /#    textreturnstrformat   "4/usr/share/ibus-typing-booster/engine/ollama_pull.py__annotate__r   F   s     . .C .C .    c                s8    \         P                  ! \        V 4      # )zGettext translation function.)gettextZdgettext
DOMAINNAMEr      &r   _r"   F   s    J--r   c                r   r   r   r   r   r   r   r   J   s      S S r   c                s    V # )z{Mark string for translation without actually translating.

Used by gettext tools to extract strings that need translation.
 r    r!   r   N_r$   J   s	    
 Kr   c                sR    V ^8  d   QhR\         \        \        3,          R\        /# )r   vr   )r   boolr   r   r   r   r   r   Q   s'     
@ 
@dCi  
@T 
@r   c                s    \        V \        4      '       d   V # V P                  4       R9   d   R# V P                  4       R9   d   R# \        P                  ! R4      h)z-
Convert a string to a boolean for argparse.
TFzBoolean value expected.)ZyesZtrueZtZ1)ZnoZfalseZfZ0)Z
isinstancer&   ZlowerargparseZArgumentTypeError)r%   r!   r   str2boolr(   Q   sL     !Twwy--wwy--

$
$%>
??r   c                s$    V ^8  d   QhR\         /# r   r   r   r   r   r   r   r   ]   s      C r   c                 s    \         P                  ! RR7      p V P                  RRR\        RRRR	7       V P                  R
RR\        RRRRR7       V P                  4       # )z#
Parse the command line arguments.
z1UI to show progress while pulling a ollama model.)Zdescriptionz-mz--modelZ?ZstoreNz0Choose the model to pull. default: "%(default)s")nargstypeactiondefaulthelpz-dz--debugTFz7Print some debug output to stdout. default: %(default)s)r*   r+   r,   Zconstr-   r.   )r'   ZArgumentParserZadd_argumentr   r(   
parse_args)Zparsers    r   r/   r/   ]   s     $$GIF
i'  ) i%  ' r   c                   s   a  ] tR t^xt o RtRV 3R lR lltV 3R lR ltV 3R lR ltV 3R lR	 lt]	V 3R
 lR l4       t
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )OllamaPullUIz3
UI to show progress while pulling a ollama model.
c                $   < V ^8  d   QhRS[ RR/# )r   modelr   Nr   r   __classdict__   "r   r   OllamaPullUI.__annotate__|   s     ;" ;"c ;"4 ;"r   c                s(	   Wn         V P                   R 8X  d   \        R4      hRV n        \        P                  ! 4       V n        R V n        . V n        . V n        RV P                    2p\        P                  P                  WR7       V P                  V4       V P                  R4       V P                  R4       \        ^8  d   V P!                  RV P"                  4       MV P!                  RV P"                  4       \        P$                  ! 4       pVP'                  \        P(                  P*                  4       VP-                  ^ 4       VP/                  R4       VP1                  R4       \3        W4       \        P4                  ! 4       V n        V P6                  P9                  R4       V P6                  P;                  R	4       \=        V P6                  ^4       V P6                  P?                  ^4       V P6                  PA                  ^
4       V P6                  PC                  R	4       V P6                  PE                  R	4       V P6                  P/                  R4       V P6                  P1                  R	4       RV n#        \3        W0P6                  4       \        P$                  ! 4       pVP'                  \        P(                  PH                  4       VP9                  R4       VP;                  R	4       VP/                  R4       VP1                  R	4       VP-                  ^ 4       \3        W44       \        PJ                  ! 4       pVP/                  R4       VP1                  R	4       \3        WE4       \M        \O        R
4      RR7      V n(        V PP                  P!                  RV PR                  4       \3        W@PP                  4       \M        \O        R4      RR7      V n*        V PT                  P!                  RV PV                  4       \3        W@PT                  4       \Y        V 4       V PT                  P9                  R	4       \Z        P\                  ! ^V P^                  4       \Z        P`                  ! V Pb                  4       R# ) zModel name should not be empty.Nu   📥 )titler
   Tzclose-requestzdelete-eventFZ_Cancel)ZlabelZuse_underlineZclickedZ_Close)2_model
ValueError_thread	threadingZEvent_stop_event_status_status_labels_status_progress_barsr   Window__init__Z	set_titleZset_nameZ	set_modalr   Zconnect	_on_closeZBoxZset_orientationZOrientationZVERTICALZset_spacingZset_hexpandset_vexpandr   ZGrid_progress_gridset_visibleZset_can_focusr   Zset_row_spacingZset_column_spacingZset_row_homogeneousZset_column_homogeneous_rowZ
HORIZONTALLabelr   r"   _cancel_button_on_cancel_clicked_close_button_on_close_clickedr   r	   Ztimeout_add_check_for_interruptidle_add_pull)selfr2   r8   Zmain_containerZdialog_action_areaZempty_hexpanding_labels   &&    r   rC   ZOllamaPullUI.__init__|   sN   ;;">??37,5OO,=/1<>"}%

D.um$t>LL$..9LL8&&s'?'?@""1%""4(""4($'!hhj''-))%0,,a0++A...r2//62259''-''.	."5"56 WWY**3??+E+EF&&t,((/&&t,&&u-&&q).5!$**40**51$=*I,d4##It/F/FG$&9&9:)H+T3""9d.D.DE$&8&89&&u-d778djj!r   c                   < V ^8  d   QhRR/# r   r   Nr#   r3   r5   r   r   r6      s     	 	t 	r   c                sN   \         P                  ! 4       pV P                  '       d   V P                  P                  4        \        P
                  ! RVP                  V P                  V P                  V P                  3R7      V n	        V P                  P                  4        R# )zPull the requested modelT)ZdaemonZtargetZargsN)
itb_ollamaZItbOllamaClientr>   clearr=   ZThreadZpullr:   _pull_progress_idle_addr<   Zstart)rQ   Zollama_clients   & r   rP   ZOllamaPullUI._pull   sy    "224""$ '' %%++t;;T=M=MNP 	r   c                :   < V ^8  d   QhRS[ S[S[3,          RR/# r   progressr   Nr   r   r   r3   r5   r   r   r6      s#     5 5S#X 54 5r   c                s@   a a \         P                  ! VV 3R l4       R# )z>Schedule an update of the progress of pulling the ollama modelc                  s&   < SP                  S 4      # N)_pull_progress)rY   rQ   s   r   Z<lambda>Z6OllamaPullUI._pull_progress_idle_add.<locals>.<lambda>   s    ))(3r   N)r	   rO   )rQ   rY   s   ffr   rV   Z$OllamaPullUI._pull_progress_idle_add   s     4 	5r   c                rW   rX   rZ   r3   r5   r   r   r6      s#     ?1 ?1tCH~ ?1$ ?1r   c                s   VP                  RR4      pVP                  RR4      pVP                  RR4      pVP                  RR4      pVe   \        P                  RV P                  V4       \        P
                  ! 4       pVP                  V4       VP                  ^ 4       V P                  P                  V^V P                  ^^4       VP                  R4       V P                  P                  R4       V P                  P                  R4       R# VEe   WPP                  8w  Ed   WPn        V ;P                  ^,          un
        V P                  P!                  \        P
                  ! 4       4       V P                  V P                  ,          P                  ^ 4       V P                  P                  V P                  V P                  ,          ^ V P                  ^^4       V P                  V P                  ,          P                  R4       V P"                  P!                  \        P$                  ! 4       4       V P"                  V P                  ,          P'                  R4       V P"                  V P                  ,          P)                  ^ 4       V P"                  V P                  ,          P+                  ^R4       V P"                  V P                  ,          P-                  R4       V P"                  V P                  ,          P/                  \        P0                  P2                  4       V P"                  V P                  ,          P5                  ^
4       V P"                  V P                  ,          P7                  ^
4       V P                  P                  V P"                  V P                  ,          ^V P                  ^^4       V P"                  V P                  ,          P                  R4       VEe]   VEeX   VR	8  d   \9        WC,          4      MR	pVe   TMR
pV R2p	VR8  d   VR,          R R2p	M)VR8  d   VR,          R R2p	MVR8  d   VR,          R R2p	\        P;                  RW^dV,          4       V P                  V P                  ,          e>   V P                  V P                  ,          P                  V RV	 R^dV,          R R24       V P"                  V P                  ,          eY   V P"                  V P                  ,          P                  R4       V P"                  V P                  ,          P=                  V4       MeVeb   \        P;                  RV4       V P                  V P                  ,          e-   V P                  V P                  ,          P                  V4       VR8X  d9   V P                  P                  R4       V P                  P                  R4       R# R# )z-Show the progress of pulling the ollama modelerrorNtotal	completedstatuszError pulling %r: %rTFg        r7   z Bi   z.1fz GBz MBz kBz%r: %r (%.1f%%)z: z (z%)z%rZsuccessr9   i   @i   )ZgetLOGGERr]   r:   r   rI   Zset_textZ
set_xalignrF   ZattachrH   rG   rJ   rL   r?   r@   ZappendrA   ZProgressBarZset_show_textZset_pulse_stepZset_size_requestrE   Z
set_valignZAlignZCENTERZset_margin_startZset_margin_endZfloatinfoZset_fraction)
rQ   rY   r]   r^   r_   r`   Zerror_labelZfractionZstatus_textZ
total_texts
   &&        r   r\   ZOllamaPullUI._pull_progress   s   Wd+Wd+LLd3	h-LL/eD))+K  '""1%&&Q		1a1##D)++E2**40&LL"8!LIINI&&syy{3		*55a8&&##DII.499a$ 		*66t<&&--coo.?@&&tyy1??F&&tyy1@@C&&tyy1BB3K&&tyy1==dC&&tyy1<<SYY=M=MN&&tyy1BB2F&&tyy1@@D&&**4995499a$ &&tyy1==eD!6383;uY./CH$*$6&BK!7"Jw %4C8
 %4C8
 %S15
KK)x9""499-9##DII.77"m2j\C(N33GrJL))$))4@**4995AA$G**4995BB8LKKf%""499-9##DII.77?Y++E2**40 r   c                rR   rS   r#   r3   r5   r   r   r6     s     B B4 Br   c                 s~    \         P                  R4       \        e   \        P                  4        R# \	        R4      h)zQuit the GLib main loopzQuit GLib main loopNGLIB_MAIN_LOOP not initialized!)ra   rb   GLIB_MAIN_LOOPquitRuntimeErrorr#   r   r   _quitZOllamaPullUI._quit
  s/     	)*%!@AAr   c                r1   r   _argsr   Nr   r3   r5   r   r   r6     s        r   c                    \         P                  R4       V P                  4        V P                  P	                  4        R# )z;The window has been closed, probably by the window manager.z%Window deleted by the window manager.Nra   rb   _cancel_pull	__class__rg   rQ   ri      &*r   rD   ZOllamaPullUI._on_close  s+    ;<r   c                rR   rS   r#   r3   r5   r   r   r6     s     - -d -r   c                s&   V P                   '       g   \        P                  R4       R# V P                  '       g   \        P                  R4       R# V P                   P	                  4       '       dH   V P                  P                  4        V P                   P                  4        V P                  RR/4       V P                  P                  4        RV n         V P                  P                  R4       V P                  P                  R4       R# )zCancel a running pullzNo thread, cannot cancel.NzNo stop event, cannot cancel.r`   Z	cancelledFT)r<   ra   rb   r>   Zis_aliveZsetZjoinr\   rU   rJ   rG   rL   rQ   r!   r   rl   ZOllamaPullUI._cancel_pull  s    |||KK34KK78<<  ""  "LL; 78 ''.&&t,r   c                r1   rh   r   r3   r5   r   r   r6   *  s        r   c                sP    \         P                  R4       V P                  4        R# )z&The button to cancel has been clicked.zCancel button clicked.N)ra   rb   rl   rn   ro   r   rK   ZOllamaPullUI._on_cancel_clicked*  s    ,-r   c                r1   rh   r   r3   r5   r   r   r6   /  s        r   c                rj   )z"The close button has been clicked.zClose clicked.Nrk   rn   ro   r   rM   ZOllamaPullUI._on_close_clicked/  s+    $%r   c                    < V ^8  d   QhRS[ /# r)   r&   r3   r5   r   r   r6   5  s      d r   c                s    \         P                  '       dB   \        P                  R4       V P	                  4        V P
                  P                  4        R# R# )z6Checks for interrupts. Is called by GLib.timeout_add()z%Interrupt requested, shutting down...FT)SIGNAL_HANDLERinterrupt_requestedra   rb   rl   rm   rg   rp   r!   r   rN   Z!OllamaPullUI._check_for_interrupt5  s=    ---KK?@NN  "r   )
rJ   rL   r:   rF   rH   r?   r@   rA   r>   r<   N)r7   )__name__
__module____qualname____firstlineno____doc__rC   rP   rV   r\   Zstaticmethodrg   rD   rl   rK   rM   rN   __static_attributes____classdictcell__r4      @r   r0   r0   x   s|     ;" ;"z	 	5 5
?1 ?1B B B - -" 
  r   r0   c                   sv   a  ] tR tRt o RtV 3R lR lt]V 3R lR l4       tV 3R lR ltV 3R	 lR
 lt	Rt
V tR# )SignalHandleri>  u  Thread-safe signal handler for interrupt requests (e.g., Ctrl+C).

This class provides a safe way to check and set an interrupt flag
from multiple threads.  It is designed to work with GLib’s signal
handling (e.g., `GLib.unix_signal_add()`) while preventing race
conditions during access.

Attributes:
    interrupt_requested (bool):
        Read-only property indicating whether an interrupt
        (e.g., SIGINT/Ctrl+C) was triggered. Thread-safe.
c                rR   rS   r#   r3   r5   r   r   SignalHandler.__annotate__K  s     & &$ &r   c                sH    RV n         \        P                  ! 4       V n        R# )zInit the signal handler class.FN)_interrupt_requestedr=   ZLock_lockrp   r!   r   rC   ZSignalHandler.__init__K  s    */!^^%
r   c                rq   r)   rr   r3   r5   r   r   r   Q  s     - -T -r   c                s    V P                   ;_uu_ 4        V P                  uuRRR4       #   + '       g   i     R# ; i)zGCheck if an interrupt was requested with thread-safe
read-only access.
N)r   r   rp   r!   r   rt   Z!SignalHandler.interrupt_requestedP  s"    
 ZZZ,, ZZZs   ,=	c                &   < V ^8  d   QhRS[ RS[/# r   ri   r   r   r&   r3   r5   r   r   r   X  s     	 	C 	D 	r   c                    \         P                  R4       V P                  ;_uu_ 4        RV n        RRR4       R#   + '       g   i     R# ; i)zqCallback for Ctrl+C (SIGINT).

:return: bool: True to keep the handler alive,
               False to remove it.
SIGINTTNra   rb   r   r   rn   ro   r   handle_sigintZSignalHandler.handle_sigintX  s4     	HZZZ(,D%  Z	   <A	c                r   r   r   r3   r5   r   r   r   c  s     	 	S 	T 	r   c                r   )zrCallback for Ctrl+C (SIGTERM).

:return: bool: True to keep the handler alive,
               False to remove it.
SIGTERMTNr   rn   ro   r   handle_sigtermZSignalHandler.handle_sigtermc  s4     	IZZZ(,D%  Zr   )r   r   N)ru   rv   rw   rx   ry   rC   Zpropertyrt   r   r   rz   r{   r|   r}   r   r~   r~   >  s<     & &
 - -	 		 	r   r~   c                sJ    V ^8  d   QhR\         R\        \        ,          RR/# )r   signum_framer   N)Zintr    r   r   r   r   r   r   p  s)     > >>%i0><@>r   c                s   V e8    \         P                  ! V 4      P                  p\
        P                  RW4       \        e   \        P                  4        R# \        R4      h  \         d    \	        T 4      p LWi ; i)u   Signal handler for signals from Python’s signal module

:param signum: The signal number
:param _frame:  Almost never used (it’s for debugging).
Nz#Received signal %s (%s), exiting...rc   )
signalZSignalsZnamer;   r   ra   rb   rd   re   rf   )r   r   Zsignal_names   && r   quit_glib_main_loopr   p  sl     	& ..055K 	96O!<==  	&f+K	&s    A% %A>=A>Z__main__)ZstreamzP%(asctime)s %(filename)s line %(lineno)d %(funcName)s %(levelname)s: %(message)sr7   z.IBUS-WARNING **: Using the fallback 'C' localeZCZIBUS_LOCALEDIR)r2   zControl+C pressed, exiting ...c                s    V ^8  d   Qh/ ^ \         9   d   \        \        P                  ,          ;R&   ^\         9   d
   \        ;R&   # )r   rd   rs   )__conditional_annotations__r    r	   MainLoopr~   r   r   r   r   r      s=      ^ / .' ._v
 0 / /w
r   r[   )Qr   ry   Ztypingr    r   r   r   r   r   Ztypesr   ZsysZosr   r'   Zlocaler=   r   ZloggingZgir   Zgi.repositoryr	   Zset_application_namerT   Zitb_gtkr   r   Zg_compat_helpersr   r   r   r   Z	getLoggerra   rd   r   r"   r$   r(   r/   Z_ARGSrB   r0   r~   rs   r   ru   ZdebugZNullHandlerZLOG_HANDLER_NULLZStreamHandlerZstdoutZLOG_HANDLER_STREAMZ	FormatterZLOG_FORMATTERZsetFormatterZsetLevelZDEBUGZ
addHandlerZ	setlocaleZLC_ALLZErrorr]   ZgetenvZ	LOCALEDIRZbindtextdomainr2   ZOLLAMA_PULL_UIr   Zunix_signal_addZPRIORITY_DEFAULTr   r   r   r   ZrunZKeyboardInterruptrb   re   r   )r   r}   r   <module>r      s  &         
 	          
   - (  " "  
		0	1*. ."
.
@2 	D3:: DL. .` !. />& z;;;"..0$22#**E)) 	''6&,--+
 		*+I:y1{{%EKK8 	!!NN))		
 	!!MM((		
	" # -  << -EF,-2 ! 	"KK89!	"s$   $J ?K ?KK(LL