
    Je                         d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 ddl
mZmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ  ej.                  e      Z G d de	      Zy)z
Internal Console Plugin.
    N)SignalSlotQIcon)PluginsSpyderDockablePlugin)on_plugin_availableon_plugin_teardown_)DEV)ConsoleWidgetConsoleWidgetActions)ApplicationMenusFileMenuSectionsc                      e Zd ZdZdZeZej                  gZ	eZ
dZej                  ej                  gZdZdZ e       Z eeee      Z	  e       Z	  ee      Z	 ed        Zd Zd Zd Z eej                  	      d
        Z e ej                  	      d        Z!d Z"ddZ#d Z$ e%       d        Z&e'd        Z(d Z)d Z*d Z+d Z, e%e      dd       Z-d Z.d Z/d Z0d Z1d Z2d Z3y)Consolez
    Console widget
    internal_consoleFTc                      t        d      S )NzInternal consoler        ?/usr/lib/python3/dist-packages/spyder/plugins/console/plugin.pyget_namezConsole.get_nameP   s    #$$r   c                     t               S Nr   selfs    r   get_iconzConsole.get_iconT   s	    wr   c                     t        d      S )Nz Internal console running Spyder.r   r   s    r   get_descriptionzConsole.get_descriptionW   s    344r   c           	         | j                         }|j                  j                  | j                         |j                  j                  | j                         |j                  j                  | j                         |j
                  j                  | j
                         | j                  ddd      }|r4t        |ddt        d      t        d      	      }|j                  |       y y )
Nprevious_crash main)defaultsectionTzSegmentation fault crashz+<h3>Spyder crashed during last session</h3>zIPlease provide any additional information you might have about the crash.)textis_tracebacktitlelabelsteps)

get_widgetsig_edit_goto_requestedconnectsig_focus_changedsig_refreshedsig_help_requestedget_confdictr   handle_exception)r   widgetr"   
error_datas       r   on_initializezConsole.on_initializeZ   s    " 	&&..t/K/KL  (()?)?@$$T%7%78!!))$*A*AB  ' 
 #!0EF 6 7J ##J/ r   )pluginc                     | j                         }| j                  t        j                        }|j	                  |j
                  t        j                  t        j                         y )N)menu_idr&   )
r,   
get_pluginr   MainMenuadd_item_to_application_menuquit_actionr   Filer   Restart)r   r5   mainmenus      r   on_main_menu_availablezConsole.on_main_menu_availableu   sR    "??7#3#34 	--$))$,, 	. 	.r   c                     | j                  t        j                        }|j                  t        j
                  t        j                         y )N)r:   )r;   r   r<   !remove_item_from_application_menur   Quitr   r?   )r   rA   s     r   on_main_menu_teardownzConsole.on_main_menu_teardown   s;    ??7#3#3422 %%$)) 	3 	+r   c                 b    | j                         }| j                         j                  |       y r   )get_fontr,   set_font)r   fonts     r   update_fontzConsole.update_font   s"    }}""4(r   c                 T    | j                         j                  j                          y)NT)r,   dialog_manager	close_all)r   
