+
   ~5q c                   s2   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	]	P                  R&8  d   ^ R	IHt M^ R	IHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ R
IHt ]! RR4       ]! RR4       ^ RIHt ^ RIHt ^ RIHtHt ]	P6                  P9                  ^ ]P6                  P;                  ]P6                  P=                  ]4      RR4      4       ^ RI H!t! ]'       d   ^ RIH!t! ^ RI"H#t#H$t$ ]R',          t%]]&.R3,          t']]%.R3,          t(]PR                  ! R4      t*R(R R llt+R)R R llt,R*R R llt-].R8X  d   ]P^                  ! ]	P`                  R7      t1]*Pe                  ]Pf                  4       ]*Pi                  ]14        ]Pj                  ! ]Pl                  R4       ]! 4        R!R"0t9R# R$ lt:]-! R]9]:R%7       R# R#   ]Pn                   d2    ]*Pq                  R4       ]Pj                  ! ]Pl                  R 4        Lai ; i)+u   
pkginstall.py – Install missing dictionaries for ibus-typing-booster

Uses pkcon (PackageKit) via Gio.Subprocess with a Gtk3 progress dialog.
Works asynchronously and integrates smoothly with the main GTK mainloop.
)Set)Dict)List)Any)Optional)Callable)TYPE_CHECKINGN)Literal)require_versionGLibz2.0Gio)r	   )r
   )_initz..Zengine)Gtk)	add_childshow_allzibus-typing-boosterc          	      s    V ^8  d   QhR\         \        \        ,          ,          R\         \        ,          R\         \        ,          R\         \
        P                  ,          /# )   packages	on_outputon_completereturn)r   r    strOutputCallbackCompleteCallbackr
   
SubprocessZformat   "2/usr/share/ibus-typing-booster/setup/pkginstall.py__annotate__r   H   sS     I Is3x I'I *+I cnn	I    c                s<  aaaaaa	 V '       g(   \         P                  R4       S'       d	   S! R4       R# . RO\        V 4      ,           p\         P                  RRP                  V4      4       \        P
                  P                  V\        P                  P                  \        P                  P                  ,          4      p\        P                  P                  VP                  4       4      o	\        P                  P                  VP                  4       4      oRR VVV	3R llloRR VVV3R	 llloS	P                  \        P                  RSR4       SP                  \        P                  RSR4       RR
 V3R lllpVP!                  RVR4       V# )zEInstall packages asynchronously using pkcon and GLib subprocess APIs.zNo packages to install.successNzRunning command: %s c                ~    V ^8  d   QhR\         P                  R\         P                  R\        \        ,          RR/# r   _streamres_datar   Nr
   DataInputStreamAsyncResultr   r   r   r   r   r   ,install_packages_async.<locals>.__annotate__[   >     5 5$$5__5 }5 
	5r   c                 s  <  S	P                  V4      w  r4V'       d{   VP                  R RR7      P                  4       p\        P	                  RV4       S'       d   \
        P                  ! SV4       S	P                  \
        P                  RSR4       R# R#   \
        P                   d"   p\        P	                  RT4        Rp?R# Rp?ii ; i)utf-8replaceZerrorsz
[pkcon] %sNzstdout finished: %s)
read_line_finishdecodestripLOGGERdebugr	   idle_addread_line_asyncPRIORITY_DEFAULTError)
r"   r#   r$   line_lentexterrr   read_stdout_linestdout_reader
   &&&    r   r:   Z0install_packages_async.<locals>.read_stdout_line[   s    

	5&77<JD{{79{=CCE\40MM)T2--))41A4I  zz 	5LL.44	5"   B >B 9B C/CCc                r    r!   r%   r   r   r   r   r(   l   r)   r   c                 s  <  S	P                  V4      w  r4V'       d{   VP                  R RR7      P                  4       p\        P	                  RV4       S'       d   \
        P                  ! SV4       S	P                  \
        P                  RSR4       R# R#   \
        P                   d"   p\        P                  RT4        Rp?R# Rp?ii ; i)r*   r+   r,   z[pkcon:stderr] %sNzstderr finished: %s)r-   r.   r/   r0   warningr	   r2   r3   r4   r5   r1   )
r"   r#   r$   r6   r7   r8   r9   r   read_stderr_linestderr_readerr<   r   r?   Z0install_packages_async.<locals>.read_stderr_linel   s    

	5&77<JD{{79{=CCE2D9MM)T2--))41A4I  zz 	5LL.44	5r=   c                r    )r   _procr#   r$   r   N)r
   r   r'   r   r   r   r   r   r   r(      sB     K K~~K__K }K 
	Kr   c                 s"  <  V P                  V4      p\        P                  RV4       S'       d$   \        P                  ! SV'       d   RMR4       R# R#   \        P                   d#   p\        P	                  R T4       Rp Rp?LuRp?ii ; i)zpkcon failed: %sFNzpkcon finished, success=%sr   Zfailed)Zwait_check_finishr	   r5   r0   Zerrorinfor2   )rA   r#   r$   r   r9   r   s   &&&  r   	on_finishZ)install_packages_async.<locals>.on_finish   sm    
	--c2G 	0':MM+GyJ 	 zz 	LL+S1G	s   A B,B		B)ZpkconZinstallz-yN)r0   rB   Zlistjoinr
   r   ZnewZSubprocessFlagsZSTDOUT_PIPEZSTDERR_PIPEr&   Zget_stdout_pipeZget_stderr_piper3   r	   r4   Zwait_check_async)
