1
# -*- coding: utf-8 -*-
3
# Copyright © 2009 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-msg=C0103
10
# pylint: disable-msg=R0903
11
# pylint: disable-msg=R0911
12
# pylint: disable-msg=R0201
14
from PyQt4.QtGui import QFontDialog, QInputDialog
18
# For debugging purpose:
22
from spyderlib.config import CONF, get_font, set_font
23
from spyderlib.utils.qthelpers import create_action
24
from spyderlib.widgets.pylintgui import PylintWidget
25
from spyderlib.plugins import SpyderPluginMixin
28
class Pylint(PylintWidget, SpyderPluginMixin):
29
"""Python source code analysis based on pylint"""
31
def __init__(self, parent=None):
32
PylintWidget.__init__(self, parent=parent,
33
max_entries=CONF.get(self.ID, 'max_entries'))
34
SpyderPluginMixin.__init__(self, parent)
36
self.set_font(get_font(self.ID))
38
#------ SpyderPluginWidget API ---------------------------------------------
39
def get_plugin_title(self):
40
"""Return widget title"""
41
return self.tr("Pylint")
43
def get_focus_widget(self):
45
Return the widget to give focus to when
46
this plugin's dockwidget is raised on top-level
48
return self.treewidget
50
def get_plugin_actions(self):
53
history_action = create_action(self, self.tr("History..."),
55
self.tr("Set history maximum entries"),
56
triggered=self.change_history_depth)
57
font_action = create_action(self, self.tr("&Font..."),
58
None, 'font.png', self.tr("Set font style"),
59
triggered=self.change_font)
60
self.treewidget.common_actions += (None, history_action, font_action)
63
def refresh_plugin(self):
64
"""Refresh pylint widget"""
65
self.remove_obsolete_items()
67
def closing_plugin(self, cancelable=False):
68
"""Perform actions before parent main window is closed"""
71
#------ Public API ---------------------------------------------------------
72
def change_history_depth(self):
73
"Change history max entries"""
74
depth, valid = QInputDialog.getInteger(self, self.tr('History'),
75
self.tr('Maximum entries'),
76
CONF.get(self.ID, 'max_entries'),
79
CONF.set(self.ID, 'max_entries', depth)
81
def change_font(self):
83
font, valid = QFontDialog.getFont(get_font(self.ID), self,
84
self.tr("Select a new font"))
87
set_font(font, self.ID)
89
def set_font(self, font):
90
"""Set pylint widget font"""
91
self.ratelabel.setFont(font)
92
self.treewidget.setFont(font)
94
def analyze(self, filename):
95
"""Reimplement analyze method"""
96
if self.dockwidget and not self.ismaximized:
97
self.dockwidget.setVisible(True)
98
self.dockwidget.setFocus()
99
self.dockwidget.raise_()
100
PylintWidget.analyze(self, filename)