
    JeV                         d Z ddlmZ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lmZmZmZ ddlmZ  G d	 d
      Z G d d      Z G d d      Z G d d      Z G d d      Z G d d      Z G d de      Zy)z'
Variable Explorer Main Plugin Widget.
    )QTimerSlot)QActionQHBoxLayoutQWidget)on_conf_change_)ShellConnectMainWidget)NamespaceBrowserNamespacesBrowserFinderVALID_VARIABLE_CHARS)is_module_installedc                   <    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)VariableExplorerWidgetActionsimport_data_actionsave_data_actionsave_data_as_actionreset_namespaces_actionsearchrefreshtoggle_exclude_private_actiontoggle_exclude_uppercase_action!toggle_exclude_capitalized_action!toggle_exclude_unsupported_action+toggle_exclude_callables_and_modules_actiontoggle_minmax_actionN)__name__
__module____qualname__
ImportDataSaveData
SaveDataAsResetNamespaceSearchRefreshToggleExcludePrivateToggleExcludeUpperCaseToggleExcludeCapitalizedToggleExcludeUnsupported ToggleExcludeCallablesAndModulesToggleMinMax     U/usr/lib/python3/dist-packages/spyder/plugins/variableexplorer/widgets/main_widget.pyr   r      sG    %J!H&J.NFG ;>BB5 %)Lr.   r   c                       e Zd ZdZdZy))VariableExplorerWidgetOptionsMenuSectionsexcludes_sectionhighlight_sectionN)r   r   r    Display	Highlightr-   r.   r/   r1   r1   .   s     G#Ir.   r1   c                       e Zd ZdZy))VariableExplorerWidgetMainToolBarSectionsmain_sectionN)r   r   r    Mainr-   r.   r/   r7   r7   3   s    Dr.   r7   c                       e Zd ZdZdZy)VariableExplorerWidgetMenusempty	populatedN)r   r   r    EmptyContextMenuPopulatedContextMenur-   r.   r/   r;   r;   7   s    &r.   r;   c                   D    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ZdZy)"VariableExplorerContextMenuActionsresize_rows_actionresize_columns_actionpaste_actioncopyedit_actionplot_actionhistogram_actionimshow_actionsave_array_actioninsert_actionremove_actionrename_actionduplicate_actionview_actionN)r   r   r    ResizeRowsActionResizeColumnsActionPasteAction
CopyAction
EditAction
PlotActionHistogramActionImshowActionSaveArrayActionInsertActionRemoveActionRenameActionDuplicateAction
ViewActionr-   r.   r/   rA   rA   <   sJ    +1 KJJJ(O"L)O"L"L"L(OJr.   rA   c                       e Zd ZdZdZdZdZy)#VariableExplorerContextMenuSectionsedit_sectioninsert_sectionview_sectionresize_sectionN)r   r   r    EditInsertViewResizer-   r.   r/   r_   r_   M   s    DFDFr.   r_   c                   @    e Zd ZdZdZdZd% fd	Zd Zd Zd Z	e
d        Zd	 Zd
 Zd Zd Zd&dZd Zd Z ee      d        Z e       d        Zd Zd Z e       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'e(d#        Z)d$ Z* xZ+S )'VariableExplorerWidgetTi`  i  c                 R    t         |   |||       d | _        d | _        d | _        y N)super__init__context_menuempty_context_menufinder)selfnamepluginparent	__class__s       r/   rm   zVariableExplorerWidget.__init__a   s/    vv. !"& r.   c                     t        d      S )NzVariable Explorerr	   rq   s    r/   	get_titlez VariableExplorerWidget.get_titlem   s    $%%r.   c                      j                  t        j                  t        d      t        d      dd      } j                  t        j                  t        d      t        d      dd      } j                  t        j
                  t        d	      t        d
      dd      } j                  t        j                  t        d      t        d      dd      } j                  t        j                  t        d      t        d      dd      } j                  t        j                  t        d      t        d      dd       _	         j                  t        j                  t        d       j                  d       fd      } j                  t        j                  t        d       j                  d       fd      } j                  t        j                  t        d       j                  d       fd      } j                  t        j                  t        d       j                  d        fd!      }	 j                  t        j                  t        d"       j                  d#       j                   d$      }
 j                  t        j"                  t        d%       j                  d&       j$                  d'      } j                  t&        j(                  t        d(       j                  d)       j*                        } j                  t&        j,                  t        d*       j                  d+       j.                  ,      } j                  t&        j0                  t        d-       j                  d.       j2                  ,       _         j                  t&        j6                  t        d/       j                  d0       j8                  ,       _         j                  t&        j<                  t        d1       j                  d2       j>                  ,       _          j                  t&        jB                  t        d3       j                  d4       jD                  ,       _#         jF                  jI                  d5        j                  t&        jJ                  t        d6       j                  d7       jL                  ,       _'         jN                  jI                  d5        j                  t&        jP                  t        d8       j                  d9       jR                  ,       _*         jT                  jI                  d5        j                  t&        jV                  t        d:       j                  d       jX                  ,       _-         jZ                  jI                  d5        j                  t&        j\                  t        d;       j                  d<       j^                  ,       _0         j                  t&        jb                  t        d=       j                  d        jd                  ,       _3         j                  t&        jh                  t        d>       j                  d?       jj                  ,       _6         j                  t&        jn                  t        d@       j                  dA       jp                  ,       _9         j                  t&        jt                  t        dB       j                  dC       jv                  ,       _<         j{                         }||||| j                  fD ]$  } j}                  ||t~        j                  D       &  j                         }||||	|
|fD ]$  } j                  ||t        j                  E       & |j                  d5        j                  t        j                         _I         j@                   j:                   j4                   jl                   jf                   jZ                  fD ].  } j}                  | j                  t        j                  D       0  j`                   jr                  fD ].  } j}                  | j                  t        j                  D       0  jx                   jF                   jN                   jT                   j                  fD ].  } j}                  | j                  t        j                  D       0 ||fD ].  } j}                  | j                  t        j                  D       0  j                  t        j                         _P         j`                   j4                  fD ].  } j}                  | j                  t        j                  D       0 y )FNzExclude private variablesz/Exclude variables that start with an underscoreTexclude_private)texttiptoggledoptionzExclude all-uppercase variablesz)Exclude variables whose name is uppercaseexclude_uppercasezExclude capitalized variablesz9Exclude variables whose name starts with a capital letterexclude_capitalizedzExclude unsupported data typeszZExclude references to data types that don't have an specialized viewer or can't be edited.exclude_unsupportedzExclude callables and modulesz@Exclude references to functions, modules and any other callable.exclude_callables_and_moduleszShow arrays min/maxz"Show minimum and maximum of arraysminmaxzImport data
fileimportc                 $    j                         S rk   )import_dataxrq   s    r/   <lambda>z.VariableExplorerWidget.setup.<locals>.<lambda>   s     0 0 2 r.   )r{   icon	triggeredz	Save datafilesavec                 $    j                         S rk   	save_datar   s    r/   r   z.VariableExplorerWidget.setup.<locals>.<lambda>        0 r.   zSave data as...
filesaveasc                 $    j                         S rk   r   r   s    r/   r   z.VariableExplorerWidget.setup.<locals>.<lambda>   r   r.   zRemove all variables
editdeletec                 $    j                         S rk   )reset_namespacer   s    r/   r   z.VariableExplorerWidget.setup.<locals>.<lambda>   s     4 4 6 r.   zSearch variable names and typesfind)r{   r   r}   register_shortcutzRefresh variablesr   )r{   r   r   r   zResize rows to contentscollapse_rowzResize columns to contentscollapse_column)r   r   Paste	editpasteCopyeditcopyrd   editPlotplotF	Histogramhistz
Show imageimshowz
Save arrayre   insertRemoveRenamerename	Duplicateedit_addzView with the Object Exploreroutline_explorer)menusection)toolbarr   )Qcreate_actionr   r'   r
   r(   r)   r*   r+   r,   show_minmax_actionr!   create_iconr"   r#   r$   r%   show_finderr&   refresh_tablerA   rP   resize_rowsrQ   resize_columnsrR   pasterD   rS   rE   copy_actionrT   	edit_itemrF   rU   	plot_itemrG   
setVisiblerV   histogram_itemhist_actionrW   imshow_itemrI   rX   
save_arrayrJ   rY   insert_itemrK   rZ   remove_itemrL   r[   rename_itemrM   r\   duplicate_itemrN   r]   	view_itemrO   get_options_menuadd_item_to_menur1   r4   get_main_toolbaradd_item_to_toolbarr7   r9   
setEnabledcreate_menur;   r?   rn   r_   rd   re   rf   rg   r>   ro   )rq   exclude_private_actionexclude_uppercase_actionexclude_capitalized_actionexclude_unsupported_action$exclude_callables_and_modules_actionr   save_actionsave_as_actionreset_namespace_actionsearch_actionrefresh_actionrB   rC   options_menuitemmain_toolbars   `                r/   setupzVariableExplorerWidget.setupp   sI	   !%!3!3)>>./CD$ "4 "
 $(#5#5)@@45=>& $6 $
  &*%7%7)BB23  ( &8 &
" &*%7%7)BB34 > ?( &8 &
" 04/A/A)JJ23 ( )2 0B 0
, #'"4"4)66()67 #5 #
 "//)44=!!!,/2	 0 
 (()22;!!*-0	 ) 
 ++)44$%!!,/0	 , 
 "&!3!3)88)*!!,/6	 "4 "
 **)0045!!&)$$" + 
 ++)11&'!!),((" , 
 "//.??,-!!.1&&	 0 
 !% 2 2.BB*+!!"34))	 !3 !
 !...::gJ!!+.jj	 / 
  --.99fI!!*-ii	 . 
  --.99fI!!&)nn	 . 
  --.99fI!!&)nn	 . 
 	##E*--.>>kN!!&)))	 . 
 	##E*!//.;;lO!!(+&&	 0 
 	%%e,!%!3!3.>>lO!!*-oo	 "4 "
 	))%0!//.;;hK!!(+&&	 0 
 "//.;;hK!!,/&&	 0 
 "//.;;hK!!(+&&	 0 
 !% 2 2.>>kN!!*-))	 !3 !
  --.99-.!!"45nn	 . 
 ,,.+-E/1K9,,. 	D !!!AII " 		 ,,.'n+]NL 	D$$$AFF % 	 	u% !,,'<<>%%t'7'79J9J''););++- 	D !!&&;@@ " 	 '')>)>? 	D!!&&;BB " 	 %%t'7'79I9I'')@)@B 	D!!&&;@@ " 	 ()>? 	D!!&&;BB " 	 #'"2"2'88#:''):):; 	D!!,,;@@ " 	r.   c                    | j                  t        j                        }|j                  t	        d             | j                         }| j                         j                         D ]m  \  }}|s	|s| j                  t        j                        }|j                  |j                  d u       |j                         }||vs]|j                  |       o y )Nnumpy)
