
    G@da<                         d 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 ddlmZ ddlmZ dd	lmZ dd
lmZ ej        Z G d d          Z G d d          Z G d d          Z G d de          ZdS )z
Plots Main Widget.
    )QtSignal)QSpinBox)on_conf_change_)PluginMainWidgetMenus)ShellConnectMainWidget)FigureBrowser)getcwd_or_home)QStylePalettec                   >    e 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dZdS )PlotsWidgetActionssavezsave allcopyclosez	close allzprevious figureznext figurezzoom inzzoom out"toggle_mute_inline_plotting_actiontoggle_show_plot_outline_actiontoggle_auto_fit_plotting_actionN)__name__
__module____qualname__SaveSaveAllCopyCloseCloseAllMoveToPreviousFigureMoveToNextFigureZoomInZoomOutToggleMuteInlinePlottingToggleShowPlotOutlineToggleAutoFitPlotting     Hlib/python3.11/site-packages/spyder/plugins/plots/widgets/main_widget.pyr   r      sT        DGDEH,$FG  D==r&   r   c                       e Zd ZdZdZdZdS )PlotsWidgetMainToolbarSectionsedit_sectionmove_sectionzoom_sectionN)r   r   r   EditMoveZoomr%   r&   r'   r)   r)   0   s        DDDDDr&   r)   c                       e Zd ZdZdS )PlotsWidgetToolbarItems	zoom_spinN)r   r   r   ZoomSpinBoxr%   r&   r'   r1   r1   6   s        KKKr&   r1   c                        e Zd Z e            Z	 d fd	Zd Zd Zd Zd Z	 e
g d          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d Zd Z xZS )PlotsWidgetNc                 b   t                                          |||           t          |           | _        t          j        | j        _        d | _        | j                            t          j
                   | j                            t          j                   | j                            d           | j                            d           | j                            dd           | j                            d           |                     d|                                            d S )NTz %r   i'  d   iP  )super__init__r   	zoom_dispr1   r3   ID_right_clicked_thumbnailsetAlignmentr   AlignCentersetButtonSymbols	NoButtonssetReadOnly	setSuffixsetRangesetValueresizeheight)selfnamepluginparent	__class__s       r'   r9   zPlotsWidget.__init__@   s    vv... "$3?(,% 	##BN333''(:;;;""4(((  &&&4((($$$ 	E4;;==)))))r&   c                      t          d          S )NPlotsr   )rG   s    r'   	get_titlezPlotsWidget.get_titleV   s    zzr&   c                     |                                  }|r)|j        j        |j        j        j        r|j        j        }|S N)current_widgetthumbnails_sbcurrent_thumbnail	figviewer	figcanvasfig
scrollarearG   widgets     r'   get_focus_widgetzPlotsWidget.get_focus_widgetY   sG    $$&& 	9f*<H)- 9-8r&   c           
      	   |                      t          j        t          d          t          d          d|                     d          d          | _        |                      t          j        t          d          t          d          d|                     d          d          | _        |                      t          j        t          d	          t          d
          d|                     d          d          | _	        |                      t          j
        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d          | j        d          }|                      t          j        t          d          t          d          |                     d           | j        d          }	|                                 }
|                     | j        |
!           |                     | j        |
!           |                     | j	        |
!           |                                 }|||||||||	| j         f
D ]$}| !                    ||tD          j#        "           %| $                    tJ          j&                  }|||fD ]}|                     ||!           d S )#NzMute inline plottingz,Mute inline plotting in the ipython console.Tmute_inline_plotting)rH   texttiptoggledinitialoptionzShow plot outlinezShow the plot outline.show_plot_outlinezFit plots to windowz*Automatically fit plots to Plot pane size.auto_fit_plottingzSave plot as...filesave)rH   r]   r^   icon	triggeredregister_shortcutzSave all plots...save_allz
Copy imagezCopy plot to clipboard as imageeditcopyzRemove plot	editclear)rH   r]   re   rf   rg   zRemove all plotsfilecloseallzPrevious plotpreviousz	Next plotnextzZoom inzoom_inzZoom outzoom_out)menu)toolbarsection)'create_actionr   r"   r   get_confmute_actionr#   outline_actionr$   
fit_actionr   create_icon	save_plotr   save_all_plotsr   
copy_imager   remove_plotr   remove_all_plotsr   previous_plotr   	next_plotr    rn   r!   ro   get_options_menuadd_item_to_menuget_main_toolbarr:   add_item_to_toolbarr)   r-   create_menur	   Context)rG   save_actionsave_all_actioncopy_actionremove_actionremove_all_actionprevious_actionnext_actionzoom_in_actionzoom_out_actionoptions_menumain_toolbaritemcontext_menus                 r'   setupzPlotsWidget.setupa   s   --#<)**@AAMM"899) . 
 
 #00#9&''*++MM"566& 1 
 
 ,,#9())>??MM"566& - 
 
 ((#($%%#$$!!*--n" ) 
 
 ,,#+&''%&&!!*--)" - 
 
 ((#(<344!!*--o" ) 
 
 **#)=!!!!+..&" + 
 
 !..#,%&&$%%!!.11+" / 
 
 ,,#8?##/""!!*--(" - 
 
 ((#4;+!!&))n" ) 
 
 ++#*9)!!),,l" , 
 
 ,,#+:*!!*--m" - 
 
 ,,..d.\BBBd1EEEdoLAAA ,,.. /;&#_dnF 	 	D $$$6; %     ''(=(EFF +}= 	; 	;D!!$\!::::	; 	;r&   c           
         d}|                                  }d }|r|j        }|j        }|j        j        d u}|                                                                 D ]\  }}	 |r|| j        | j        | j	        | j
        | j        | j        | j        | j        fvrq|                    |           |rZ|                                }|                                }||vr|                    |           ||vr|                    |           # t$          t&          f$ r Y w xY w| j                            |           |r|                     d           }|                     t.          j                                      |           |                     t.          j                                      |           | j                            |           d S d S )NFrc   )rQ   rT   rR   rU   rV   get_actionsitemsru   rv   rw   undock_actionclose_actiondock_actiontoggle_view_actionlock_unlock_action