r   r   r   ZargsZprocrC   r?   r:   r@   r;   s
   &ff   @@@@r   install_packages_asyncrF   H   s7    -.	"%X6D
KK%sxx~6>>''#*=*=*I*IIKD ''++D,@,@,BCM''++D,@,@,BCM5 5"5 5" !!t%5t=!!t%5t=K K 	$	40Kr   c          
      s    V ^8  d   QhR\         \        ,          R\        \        ,          R\        \        ,          R\
        . R3,          /# )r   r   r   r   r   N)r    r   r   r   r   r   r   r   r   r   r      sN     A A#hA'A *+A b$h	Ar   c           	     s|   aaaaaaa \        V 4      o/ oRoRoR VVV3R llpRR VVVVVVV3R llloS! 4        V# )zInstall packages sequentially using pkcon, one by one.

This avoids the 'already installed' fatal error that breaks multi-install.
NFc                s    V ^8  d   QhRR/# )r   r   N r   r   r   r   9install_packages_sequentially_async.<locals>.__annotate__   s     % %D %r   c                 s<  < RoS'       dG    SP                  4       p \        P                  RV 4       SP                  \        P
                  4       S'       d   S! R4       R# R#   \        P                   d!   p\        P                  RT4        Rp?LDRp?ii ; i)z Cancel the current pkcon processTzCancelling pkcon (pid=%r)...z#Failed to send SIGTERM to pkcon: %sN	cancelled)	Zget_identifierr0   rB   Zsend_signalsignalZSIGTERMr	   r5   r>   )Zpidr9   rI   current_procr   s     r   cancelZ3install_packages_sequentially_async.<locals>.cancel   s~     	K"113:C@((8 $  :: KDcJJKs   AA& &B;BBc                (    V ^8  d   QhR\         RR/# )r   indexr   N)intr   r   r   r   rH      s     "I "IC "I "Ir   c                s  <a a S'       d   \         P                  RS 4       R# S \        S
4      8  dL   \        SP	                  4       4      p\         P                  RS4       S'       d   S! V'       d   RMR4       R# S
S ,          o\         P                  RSS ^,           \        S
4      4       S	'       d   S	! RS R24       R	 V	V3R
 llpR V VV	VV3R llp\        S0W#R7      oR# )zInstall the next packagez)Installation cancelled before package #%dNzAll installations done: %sr   failurezInstalling package %s (%d/%d)zInstalling z...c                rM   r   r6   r   Nr   r   r   r   r   Oinstall_packages_sequentially_async.<locals>.install_next.<locals>.__annotate__   s     	- 	- 	- 	-r   c                s8   < S'       d   S! RS RV  24       R# R# )z/Call on_output and prefix each line for clarityZ[z] NrG   )r6   r   pkg   &r   handle_outputZPinstall_packages_sequentially_async.<locals>.install_next.<locals>.handle_output   s     AcU"TF+, r   c                rM   r   statusr   NInstallStatusr   r   r   r   rS      s     		$ 		$M 		$d 		$r   c                sr   < V R8H  SS&   S'       d   S! S RV R8X  d   RMR 24       S! S^,           4       R# )zCalled when one package is completed

