3
# Copyright © 2009-2011 Pierre Raybaut
4
# Licensed under the terms of the MIT License
5
# (see spyderlib/__init__.py for details)
7
"""Pylint Code Analysis Plugin"""
9
# pylint: disable=C0103
10
# pylint: disable=R0903
11
# pylint: disable=R0911
12
# pylint: disable=R0201
14
from spyderlib.qt.QtGui import QInputDialog, QVBoxLayout, QGroupBox, QLabel
15
from spyderlib.qt.QtCore import SIGNAL, Qt
18
from spyderlib.baseconfig import get_translation
19
_ = get_translation("p_pylint", dirname="spyderplugins")
20
from spyderlib.guiconfig import get_icon
21
from spyderlib.utils.qthelpers import create_action
22
from spyderlib.plugins import SpyderPluginMixin, PluginConfigPage
24
from spyderplugins.widgets.pylintgui import PylintWidget, PYLINT_PATH
27
class PylintConfigPage(PluginConfigPage):
29
settings_group = QGroupBox(_("Settings"))
30
save_box = self.create_checkbox(_("Save script before analyzing it"),
31
'save_before', default=True)
33
hist_group = QGroupBox(_("History"))
34
hist_label1 = QLabel(_("The following option will be applied at next "
36
hist_label1.setWordWrap(True)
37
hist_spin = self.create_spinbox(_("History: "),
38
_(" results"), 'max_entries', default=50,
39
min_=10, max_=1000000, step=10)
41
results_group = QGroupBox(_("Results"))
42
results_label1 = QLabel(_("Pylint plugin results are stored here:"))
43
results_label1.setWordWrap(True)
45
# Warning: do not try to regroup the following QLabel contents with
46
# widgets above -- this string was isolated here in a single QLabel
47
# on purpose: to fix Issue 863
48
results_label2 = QLabel(PylintWidget.DATAPATH)
50
results_label2.setTextInteractionFlags(Qt.TextSelectableByMouse)
51
results_label2.setWordWrap(True)
53
settings_layout = QVBoxLayout()
54
settings_layout.addWidget(save_box)
55
settings_group.setLayout(settings_layout)
57
hist_layout = QVBoxLayout()
58
hist_layout.addWidget(hist_label1)
59
hist_layout.addWidget(hist_spin)
60
hist_group.setLayout(hist_layout)
62
results_layout = QVBoxLayout()
63
results_layout.addWidget(results_label1)
64
results_layout.addWidget(results_label2)
65
results_group.setLayout(results_layout)
67
vlayout = QVBoxLayout()
68
vlayout.addWidget(settings_group)
69
vlayout.addWidget(hist_group)
70
vlayout.addWidget(results_group)
72
self.setLayout(vlayout)
75
class Pylint(PylintWidget, SpyderPluginMixin):
76
"""Python source code analysis based on pylint"""
77
CONF_SECTION = 'pylint'
78
CONFIGWIDGET_CLASS = PylintConfigPage
79
def __init__(self, parent=None):
80
PylintWidget.__init__(self, parent=parent,
81
max_entries=self.get_option('max_entries', 50))
82
SpyderPluginMixin.__init__(self, parent)
85
self.initialize_plugin()
87
#------ SpyderPluginWidget API --------------------------------------------
88
def get_plugin_title(self):
89
"""Return widget title"""
92
def get_plugin_icon(self):
93
"""Return widget icon"""
94
return get_icon('pylint.png')
96
def get_focus_widget(self):
98
Return the widget to give focus to when
99
this plugin's dockwidget is raised on top-level
101
return self.treewidget
103
def get_plugin_actions(self):
104
"""Return a list of actions related to plugin"""
106
history_action = create_action(self, _("History..."),
108
_("Set history maximum entries"),
109
triggered=self.change_history_depth)
110
self.treewidget.common_actions += (None, history_action)
113
def register_plugin(self):
114
"""Register plugin in Spyder's main window"""
115
self.connect(self, SIGNAL("edit_goto(QString,int,QString)"),
116
self.main.editor.load)
117
self.connect(self, SIGNAL('redirect_stdio(bool)'),
118
self.main.redirect_internalshell_stdio)
119
self.main.add_dockwidget(self)
121
pylint_act = create_action(self, _("Run pylint code analysis"),
122
triggered=self.run_pylint)
123
pylint_act.setEnabled(PYLINT_PATH is not None)
124
self.register_shortcut(pylint_act, context="Pylint",
125
name="Run analysis", default="F8")
127
self.main.source_menu_actions += [None, pylint_act]
128
self.main.editor.pythonfile_dependent_actions += [pylint_act]
130
def refresh_plugin(self):
131
"""Refresh pylint widget"""
132
self.remove_obsolete_items()
134
def closing_plugin(self, cancelable=False):
135
"""Perform actions before parent main window is closed"""
138
def apply_plugin_settings(self, options):
139
"""Apply configuration file's plugin settings"""
140
# The history depth option will be applied at
141
# next Spyder startup, which is soon enough
144
#------ Public API --------------------------------------------------------
145
def change_history_depth(self):
146
"Change history max entries"""
147
depth, valid = QInputDialog.getInteger(self, _('History'),
148
_('Maximum entries'),
149
self.get_option('max_entries'),
152
self.set_option('max_entries', depth)
154
def run_pylint(self):
155
"""Run pylint code analysis"""
156
if self.get_option('save_before', True)\
157
and not self.main.editor.save():
159
self.analyze( self.main.editor.get_current_filename() )
161
def analyze(self, filename):
162
"""Reimplement analyze method"""
163
if self.dockwidget and not self.ismaximized:
164
self.dockwidget.setVisible(True)
165
self.dockwidget.setFocus()
166
self.dockwidget.raise_()
167
PylintWidget.analyze(self, filename)
170
#==============================================================================
171
# The following statements are required to register this 3rd party plugin:
172
#==============================================================================
173
PLUGIN_CLASS = Pylint
3
# Copyright © 2009-2011 Pierre Raybaut
4
# Licensed under the terms of the MIT License
5
# (see spyderlib/__init__.py for details)
7
"""Pylint Code Analysis Plugin"""
9
# pylint: disable=C0103
10
# pylint: disable=R0903
11
# pylint: disable=R0911
12
# pylint: disable=R0201
14
from spyderlib.qt.QtGui import QInputDialog, QVBoxLayout, QGroupBox, QLabel
15
from spyderlib.qt.QtCore import SIGNAL, Qt
18
from spyderlib.baseconfig import get_translation
19
_ = get_translation("p_pylint", dirname="spyderplugins")
20
from spyderlib.utils.qthelpers import get_icon, create_action
21
from spyderlib.plugins import SpyderPluginMixin, PluginConfigPage
23
from spyderplugins.widgets.pylintgui import PylintWidget, PYLINT_PATH
26
class PylintConfigPage(PluginConfigPage):
28
settings_group = QGroupBox(_("Settings"))
29
save_box = self.create_checkbox(_("Save script before analyzing it"),
30
'save_before', default=True)
32
hist_group = QGroupBox(_("History"))
33
hist_label1 = QLabel(_("The following option will be applied at next "
35
hist_label1.setWordWrap(True)
36
hist_spin = self.create_spinbox(_("History: "),
37
_(" results"), 'max_entries', default=50,
38
min_=10, max_=1000000, step=10)
40
results_group = QGroupBox(_("Results"))
41
results_label1 = QLabel(_("Pylint plugin results are stored here:"))
42
results_label1.setWordWrap(True)
44
# Warning: do not try to regroup the following QLabel contents with
45
# widgets above -- this string was isolated here in a single QLabel
46
# on purpose: to fix Issue 863
47
results_label2 = QLabel(PylintWidget.DATAPATH)
49
results_label2.setTextInteractionFlags(Qt.TextSelectableByMouse)
50
results_label2.setWordWrap(True)
52
settings_layout = QVBoxLayout()
53
settings_layout.addWidget(save_box)
54
settings_group.setLayout(settings_layout)
56
hist_layout = QVBoxLayout()
57
hist_layout.addWidget(hist_label1)
58
hist_layout.addWidget(hist_spin)
59
hist_group.setLayout(hist_layout)
61
results_layout = QVBoxLayout()
62
results_layout.addWidget(results_label1)
63
results_layout.addWidget(results_label2)
64
results_group.setLayout(results_layout)
66
vlayout = QVBoxLayout()
67
vlayout.addWidget(settings_group)
68
vlayout.addWidget(hist_group)
69
vlayout.addWidget(results_group)
71
self.setLayout(vlayout)
74
class Pylint(PylintWidget, SpyderPluginMixin):
75
"""Python source code analysis based on pylint"""
76
CONF_SECTION = 'pylint'
77
CONFIGWIDGET_CLASS = PylintConfigPage
78
def __init__(self, parent=None):
79
PylintWidget.__init__(self, parent=parent,
80
max_entries=self.get_option('max_entries', 50))
81
SpyderPluginMixin.__init__(self, parent)
84
self.initialize_plugin()
86
#------ SpyderPluginWidget API --------------------------------------------
87
def get_plugin_title(self):
88
"""Return widget title"""
91
def get_plugin_icon(self):
92
"""Return widget icon"""
93
return get_icon('pylint.png')
95
def get_focus_widget(self):
97
Return the widget to give focus to when
98
this plugin's dockwidget is raised on top-level
100
return self.treewidget
102
def get_plugin_actions(self):
103
"""Return a list of actions related to plugin"""
105
history_action = create_action(self, _("History..."),
107
_("Set history maximum entries"),
108
triggered=self.change_history_depth)
109
self.treewidget.common_actions += (None, history_action)
112
def register_plugin(self):
113
"""Register plugin in Spyder's main window"""
114
self.connect(self, SIGNAL("edit_goto(QString,int,QString)"),
115
self.main.editor.load)
116
self.connect(self, SIGNAL('redirect_stdio(bool)'),
117
self.main.redirect_internalshell_stdio)
118
self.main.add_dockwidget(self)
120
pylint_act = create_action(self, _("Run pylint code analysis"),
121
triggered=self.run_pylint)
122
pylint_act.setEnabled(PYLINT_PATH is not None)
123
self.register_shortcut(pylint_act, context="Pylint",
124
name="Run analysis", default="F8")
126
self.main.source_menu_actions += [None, pylint_act]
127
self.main.editor.pythonfile_dependent_actions += [pylint_act]
129
def refresh_plugin(self):
130
"""Refresh pylint widget"""
131
self.remove_obsolete_items()
133
def closing_plugin(self, cancelable=False):
134
"""Perform actions before parent main window is closed"""
137
def apply_plugin_settings(self, options):
138
"""Apply configuration file's plugin settings"""
139
# The history depth option will be applied at
140
# next Spyder startup, which is soon enough
143
#------ Public API --------------------------------------------------------
144
def change_history_depth(self):
145
"Change history max entries"""
146
depth, valid = QInputDialog.getInteger(self, _('History'),
147
_('Maximum entries'),
148
self.get_option('max_entries'),
151
self.set_option('max_entries', depth)
153
def run_pylint(self):
154
"""Run pylint code analysis"""
155
if self.get_option('save_before', True)\
156
and not self.main.editor.save():
158
self.analyze( self.main.editor.get_current_filename() )
160
def analyze(self, filename):
161
"""Reimplement analyze method"""
162
if self.dockwidget and not self.ismaximized:
163
self.dockwidget.setVisible(True)
164
self.dockwidget.setFocus()
165
self.dockwidget.raise_()
166
PylintWidget.analyze(self, filename)
169
#==============================================================================
170
# The following statements are required to register this 3rd party plugin:
171
#==============================================================================
172
PLUGIN_CLASS = Pylint