Skip to content

Commit

Permalink
Merge pull request #2584 from goanpeca/update-varex
Browse files Browse the repository at this point in the history
Homogenize variable explorer UI
  • Loading branch information
ccordoba12 committed Aug 8, 2015
2 parents fb423c5 + c437485 commit ceffc5c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 42 deletions.
2 changes: 1 addition & 1 deletion spyderlib/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def register_client(self, client, restart=False, give_focus=True):

# Connect to our variable explorer
if kernel_widget is not None and self.variableexplorer is not None:
nsb = self.variableexplorer.currentWidget()
nsb = self.variableexplorer.current_widget()
# When the autorefresh button is active, our kernels
# start to consume more and more CPU during time
# Fix Issue 1450
Expand Down
56 changes: 40 additions & 16 deletions spyderlib/plugins/variableexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

"""Namespace Browser Plugin"""

from spyderlib.qt.QtGui import QStackedWidget, QGroupBox, QVBoxLayout
from spyderlib.qt.QtCore import Signal
from spyderlib.qt.QtGui import QGroupBox, QStackedWidget, QVBoxLayout, QWidget
from spyderlib.qt.QtCore import Signal, Slot
import spyderlib.utils.icon_manager as ima

# Local imports
Expand Down Expand Up @@ -75,7 +75,7 @@ def setup_page(self):
self.setLayout(vlayout)


class VariableExplorer(QStackedWidget, SpyderPluginMixin):
class VariableExplorer(QWidget, SpyderPluginMixin):
"""
Variable Explorer Plugin
"""
Expand All @@ -84,10 +84,18 @@ class VariableExplorer(QStackedWidget, SpyderPluginMixin):
sig_option_changed = Signal(str, object)

def __init__(self, parent):
QStackedWidget.__init__(self, parent)
QWidget.__init__(self, parent)
SpyderPluginMixin.__init__(self, parent)

# Widgets
self.stack = QStackedWidget(self)
self.shellwidgets = {}

# Layout
layout = QVBoxLayout()
layout.addWidget(self.stack)
self.setLayout(layout)

# Initialize plugin
self.initialize_plugin()

Expand All @@ -102,11 +110,27 @@ def get_settings():
for name in REMOTE_SETTINGS:
settings[name] = CONF.get(VariableExplorer.CONF_SECTION, name)
return settings

#------ Public API ---------------------------------------------------------

# ----- Stack accesors ----------------------------------------------------
def set_current_widget(self, nsb):
self.stack.setCurrentWidget(nsb)

def current_widget(self):
return self.stack.currentWidget()

def count(self):
return self.stack.count()

def remove_widget(self, nsb):
self.stack.removeWidget(nsb)

def add_widget(self, nsb):
self.stack.addWidget(nsb)

# ----- Public API --------------------------------------------------------
def add_shellwidget(self, shellwidget):
shellwidget_id = id(shellwidget)
# Add shell only once: this method may be called two times in a row
# Add shell only once: this method may be called two times in a row
# by the External console plugin (dev. convenience)
from spyderlib.widgets.externalshell import systemshell
if isinstance(shellwidget, systemshell.ExternalSystemShell):
Expand All @@ -116,7 +140,7 @@ def add_shellwidget(self, shellwidget):
nsb.set_shellwidget(shellwidget)
nsb.setup(**VariableExplorer.get_settings())
nsb.sig_option_changed.connect(self.sig_option_changed.emit)
self.addWidget(nsb)
self.add_widget(nsb)
self.shellwidgets[shellwidget_id] = nsb
self.set_shellwidget_from_id(shellwidget_id)
return nsb
Expand All @@ -126,22 +150,22 @@ def remove_shellwidget(self, shellwidget_id):
# that shell was not a Python-based console (it was a terminal)
if shellwidget_id in self.shellwidgets:
nsb = self.shellwidgets.pop(shellwidget_id)
self.removeWidget(nsb)
self.remove_widget(nsb)
nsb.close()

def set_shellwidget_from_id(self, shellwidget_id):
if shellwidget_id in self.shellwidgets:
nsb = self.shellwidgets[shellwidget_id]
self.setCurrentWidget(nsb)
self.set_current_widget(nsb)
if self.isvisible:
nsb.visibility_changed(True)