Puts easily parsable lines into the output to make it
easy for dialog to update the progress.
r   r      ✔️   ⚠️NrG   )rX   rN   install_nextr   rT   resultss   &r   handle_completeZRinstall_packages_sequentially_async.<locals>.install_next.<locals>.handle_complete   s?     "Y.GCLSEv/B8"QRS#r   r   r   )r0   rB   lenZallZvaluesrF   )rN   r   rV   r_   rT   rI   rK   r]   r   r   package_listr^   s   f   @r   r]   Z9install_packages_sequentially_async.<locals>.install_next   s     KKCUKC%%'..*+GKK4g>Ii@5!3S%!)SEVWC5,-	- 	-
		$ 		$ .E]Ir   )i    )Zsorted)	r   r   r   rL   rI   rK   r]   rb   r^   s	   &ff @@@@@r   #install_packages_sequentially_asyncrc      sG     %X.L!G-1LI% %"I "I "IH NMr   c                s    V ^8  d   QhR\         \        P                  ,          R\        \        ,          R\         \
        ,          RR/# )r   parentr   r   r   N)r   r   ZWindowr    r   r   r   r   r   r   r      sI     C CSZZ C#hC *+C 
	Cr   c                s  aa
aaaaaaaaaaaaaa \         P                  ! R\        R4      ,           V RRR7      oSP                  RR4       SP	                  4       p\         P
                  ! RR7      oSP                  ^ 4       \        VS4       \         P                  ! 4       oSP                  R	4       SP                  \         P                  P                  4       SP                  4       o\         P                  ! 4       pVP                  R4       VP!                  \         P"                  P$                  \         P"                  P$                  4       \        VS4       \        W44       \         P&                  ! 4       oSP)                  R4       SP+                  R
4       \        VS4       \         P,                  ! 4       pVP/                  \         P0                  P2                  4       VP5                  \         P6                  P8                  4       VP;                  \         P6                  P<                  4       VP?                  R	4       VPA                  R4       VP                  R	4       VPC                  ^ 4       \        W54       \         PD                  PG                  \        R4      4      o
\        VS
4       \         PD                  PG                  \        R4      4      o\        VS4       \I        S4       SPK                  4        ^ o\M        V4      o^ o^ o^ o\N        PP                  ! R4      oRoR VVVVVVVVVV3
R llpR V
VVVV3R llpR V
VV3R llpR VV3R llp	S
PS                  RV4       SPS                  RV	4       \U        WVR7      oRo\V        PX                  ! 4       ^ 8  d   R# \V        PZ                  ! 4       oSP]                  4        SP_                  4        R# )z?Show a transient GTK dialog to install packages asynchronously.u   📦 zInstall missing dictionariesT)ZtitleZtransient_forZmodalZdestroy_with_parenti  i@   )ZlabelFz0%Z_CancelZ_Closez(\d{1,3})\s*$Nc                rM   rQ   rR   r   r   r   r   2install_packages_with_dialog.<locals>.__annotate__  s     !J !J# !J$ !Jr   c                sv  <
 SP                  4       pSP                  WR,           4       SP                  SP                  4       4       SP	                  V 4      pV'       d    \        VP                  ^4      4      p^ Tu;8:  d   ^d8:  dw   M MtVS	8  d   SVS	,
          ,          oVo	S