get_actionr   r,   r   r   current_widgetget_actionsitemsr"   filenameactions	addAction)rq   actionnsb__r   nsb_actionss         r/   update_actionsz%VariableExplorerWidget.update_actions|  s    !>!K!KL-g67!!#**,224 	.JB
 '+5>>(@$$//D0HI"%++-K[0f-	.r.   c                     t        | j                               D ]0  }| j                  j                  |      }|s!|j	                          2 y rk   )rangecount_stackwidgetr   )rq   r   indexr   s       r/   on_section_conf_changez-VariableExplorerWidget.on_section_conf_change  s<    4::<( 	E[[''.F	r.   c                 :   | j                   ?t        |       | _         t        |j                  |j                  j                  |t
              | _        | j                  | j                   _        | j                  d| j                  | j                  d            | _
        t               }|j                  | j                         |j                  | j                         |j                  dddd       | j                   j                  |       | j                         }|j!                  d       |j                  | j                          y|| j#                  |       | j                  j%                  |j                  |j                  j                  |       y)	z#Initialize or update finder widget.N)callbackmain
regex_baseclose_finderDialogCloseButton)r   r   r      )r   r   )rp   r   r   editor	set_regexr   text_findercreate_toolbuttonhide_finderr   finder_close_buttonr   	addWidgetsetContentsMargins	setLayoutlayout
addSpacingsave_finder_stateupdate_parent)rq   r   old_nsbfinder_layoutr   s        r/   update_finderz$VariableExplorerWidget.update_finder  sM   ;;!$-DK6

