New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PR: Create a separate window when undocking plugins #3824
Changes from 23 commits
6f45e71
ece67e1
238ffd6
71ec0aa
6769d6d
ecac519
5dad62d
e679c2d
aa36f3c
aaa59e8
21cee40
b668163
d2589cd
d7db783
a9da3f1
160adca
9f134f8
b899227
c37f541
072c4a3
9fae0b0
43a55ad
5ebbc84
f9168c4
c186de6
3437f75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,15 @@ | |
""" | ||
|
||
# Third party imports | ||
from qtpy.QtCore import Qt | ||
from qtpy.QtCore import Qt, Slot | ||
from qtpy.QtGui import QKeySequence | ||
from qtpy.QtWidgets import QDockWidget, QShortcut, QWidget | ||
from qtpy.QtWidgets import QDockWidget, QMainWindow, QShortcut, QWidget | ||
|
||
# Local imports | ||
from spyder.config.base import _ | ||
from spyder.config.gui import get_font | ||
from spyder.config.main import CONF | ||
from spyder.utils import icon_manager as ima | ||
from spyder.utils.qthelpers import create_action | ||
from spyder.widgets.dock import SpyderDockWidget | ||
|
||
|
@@ -85,8 +86,10 @@ def create_dockwidget(self): | |
dock.setWidget(self) | ||
self.update_margins() | ||
dock.visibilityChanged.connect(self.visibility_changed) | ||
dock.topLevelChanged.connect(self.create_window) | ||
dock.plugin_closed.connect(self.plugin_closed) | ||
self.dockwidget = dock | ||
self.undocked = False | ||
if self.shortcut is not None: | ||
sc = QShortcut(QKeySequence(self.shortcut), self.main, | ||
self.switch_to_plugin) | ||
|
@@ -169,3 +172,53 @@ def toggle_view(self, checked): | |
self.dockwidget.raise_() | ||
else: | ||
self.dockwidget.hide() | ||
|
||
@Slot() | ||
def create_window(self): | ||
"""Open a window of the plugin instead of undocking it.""" | ||
if self.dockwidget.isFloating() and not self.undocked: | ||
self.dockwidget.setFloating(False) | ||
self.dockwidget.setVisible(False) | ||
self.undock_action.setDisabled(True) | ||
window = self.create_mainwindow() | ||
window.show() | ||
elif self.undocked: | ||
self.undock_action.setDisabled(True) | ||
else: | ||
self.undock_action.setDisabled(False) | ||
self.undocked = False | ||
|
||
def create_mainwindow(self): | ||
""" | ||
Create a QMainWindow instance containing this plugin. | ||
""" | ||
raise NotImplementedError | ||
|
||
def create_undock_action(self): | ||
"""Create the undock action for the plugin.""" | ||
self.undock_action = create_action(self, | ||
_("Undock the plugin"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's change this to simply |
||
icon=ima.icon('newwindow'), | ||
tip=_("Undock the plugin"), | ||
triggered=self.undock_plugin) | ||
|
||
def undock_plugin(self): | ||
"""Undocks the plugin from the MainWindow.""" | ||
self.undocked = True | ||
self.dockwidget.setFloating(True) | ||
self.undock_action.setDisabled(True) | ||
|
||
|
||
class PluginMainWindow(QMainWindow): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this class to be before |
||
"""Spyder Plugin MainWindow class.""" | ||
def __init__(self, plugin): | ||
QMainWindow.__init__(self) | ||
self.plugin = plugin | ||
|
||
def closeEvent(self, event): | ||
"""Reimplement Qt method.""" | ||
self.plugin.dockwidget.setWidget(self.plugin) | ||
self.plugin.dockwidget.setVisible(True) | ||
self.plugin.undock_action.setDisabled(False) | ||
self.plugin.switch_to_plugin() | ||
QMainWindow.closeEvent(self, event) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,9 @@ | |
# Local imports | ||
from spyder.config.base import _ | ||
from spyder.api.plugins import SpyderPluginWidget | ||
from spyder.py3compat import to_text_string | ||
from spyder.utils.qthelpers import add_actions, MENU_SEPARATOR | ||
from spyder.widgets.explorer import ExplorerWidget | ||
|
||
|
||
class Explorer(SpyderPluginWidget): | ||
"""File and Directories Explorer DockWidget.""" | ||
|
||
|
@@ -33,19 +32,20 @@ def __init__(self, parent=None): | |
"""Initialization.""" | ||
SpyderPluginWidget.__init__(self, parent) | ||
|
||
# Initialize plugin | ||
self.initialize_plugin() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (A comment out of the scope of this PR) We could consider moving |
||
|
||
self.fileexplorer = ExplorerWidget( | ||
self, | ||
name_filters=self.get_option('name_filters'), | ||
show_all=self.get_option('show_all'), | ||
show_icontext=self.get_option('show_icontext')) | ||
show_icontext=self.get_option('show_icontext'), | ||
options_button=self.options_button) | ||
|
||
layout = QVBoxLayout() | ||
layout.addWidget(self.fileexplorer) | ||
self.setLayout(layout) | ||
|
||
# Initialize plugin | ||
self.initialize_plugin() | ||
|
||
#------ SpyderPluginWidget API --------------------------------------------- | ||
def get_plugin_title(self): | ||
"""Return widget title""" | ||
|
@@ -66,9 +66,11 @@ def register_plugin(self): | |
"""Register plugin in Spyder's main window""" | ||
ipyconsole = self.main.ipyconsole | ||
treewidget = self.fileexplorer.treewidget | ||
undock = [MENU_SEPARATOR, self.undock_action] | ||
|
||
self.main.add_dockwidget(self) | ||
self.fileexplorer.sig_open_file.connect(self.main.open_file) | ||
add_actions(self.fileexplorer.menu, undock) | ||
|
||
treewidget.sig_edit.connect(self.main.editor.load) | ||
treewidget.sig_removed.connect(self.main.editor.removed) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
menu
is too generic. Please change it tooptions_menu
.