-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
plugin.py
122 lines (97 loc) · 3.54 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
"""
Plots Plugin.
"""
# Third party imports
from qtpy.QtCore import Signal
# Local imports
from spyder.api.plugins import Plugins, SpyderDockablePlugin
from spyder.api.translations import get_translation
from spyder.plugins.plots.widgets.main_widget import PlotsWidget
# Localization
_ = get_translation('spyder')
class Plots(SpyderDockablePlugin):
"""
Plots plugin.
"""
NAME = 'plots'
REQUIRES = [Plugins.IPythonConsole]
TABIFY = [Plugins.VariableExplorer, Plugins.Help]
WIDGET_CLASS = PlotsWidget
CONF_SECTION = NAME
CONF_FILE = False
DISABLE_ACTIONS_WHEN_HIDDEN = False
# --- SpyderDockablePlugin API
# ------------------------------------------------------------------------
def get_name(self):
return _('Plots')
def get_description(self):
return _('Display, explore and save console generated plots.')
def get_icon(self):
return self.create_icon('hist')
def register(self):
# Plugins
ipyconsole = self.get_plugin(Plugins.IPythonConsole)
# Signals
ipyconsole.sig_shellwidget_changed.connect(self.set_shellwidget)
ipyconsole.sig_shellwidget_process_started.connect(
self.add_shellwidget)
ipyconsole.sig_shellwidget_process_finished.connect(
self.remove_shellwidget)
# If a figure is loaded raise the dockwidget but do not give focus
self.get_widget().sig_figure_loaded.connect(
lambda: self.switch_to_plugin(force_focus=False))
def unregister(self):
# Plugins
ipyconsole = self.get_plugin(Plugins.IPythonConsole)
# Signals
ipyconsole.sig_shellwidget_id_changed.disconnect(
self.set_shellwidget_from_id)
ipyconsole.sig_shellwidget_process_started.disconnect(
self.add_shellwidget)
ipyconsole.sig_shellwidget_id_process_finished.disconnect(
self.remove_shellwidget_from_id)
# --- Public API
# ------------------------------------------------------------------------
def current_widget(self):
"""
Return the current shellwidget.
Returns
-------
spyder.plugins.plots.widgets.figurebrowser.FigureBrowser
The current figure browser widget.
"""
return self.get_widget().current_widget()
def add_shellwidget(self, shellwidget):
"""
Add a new shellwidget registered with the plots plugin.
This function registers a new FigureBrowser for browsing the figures
in the shellwidget.
Parameters
----------
shellwidget: spyder.plugins.ipyconsole.widgets.shell.ShellWidget
The shell widget.
"""
self.get_widget().add_shellwidget(shellwidget)
def remove_shellwidget(self, shellwidget):
"""
Remove the shellwidget registered with the plots plugin.
Parameters
----------
shellwidget: spyder.plugins.ipyconsole.widgets.shell.ShellWidget
The shell widget.
"""
self.get_widget().remove_shellwidget(shellwidget)
def set_shellwidget(self, shellwidget):
"""
Update the current shellwidget displayed with the plots plugin.
Parameters
----------
shellwidget: spyder.plugins.ipyconsole.widgets.shell.ShellWidget
The shell widget.
"""
self.get_widget().add_shellwidget(shellwidget)