o
    º¼tf–  ã                   @   sš   d Z ddlZddl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 ddlmZ dd	lmZ dd
lmZ dd„ ZG dd„ dejƒZdS )zThe Qt MainWindow for the QtConsole

This is a tabbed pseudo-terminal of Jupyter sessions, with a menu bar for
common actions.
é    N)Úpartial)ÚThread)Újupyter_runtime_dir)Úget_all_styles)ÚQtGuiÚQtCoreÚ	QtWidgets)Ústyles)ÚJupyterWidget)Úgui_referencec                 C   s   t | d}| ¡  |S )z7call a function in a simple thread, to prevent blocking)Útarget)r   Ústart)ÚfÚt© r   ú]/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/qtconsole/mainwindow.pyÚ
background   s   
r   c                       sè  e Zd Z				dr‡ fdd„	Zdd„ Zedd„ ƒZed	d
„ ƒZedd„ ƒZdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdsdd„Zdd„ Zdd„ Zdd „ Zdtd"d#„Zd$d%„ Zdtd&d'„Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dVdW„ Z-dXdY„ Z.dZd[„ Z/d\d]„ Z0d^d_„ Z1d`da„ Z2dbdc„ Z3ddde„ Z4dfdg„ Z5dhdi„ Z6djdk„ Z7dldm„ Z8dndo„ Z9dpdq„ Z:‡  Z;S )uÚ
MainWindowTNc                    s    t ƒ j|d d| _d| _|| _|| _|| _|| _|| _t	 
| ¡| _| j d¡ | j d¡ | jjt  | j¡ |  | j¡ | j ¡  d¡ | j tjj¡ dS )aI   Create a tabbed MainWindow for managing FrontendWidgets

        Parameters
        ----------

        app : reference to QApplication parent
        confirm_exit : bool, optional
            Whether we should prompt on close of tabs
        new_frontend_factory : callable
            A callable that returns a new JupyterWidget instance, attached to
            its own running kernel.
        slave_frontend_factory : callable
            A callable that takes an existing JupyterWidget, and  returns a new
            JupyterWidget instance, attached to the same kernel.
        )Úparentr   TFN)ÚsuperÚ__init__Ú_kernel_counterÚ_external_kernel_counterÚ_appÚconfirm_exitÚnew_frontend_factoryÚslave_frontend_factoryÚconnection_frontend_factoryr   Z
QTabWidgetÚ
tab_widgetZsetDocumentModeZsetTabsClosableZtabCloseRequestedÚintÚconnectÚ	close_tabZsetCentralWidgetÚtabBarÚ
setVisibleZsetFocusPolicyr   ÚQtZNoFocus)ÚselfZappr   r   r   r   r   ©Ú	__class__r   r   r   $   s   zMainWindow.__init__c                 C   sN   | j  ¡ dkr| j  ¡  d¡ n| j  ¡  d¡ | j  ¡ dkr%|  ¡  dS dS )a   update visibility of the tabBar depending of the number of tab

        0 or 1 tab, tabBar hidden
        2+ tabs, tabBar visible

        send a self.close if number of tab ==0

        need to be called explicitly, or be connected to tabInserted/tabRemoved
        é   FTr   N)r   Úcountr"   r#   Úclose©r%   r   r   r   Úupdate_tab_bar_visibilityN   s   
ÿz$MainWindow.update_tab_bar_visibilityc                 C   ó   | j }|  j d7  _ |S )z,constantly increasing counter for kernel IDsr(   )r   ©r%   Úcr   r   r   Únext_kernel_id_   ó   zMainWindow.next_kernel_idc                 C   r-   )z5constantly increasing counter for external kernel IDsr(   )r   r.   r   r   r   Únext_external_kernel_idf   r1   z"MainWindow.next_external_kernel_idc                 C   s
   | j  ¡ S ©N)r   ÚcurrentWidgetr+   r   r   r   Úactive_frontendm   s   