P                  SS,           S^,          ,          4       S
P                  \        SS,           S^,          ,          4       R24       R#  RV 9   g   RV 9   d   S^,          o^ oS^,          oS
P                  SS^,          ,          4       S
P                  \        SS^,          ,          4       R24       SP                  4       pRpSP                  V'       d	   WE,           MR V  24       R# R#   \         d     Li ; i)z9Append a line to the textbuffer showing detailed progressZ
Z%Nr[   r\   re   )get_end_iterinsertZscroll_mark_onscreenZ
get_insertZsearchrO   Zgroupset_fractionset_textZ
ValueErrorZget_text)r6   endZmatchZpercentr8   Znewlinepackage_countpackage_index
percent_rephase_percentprogressbarsummed_phase_percent
textbuffertextview	top_labeltotal_percents   &     r   append_lineZ1install_packages_with_dialog.<locals>.append_line  s    %%'#d{+%%j&;&;&=>!!$'ekk!n-&3&.,-0GG,$+M,,&)==-RUBUVX((0D DYZIZ[\]]^_a ' tx4/QM#$ )C/M$$]mc6I%JK  C9J(K$L#MQ!OP%%'DGD$.b!A$HI  0  s   #+F* A1F* *F87F8c                rM   rW   rY   r   r   r   r   rf   .  s        }    r   c                sX  < V R8X  d$   SP                  R4       SP                  R4       MLV R8X  d$   SP                  4       pSP                  VR4       M"SP                  4       pSP                  VR4       SP	                  4        SP                  4        S'       d   S! V 4       R# R# )z3Installation of all packages finished or cancelled.r   g      ?z100%rI   u'   ⚠️ Installation cancelled by user.
u   ❌ There were some failures.
N)ri   rj   rg   rh   hideshow)rX   rk   cancel_buttonclose_buttonr   rp   rr   s   & r   finishZ,install_packages_with_dialog.<locals>.finish.  s    Y$$S)  ({"))+Cc#MN))+Cc#DE r   c                <    V ^8  d   QhR\         P                  RR/# r   _buttonr   Nr   Buttonr   r   r   r   rf   >  s      3:: $ r   c                s   < Se   \        S4      '       d   S! 4        SP                  4        SP                  4        R# )zCancel button clickedN)Zcallablerw   rx   )r~   ry   cancel_funcrz   s   &r   	on_cancelZ/install_packages_with_dialog.<locals>.on_cancel>  s2     "x'<'<Mr   c                r|   r}   r   r   r   r   r   rf   F  s      #**  r   c                s|   < Se'   SP                  4       '       d   SP                  4        SP                  4        R# )zClose button clickedN)Z
is_runningZquitdestroy)r~   dialogglib_main_looprU   r   on_closeZ.install_packages_with_dialog.<locals>.on_closeF  s-    %.*C*C*E*E!r   Zclickedr`   )0r   ZDialogr   Zset_default_sizeZget_content_areaZLabelZ
set_xalignr   ZTextViewZset_editableZset_wrap_modeZWrapModeZ	WORD_CHARZ
get_bufferZScrolledWindowZset_vexpandZ
set_policyZ
PolicyTypeZ	AUTOMATICZProgressBarZset_show_textrj   ZBoxZset_orientationZOrientationZ
HORIZONTALZ
set_halignZAlignZENDZ
set_valignZCENTERZset_can_focusZset_hexpandZset_spacingr   Znew_with_mnemonicr   rw   ra   reZcompileZconnectrc   r	   Z
main_depthZMainLoopZrunr   )rd   r   r   ZvboxZscrolledZaction_arearv   r{   r   r   ry   r   rz   r   r   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   s   &&f       @@@@@@@@@@@@@@@r   install_packages_with_dialogr      s    ZZ899 	"F
 C%""$D		#IdI||~H% 3<<112$$&J!!#H00#..2J2JKh!d//#Kd#dK '')K : :;399==)399++,e$D!E"Ad JJ009>Mk=):://(<Lk<(VMMMMM,-J04K!J !J !JF       )Y/H-5V=K.2N 1]]_N
NNr   Z__main__)Zstreamre   z.IBUS-WARNING **: Using the fallback 'C' localeZCzhunspell-dezhunspell-frc                rM   rW   rY   r   r   r   r   r   i  s     9 9M 9d 9r   c                s    V R8X  d   \         P                  R4       R# V R8X  d   \         P                  R4       R# \         P                  R4       R# )z&Called when the installation completesr   z!Install completed without errors.rI   u&   ⚠️ Installation cancelled by user.u   ❌ There were some failures.N)r0   rB   )rX   s   &r   finish_testr   i  s9    YKK;<{"KK@AKK78r   )r   )i   i   )r   rI   rP   )NNN)NNrD   );Z__doc__Ztypingr    r   r   r   r   r   r   ZsysZversion_infor   Ztyping_extensionsZosr   rJ   ZlocaleZloggingZgir   Zgi.repositoryr	   r
   Zi18nr   r   Z	i18n_initZpathrh   rE   ZdirnameZ__file__Zitb_gtkr   Zg_compat_helpersr   r   rZ   r   r   r   Z	getLoggerr0   rF   rc   r   Z__name__ZStreamHandlerZstderrZLOG_HANDLERZsetLevelZDEBUGZ
addHandlerZ	setlocaleZLC_ALLr5   Z	exceptionZmissingr   rG   r   r   <module>r      s  &         
v) 	 	       u    % 277<< 94J K  "
 9:3%+&]OT12 			0	1IVAFCJ z''szz:K
OOGMM"
k"-+ Km,G9 !wKH/  << -IJ,-s   G ?HH