
    Je;                        d Z ddlZddlmZmZmZmZ ddlmZ ddl	m
Z
mZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZmZ ddl m!Z! dZ"dZ#ejH                  dk(  Z% G d de      Z& G d de      Z' G d de      Z( G d de      Z)e*dk(  r6ddl+m,Z,  e,       Z- e(d      Z.e.j_                          e-ja                          yy)zKite installation widget.    N)QEventQObjectQtSignal)QPixmap)	QApplicationQDialogQHBoxLayoutQMessageBoxQLabelQProgressBarQPushButtonQVBoxLayoutQWidget)_)get_image_path)ima)QStylePalette)ERRORED
INSTALLINGFINISHED	CANCELLED)DialogStylez$https://kite.com/integrations/spyderzhttps://kite.com/contact/darwinc                   >     e Zd ZdZ e       Z e       Z fdZ xZS )KiteIntegrationInfoz9Initial Widget with info about the integration with Kite.c                 h
   t         t        |   |       t               }d}t	        |      }t        |      }t               }t               }t        |j                         t        j                  z        }t        |j                         t        j                  z        }|j                  ||t        j                  t        j                        }|j!                  |       |j#                          |j%                  |       |j#                          t               }	|	j'                  |       t        d      }
|
j)                  dt        j*                          |
j-                  d       t        t/        d      j1                  t2                    }|j)                  dt        j4                          |j7                  d       |j-                  d       |j9                  d       t;               }|j%                  |
       |j%                  |       t<        j>                  }t<        j@                  }t<        jB                  }t<        jD                  }t<        jF                  }t<        jH                  }t<        jJ                  }t               }tM        t/        d            }|jO                  d	       |j)                  d
j1                  ||t        jP                  |t        jR                  ||             tM        t/        d            }|jO                  d	       |j)                  d
j1                  ||t        jP                  |t        jR                  ||             |j#                          |j%                  |       tT        s|jW                  d       |j%                  |       t;               }tT        sT|j#                          |j'                  |       |jW                  d       |j'                  |       |j#                          n"|j'                  |       |j'                  |       t               }|j#                          |j'                  |	       |jW                  d       |j'                  |       |j#                          | jY                  |       |jZ                  j]                  | j^                         |jZ                  j]                  | j`                         | j)                  dt<        jb                          | je                  dddd       tT        s| jg                  dd       y y )Nkite_completionsz%Get better code completions in Spyderzfont-size: Ta
  Now Spyder can use Kite to provide better code completions for key packages in the scientific Python Ecosystem. Install Kite for a better editor experience in Spyder. <br><br>Kite is free to use but is not open source. <a href="{kite_url}">Learn more about Kite </a>)kite_urlih  zInstall KiteFa	  QPushButton {{ background-color: {background_color};border-color: {border_color};font-size: {font_size};color: {font_color};padding: {padding}}}QPushButton:hover:!pressed {{ background-color: {color_hover}}}QPushButton:pressed {{ background-color: {color_pressed}}})background_colorborder_color	font_size
font_colorpaddingcolor_hovercolor_pressedDismiss
         background-color:    (   i   i^  )4superr   __init__r
   r   r   r   intheightr   IconScaleFactorwidthscaledr   KeepAspectRatioSmoothTransformation	setPixmap
addStretch	addWidget	addLayoutsetStyleSheetTitleFontSizesetWordWrapr   formatKITE_SPYDER_URLContentFontSizesetOpenExternalLinkssetFixedWidthr   r   COLOR_ACCENT_2COLOR_ACCENT_3COLOR_ACCENT_4COLOR_BACKGROUND_4COLOR_BACKGROUND_5COLOR_BACKGROUND_6COLOR_TEXT_1r   setAutoDefaultButtonsFontSizeButtonsPaddingMAC
addSpacing	setLayoutclickedconnectsig_install_button_clickedsig_dismiss_button_clickedCOLOR_BACKGROUND_2setContentsMarginssetFixedSize)selfparentimages_layouticon_filename
image_pathimageimage_labelimage_heightimage_widthilayoutintegration_label_titleintegration_labellabel_layoutinstall_button_colorinstall_button_hoverinstall_button_presseddismiss_button_colordismiss_button_hoverdismiss_button_pressedr#   buttons_layoutinstall_buttondismiss_buttonvertical_layoutgeneral_layout	__class__s                            Z/usr/lib/python3/dist-packages/spyder/plugins/completion/providers/kite/widgets/install.pyr/   zKiteIntegrationInfo.__init__)   sU   !41&9#*#M2

#hh5<<>K,G,GGH%++-+*E*EEF[,8J8J446e$  ",  "--( #)2#4--2234	6++D1" J K
 V_V-/ 	''+5567	9..t4%%d+'',"}6701  -;;,;;!.!=!=,??,??!.!A!A"//
