
    Jea<                         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y)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y)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     J/usr/lib/python3/dist-packages/spyder/plugins/plots/widgets/main_widget.pyr   r      sF    DGDEH,$FG  D==r&   r   c                       e Zd ZdZdZdZy)PlotsWidgetMainToolbarSectionsedit_sectionmove_sectionzoom_sectionN)r   r   r   EditMoveZoomr%   r&   r'   r)   r)   0   s    DDDr&   r)   c                       e Zd ZdZy)PlotsWidgetToolbarItems	zoom_spinN)r   r   r   ZoomSpinBoxr%   r&   r'   r1   r1   6   s    Kr&   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 )PlotsWidgetc                 R   t         |   |||       t        |       | _        t        j
                  | j                  _        d | _        | j                  j                  t        j                         | j                  j                  t        j                         | j                  j                  d       | j                  j                  d       | j                  j                  dd       | j                  j!                  d       | j#                  d| j%                                y )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??(,% 	##BNN3''(:(:;""4(  &4($ 	E4;;=)r&   c                     t        d      S )NPlotsr   )rG   s    r'   	get_titlezPlotsWidget.get_titleV   s    zr&   c                     | j                         }|rL|j                  j                  6|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   sO    $$&f**<<H))----88r&   c           
      2	   | j                  t        j                  t        d      t        d      d| j	                  d      d      | _        | j                  t        j                  t        d      t        d      d| j	                  d      d      | _        | j                  t        j                  t        d	      t        d
      d| j	                  d      d      | _	        | j                  t        j                  t        d      t        d      | j                  d      | j                  d      }| j                  t        j                  t        d      t        d      | j                  d      | j                  d      }| j                  t        j                  t        d      t        d      | j                  d      | j                   d      }| j                  t        j"                  t        d      | j                  d      | j$                  d      }| j                  t        j&                  t        d      t        d      | j                  d      | j(                  d      }| j                  t        j*                  t        d      t        d      | j                  d      | j,                  d      }| j                  t        j.                  t        d      t        d      | j                  d      | j0                  d      }| j                  t        j2                  t        d      t        d      | j                  d      | j4                  d      }| j                  t        j6                  t        d      t        d      | j                  d       | j8                  d      }	| j;                         }
| j=                  | j
                  |