setEnabledactions	addActionRuntimeErrorAttributeErrorr:   rt   
get_actionr   r    r!   )	rG   valuerY   rT   rR   __actionfigviewer_actionsthumbnails_sb_actionss	            r'   update_actionszPlotsWidget.update_actions   s   $$&&	 	8(I"0M'+47E**,,2244 	 	JB <fT-=-1-@-1_-1-?-1->-1-=-1-D-1-D-F F F %%e,,, ! <,5,=,=,?,?)0=0E0E0G0G-!):::%//777!)>>>)33F;;; .1    	!!%(((  	-&9:::EOO.566AA%HHHOO.677BB5IIIN%%e,,,,,		- 	-s   #B'DDD)rc   r\   rb   save_dir)ra   c                     t          |                                           D ]I}| j                            |          }|r+|                    ||i           |                                  Jd S rP   )rangecount_stackrY   r   r   )rG   ra   r   indexrY   s        r'   on_section_conf_changez"PlotsWidget.on_section_conf_change	  ss     4::<<(( 	& 	&E[''..F &fe_---##%%%		& 	&r&   c                 &    t           t                    }|                                                                |                    |           |j                             j                   |j                             j                   |j	                             j
                   |j                             j                   |j                             fd           |j                             j        j                   |S )N)rJ   background_colorc                 0                         d|           S )Nr   )set_conf)valrG   s    r'   <lambda>z/PlotsWidget.create_new_widget.<locals>.<lambda>#  s    j#66 r&   )r   MAIN_BG_COLORupdate_splitter_widthswidthset_shellwidgetsig_redirect_stdio_requestedconnectsig_figure_menu_requestedshow_figure_menusig_thumbnail_menu_requestedshow_thumbnail_menusig_figure_loadedr   sig_save_dir_changedsig_zoom_changedr:   rD   )rG   shellwidgetfig_browsers   `  r'   create_new_widgetzPlotsWidget.create_new_widget  s   #45BD D D**4::<<888##K000088-	/ 	/ 	/ 	-55!	# 	# 	#088$	& 	& 	&%--d.ABBB(006666	8 	8 	8$,,T^-DEEEr&   c                 X    |                                  |                    d            d S rP   )r   	setParent)rG   r   s     r'   close_widgetzPlotsWidget.close_widget'  s.    d#####r&   c                 v     ddddt                      fg} fd|D             }|                    |           d S )N)rc   T)r\   T)rb   Tr   c                 D    i | ]\  }}|                     ||          S r%   )rt   ).0kdrG   s      r'   
