
    Je                     F    d Z ddlmZmZ ddlmZ ddlmZ  G d de      Zy)z~
Main widget to use in plugins that show content that comes from the IPython
console, such as the Variable Explorer or Plots.
    )QStackedWidgetQVBoxLayout)_)PluginMainWidgetc                   j     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z xZS )ShellConnectMainWidgetac  
    Main widget to use in a plugin that shows console-specific content.

    Notes
    -----
    * This is composed of a QStackedWidget to stack widgets associated to each
      shell widget in the console and only show one of them at a time.
    * The current widget in the stack will display the content associated to
      the console with focus.
    c                    t        |   |i | t        |       | _        i | _        t               }|j                  d       |j                  dddd       |j                  | j                         | j                  |       y )Nr   )
super__init__r   _stack_shellwidgetsr   
setSpacingsetContentsMargins	addWidget	setLayout)selfargskwargslayout	__class__s       E/usr/lib/python3/dist-packages/spyder/api/shellconnect/main_widget.pyr   zShellConnectMainWidget.__init__   st    $)&) %T* !!!!Q1-%v    c                 :    | j                   j                  d       y )Nz*QStackedWidget {padding: 0px; border: 0px})r   setStyleSheetr   s    r   update_stylez#ShellConnectMainWidget.update_style-   s    !!"NOr   c                 6    | j                   j                         S )z
        Return the number of widgets in the stack.

        Returns
        -------
        int
            The number of widgets in the stack.
        )r   countr   s    r   r   zShellConnectMainWidget.count2   s     {{  ""r   c                 6    | j                   j                         S )z
        Return the current figure browser widget in the stack.

        Returns
        -------
        QWidget
            The current widget.
        )r   currentWidgetr   s    r   current_widgetz%ShellConnectMainWidget.current_widget=   s     {{((**r   c                 "    | j                         S )N)r!   r   s    r   get_focus_widgetz'ShellConnectMainWidget.get_focus_widgetH   s    ""$$r   c                     t        |      }|| j                  vr]| j                  |      }| j                  j	                  |       || j                  |<   | j                  |       | j                          yy)z[
        Create a new widget in the stack and associate it to
        shellwidget.
        N)idr   create_new_widgetr   r   set_shellwidgetupdate_actionsr   shellwidgetshellwidget_idwidgets       r   add_shellwidgetz&ShellConnectMainWidget.add_shellwidgetM   sl    
 K!3!33++K8FKK!!&)17D~.  -! 4r   c                     t        |      }|| j                  v rH| j                  j                  |      }| j                  j	                  |       | j                  |       yy)z(Remove widget associated to shellwidget.N)r%   r   popr   removeWidgetclose_widgetr)   s       r   remove_shellwidgetz)ShellConnectMainWidget.remove_shellwidgetZ   sT    KT///''++N;FKK$$V,f% 0r   c                     t        |      }| j                         }|| j                  v r=| j                  |   }| j                  ||       | j                  j                  |       yy)zO
        Set widget associated with shellwidget as the current widget.
        N)r%   r!   r   switch_widgetr   setCurrentWidget)r   r*   r+   
old_widgetr,   s        r   r'   z&ShellConnectMainWidget.set_shellwidgetb   s`     K((*
T///''7Fvz2KK((0 0r   c                     t         )z0Create a widget to communicate with shellwidget.NotImplementedError)r   r*   s     r   r&   z(ShellConnectMainWidget.create_new_widgetm       !!r   c                     t         )zClose the widget.r8   r   r,   s     r   r1   z#ShellConnectMainWidget.close_widgetq   r:   r   c                     t         )zSwitch the current widget.r8   )r   r,   r6   s      r   r4   z$ShellConnectMainWidget.switch_widgetu   r:   r   c                 f    | j                         r!| j                         }|j                          yy)zRefresh widgets.N)r   r!   refreshr<   s     r   r?   zShellConnectMainWidget.refreshy   s(    ::<((*FNN r   c                     | j                         }| j                         j                         D ]1  \  }}|s	|s|j                         }||vs!|j	                  |       3 y)zUpdate the actions.N)r!   get_actionsitemsactions	addAction)r   r,   __actionwidget_actionss        r   r(   z%ShellConnectMainWidget.update_actions   s_    $$&**,224 		1JB
 %+^^%5N^3((0		1r   )__name__
__module____qualname____doc__r   r   r   r!   r#   r-   r2   r'   r&   r1   r4   r?   r(   __classcell__)r   s   @r   r   r      sJ    	P
	#	+%
"&	1"""1r   r   N)	rK   qtpy.QtWidgetsr   r   spyder.api.translationsr   spyder.api.widgets.main_widgetr   r    r   r   <module>rQ      s&    7 & ;x1- x1r   