zMainWindow.active_frontendc                 C   s   |   ¡ }|  |¡ dS )z0create a new frontend and attach it to a new tabN)r   Úadd_tab_with_frontend©r%   Úwidgetr   r   r   Úcreate_tab_with_new_frontendq   s   z'MainWindow.create_tab_with_new_frontendc                 C   s6   |   ¡ }tjj| dd|d\}}|r|  |¡ dS dS )z#Set the title of the console windowzRename Windowú
New title:©ÚtextN)ÚwindowTitler   ÚQInputDialogÚgetTextZsetWindowTitle©r%   Z	old_titleÚtitleÚokr   r   r   Úset_window_titlev   s   
ýÿzMainWindow.set_window_titlec                 C   sH   t j | dtƒ d¡\}}|sdS |  |¡}d | j¡}| j||d dS )zAcreate a new frontend attached to an external kernel in a new tabzConnect to Existing KernelzConnection file (*.json)Nzexternal {}©Úname)r   ZQFileDialogZgetOpenFileNamer   r   Úformatr2   r6   )r%   Úconnection_fileÚ	file_typer8   rE   r   r   r   Úcreate_tab_with_existing_kernel€   s   ý
z*MainWindow.create_tab_with_existing_kernelc                 C   sT   | j  ¡ }| j  |¡}| j  |¡}|  |¡}d|v r|}nd| }| j||d dS )zDcreate a new frontend attached to the same kernel as the current tabÚslavez
(%s) slaverD   N)r   r4   ÚindexOfÚtabTextr   r6   )r%   Zcurrent_widgetZcurrent_widget_indexZcurrent_widget_namer8   rE   r   r   r   Úcreate_tab_with_current_kernelŒ   s   

z)MainWindow.create_tab_with_current_kernelc                 C   sJ   | j  | j  ¡ ¡}tjj| dd|d\}}|r#| j  | j  ¡ |¡ dS dS )z Set the title of the current tabz
Rename Tabr:   r;   N)r   rL   ÚcurrentIndexr   r>   r?   Z
setTabTextr@   r   r   r   Úset_tab_title™   s   
ýÿzMainWindow.set_tab_titlec                 C   s.  t |ƒtur| j |¡}| j |¡}|du rdS |  |¡}d}t|dƒr]|j}|dur]|D ]}d|_q-||v r]z
|  	|¡ 
d¡ W n tyV   | j d¡ | j |¡ Y nw |  ¡  dS |j}|j}|du rm|jsm|j}|du rS|rR|jrR|  ¡  ¡ }tjj}	tjj}
|jr:d| j |¡ d }d}t d	| ¡}| d
¡ t d| ¡}| d¡ | d¡ t tjj||¡}|  |¡ | !|	¡ | !|tjj"¡ | !|tjj#¡ | $|¡ | %|	¡ t& '| j(j) *t+ ,dd¡¡¡}| -|¡ | .¡ }|dkr |D ]}t/|jj0ƒ | j | j |¡¡ qý| 1¡  | j |¡ t/|j0ƒ nq|dkr9|js.| 
d¡ | j |¡ t/|j0ƒ nWtjj2| |d|
|	B |
d}||
krR| j |¡ n>|rb| j |¡ t/|j0ƒ n/| j |¡ |r‘|jr‘|D ]}t/|jj0ƒ | j | j |¡¡ qq|rŒ| 1¡  t/|j0ƒ |  ¡  dS )z¬ Called when you need to try to close a tab.

        It takes the number of the tab to be closed as argument, or a reference
        to the widget inside this tab
        NÚ_keep_kernel_on_exitTÚexitz<Master already closed or not local, closing only current tabzYou are closing the tab : "ú"zJWould you like to quit the Kernel and close all attached Consoles as well?z&No, just this TabÚNz&Yes, close allÚYzCtrl+Dé@   r(   r   z	exit Truez^Are you sure you want to close this Console?
The Kernel and other Consoles will remain active.)ZdefaultButton)3Útyper   r   rK   r8   Úfind_slave_widgetsÚhasattrrP   Z_hiddenÚfind_master_tabÚexecuteÚAttributeErrorÚlogÚinfoZ	removeTabr,   Úkernel_clientÚkernel_managerÚ_confirm_exitZ	_existingZchannels_runningÚwindowr=   r   ÚQMessageBoxÚCancelÚOkÚ
_may_closerL   ÚQPushButtonÚsetShortcutÚQuestionÚsetInformativeTextÚ	addButtonZNoRoleÚYesRoleÚsetDefaultButtonÚsetEscapeButtonr   ÚQPixmapr   ÚiconÚpixmapr   ÚQSizeÚsetIconPixmapÚexec_r   Zstop_channelsZshutdown_kernelÚquestion)r%   Zcurrent_tabZclosing_widgetZ
slave_tabsZ
keepkernelÚtabr^   r_   rA   ÚcancelÚokayÚmsgr]   ZjustthisÚcloseallÚboxrp   ÚreplyrJ   r   r   r   r!   £   s¦   		