def import_data(self, fname):
"""Import data in current namespace"""
if self.count():
nsb = self.currentWidget()
nsb = self.current_widget()
nsb.refresh_table()
nsb.import_data(fname)
nsb.import_data(filename=fname)
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.raise_()
Expand All @@ -151,7 +175,7 @@ def visibility_changed(self, enable):
"""DockWidget visibility has changed"""
SpyderPluginMixin.visibility_changed(self, enable)
for nsb in list(self.shellwidgets.values()):
nsb.visibility_changed(enable and nsb is self.currentWidget())
nsb.visibility_changed(enable and nsb is self.current_widget())

#------ SpyderPluginWidget API ---------------------------------------------
def get_plugin_title(self):
Expand All @@ -167,7 +191,7 @@ def get_focus_widget(self):
Return the widget to give focus to when
this plugin's dockwidget is raised on top-level
"""
return self.currentWidget()
return self.current_widget()

def closing_plugin(self, cancelable=False):
"""Perform actions before parent main window is closed"""
Expand All @@ -192,4 +216,4 @@ def apply_plugin_settings(self, options):
nsb.setup(**VariableExplorer.get_settings())
ar_timeout = self.get_option('autorefresh/timeout')
for shellwidget in self.main.extconsole.shellwidgets:
shellwidget.set_autorefresh_timeout(ar_timeout)
shellwidget.set_autorefresh_timeout(ar_timeout)
50 changes: 25 additions & 25 deletions spyderlib/widgets/externalshell/namespacebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,35 @@ def setup(self, check_all=None, exclude_private=None,
self.editor.sig_option_changed.connect(self.sig_option_changed.emit)
self.editor.sig_files_dropped.connect(self.import_data)


# Menu
options_button = create_toolbutton(self, text=_('Options'),
icon=ima.icon('tooloptions'))
options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
editor = self.editor
actions = [self.exclude_private_action, self.exclude_uppercase_action,
self.exclude_capitalized_action,
self.exclude_unsupported_action, None,
editor.truncate_action]
if is_module_installed('numpy'):
actions.append(editor.minmax_action)
add_actions(menu, actions)
options_button.setMenu(menu)

# Setup layout
hlayout = QHBoxLayout()
vlayout = QVBoxLayout()
layout = QVBoxLayout()
blayout = QHBoxLayout()
toolbar = self.setup_toolbar(exclude_private, exclude_uppercase,
exclude_capitalized, exclude_unsupported,
autorefresh)
vlayout.setAlignment(Qt.AlignTop)
for widget in toolbar:
vlayout.addWidget(widget)
hlayout.addWidget(self.editor)
hlayout.addLayout(vlayout)
self.setLayout(hlayout)
hlayout.setContentsMargins(0, 0, 0, 0)
blayout.addWidget(widget)
blayout.addStretch()
blayout.addWidget(options_button)
layout.addLayout(blayout)
layout.addWidget(self.editor)
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)

self.sig_option_changed.connect(self.option_changed)

Expand Down Expand Up @@ -226,21 +241,6 @@ def setup_toolbar(self, exclude_private, exclude_uppercase,
self.sig_option_changed.emit('exclude_unsupported', state))
self.exclude_unsupported_action.setChecked(exclude_unsupported)

options_button = create_toolbutton(self, text=_('Options'),
icon=ima.icon('tooloptions'))
toolbar.append(options_button)
options_button.setPopupMode(QToolButton.InstantPopup)
menu = QMenu(self)
editor = self.editor
actions = [self.exclude_private_action, self.exclude_uppercase_action,
self.exclude_capitalized_action,
self.exclude_unsupported_action, None,
editor.truncate_action]
if is_module_installed('numpy'):
actions.append(editor.minmax_action)
add_actions(menu, actions)
options_button.setMenu(menu)

self.setup_in_progress = False

return toolbar
Expand Down Expand Up @@ -437,6 +437,7 @@ def collapse(self):
"""Collapse"""
self.sig_collapse.emit()

# FIXME: This method raises an error when called from the button in the UI
@Slot(list)
def import_data(self, filenames=None):
"""Import data from text file"""
Expand Down Expand Up @@ -553,4 +554,3 @@ def save_data(self, filename=None):
_("<b>Unable to save current workspace</b>"
"<br><br>Error message:<br>%s") % error_message)
self.save_button.setEnabled(self.filename is not None)

0 comments on commit ceffc5c

Please sign in to comment.