$$Q~%67%%e,$$	0 &"62&66&$3315  7	8$ %Qy\2%%e,$$	0 &"62&66&$3315  7	8$ 	!!#  0%%b)  0 &-&&(%%l3&&r*%%n5&&(%%l3%%n5$!!#  )!!"%  1!!#~& 	&&t'F'FG&&t'F'FG !A!A BC	EBB/c3'     )	__name__
__module____qualname____doc__r   rR   rS   r/   __classcell__ro   s   @rp   r   r   "   s"    C!'!'@( @(rq   r   c                   >     e Zd ZdZ e       Z e       Z fdZ xZS )HoverEventFilterz"QObject to handle event filtering.c                    |j                         t        j                  k(  r| j                  j	                          n;|j                         t        j
                  k(  r| j                  j	                          t        t        | '  ||      S )zReimplemented Qt method.)
typer   
HoverEntersig_hover_enteremit
HoverLeavesig_hover_leaver.   ry   eventFilter)rW   widgeteventro   s      rp   r   zHoverEventFilter.eventFilter   sd    ::<6,,,  %%'ZZ\V...  %%'%t8GGrq   )	rr   rs   rt   ru   r   r}   r   r   rv   rw   s   @rp   ry   ry      s     ,hOhOH Hrq   ry   c                   .     e Zd ZdZ fdZd Zd Z xZS )KiteInstallationz"Kite progress installation widget.c                 $   t         t        |   |       t               }t	               }t        |       | _        | j                  j                  d       t               | _	        t        |       | _        | j                  j                  d       | j                  j                  | j                         t               | _        | j                  j!                  t#        j$                  d             | j                  j'                          |j)                  | j                  t*        j,                         |j)                  | j                         | j                  j/                  |       t1        t3        d            | _        t1        t3        d            }t	               }t        t3        d            | _        |j9                          |j)                  | j6                         |j9                          |j9                          |j)                  | j4                         |j)                  | j                         |j)                  |       |j;                  d       |j=                  |       |j9                          t?        d	      }tA        |      }t1               }tC        jD                         }	|	jG                         }
|
d
kD  r#|jI                  |
       |jK                  |       nwtM        |jO                         dz        }tM        |jQ                         dz        }|jK                  |jS                  ||t*        jT                  t*        jV                               t	               }|j=                  |       |j)                  |       | j/                  |       | j                  jX                  j[                  | j                  j\                         | j                  j^                  j[                  | j                  j&                         y )N2      DialogCloseButton)	alignmentDownloadingzKite comes with a native app called the Copilot <br>which provides you with real time <br>documentation as you code.<br><br>When Kite is done installing, the Copilot will <br>launch automatically and guide you through the <br>rest of the setup process.OKr(   kite_copilot   g?)0r.   r   r/   r   r
   r   _progress_widgetsetFixedHeightry   _progress_filterr   _progress_barrB   installEventFilterr   cancel_buttonsetIconr   iconhider9   r   	AlignLeftrO   r   r   _progress_label	ok_buttonr8   rN   r:   r   r   r   primaryScreendevicePixelRatiosetDevicePixelRatior7   r0   r1   r3   r4   r5   r6   r}   rQ   showr   )rW   rX   action_layoutprogress_layoutinstall_infobutton_layoutcopilot_image_sourcecopilot_imagecopilot_labelscreendevice_pixel_ratior^   r_   rn   ro   s                 rp   r/   zKiteInstallation.__init__   s    .v6 $%- ',,R0 0 2)$/((-001F1FG(]""388,?#@A!!!$"4"4!M!!$"4"45''8%a&67 + ,- $$QtW-  "/  "  " 4 45 5 56-  $.  "  .n= 45++-#446!--.@A##M2}335;<Lm113c9:K##$$[,%'%7%7%'%<%<>? %  /  /~& 	--55d6H6H6M6MN--55d6H6H6M6MNrq   c                     | j                   j                  |       |t        k(  r| j                  j	                  dd       yy)z?Update installation status (downloading, installing, finished).r   N)r   setTextr   r   setRangerW   statuss     rp   update_installation_statusz+KiteInstallation.update_installation_status  s9    $$V,Z''1-  rq   c                 p    | j                   j                  |       | j                   j                  |       y)z!Update installation progress bar.N)r   
