Skip to content

Commit 6324854

Browse files
committed
Added remove_plugin method for DockMixin
1 parent 067787f commit 6324854

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

psyplot_gui/common.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ def create_view_action(self, main, docktype='pane'):
133133
main.dataframe_menu.addAction(action)
134134
return self._view_action
135135

136+
def remove_plugin(self):
137+
"""Remove this plugin and close it"""
138+
mainwindow = self.dock.parent() if self.dock else self.parent()
139+
key = next((key for key, w in mainwindow.plugins.items()
140+
if w is self), None)
141+
if mainwindow.centralWidget() is self:
142+
mainwindow.set_central_widget(
143+
mainwindow.__class__.central_widget_key)
144+
if self._view_action is not None:
145+
mainwindow.panes_menu.removeAction(self._view_action)
146+
mainwindow.dataframe_menu.removeAction(self._view_action)
147+
if self._set_central_action is not None:
148+
mainwindow.central_widgets_menu.removeAction(
149+
self._set_central_action)
150+
if key is not None:
151+
del mainwindow.plugins[key]
152+
if self.dock is not None:
153+
mainwindow.removeDockWidget(self.dock)
154+
self.dock.close()
155+
self.close()
156+
136157

137158
class LoadFromConsoleButton(QToolButton):
138159
"""A toolbutton to load an object from the console"""

tests/test_main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def test_central_widget(self):
3232
self.window.set_central_widget(self.window.figures_tree)
3333
self.assertIs(self.window.centralWidget(), self.window.figures_tree)
3434

35+
def test_remove_plugin(self):
36+
self.window.plugins['psyplot_gui_test.plugin:W1:w1'].remove_plugin()
37+
self.assertNotIn('psyplot_gui_test.plugin:W1:w1', self.window.plugins)
38+
3539

3640
if __name__ == "__main__":
3741
unittest.main()

0 commit comments

Comments
 (0)