1
# -*- coding: utf-8 -*-
3
# Copyright © 2009-2010 Pierre Raybaut
4
# Licensed under the terms of the MIT License
5
# (see spyderlib/__init__.py for details)
7
"""Namespace Browser Plugin"""
9
from spyderlib.qt.QtGui import QStackedWidget, QGroupBox, QVBoxLayout
10
from spyderlib.qt.QtCore import Signal
13
from spyderlib.baseconfig import _
14
from spyderlib.config import CONF, get_icon
15
from spyderlib.utils import programs
16
from spyderlib.plugins import SpyderPluginMixin, PluginConfigPage
17
from spyderlib.widgets.externalshell.monitor import REMOTE_SETTINGS
18
from spyderlib.widgets.externalshell.namespacebrowser import NamespaceBrowser
21
class VariableExplorerConfigPage(PluginConfigPage):
23
ar_group = QGroupBox(_("Autorefresh"))
24
ar_box = self.create_checkbox(_("Enable autorefresh"),
26
ar_spin = self.create_spinbox(_("Refresh interval: "),
27
_(" ms"), 'autorefresh/timeout',
28
min_=100, max_=1000000, step=100)
30
filter_group = QGroupBox(_("Filter"))
32
('exclude_private', _("Exclude private references")),
33
('exclude_capitalized', _("Exclude capitalized references")),
34
('exclude_uppercase', _("Exclude all-uppercase references")),
35
('exclude_unsupported', _("Exclude unsupported data types")),
37
filter_boxes = [self.create_checkbox(text, option)
38
for option, text in filter_data]
40
display_group = QGroupBox(_("Display"))
42
('truncate', _("Truncate values"), ''),
43
('inplace', _("Always edit in-place"), ''),
44
('collvalue', _("Show collection contents"), ''),
46
if programs.is_module_installed('numpy'):
47
display_data.append(('minmax', _("Show arrays min/max"), ''))
49
('remote_editing', _("Edit data in the remote process"),
50
_("Editors are opened in the remote process for NumPy "
51
"arrays, PIL images, lists, tuples and dictionaries.\n"
52
"This avoids transfering large amount of data between "
53
"the remote process and Spyder (through the socket)."))
55
display_boxes = [self.create_checkbox(text, option, tip=tip)
56
for option, text, tip in display_data]
58
ar_layout = QVBoxLayout()
59
ar_layout.addWidget(ar_box)
60
ar_layout.addWidget(ar_spin)
61
ar_group.setLayout(ar_layout)
63
filter_layout = QVBoxLayout()
64
for box in filter_boxes:
65
filter_layout.addWidget(box)
66
filter_group.setLayout(filter_layout)
68
display_layout = QVBoxLayout()
69
for box in display_boxes:
70
display_layout.addWidget(box)
71
display_group.setLayout(display_layout)
73
vlayout = QVBoxLayout()
74
vlayout.addWidget(ar_group)
75
vlayout.addWidget(filter_group)
76
vlayout.addWidget(display_group)
78
self.setLayout(vlayout)
81
class VariableExplorer(QStackedWidget, SpyderPluginMixin):
83
Variable Explorer Plugin
85
CONF_SECTION = 'variable_explorer'
86
CONFIGWIDGET_CLASS = VariableExplorerConfigPage
87
sig_option_changed = Signal(str, object)
88
def __init__(self, parent):
89
QStackedWidget.__init__(self, parent)
90
SpyderPluginMixin.__init__(self, parent)
91
self.shellwidgets = {}
94
self.initialize_plugin()
99
Return Variable Explorer settings dictionary
100
(i.e. namespace browser settings according to Spyder's configuration file)
103
# CONF.load_from_ini() # necessary only when called from another process
104
for name in REMOTE_SETTINGS:
105
settings[name] = CONF.get(VariableExplorer.CONF_SECTION, name)
108
#------ Public API ---------------------------------------------------------
109
def add_shellwidget(self, shellwidget):
110
shellwidget_id = id(shellwidget)
111
# Add shell only once: this method may be called two times in a row
112
# by the External console plugin (dev. convenience)
113
from spyderlib.widgets.externalshell import systemshell
114
if isinstance(shellwidget, systemshell.ExternalSystemShell):
116
if shellwidget_id not in self.shellwidgets:
117
nsb = NamespaceBrowser(self)
118
nsb.set_shellwidget(shellwidget)
119
nsb.setup(**VariableExplorer.get_settings())
120
nsb.sig_option_changed.connect(self.sig_option_changed.emit)
122
self.shellwidgets[shellwidget_id] = nsb
123
self.set_shellwidget_from_id(shellwidget_id)
126
def remove_shellwidget(self, shellwidget_id):
127
# If shellwidget_id is not in self.shellwidgets, it simply means
128
# that shell was not a Python/IPython-based console (it was a terminal)
129
if shellwidget_id in self.shellwidgets:
130
nsb = self.shellwidgets.pop(shellwidget_id)
131
self.removeWidget(nsb)
134
def set_shellwidget_from_id(self, shellwidget_id):
135
if shellwidget_id in self.shellwidgets:
136
nsb = self.shellwidgets[shellwidget_id]
137
self.setCurrentWidget(nsb)
139
nsb.visibility_changed(True)
141
def import_data(self, fname):
142
"""Import data in current namespace"""
144
nsb = self.currentWidget()
146
nsb.import_data(fname)
147
if self.dockwidget and not self.ismaximized:
148
self.dockwidget.setVisible(True)
149
self.dockwidget.raise_()
151
#------ SpyderPluginMixin API ---------------------------------------------
152
def visibility_changed(self, enable):
153
"""DockWidget visibility has changed"""
154
SpyderPluginMixin.visibility_changed(self, enable)
155
for nsb in self.shellwidgets.values():
156
nsb.visibility_changed(enable and nsb is self.currentWidget())
158
#------ SpyderPluginWidget API ---------------------------------------------
159
def get_plugin_title(self):
160
"""Return widget title"""
161
return _('Variable explorer')
163
def get_plugin_icon(self):
164
"""Return plugin icon"""
165
return get_icon('dictedit.png')
167
def get_focus_widget(self):
169
Return the widget to give focus to when
170
this plugin's dockwidget is raised on top-level
172
return self.currentWidget()
174
def closing_plugin(self, cancelable=False):
175
"""Perform actions before parent main window is closed"""
178
def refresh_plugin(self):
182
def get_plugin_actions(self):
183
"""Return a list of actions related to plugin"""
186
def register_plugin(self):
187
"""Register plugin in Spyder's main window"""
188
self.main.extconsole.set_variableexplorer(self)
189
self.main.add_dockwidget(self)
191
def apply_plugin_settings(self, options):
192
"""Apply configuration file's plugin settings"""
193
for nsb in self.shellwidgets.values():
194
nsb.setup(**VariableExplorer.get_settings())
195
ar_timeout = self.get_option('autorefresh/timeout')
196
for shellwidget in self.main.extconsole.shellwidgets:
1
# -*- coding: utf-8 -*-
3
# Copyright © 2009-2010 Pierre Raybaut
4
# Licensed under the terms of the MIT License
5
# (see spyderlib/__init__.py for details)
7
"""Namespace Browser Plugin"""
9
from spyderlib.qt.QtGui import QStackedWidget, QGroupBox, QVBoxLayout
10
from spyderlib.qt.QtCore import Signal
13
from spyderlib.baseconfig import _
14
from spyderlib.config import CONF
15
from spyderlib.guiconfig import get_icon
16
from spyderlib.utils import programs
17
from spyderlib.plugins import SpyderPluginMixin, PluginConfigPage
18
from spyderlib.widgets.externalshell.monitor import REMOTE_SETTINGS
19
from spyderlib.widgets.externalshell.namespacebrowser import NamespaceBrowser
22
class VariableExplorerConfigPage(PluginConfigPage):
24
ar_group = QGroupBox(_("Autorefresh"))
25
ar_box = self.create_checkbox(_("Enable autorefresh"),
27
ar_spin = self.create_spinbox(_("Refresh interval: "),
28
_(" ms"), 'autorefresh/timeout',
29
min_=100, max_=1000000, step=100)
31
filter_group = QGroupBox(_("Filter"))
33
('exclude_private', _("Exclude private references")),
34
('exclude_capitalized', _("Exclude capitalized references")),
35
('exclude_uppercase', _("Exclude all-uppercase references")),
36
('exclude_unsupported', _("Exclude unsupported data types")),
38
filter_boxes = [self.create_checkbox(text, option)
39
for option, text in filter_data]
41
display_group = QGroupBox(_("Display"))
43
('truncate', _("Truncate values"), ''),
44
('inplace', _("Always edit in-place"), ''),
45
('collvalue', _("Show collection contents"), ''),
47
if programs.is_module_installed('numpy'):
48
display_data.append(('minmax', _("Show arrays min/max"), ''))
50
('remote_editing', _("Edit data in the remote process"),
51
_("Editors are opened in the remote process for NumPy "
52
"arrays, PIL images, lists, tuples and dictionaries.\n"
53
"This avoids transfering large amount of data between "
54
"the remote process and Spyder (through the socket)."))
56
display_boxes = [self.create_checkbox(text, option, tip=tip)
57
for option, text, tip in display_data]
59
ar_layout = QVBoxLayout()
60
ar_layout.addWidget(ar_box)
61
ar_layout.addWidget(ar_spin)
62
ar_group.setLayout(ar_layout)
64
filter_layout = QVBoxLayout()
65
for box in filter_boxes:
66
filter_layout.addWidget(box)
67
filter_group.setLayout(filter_layout)
69
display_layout = QVBoxLayout()
70
for box in display_boxes:
71
display_layout.addWidget(box)
72
display_group.setLayout(display_layout)
74
vlayout = QVBoxLayout()
75
vlayout.addWidget(ar_group)
76
vlayout.addWidget(filter_group)
77
vlayout.addWidget(display_group)
79
self.setLayout(vlayout)
82
class VariableExplorer(QStackedWidget, SpyderPluginMixin):
84
Variable Explorer Plugin
86
CONF_SECTION = 'variable_explorer'
87
CONFIGWIDGET_CLASS = VariableExplorerConfigPage
88
sig_option_changed = Signal(str, object)
89
def __init__(self, parent):
90
QStackedWidget.__init__(self, parent)
91
SpyderPluginMixin.__init__(self, parent)
92
self.shellwidgets = {}
95
self.initialize_plugin()
100
Return Variable Explorer settings dictionary
101
(i.e. namespace browser settings according to Spyder's configuration file)
104
# CONF.load_from_ini() # necessary only when called from another process
105
for name in REMOTE_SETTINGS:
106
settings[name] = CONF.get(VariableExplorer.CONF_SECTION, name)
109
#------ Public API ---------------------------------------------------------
110
def add_shellwidget(self, shellwidget):
111
shellwidget_id = id(shellwidget)
112
# Add shell only once: this method may be called two times in a row
113
# by the External console plugin (dev. convenience)
114
from spyderlib.widgets.externalshell import systemshell
115
if isinstance(shellwidget, systemshell.ExternalSystemShell):
117
if shellwidget_id not in self.shellwidgets:
118
nsb = NamespaceBrowser(self)
119
nsb.set_shellwidget(shellwidget)
120
nsb.setup(**VariableExplorer.get_settings())
121
nsb.sig_option_changed.connect(self.sig_option_changed.emit)
123
self.shellwidgets[shellwidget_id] = nsb
124
self.set_shellwidget_from_id(shellwidget_id)
127
def remove_shellwidget(self, shellwidget_id):
128
# If shellwidget_id is not in self.shellwidgets, it simply means
129
# that shell was not a Python-based console (it was a terminal)
130
if shellwidget_id in self.shellwidgets:
131
nsb = self.shellwidgets.pop(shellwidget_id)
132
self.removeWidget(nsb)
135
def set_shellwidget_from_id(self, shellwidget_id):
136
if shellwidget_id in self.shellwidgets:
137
nsb = self.shellwidgets[shellwidget_id]
138
self.setCurrentWidget(nsb)
140
nsb.visibility_changed(True)
142
def import_data(self, fname):
143
"""Import data in current namespace"""
145
nsb = self.currentWidget()
147
nsb.import_data(fname)
148
if self.dockwidget and not self.ismaximized:
149
self.dockwidget.setVisible(True)
150
self.dockwidget.raise_()
152
#------ SpyderPluginMixin API ---------------------------------------------
153
def visibility_changed(self, enable):
154
"""DockWidget visibility has changed"""
155
SpyderPluginMixin.visibility_changed(self, enable)
156
for nsb in self.shellwidgets.values():
157
nsb.visibility_changed(enable and nsb is self.currentWidget())
159
#------ SpyderPluginWidget API ---------------------------------------------
160
def get_plugin_title(self):
161
"""Return widget title"""
162
return _('Variable explorer')
164
def get_plugin_icon(self):
165
"""Return plugin icon"""
166
return get_icon('dictedit.png')
168
def get_focus_widget(self):
170
Return the widget to give focus to when
171
this plugin's dockwidget is raised on top-level
173
return self.currentWidget()
175
def closing_plugin(self, cancelable=False):
176
"""Perform actions before parent main window is closed"""
179
def refresh_plugin(self):
183
def get_plugin_actions(self):
184
"""Return a list of actions related to plugin"""
187
def register_plugin(self):
188
"""Register plugin in Spyder's main window"""
189
self.main.extconsole.set_variableexplorer(self)
190
self.main.add_dockwidget(self)
192
def apply_plugin_settings(self, options):
193
"""Apply configuration file's plugin settings"""
194
for nsb in self.shellwidgets.values():
195
nsb.setup(**VariableExplorer.get_settings())
196
ar_timeout = self.get_option('autorefresh/timeout')
197
for shellwidget in self.main.extconsole.shellwidgets:
197
198
shellwidget.set_autorefresh_timeout(ar_timeout)
b'\\ No newline at end of file'