--/	 1D
 '+&6&6DKK#'+'='=**%%&9: (> (D$ (MM##D$<$<=##D$4$45,,Q1a8KK!!-0[[]Fa T[[)
 "&&w/**

-- + r.   c                     | j                  ||       |j                  | j                        }| j                  j	                  |       | j                  t        j                        }|j                  |       y)z
        Set the current NamespaceBrowser.

        This also setup the finder widget to work with the current
        NamespaceBrowser.
        N)	r  set_text_finderr   rp   r   r   r   r%   
setChecked)rq   r   r   finder_visibler   s        r/   switch_widgetz$VariableExplorerWidget.switch_widget  s_     	3(,,T-=-=>~.(E(L(LM  0r.   c                    t        |       }|j                  |       |j                          |j                  j	                  | j
                         |j                  j	                  | j                         |j                  j	                  | j                         |j                  j	                  | j                         | j                  |       |S rk   )r   set_shellwidgetr   sig_free_memory_requestedconnectfree_memorysig_start_spinner_requestedstart_spinnersig_stop_spinner_requestedstop_spinnersig_hide_finder_requestedr   _set_actions_and_menus)rq   shellwidgetr   s      r/   create_new_widgetz(VariableExplorerWidget.create_new_widget  s    t$K(		%%--	''//	 &&..	%%--	##C(
r.   c                 F    |j                          |j                  d        y rk   )close	setParentrq   r   s     r/   close_widgetz#VariableExplorerWidget.close_widget  s    		dr.   c                     | j                         r3| j                         }|j                          |j                  |       yy)z3
        Import data in current namespace.
        )	filenamesN)r   r   r   r   )rq   r  r   s      r/   r   z"VariableExplorerWidget.import_data  s:     ::<%%'COOiO0 r.   c                     | j                         r1| j                         }|j                          | j                          y y rk   )r   r   r   r   r  s     r/   r   z VariableExplorerWidget.save_data  s3    ::<%%'CMMO! r.   c                 f    | j                         r!| j                         }|j                          y y rk   )r   r   r   r  s     r/   r   z&VariableExplorerWidget.reset_namespace  s*    ::<%%'C! r.   c                    | j                         r| j                         }|r0| j                  j                  j	                  |j
                         n6| j                  |       | j                  j                  j	                  d       | j                  j                  |       | j                  j                         r%| j                  j                  j                          y |j                  j                          y y )N )r   r   rp   r   setText	last_findr   r   	isVisiblesetFocusr   )rq   checkedr   s      r/   r   z"VariableExplorerWidget.show_finder  s    ::<%%'C''//>&&s+''//3KK""7+{{$$&''002