þ




ÿ








€
ü
€
zMainWindow.close_tabc                 C   s@   |sd| j  }| j ||¡ |  ¡  |  |¡ |j | j¡ dS )zP insert a tab with a given frontend in the tab bar, and give it a name

        z	kernel %iN)r0   r   ZaddTabr,   Úmake_frontend_visibleZexit_requestedr    r!   )r%   ÚfrontendrE   r   r   r   r6     s   

z MainWindow.add_tab_with_frontendc                 C   s   | j  | j  ¡ d ¡ d S ©Nr(   ©r   ÚsetCurrentIndexrN   r+   r   r   r   Únext_tab   ó   zMainWindow.next_tabc                 C   s   | j  | j  ¡ d ¡ d S r~   r   r+   r   r   r   Úprev_tab#  r‚   zMainWindow.prev_tabc                 C   s(   | j  |¡}|dkr| j  |¡ d S d S )Nr   )r   rK   r€   )r%   r}   Zwidget_indexr   r   r   r|   &  s   ÿz MainWindow.make_frontend_visibleFc                    sˆ   t |tƒrˆj |¡}|j‰ ‡fdd„tˆj ¡ ƒD ƒ}‡ fdd„|D ƒ}dd„ |D ƒ}|r0|S t|ƒdks8J ‚t|ƒdkr@dS |d S )a  
        Try to return the frontend that owns the kernel attached to the given widget/tab.

            Only finds frontend owned by the current application. Selection
            based on port of the kernel might be inaccurate if several kernel
            on different ip use same port number.

            This function does the conversion tabNumber/widget if needed.
            Might return None if no master widget (non local kernel)
            Will crash if more than 1 masterWidget

            When asList set to True, always return a list of widget(s) owning
            the kernel. The list might be empty or containing several Widget.
        c                    ó   g | ]}ˆ j  |¡‘qS r   ©r   r8   ©Ú.0Úir+   r   r   Ú