<dictcomp>z-PlotsWidget.switch_widget.<locals>.<dictcomp>1  s-    FFF$!Qq$--1--FFFr&   )r   r   )rG   r   old_fig_browseroption_keysconf_valuess   `    r'   switch_widgetzPlotsWidget.switch_widget+  sW    252"N$4$457
 GFFF+FFF+&&&&&r&   c                     d| _         |                                 }|r4|                     t          j                                      |           dS dS )z
        Show main figure menu and display on given `qpoint`.

        Parameters
        ----------
        qpoint: QPoint
            The point to display the menu in global coordinated.
        Nr<   rQ   get_menur	   r   popup)rG   qpointrY   s      r'   r   zPlotsWidget.show_figure_menu4  s\     )-%$$&& 	GMM/788>>vFFFFF	G 	Gr&   c                     || _         |                                 }|r4|                     t          j                                      |           dS dS )z
        Show menu on a given `thumbnail` and display on given `qpoint`.

        Parameters
        ----------
        qpoint: QPoint
            The point to display the menu in global coordinated.
        Nr   )rG   r   	thumbnailrY   s       r'   r   zPlotsWidget.show_thumbnail_menuB  s\     )2%$$&& 	GMM/788>>vFFFFF	G 	Gr&   c                     |                                  }|rJ| j        |j                                         dS |j                            | j                   d| _        dS dS )z
        Save currently active plot or plot selected to be saved with
        context menu in the thumbnails scrollbar.
        N)rQ   r<   rR   save_current_figure_assave_thumbnail_figure_asrX   s     r'   ry   zPlotsWidget.save_plotP  s|    
 $$&& 	5,4$;;=====$==13 3 3 15---	5 	5r&   c                 h    |                                  }|r|j                                         dS dS )zSave all available plots.N)rQ   rR   save_all_figures_asrX   s     r'   rz   zPlotsWidget.save_all_plots`  s@    $$&& 	7 4466666	7 	7r&   c                    |                                  }|rf|j        ra|j        j        j        rR| j         |j        j                                         dS | j        j                                         d| _        dS dS dS dS )z
        Copy currently active plot or plot selected to be copied with
        context menu in the thumbnails scrollbar into the clipboard.
        N)rQ   rT   rU   rV   r<   copy_figurecanvasrX   s     r'   r{   zPlotsWidget.copy_imagef  s    
 $$&& 	5f& 	56+;+E+I 	5,4 *6688888-4@@BBB 15---	5 	5 	5 	5 	5 	5r&   c                     |                                  }|rG| j        |j                                         n&|j                            | j                   d| _        |                                  dS )z
        Remove currently active plot or plot selected to be removed with
        context menu in the thumbnails scrollbar.
        N)rQ   r<   rR   remove_current_thumbnailremove_thumbnailr   rX   s     r'   r|   zPlotsWidget.remove_plotu  s    
 $$&& 	5,4$==????$5513 3 3 15-r&   c                     |                                  }|r|j                                         |                                  dS )zRemove all available plots..N)rQ   rR   remove_all_thumbnailsr   rX   s     r'   r}   zPlotsWidget.remove_all_plots  sH    $$&& 	9 66888r&   c                 h    |                                  }|r|j                                         dS dS )z5Select the previous plot in the thumbnails scrollbar.N)rQ   rR   go_previous_thumbnailrX   s     r'   r~   zPlotsWidget.previous_plot  s@    $$&& 	9 6688888	9 	9r&   c                 h    |                                  }|r|j                                         dS dS )z1Select the next plot in the thumbnails scrollbar.N)rQ   rR   go_next_thumbnailrX   s     r'   r   zPlotsWidget.next_plot  s@    $$&& 	5 2244444	5 	5r&   c                 ^    |                                  }|r|                                 dS dS )z%Perform a zoom in on the main figure.N)rQ   rn   rX   s     r'   rn   zPlotsWidget.zoom_in  s;    $$&& 	NN	 	r&   c                 ^    |                                  }|r|                                 dS dS )z&Perform a zoom out on the main figure.N)rQ   ro   rX   s     r'   ro   zPlotsWidget.zoom_out  s;    $$&& 	OO	 	r&   )NNN)r   r   r   r   r   r9   rN   rZ   r   r   r   r   r   r   r   r   r   ry   rz   r{   r|   r}   r~   r   rn   ro   __classcell__)rK   s   @r'   r5   r5   <   s       D* * * * * *,    x; x; x;t,- ,- ,-\ ^ = = = > > >& &> >&  $$ $ $' ' 'G G GG G G5 5 5 7 7 75 5 5  $  9 9 95 5 5        r&   r5   N)__doc__qtpy.QtCorer   r   qtpy.QtWidgetsr   spyder.api.config.decoratorsr   spyder.api.translationsr   spyder.api.widgets.main_widgetr	   #spyder.api.shellconnect.main_widgetr
   *spyder.plugins.plots.widgets.figurebrowserr   spyder.utils.miscr   spyder.utils.paletter   COLOR_BACKGROUND_1r   r   r)   r1   r5   r%   r&   r'   <module>r      s|   
 # " " " " " " " # # # # # # 8 7 7 7 7 7 % % % % % % @ @ @ @ @ @ F F F F F F D D D D D D , , , , , , . . . . . . 0
> > > > > > > >$              i i i i i( i i i i ir&   