setMaximumsetValue)rW   current_valuetotals      rp   update_installation_progressz-KiteInstallation.update_installation_progress  s*    %%e,##M2rq   )rr   rs   rt   ru   r/   r   r   rv   rw   s   @rp   r   r      s    ,EON.3rq   r   c                   R     e Zd ZdZ fdZd Zd
dZd Zd Zd Z	d Z
 fd	Z xZS )KiteInstallerDialogzKite installer.c                    t         t        |   |       | j                  dt        j
                          t        j                  dk(  rB| j                  t        j                  t        j                  z  t        j                  z         n0| j                  t        j                  t        j                  z         || _        || _        t        |       | _        t#        |       | _        t'               }|j)                  | j                          |j)                  | j$                         | j+                  |       | j                  j,                  j/                  | j$                  j0                         | j                  j2                  j/                  | j$                  j4                         | j                  j2                  j/                  | j6                         | j                  j8                  j/                  | j:                         | j                   j<                  j/                  | j>                         | j                   j@                  j/                  | jB                         | j$                  jD                  jF                  j/                  | jH                         | j$                  jJ                  jF                  j/                  | jL                         | jO                          y )Nr+   r   )(r.   r   r/   r;   r   rT   sysplatformsetWindowFlagsr   DialogMSWindowsFixedSizeDialogHintTool_parent_installation_threadr   _integration_widgetr   _installation_widgetr   r9   rO   sig_download_progressrQ   r   sig_installation_statusr   finished_installationsig_error_msg_handle_error_msgrR   installrS   rejectr   rP   close_installerr   cancel_installsetup)rW   rX   installation_threadinstaller_layoutro   s       rp   r/   zKiteInstallerDialog.__init__  s)   !41&9 !A!A BC	E<<8#		B,K,K K"$''!* + 		B,K,K KL$7!#6t#< $4T$:! '=""4#;#;<""4#<#<='( 	!!77??%%BB	D!!99AA%%@@	B!!99AA&&	(!!//778N8NO  ;;CCLL	  ;;CCKK	!!++33;;  	"!!//77??	! 	

rq   c                     t        j                  | j                  t        d      t        d      j	                  t
        t                     | j                          y)z*Handle error message with an error dialog.zKite installation errorz<b>An error ocurred while installing Kite!</b><br><br>Please try to <a href="{kite_url}">install it manually</a> or <a href="{kite_contact}">contact Kite</a> for help)r   kite_contactN)r   criticalr   r   r>   r?   KITE_CONTACT_URLaccept)rW   msgs     rp   r   z%KiteInstallerDialog._handle_error_msg?  sL    LL'( E F V_;KVL	N 	rq   c                     | j                   j                  |       | j                  j                  |       | j                          y)zSetup visibility of widgets.N)r   
setVisibler   
adjustSize)rW   integrationinstallations      rp   r   zKiteInstallerDialog.setupK  s4      ++K8!!,,\:rq   c                     | j                  dd       d| j                  _        | j                  j                          y)z8Initialize installation process and show install widget.FT)r   r   N)r   r   	cancelledr   rW   s    rp   r   zKiteInstallerDialog.installQ  s2    

u4
8.3!!+!!))+rq   c                    t        j                  | j                  dt        d      t         j                  t         j
                        }|t         j                  k(  rf| j                  j                         rLd| j                  _        | j                  j                          | j                          | j                          yy)z$Cancel the installation in progress.Spyderz/Do you really want to cancel Kite installation?TF)r   r   r   r   YesNor   	isRunningr   quitr   r   )rW   replys     rp   r   z"KiteInstallerDialog.cancel_installW  s    $$LL(?@OO[^^- KOO#(A(A(K(K(M26D%%/%%**,JJLKKMrq   c                 X    |t         k(  r!| j                          | j                          yy)zHandle finished installation.N)r   r   r   r   s     rp   r   z)KiteInstallerDialog.finished_installatione  s!    XJJLKKM rq   c                    | j                   j                  t        k(  s:| j                   j                  t        k(  s| j                   j                  t        k(  r!| j                          | j                          y| j                          y)zClose the installation dialog.N)r   r   r   r   r   r   r   r   r   s    rp   r   z#KiteInstallerDialog.close_installerk  sY    %%,,7,,33x?,,33y@JJLKKMIIKrq   c                     | j                   j                         }|r| j                          yt        t        |           y)zReimplement Qt method.N)r   	isVisibler   r.   r   r   )rW   on_installation_widgetro   s     rp   r   zKiteInstallerDialog.rejectu  s5    !%!:!:!D!D!F!  "%t35rq   )TF)rr   rs   rt   ru   r/   r   r   r   r   r   r   r   rv   rw   s   @rp   r   r     s4    'R
,6 6rq   r   __main__)qapplication)1ru   r   qtpy.QtCorer   r   r   r   
qtpy.QtGuir   qtpy.QtWidgetsr   r	   r
   r   r   r   r   r   r   spyder.config.baser   spyder.utils.image_path_managerr   spyder.utils.icon_managerr   spyder.utils.paletter   6spyder.plugins.completion.providers.kite.utils.installr   r   r   r   spyder.utils.stylesheetr   r?   r   r   rM   r   ry   r   r   rr   spyder.utils.qthelpersr   appinstall_progressr   exec_ rq   rp   <module>r      s       4 3 % % %
 ! : ) .. . / 9. 	llhG(' G(THw H"S3w S3lh6' h6V z3
.C'-IIK rq   