
_y]c        	   @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z e j d k r e j Z d   Z	 e	 d    Z
 e
 e _ y$ d d l m Z e j j d  Wn e k
 r n Xn  d d	 l 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 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) m* Z* m+ Z+ d d l, m- Z- m. Z. m/ Z/ d d l0 m1 Z1 d Z2 e3 e*  Z4 i i i e5 d 6d 6d f d 6Z6 e6 j7 e d d d d   e6 j7 e/  e4 j7 e6  e3 e+  Z8 e3 d d d  d! d" d# d$ d%  Z9 e9 j7 e.  e9 j7 i d& d' 6 e8 j7 e9  e: e9 j;    Z9 e: e6 j;    Z6 d e) e- f d(     YZ< d) e< f d*     YZ= d+   Z> e? d, k re>   n  d S(-   s    A minimal application using the Qt console-style Jupyter frontend.

This is not a complete console app, as subprocess will not be able to receive
input, there is no real readline support, among other limitations.
iN(   t   warnt   ntc         C   s   |  S(   N(    (   t   func(    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   <lambda>$   t    c         C   sz   zb d d  l  } d d  l } d } d } d j | j |  | |   } | j j j d | | |  Wd  t |  | |  Xd  S(   Nii   u   Error starting QtConsoleu    i    (   t   ctypest	   tracebackt   joint   format_exceptiont   windllt   user32t   MessageBoxWt   old_excepthook(   t   exctypet   valuet   tbR   R   t   MB_ICONERRORt   titlet   msg(    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   gui_excepthook&   s     (   R	   s   Jupyter.Qtconsole(   t   QtCoret   QtGui(   t   boolean_flag(   t   catch_config_error(   t   JupyterWidget(   t   RichJupyterWidget(   t   stylest   __version__(   t
   MainWindow(   t   QtKernelClient(   t   QtKernelManager(   t   Dictt   Unicodet   CBoolt   Any(   t
   JupyterAppt
   base_flagst   base_aliases(   t   JupyterConsoleAppt   app_aliasest	   app_flags(   t   is_local_ips>   
jupyter qtconsole                      # start the qtconsole
t   plaint   JupyterQtConsoleApps   Disable rich text support.t   banners"   JupyterQtConsoleApp.display_banners-   Display a banner upon starting the QtConsole.s3   Don't display a banner upon starting the QtConsole.t   styles   JupyterWidget.syntax_stylet
   stylesheets   JupyterQtConsoleApp.stylesheett   editors   JupyterWidget.editort   pagings   ConsoleWidget.pagings   ConsoleWidget.gui_completions   gui-completionc           B   sh  e  Z d  Z e Z d Z e Z e g e	 j
 Z
 e e  Z e e  Z e e  Z e e  Z e Z e Z e d d e d d Z e e d e d d Z e e d e d d Z e e d e d d Z e e d e d d	 Z d
   Z  e e!  Z" d d  Z$ d   Z% d   Z& d   Z' d   Z( d   Z) d   Z* d   Z+ d   Z, e- d d   Z. d   Z/ RS(   s   jupyter-qtconsoles   
        The Jupyter QtConsole.
        
        This launches a Console-style application using Qt.  It is not a full
        console, in that launched terminal subprocesses will not be able to accept
        input.
        
    R   t   configt   helps   path to a custom CSS stylesheets2   Start the console window with the menu bar hidden.s#   Start the console window maximized.sE   Use a plaintext widget instead of rich text (plain can't print/save).s8   Whether to display a banner upon starting the QtConsole.c         C   s@   | r d n d } | |  j  j _ | r3 t |  _ n	 t |  _ d  S(   NR*   t   rich(   R1   t   ConsoleWidgett   kindR   t   widget_factoryR   (   t   selft   namet   oldt   newR5   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   _plain_changed   s
    c         C   s*   t  t |   j |  |  j |  j  d  S(   N(   t   superR+   t   parse_command_linet   build_kernel_argvt
   extra_args(   R7   t   argv(    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR=      s    c         C   s   |  j  d |  j   d |  d t  } i  } |  j j rF |  j | d <n  | j |   |  j | _ | j	   } | j
 d t d t  |  j d |  j d t  } |  j |  | | _ | | _ t | _ t | _ |  j | _ |  j | _ | S(	   sW    Create and return new frontend attached to new kernel, launched on localhost.
        t   connection_filet   parentt   autorestartt   extra_argumentst   shellt   iopubR1   t   local_kernel(   t   kernel_manager_classt   _new_connection_filet   Truet   kernel_managert	   ipykernelt   kernel_argvt   start_kernelt   kernel_client_classt   client_factoryt   clientt   start_channelsR6   R1   t   init_colorst   kernel_clientt   Falset	   _existingt
   _may_closet   confirm_exitt   _confirm_exitt   display_bannert   _display_banner(   R7   RK   t   kwargsRT   t   widget(    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   new_frontend_master   s*    							c         C   s   |  j  d | d |  j  } | j   | j   |  j d |  j d t  } |  j |  t | _ t | _	 t | _
 |  j | _ | | _ d | _ | S(   s   Create and return a new frontend attached to an existing kernel.

        Parameters
        ----------
        connection_file : str
            The connection_file path this frontend is to connect to
        RA   R1   RG   N(   RO   R1   t   load_connection_fileRR   R6   RU   RS   RJ   RV   RW   RY   RZ   R[   RT   t   NoneRK   (   R7   RA   RT   R]   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   new_frontend_connection   s    	

						c         C   s   |  j  d | j j d |  j  } | j   | j   |  j d |  j d t  } |  j |  t	 | _
 t | _ t | _ |  j | _ | | _ | j | _ | S(   s   Create and return a new frontend attached to an existing kernel.
        
        Parameters
        ----------
        current_widget : JupyterWidget
            The JupyterWidget whose kernel this frontend is to share
        RA   R1   RG   (   RO   RT   RA   R1   R_   RR   R6   RU   RS   RJ   RV   RW   RY   RZ   R[   RK   (   R7   t   current_widgetRT   R]   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   new_frontend_slave   s    	

					c         C   s)   t  j d g  |  _ |  j j d  d  S(   Ns   jupyter-qtconsole(   R   t   QApplicationt   appt   setApplicationName(   R7   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   init_qt_app  s    c      
   C   s  t  j j t  j j t   } t  j j | d d d  } t j |  |  j _	 t j
 j |  j j	  |  j } |  j p t |  } |  j d |  j d |  |  _ |  j |  j  |  j |  j _ |  j |  j _ |  j |  j _ |  j |  j _ |  j |  j _ |  j |  j _ t |  j d |  j d |  j d |  j d	 |  j |  _ |  j  |  j _  |  j j! |  j  |  j j"   t# j$ d
 k r|  j% r|  j j&   j' t(  n  |  j j) d  d  S(   Nt	   resourcest   icons   JupyterConsole.svgR1   RG   RX   t   new_frontend_factoryt   slave_frontend_factoryt   connection_frontend_factoryt   darwins   Jupyter QtConsole(*   t   ost   patht   abspatht   dirnamet   __file__R   R   t   QIconRe   Ri   Rd   t   setWindowIcont   ipt   existingR)   R6   R1   R]   RS   RV   RW   RX   RY   RZ   R[   RK   RT   R   R^   Rc   Ra   t   windowt   logt   add_tab_with_frontendt   init_menu_bart   syst   platformt   hide_menubart   menuBart
   setVisibleRU   t   setWindowTitle(   R7   t	   base_patht	   icon_pathRu   RG   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   init_qt_elements  s4    				c         C   s  |  j  } d | k r! | j j n d } d | k r? | j j n d } d | k r] | j j n d } | r | j   } | d k r d } q | d k r d } q d } nB | r | d	 k r d } q t j	 |  r d } q d } n d } | r%t j
 | |  | _ | | _ | j   | j   n | r>| j d
 |  n  |  j rt j j |  j  rt |  j   } | j   } Wd QXqt d |  j   n  | r| | _ | j   n  d S(   s$   Configure the coloring of the widgets   ZMQInteractiveShell.colorss   JupyterWidget.syntax_styles   JupyterWidget.style_sheett   lightbgt   lightt   darkt   linuxt   nocolort   bwt   colorsNs   Stylesheet %r not found.(   R   R   (   R   R   (   R1   t   ZMQInteractiveShellR   R`   R   t   syntax_stylet   style_sheett   lowerR   t
   dark_stylet   sheet_from_templatet   _syntax_style_changedt   _style_sheet_changedt   set_default_styleR.   Rn   Ro   t   isfilet   opent   readt   IOError(   R7   R]   t   cfgR   R-   t   sheett   f(    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyRS   ,  sB    								
		c            sU   t  j  t  j   f d    t j   } | j j d    | j d  |   _ d S(   s   allow clean shutdown on sigintc            s     j  d  S(   Ni(   t   exit(   t   sigt   frame(   R7   (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR   b  R   c           S   s   d  S(   N(   R`   (    (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR   h  R   i   N(   t   signalt   SIGINTR   t   QTimert   timeoutt   connectt   startt   _sigint_timer(   R7   t   timer(    (   R7   s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   init_signal`  s
    c            st     | k rp |  j  j d |   d j   f d   |  j   j   D   | j   } | | j |    | Sd S(   s   Warn about deprecated config.s1   Use %s in config, not %s. Outdated config:
    %ss   
    c         3   s3   |  ]) \ } } d  j  d | d | d    Vq d S(   s   {name}.{key} = {value!r}t   keyR   R8   N(   t   format(   t   .0R   R   (   t   old_name(    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pys	   <genexpr>t  s   N(   Rx   t   warningR   R1   t   itemst   copyt   merge(   R7   R   R   t   new_name(    (   R   s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   _deprecate_configm  s    	c         C   s   |  j    t t |   j |  |  j r- d  SxK d d d	 g D]: \ } } |  j |  j | |  } | r= |  j |  q= q= Wt j |  |  |  j	   |  j
   d  S(
   Nt   IPythonQtConsoleAppt   JupyterQtConsolet   IPythonWidgetR   t   RichIPythonWidgetR   (   R   R   (   R   R   (   R   R   (   Rg   R<   R+   t
   initializet   _dispatchingR   R1   t   update_configR&   R   R   (   R7   R@   R   R   R   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR   }  s    
	
c         C   sW   t  t |   j   |  j r, |  j j   n |  j j   |  j j   |  j j	   d  S(   N(
   R<   R+   R   t   maximizeRw   t   showMaximizedt   showt   raise_Re   t   exec_(   R7   (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR     s    	N(0   t   __name__t
   __module__R8   R   t   versiont   descriptiont	   _examplest   examplesR   R&   t   classesR   t   flagst   aliasesR"   t   qt_flagst   frontend_flagst
   qt_aliasest   frontend_aliasesR   RO   R   RH   R    RJ   R.   R!   RU   R}   R   R*   RZ   R;   R   R6   R`   R=   R^   Ra   Rc   Rg   R   RS   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR+      sF   												$	4		R   c           B   s   e  Z d    Z RS(   c         O   s*   t  d t  t t |   j | |   d  S(   Ns:   IPythonQtConsoleApp is deprecated; use JupyterQtConsoleApp(   R    t   DeprecationWarningR<   R   t   __init__(   R7   t   at   kw(    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR     s    (   R   R   R   (    (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyR     s   c           C   s   t  j   d  S(   N(   R+   t   launch_instance(    (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   main  s    t   __main__(@   t   __doc__Rn   R   R{   t   warningsR    R8   t
   excepthookR   t   undocR   R   R	   t   shell32t'   SetCurrentProcessExplicitAppUserModelIDt   AttributeErrort   qtconsole.qtR   R   t   traitlets.config.applicationR   R   t   qtconsole.jupyter_widgetR   t   qtconsole.rich_jupyter_widgetR   t	   qtconsoleR   R   t   qtconsole.mainwindowR   t   qtconsole.clientR   t   qtconsole.managerR   t	   traitletsR   R    R!   R"   t   jupyter_core.applicationR#   R$   R%   t   jupyter_client.consoleappR&   R'   R(   t   jupyter_client.localinterfacesR)   R   t   dictR   RJ   R   t   updateR   R   t   sett   keysR+   R   R   R   (    (    (    s5   lib/python2.7/site-packages/qtconsole/qtconsoleapp.pyt   <module>   sn   			"	
	 	