Skip to content

Commit

Permalink
Use a signal to request unmaximizing plugins
Browse files Browse the repository at this point in the history
That way it'll be easier for external plugin developers to ask for this
programmatically.
  • Loading branch information
ccordoba12 committed Aug 8, 2022
1 parent 7dc3231 commit 379b4cf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
11 changes: 11 additions & 0 deletions spyder/api/plugins/new_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ class SpyderPluginV2(QObject, SpyderActionMixin, SpyderConfigurationObserver,
To be used by plugins tracking main window position changes.
"""

sig_unmaximize_plugin_requested = Signal((), (object,))
"""
This signal is emitted to inform the main window that it needs to
unmaximize the currently maximized plugin, if any.
Parameters
----------
plugin_instance: SpyderDockablePlugin
Unmaximize plugin only if it is not `plugin_instance`.
"""

# --- Private attributes -------------------------------------------------
# ------------------------------------------------------------------------
# Define configuration name map for plugin to split configuration
Expand Down
19 changes: 19 additions & 0 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def register_plugin(self, plugin_name, external=False, omit_conf=False):
plugin.sig_focus_changed.connect(self.plugin_focus_changed)
plugin.sig_switch_to_plugin_requested.connect(
self.switch_to_plugin)
plugin.sig_unmaximize_plugin_requested.connect(
self.unmaximize_plugin)
plugin.sig_unmaximize_plugin_requested[object].connect(
self.unmaximize_plugin)
plugin.sig_update_ancestor_requested.connect(
lambda: plugin.set_ancestor(self))

Expand Down Expand Up @@ -357,6 +361,21 @@ def switch_to_plugin(self, plugin, force_focus=None):
"""
self.layouts.switch_to_plugin(plugin, force_focus=force_focus)

def unmaximize_plugin(self, not_this_plugin=None):
"""
Unmaximize currently maximized plugin, if any.
Parameters
----------
not_this_plugin: SpyderDockablePlugin, optional
Unmaximize plugin if the maximized one is `not_this_plugin`.
"""
if not_this_plugin is None:
self.layouts.unmaximize_dockwidget()
else:
self.layouts.unmaximize_other_dockwidget(
plugin_instance=not_this_plugin)

def remove_dockwidget(self, plugin):
"""
Remove a plugin QDockWidget from the main window.
Expand Down
27 changes: 7 additions & 20 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IPythonConsole(SpyderDockablePlugin):

# This is required for the new API
NAME = 'ipython_console'
REQUIRES = [Plugins.Console, Plugins.Preferences, Plugins.Layout]
REQUIRES = [Plugins.Console, Plugins.Preferences]
OPTIONAL = [Plugins.Editor, Plugins.History, Plugins.MainMenu,
Plugins.Projects, Plugins.WorkingDirectory]
TABIFY = [Plugins.History]
Expand Down Expand Up @@ -437,19 +437,6 @@ def _set_working_directory(self, new_dir):
"""Set current working directory on the main widget."""
self.get_widget().set_working_directory(new_dir)

def _unmaximize_plugin(self):
"""
Unmaximize the currently maximized plugin, if any.
Notes
-----
We assume that users want to check output in the IPython console
after running or debugging code. And for that we need to unmaximize any
plugin that is currently maximized.
"""
layouts = self.get_plugin(Plugins.Layout)
layouts.unmaximize_dockwidget()

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

Expand Down Expand Up @@ -663,7 +650,7 @@ def run_script(self, filename, wdir, args='', debug=False,
-------
None.
"""
self._unmaximize_plugin()
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().run_script(
filename,
wdir,
Expand Down Expand Up @@ -704,7 +691,7 @@ def run_cell(self, code, cell_name, filename, run_cell_copy,
-------
None.
"""
self._unmaximize_plugin()
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().run_cell(
code, cell_name, filename, run_cell_copy, focus_to_editor,
function=function)
Expand Down Expand Up @@ -734,7 +721,7 @@ def debug_cell(self, code, cell_name, filename, run_cell_copy,
-------
None.
"""
self._unmaximize_plugin()
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().debug_cell(code, cell_name, filename, run_cell_copy,
focus_to_editor)

Expand Down Expand Up @@ -764,12 +751,12 @@ def execute_code(self, lines, current_client=True, clear_variables=False):

def run_selection(self, lines, focus_to_editor=True):
"""Execute selected lines in the current console."""
self._unmaximize_plugin()
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().execute_code(lines, set_focus=not focus_to_editor)

def stop_debugging(self):
"""Stop debugging in the current console."""
self._unmaximize_plugin()
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().stop_debugging()

def get_pdb_state(self):
Expand All @@ -795,7 +782,7 @@ def pdb_execute_command(self, command, focus_to_editor):
-------
None.
"""
self._unmaximize_plugin()
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().pdb_execute_command(command, focus_to_editor)

def print_debug_file_msg(self):
Expand Down
5 changes: 2 additions & 3 deletions spyder/plugins/projects/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Projects(SpyderDockablePlugin):
NAME = 'project_explorer'
CONF_SECTION = NAME
CONF_FILE = False
REQUIRES = [Plugins.Layout]
REQUIRES = []
OPTIONAL = [Plugins.Completions, Plugins.IPythonConsole, Plugins.Editor,
Plugins.MainMenu]
WIDGET_CLASS = ProjectExplorerWidget
Expand Down Expand Up @@ -392,8 +392,7 @@ def on_close(self, cancelable=False):
def unmaximize(self):
"""Unmaximize the currently maximized plugin, if not self."""
if self.main:
layouts = self.get_plugin(Plugins.Layout)
layouts.unmaximize_other_dockwidget(plugin_instance=self)
self.sig_unmaximize_plugin_requested[object].emit(self)

def build_opener(self, project):
"""Build function opening passed project"""
Expand Down
4 changes: 1 addition & 3 deletions spyder/plugins/tours/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class Tours(SpyderPluginV2):
"""
NAME = 'tours'
CONF_SECTION = NAME
REQUIRES = [Plugins.Layout]
OPTIONAL = [Plugins.MainMenu]
CONF_FILE = False
CONTAINER_CLASS = ToursContainer
Expand Down Expand Up @@ -103,8 +102,7 @@ def show_tour(self, index):
index: int
The tour index to display.
"""
layouts = self.get_plugin(Plugins.Layout)
layouts.unmaximize_dockwidget()
self.sig_unmaximize_plugin_requested.emit()
self.get_container().show_tour(index)

def show_tour_message(self, force=False):
Expand Down

0 comments on commit 379b4cf

Please sign in to comment.