##% r.   c                     | j                  t        j                        }|j                  d       | j	                         }| j                  |       | j                  j                  j                  d       y )NFr  )	r   r   r%   r  r   r   rp   r   r   )rq   r   r   s      r/   r   z"VariableExplorerWidget.hide_finder  sY    !>!E!EF% !!#s#''+r.   c                     | j                   j                         }| j                  j                         }|j	                  ||       y)z
        Save finder state (last input text and visibility).

        The values are saved in the given NamespaceBrowser.
        N)r   r{   rp   r"  r   )rq   r   r!  finder_visibilitys       r/   r   z(VariableExplorerWidget.save_finder_state  s<     $$))+	 KK113i):;r.   c                 f    | j                         r!| j                         }|j                          y y rk   )r   r   r   r  s     r/   r   z$VariableExplorerWidget.refresh_table  s*    ::<%%'C r.   c                     | j                   j                          t        j                  | j                  | j                          t        j                  | j
                  | j                          y)z%
        Free memory signal.
        N)r
  emitr   
singleShot INITIAL_FREE_MEMORY_TIME_TRIGGER"SECONDARY_FREE_MEMORY_TIME_TRIGGERrw   s    r/   r  z"VariableExplorerWidget.free_memory  sT    
 	&&++-$??88	:$AA88	:r.   c                 8    | j                   j                          y rk   )_current_editorresizeRowsToContentsrw   s    r/   r   z"VariableExplorerWidget.resize_rows'  s    113r.   c                 8    | j                   j                          y rk   )r/  resize_column_contentsrw   s    r/   r   z%VariableExplorerWidget.resize_columns*  s    335r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   zVariableExplorerWidget.paste-  s    ""$r.   c                 8    | j                   j                          y rk   )r/  rE   rw   s    r/   rE   zVariableExplorerWidget.copy0  s    !!#r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z VariableExplorerWidget.edit_item3      &&(r.   c                 :    | j                   j                  d       y )Nr   r/  r   rw   s    r/   r   z VariableExplorerWidget.plot_item6      &&v.r.   c                 :    | j                   j                  d       y )Nr   r8  rw   s    r/   r   z%VariableExplorerWidget.histogram_item9  r9  r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z"VariableExplorerWidget.imshow_item<      ((*r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z!VariableExplorerWidget.save_array?  s    '')r.   c                 <    | j                   j                  d       y )NF)below)r/  r   rw   s    r/   r   z"VariableExplorerWidget.insert_itemB  s    ((u(5r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z"VariableExplorerWidget.remove_itemE  r<  r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z"VariableExplorerWidget.rename_itemH  r<  r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z%VariableExplorerWidget.duplicate_itemK  s    ++-r.   c                 8    | j                   j                          y rk   )r/  r   rw   s    r/   r   z VariableExplorerWidget.view_itemN  r6  r.   c                 b    d }| j                         r| j                         }|j                  }|S rk   )r   r   r   )rq   r   r   s      r/   r/  z&VariableExplorerWidget._current_editorS  s,    ::<%%'CZZFr.   c                 V   |j                   }| j                  |_        | j                  |_        | j                  |_        | j                  |_        | j
                  |_        | j                  |_        | j                  |_        | j                  |_        | j                  |_	        | j                  |_        | j                  |_        | j                  |_        | j                  |_        | j                  |_        | j"                  |_        t'               |_        t'               |_        y)z
        Set actions and menus created here and used by the namespace
        browser editor.

        Although this is not ideal, it's necessary to be able to use
        the CollectionsEditor widget separately from this plugin.
        N)r   rD   r   rF   rG   r   rI   rJ   rK   rL   r   minmax_actionrM   rN   rO   rn   r   ro   empty_ws_menur   insert_action_aboveinsert_action_below)rq   r   r   s      r/   r  z-VariableExplorerWidget._set_actions_and_menus[  s      #//!--!--!--!--#11#'#9#9 #11#11#66#11"&"7"7!-- ''#66
 &-Y"%,Y"r.   )NNNrk   ),r   r   r    ENABLE_SPINNERr,  r-  rm   rx   r   r   r   r   r  r  r  r  r   r   r   r   boolr   r   r   r   r  r   r   r   rE   r   r   r   r   r   r   r   r   r   r   propertyr/  r  __classcell__)ru   s   @r/   ri   ri   X   s    N (1$)3&&JX.(  $L1 1""
 
$Z& & 
V, ,< 
 
V: :46%$)//+*6++.)
  !/r.   ri   N)__doc__qtpy.QtCorer   r   qtpy.QtWidgetsr   r   r   spyder.api.config.decoratorsr   spyder.api.translationsr
   #spyder.api.shellconnect.main_widgetr   8spyder.plugins.variableexplorer.widgets.namespacebrowserr   r   r   spyder.utils.programsr   r   r1   r7   r;   rA   r_   ri   r-   r.   r/   <module>rV     sz   
 % 8 8 8 % FE E 5* *&$ $
 ' '
 " d/3 d/r.   