<listcomp>A  ó    z.MainWindow.find_master_tab.<locals>.<listcomp>c                    s(   g | ]}|j jˆ jkrt|d ƒr|‘qS ©re   )r^   rG   rX   ©r‡   r8   ©Úkmr   r   r‰   E  s    ÿÿc                 S   s   g | ]}|j r|‘qS r   r‹   rŒ   r   r   r   r‰   I  s    r(   r   N)Ú
isinstancer   r   r8   r^   Úranger)   Úlen)r%   ru   Úas_listÚwidget_listÚfiltered_widget_listZmaster_widgetr   )rŽ   r%   r   rY   +  s   
zMainWindow.find_master_tabc                    sn   t |tƒrˆj |¡}|j‰ ‡fdd„tˆj ¡ ƒD ƒ}‡ fdd„|D ƒ}ˆj|dd‰‡fdd„|D ƒ}|S )a*  return all the frontends that do not own the kernel attached to the given widget/tab.

            Only find frontends owned by the current application. Selection
            based on connection file of the kernel.

            This function does the conversion tabNumber/widget if needed.
        c                    r„   r   r…   r†   r+   r   r   r‰   `  rŠ   z1MainWindow.find_slave_widgets.<locals>.<listcomp>c                 3   s"    | ]}|j jˆ jkr|V  qd S r3   )r^   rG   rŒ   r   r   r   Ú	<genexpr>c  s   € ÿÿz0MainWindow.find_slave_widgets.<locals>.<genexpr>T)r’   c                    s   g | ]}|ˆ vr|‘qS r   r   rŒ   )Úmaster_widget_listr   r   r‰   h  rŠ   )r   r   r   r8   r^   r   r)   rY   )r%   ru   r“   r”   Z
slave_listr   )rŽ   r–   r%   r   rW   R  s   
	zMainWindow.find_slave_widgetsc                 C   s.   |  |¡ |   |¡ |r| tjj¡ dS dS )a/  Add action to menu as well as self

        So that when the menu bar is invisible, its actions are still available.

        If defer_shortcut is True, set the shortcut context to widget-only,
        where it will avoid conflict with shortcuts already bound to the
        widgets themselves.
        N)Ú	addActionZsetShortcutContextr   r$   ZWidgetShortcut)r%   ZmenuÚactionZdefer_shortcutr   r   r   Úadd_menu_actionm  s
   
	
ÿzMainWindow.add_menu_actionc                 C   s4   |   ¡  |  ¡  |  ¡  |  ¡  |  ¡  |  ¡  d S r3   )Úinit_file_menuÚinit_edit_menuÚinit_view_menuÚinit_kernel_menuÚinit_window_menuÚinit_help_menur+   r   r   r   Úinit_menu_bar|  s   zMainWindow.init_menu_barc                 C   s€  |   ¡  d¡| _tjd| d| jd| _|  | j| j¡ tjd| d| jd| _	|  | j| j	¡ tjd| d| j
d| _|  | j| j¡ | j ¡  tjd	| tjj| jd| _|  | j| j¡ tjd
| tjj| jd| _|  | j| jd¡ | j ¡  t tjj¡}| d¡r‰tjdkr‰d}tjd| || jd| _|  | j| jd¡ tjdkr¾| j ¡  tjd| tjj| jd| _|  | j| j¡ d S d S )Nz&FilezNew Tab with &New kernelzCtrl+T©ÚshortcutÚ	triggeredzNew Tab with Sa&me kernelzCtrl+Shift+TzNew Tab with &Existing kernelzAlt+Tz
&Close Tabz&Save to HTML/XHTMLTzCtrl+PÚdarwinzCtrl+Shift+Pz&Printú&Quit)ÚmenuBarÚaddMenuZ	file_menur   ÚQActionr9   Znew_kernel_tab_actr™   rM   Zslave_kernel_tab_actrI   Zexisting_kernel_tab_actÚaddSeparatorr   ÚQKeySequenceÚCloseÚclose_active_frontendZclose_actionZSaveÚexport_action_active_frontendÚexport_actionZPrintÚmatchesÚsysÚplatformÚprint_action_active_frontendÚprint_actionZQuitr*   Zquit_action)r%   Zprintkeyr   r   r   rš   …  sf   ýýý
ýý
ý

ýõzMainWindow.init_file_menuc                 C   sz  |   ¡  d¡| _tjd| tjjd| jd| _	|  
| j| j	¡ tjd| tjjd| jd| _|  
| j| j¡ | j ¡  tjd| tjj| jd| _|  
| j| jd	¡ tjd
| tjj| jd| _|  
| j| jd	¡ tjd| d| jd| _|  
| j| jd	¡ tjd| tjj| jd| _|  
| j| jd	¡ | j ¡  t tjj¡}| d¡r§tjdkr§d}tjd| || jd| _|  
| j| jd	¡ d S )Nz&Editz&UndozUndo last action if possible©r¢   Z	statusTipr£   z&RedozRedo last action if possiblez&Cutr¡   Tz&CopyzCopy (&Raw Text)zCtrl+Shift+Cz&PastezCtrl+Ar¤   zCtrl+Shift+AzSelect Cell/&All) r¦   r§   Z	edit_menur   r¨   r   rª   ZUndoÚundo_active_frontendZundo_actionr™   ZRedoÚredo_active_frontendZredo_actionr©   ZCutÚcut_active_frontendZ
cut_actionZCopyÚcopy_active_frontendZcopy_actionÚcopy_raw_active_frontendZcopy_raw_actionZPasteÚpaste_active_frontendZpaste_actionZ	SelectAllr¯   r°   r±   Úselect_all_active_frontendÚselect_all_action)r%   Z	selectallr   r   r   r›   Å  sd   üü
ýýýý
ýzMainWindow.init_edit_menuc                    sX  ˆ   ¡  d¡ˆ _tjdkr!tjdˆ ddˆ jdˆ _ˆ  	ˆ jˆ j¡ tjdkr(dnd}tjd	ˆ |d
ˆ j
dˆ _ˆ  	ˆ jˆ j¡ ˆ j ¡  tjdˆ tjjˆ jdˆ _ˆ  	ˆ jˆ jd¡ tjdˆ tjjˆ jdˆ _ˆ  	ˆ jˆ jd¡ tjdˆ dˆ jdˆ _ˆ  	ˆ jˆ jd¡ ˆ j ¡  tjdˆ ddˆ jdˆ _ˆ  	ˆ jˆ j¡ ˆ j d¡ˆ _t ˆ ¡}ˆ jj}tjdˆ ‡ fdd„d}| d¡ | |dk¡ tjdˆ ‡ fdd„d}| d¡ | |dk¡ tjdˆ ‡ fdd„d}| d¡ | |dk¡ | |¡ | |¡ | |¡ ˆ j |¡ ˆ j |¡ ˆ j |¡ ˆ j  |¡ ˆ j d ¡ˆ _!tjd!ˆ ‡ fd"d„d}tjd#ˆ ‡ fd$d„d}tjd%ˆ ‡ fd&d„d}	ˆ j! |¡ ˆ j! |¡ ˆ j! |	¡ ˆ  "¡ }
t#|
ƒd'kr¨ˆ j d(¡ˆ _$t ˆ ¡}|
D ]8}t d) %|¡ˆ ¡}|j& 't(ˆ j)|ƒ¡ | d¡ | |¡ ˆ j$ |¡ |d*kr¦| d¡ ˆ j$  |¡ qqd S d S )+Nz&Viewr¤   zToggle &Menu BarúCtrl+Shift+MzToggle visibility of menubarr´   zCtrl+Meta+FZF11z&Full Screenz)Toggle between Fullscreen and Normal SizezZoom &Inr¡   Tz	Zoom &OutzZoom &ResetzCtrl+0z&Clear ScreenzCtrl+LzClear the consolez&Completion typez&ncursesc                      ó
   ˆ   d¡S )NÚncurses©Ú%set_completion_widget_active_frontendr   r+   r   r   Ú<lambda>?  ó    ÿz+MainWindow.init_view_menu.<locals>.<lambda>©r£   r¿   z	&droplistc                      r¾   )NÚdroplistrÀ   r   r+   r   r   rÂ   G  rÃ   rÅ   z&plainc                      r¾   )NÚplainrÀ   r   r+   r   r   rÂ   O  rÃ   rÆ   z&Pagerz.. &Horizontal Splitc                      r¾   )NZhsplit©Úset_paging_active_frontendr   r+   r   r   rÂ   b  ó   
 z : &Vertical Splitc                      r¾   )NZvsplitrÇ   r   r+   r   r   rÂ   f  rÉ   z   &Inside Pagerc                      r¾   )NZinsiderÇ   r   r+   r   r   rÂ   j  rÉ   r   z&Syntax Stylez{}Údefault)*r¦   r§   Z	view_menur°   r±   r   r¨   Útoggle_menu_barZtoggle_menu_bar_actr™   ÚtoggleFullScreenZfull_screen_actr©   r   rª   ZZoomInÚ"increase_font_size_active_frontendÚincrease_font_sizeZZoomOutÚ"decrease_font_size_active_frontendÚdecrease_font_sizeÚreset_font_size_active_frontendÚreset_font_sizeÚclear_active_frontendZclear_actionZcompletion_menuZQActionGroupr5   Úgui_completionZsetCheckableÚ
setCheckedr—   ZsetDefaultActionZ
pager_menuÚget_available_syntax_stylesr‘   Zsyntax_style_menurF   r£   r    r   Úset_syntax_style)r%   Zfs_keyZcompletion_groupZactive_frontend_completionZncurses_completion_actionZdroplist_completion_actionZplain_commpletion_actionZhsplit_actionZvsplit_actionZinside_actionZavailable_syntax_stylesZstyle_groupÚstyler˜   r   r+   r   rœ     sæ   
üü
ýýý
ü

ý
ÿ
ý
ÿ
ý
ÿ



þ
þ
þ
ÿ



€ôzMainWindow.init_view_menuc                 C   sÀ   |   ¡  d¡| _tjdkrdnd}tjd| | j|d d| _|  	| j| j¡ tjd| | j
|d	 d| _|  	| j| j¡ | j ¡  tjd
| d| jj| jd| _|  	| j| j¡ | jj | j¡ d S )Nz&Kernelr¤   ZMetaZCtrlz&Interrupt current Kernelz+C)r£   r¢   z&Restart current Kernelz+.z&Confirm kernel restartT)Z	checkableÚcheckedr£   )r¦   r§   Zkernel_menur°   r±   r   r¨   Ú interrupt_kernel_active_frontendZinterrupt_kernel_actionr™   Úrestart_kernel_active_frontendZrestart_kernel_actionr©   r5   Úconfirm_restartÚ&toggle_confirm_restart_active_frontendÚconfirm_restart_kernel_actionr   ZcurrentChangedr    Úupdate_restart_checkbox)r%   Zctrlr   r   r   r     s.   ýý
üzMainWindow.init_kernel_menuc                 C   s<  |   ¡  d¡| _tjdkr:tjd| dd| jd| _tjd| dd	| j	d| _
|  | j| j¡ |  | j| j
¡ | j ¡  tjdkrAd
nd}tjd| |d| jd| _|  | j| j¡ tjdkr^dnd}tjd| |d| jd| _|  | j| j¡ tjd| dd| jd| _|  | j| j¡ tjd| dd| jd| _|  | j| j¡ d S )Nz&Windowr¤   z	Mini&mizezCtrl+mz'Minimize the window/Restore Normal Sizer´   z&Zoomr½   z'Maximize the window/Restore Normal SizezCtrl+Alt+Leftz	Ctrl+PgUpzPre&vious TabzSelect previous tabzCtrl+Alt+RightzCtrl+PgDownz	Ne&xt TabzSelect next tabzRename &WindowzAlt+RzRename windowz&Rename Current TabzCtrl+RzRename current tab)r¦   r§   Zwindow_menur°   r±   r   r¨   ÚtoggleMinimizedÚminimizeActÚtoggleMaximizedÚmaximizeActr™   r©   rƒ   Zprev_tab_actr   Znext_tab_actrC   Zrename_window_actrO   Zrename_current_tab_act)r%   Zprev_keyZnext_keyr   r   r   rž   ¡  s^   
üü
üüüüzMainWindow.init_window_menuc                 C   s\   |   ¡  d¡| _tjd| | jd| _tjd| | jd| _|  	| j| j¡ |  	| j| j¡ d S )Nz&HelpzShow &QtConsole helprÄ   zOpen online &help)
r¦   r§   Z	help_menur   r¨   Ú
_show_helpZhelp_actionÚ_open_online_helpZonline_help_actionr™   r+   r   r   r   rŸ   Ô  s   ÿÿzMainWindow.init_help_menuc                 C   s   t j d| jjj¡ d S )NéÈ   )r   ZQTimerZ
singleShotr5   Ú_controlZsetFocusr+   r   r   r   Ú_set_active_frontend_focusä  s   z%MainWindow._set_active_frontend_focusc                 C   s,   |   ¡ }| ¡ r| d¡ d S | d¡ d S )NFT)r¦   Z	isVisibler#   )r%   Zmenu_barr   r   r   rË   ì  s   zMainWindow.toggle_menu_barc                 C   ó    |   ¡ s
|  ¡  d S |  ¡  d S r3   )ZisMinimizedZshowMinimizedÚ
showNormalr+   r   r   r   rà   ó  ó   zMainWindow.toggleMinimizedc                 C   s   | j  t¡ d S r3   )r5   Z_pager   r+   r   r   r   rä   ù  ó   zMainWindow._show_helpc                 C   s   t jdddd d S )Nz https://qtconsole.readthedocs.ior(   T)ÚnewZ	autoraise)Ú
webbrowserÚopenr+   r   r   r   rå   ü  s   zMainWindow._open_online_helpc                 C   ré   r3   )ZisMaximizedZshowMaximizedrê   r+   r   r   r   râ   ÿ  rë   zMainWindow.toggleMaximizedc                 C   sl   |   ¡ s|  ¡  tjdkr| j d¡ | j d¡ d S d S |  ¡  tjdkr4| j d¡ | j d¡ d S d S )Nr¤   FT)ZisFullScreenZshowFullScreenr°   r±   rã   Z
setEnabledrá   rê   r+   r   r   r   rÌ     s   
þ
þzMainWindow.toggleFullScreenc                 C   ó   | j  |¡ d S r3   )r5   Z_set_paging)r%   Zpagingr   r   r   rÈ     rì   z%MainWindow.set_paging_active_frontendc                 C   rð   r3   )r5   Z_set_completion_widget)r%   rÔ   r   r   r   rÁ     rì   z0MainWindow.set_completion_widget_active_frontendc                 C   s   t tƒ ƒ}t|ƒS )z,Get a list with the syntax styles available.)Úlistr   Úsorted)r%   r	   r   r   r   rÖ     s   
z&MainWindow.get_available_syntax_stylesc                 C   sr   |dkrd}n
t  |¡rd}nd}|| j_t  ||¡}|| j_| j ¡  | j ¡  | jjdd | j 	dd¡ dS )	z,Set up syntax style for the current console.ÚbwZnocolorÚlinuxZlightbgT)Úclearz%colors linuxN)
r	   Z
dark_styler5   Úsyntax_styleZsheet_from_templateÚstyle_sheetZ_syntax_style_changedZ_style_sheet_changedÚresetZ_execute)r%   rö   Úcolorsr÷   r   r   r   r×     s   


zMainWindow.set_syntax_stylec                 C   s   |   | j¡ d S r3   )r!   r5   r+   r   r   r   r¬   .  rì   z MainWindow.close_active_frontendc                 C   ó   | j  ¡  d S r3   )r5   Zrequest_restart_kernelr+   r   r   r   rÛ   1  ó   z)MainWindow.restart_kernel_active_frontendc                 C   rú   r3   )r5   Zrequest_interrupt_kernelr+   r   r   r   rÚ   4  rû   z+MainWindow.interrupt_kernel_active_frontendc                 C   s"   | j }|j |_| j |j¡ d S r3   )r5   rÜ   rÞ   rÕ   r7   r   r   r   rÝ   7  s   
z1MainWindow.toggle_confirm_restart_active_frontendc                 C   s&   | j d u rd S | j }| j |j¡ d S r3   )r5   rÞ   rÕ   rÜ   r7   r   r   r   rß   <  s   
z"MainWindow.update_restart_checkboxc                 C   rú   r3   )r5   rõ   r+   r   r   r   rÓ   B  rû   z MainWindow.clear_active_frontendc                 C   ó   | j }| ¡ r| ¡  d S d S r3   )r5   Zcan_cutÚcutr7   r   r   r   r·   E  ó   ÿzMainWindow.cut_active_frontendc                 C   s   | j }| ¡  d S r3   )r5   Úcopyr7   r   r   r   r¸   J  s   zMainWindow.copy_active_frontendc                 C   ó   | j j ¡  d S r3   )r5   Z_copy_raw_actionÚtriggerr+   r   r   r   r¹   N  rì   z#MainWindow.copy_raw_active_frontendc                 C   rü   r3   )r5   Z	can_pasteZpaster7   r   r   r   rº   Q  rþ   z MainWindow.paste_active_frontendc                 C   rú   r3   )r5   Zundor+   r   r   r   rµ   V  rû   zMainWindow.undo_active_frontendc                 C   rú   r3   )r5   Zredor+   r   r   r   r¶   Y  rû   zMainWindow.redo_active_frontendc                 C   r   r3   )r5   r³   r  r+   r   r   r   r²   \  rì   z'MainWindow.print_action_active_frontendc                 C   r   r3   )r5   r®   r  r+   r   r   r   r­   _  rì   z(MainWindow.export_action_active_frontendc                 C   r   r3   )r5   r¼   r  r+   r   r   r   r»   b  rì   z%MainWindow.select_all_active_frontendc                 C   r   r3   )r5   rÎ   r  r+   r   r   r   rÍ   e  rì   z-MainWindow.increase_font_size_active_frontendc                 C   r   r3   )r5   rÐ   r  r+   r   r   r   rÏ   h  rì   z-MainWindow.decrease_font_size_active_frontendc                 C   r   r3   )r5   rÒ   r  r+   r   r   r   rÑ   k  rì   z*MainWindow.reset_font_size_active_frontendc                 C   sZ  | j  ¡ dkr| ¡  dS |  ¡  ¡ }tjj}tjj}tjj	}| j
rx| j  ¡ dkr,d}nd}d}t d| ¡}| d¡ t tjj||¡}	|	 |¡ |	 |¡ |	 |tjj¡ |	 |¡ |	 |¡ t | jj t d	d	¡¡¡}
|	 |
¡ |	 ¡ }n|}||kr„| ¡  dS ||ksŒ||kr«| j  ¡ dkr¥| j}d
|_|  |¡ | j  ¡ dks“| ¡  dS dS )zH Forward the close event to every tabs contained by the windows
        r   Nr(   z+Close all tabs, stop all kernels, and Quit?z%Close console, stop kernel, and Quit?z=Kernels not started here (e.g. notebooks) will be left alone.r¥   ÚQrU   F) r   r)   Úacceptra   r=   r   rb   rc   rd   Z
AcceptRoler   rf   rg   rh   ri   rj   rk   rl   rm   r   rn   r   ro   rp   r   rq   rr   rs   Úignorer5   r`   r!   )r%   ÚeventrA   rv   rw   Zaccept_rolerx   r]   ry   rz   rp   r{   r8   r   r   r   Ú
closeEventr  sJ   

ÿ






üúzMainWindow.closeEvent)TNNNNr3   )F)<Ú__name__Ú
__module__Ú__qualname__r   r,   Úpropertyr0   r2   r5   r9   rC   rI   rM   rO   r!   r6   r   rƒ   r|   rY   rW   r™   r    rš   r›   rœ   r   rž   rŸ   rè   rË   rà   rä   rå   râ   rÌ   rÈ   rÁ   rÖ   r×   r¬   rÛ   rÚ   rÝ   rß   rÓ   r·   r¸   r¹   rº   rµ   r¶   r²   r­   r»   rÍ   rÏ   rÑ   r  Ú__classcell__r   r   r&   r   r      s~    ü*





r
'
	@?{"3r   )Ú__doc__r°   rî   Ú	functoolsr   Ú	threadingr   Zjupyter_core.pathsr   Zpygments.stylesr   Zqtpyr   r   r   Z	qtconsoler	   Zqtconsole.jupyter_widgetr
   Zqtconsole.usager   r   ZQMainWindowr   r   r   r   r   Ú<module>   s    