!       | j=                  | j                  |
!       | j=                  | j                  |
!       | j?                         }|||||||||	| j@                  f
D ]$  }| jC                  ||tD        jF                  "       & | jI                  tJ        jL                        }|||fD ]  }| j=                  ||!        y )#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MM"89) . 
 #00#99&'*+MM"56& 1 
 ,,#99()>?MM"56& - 
 ((#(($%#$!!*-nn" ) 
 ,,#++&'%&!!*-))" - 
 ((#((<34!!*-oo" ) 
 **#))=!!!+.&&" + 
 !..#,,%&$%!!.1++" / 
 ,,#88?#/"!!*-((" - 
 ((#44;+!!&)nn" ) 
 ++#**9)!!),ll" , 
 ,,#++:*!!*-mm" - 
 ,,.d..\Bd11EdooLA ,,. /;&#_dnnF 	D $$$6;; % 	 ''(=(E(EF +}= 	;D!!$\!:	;r&   c           
         d}| j                         }d }|r0|j                  }|j                  }|j                  j                  d u}| j                         j                         D ]  \  }}	 |r|| j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  fvr]|j                  |       |rJ|j!                         }j!                         }||vr|j#                  |       ||vr|j#                  |        | j(                  j                  |       |r| j+                  d       }| j-                  t.        j0                        j                  |       | j-                  t.        j2                        j                  |       | j(                  j                  |       y y # t$        t&        f$ r Y ~w xY w)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   $$&	((I"00M''++47E**,224 	JBfT-=-=-1-@-@-1__-1-?-?-1->->-1-=-=-1-D-D-1-D-D-F F %%e, !,5,=,=,?)0=0E0E0G-!)::%//7!)>>)33F;1	8 	!!%( &9::EOO.556AA%HOO.667BB5INN%%e,	  !.1 s   ,B;GG$#G$)rc   r\   rb   save_dir)ra   c                     t        | j                               D ]C  }| j                  j                  |      }|s!|j	                  ||i       | j                          E y rP   )rangecount_stackrY   r   r   )rG   ra   r   indexrY   s        r'   on_section_conf_changez"PlotsWidget.on_section_conf_change	  sQ     4::<( 	&E[[''.Ffe_-##%		&r&   c                 L    t         t              }|j                   j                                |j	                  |       |j
                  j                   j
                         |j                  j                   j                         |j                  j                   j                         |j                  j                   j                         |j                  j                   fd       |j                  j                   j                  j                          |S )N)rJ   background_colorc                 (    j                  d|       S )Nr   )set_conf)valrG   s    r'   <lambda>z/PlotsWidget.create_new_widget.<locals>.<lambda>#  s    j#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**4::<8##K00088--	/ 	--55!!	#0088$$	&%%--d.A.AB((006	8$$,,T^^-D-DEr&   c                 F    |j                          |j                  d        y rP   )r   	setParent)rG   r   s     r'   close_widgetzPlotsWidget.close_widget'  s    d#r&   c           	          ddddt               fg}|D ci c]  \  }}|| j                  ||       }}}|j                  |       y c c}}w )N)rc   T)r\   T)rb   Tr   )r   rt   r   )rG   r   old_fig_browseroption_keyskdconf_valuess          r'   switch_widgetzPlotsWidget.switch_widget+  s[    252"N$457
 ;FF$!Qq$--1--FF+& Gs   Ac                     d| _         | j                         }|r/| j                  t        j                        j                  |       yy)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@     )-%$$&MM/778>>vF r&   c                     || _         | j                         }|r/| j                  t        j                        j                  |       yy)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%$$&MM/778>>vF r&   c                     | j                         }|rT| j                  |j                  j                          y|j                  j	                  | j                         d| _        yy)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_    
 $$&,,4$$;;=$$==113 15- r&   c                 ^    | j                         }|r|j                  j                          yy)zSave all available plots.N)rQ   rR   save_all_figures_asrX   s     r'   rz   zPlotsWidget.save_all_plots`  s*    $$&  446 r&   c                 >   | j                         }|r|j                  r~|j                  j                  j                  r]| j                  %|j                  j                  j                          y| j                  j                  j                          d| _        yyyy)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    
 $$&f&&6+;+;+E+E+I+I,,4  **668--44@@B 15- ,J&6r&   c                     | j                         }|rS| j                  |j                  j                          n,|j                  j	                  | j                         d| _        | j                          y)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  sf    
 $$&,,4$$==?$$55113 15-r&   c                 |    | j                         }|r|j                  j                          | j                          y)zRemove all available plots..N)rQ   rR   remove_all_thumbnailsr   rX   s     r'   r}   zPlotsWidget.remove_all_plots  s1    $$&  668r&   c                 ^    | j                         }|r|j                  j                          yy)z5Select the previous plot in the thumbnails scrollbar.N)rQ   rR   go_previous_thumbnailrX   s     r'   r~   zPlotsWidget.previous_plot  s*    $$&  668 r&   c                 ^    | j                         }|r|j                  j                          yy)z1Select the next plot in the thumbnails scrollbar.N)rQ   rR   go_next_thumbnailrX   s     r'   r   zPlotsWidget.next_plot  s*    $$&  224 r&   c                 J    | j                         }|r|j                          yy)z%Perform a zoom in on the main figure.N)rQ   rn   rX   s     r'   rn   zPlotsWidget.zoom_in  s"    $$&NN r&   c                 J    | j                         }|r|j                          yy)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;t,-\  = >&>&$$'GG5 75$9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      sc   
 # # 8 % @ F D , . 00
> >$  i( ir&   