cancelables     r   on_closezConsole.on_close   s    ((224r   c                     | j                  | j                  j                         t        6| j                  j                  d       | j                  j                          y y )NF)set_exit_functionr$   closingr   toggle_view_action
setChecked
dockwidgethider   s    r   on_mainwindow_visiblezConsole.on_mainwindow_visible   sJ    tyy001 ;##..u5OO  " r   c                 @    | j                         j                          y)z+Report an issue with the SpyderErrorDialog.N)r,   report_issuer   s    r   rZ   zConsole.report_issue   s     	&&(r   c                 6    | j                         j                  S )z1
        Error dialog attribute accesor.
        )r,   	error_dlgr   s    r   error_dialogzConsole.error_dialog   s    
  ***r   c                 @    | j                         j                          y)z4
        Close the error dialog if visible.
        N)r,   close_error_dlgr   s    r   close_error_dialogzConsole.close_error_dialog   s     	))+r   c                 @    | j                         j                          y)z
        Exit the internal console interpreter.

        This is equivalent to requesting the main application to quit.
        N)r,   exit_interpreterr   s    r   rb   zConsole.exit_interpreter   s     	**,r   c                 B    | j                         j                  |       y)zL
        Execute the given `lines` of code in the internal console.
        N)r,   execute_lines)r   liness     r   rd   zConsole.execute_lines   s     	''.r   c                 >    | j                         j                         S )zA
        Return the system path of the internal console.
        )r,   get_sys_pathr   s    r   rg   zConsole.get_sys_path   s      --//r   Nc                 j    || j                         }| j                         j                  ||       y)a)  
        Handle any exception that occurs during Spyder usage.

        Parameters
        ----------
        error_data: dict
            The dictionary containing error data. The expected keys are:
            >>> error_data= {
                "text": str,
                "is_traceback": bool,
                "repo": str,
                "title": str,
                "label": str,
                "steps": str,
            }

        Notes
        -----
        The `is_traceback` key indicates if `text` contains plain text or a
        Python error traceback.

        The `title` and `repo` keys indicate how the error data should
        customize the report dialog and Github error submission.

        The `label` and `steps` keys allow customizing the content of the
        error dialog.
        N)sender)ri   r,   r4   )r   r6   ri   s      r   r4   zConsole.handle_exception   s4    : >[[]F** 	+ 	
r   c                 8    | j                   j                          y)z@
        Send the quit request to the main application.
        N)sig_quit_requestedemitr   s    r   quitzConsole.quit   s     	$$&r   c                 @    | j                         j                          y)zI
        Restore stdout and stderr when using open file dialogs.
        N)r,   restore_stdsr   s    r   ro   zConsole.restore_stds   s     	&&(r   c                 @    | j                         j                          y)zJ
        Redirect stdout and stderr when using open file dialogs.
        N)r,   redirect_stdsr   s    r   rq   zConsole.redirect_stds   s     	'')r   c                 B    | j                         j                  |       y)ze
        Set the callback function to execute when the `exit_interpreter` is
        called.
        N)r,   rR   )r   funcs     r   rR   zConsole.set_exit_function   s    
 	++D1r   c                 F    | j                         }|j                  |       y)z
        Start the internal console interpreter.

        Stdin and stdout are now redirected through the internal console.
        N)r,   start_interpreter)r   	namespacer5   s      r   ru   zConsole.start_interpreter   s     "  +r   c                 D    | j                         j                  ||       y)zT
        Add an object to the namespace dictionary of the internal console.
        N)r,   set_namespace_item)r   namevalues      r   rx   zConsole.set_namespace_item  s     	,,T59r   )Fr   )4__name__
__module____qualname____doc__NAMEr   WIDGET_CLASSr   r<   OPTIONALCONF_SECTION	CONF_FILEIPythonConsoleHistoryTABIFYCAN_BE_DISABLEDRAISE_AND_FOCUSr   r/   strintr-   r0   r3   r1   staticmethodr   r   r    r7   r	   rB   r
   rF   rK   rP   rX   r   rZ   propertyr]   r`   rb   rd   rg   r4   rm   ro   rq   rR   ru   rx   r   r   r   r   r   !   sg    D L  !HLI$$goo6FOO $S#s3 HMH % %506  0 01. 2. w//0+ 1+)# 
V) ) + +,-/0 
$Z!
 !
F')*2,:r   r   )r~   loggingqtpy.QtCorer   r   
qtpy.QtGuir   spyder.api.pluginsr   r   )spyder.api.plugin_registration.decoratorsr	   r
   spyder.api.translationsr   spyder.config.baser   *spyder.plugins.console.widgets.main_widgetr   r   spyder.plugins.mainmenu.apir   r   	getLoggerr{   loggerr   r   r   r   <module>r      sR   
  %  =- % ") J 
		8	$i:" i:r   