~ubuntu-branches/ubuntu/trusty/spyder/trusty-backports

« back to all changes in this revision

Viewing changes to spyderlib/plugins/pylintgui.py

  • Committer: Bazaar Package Importer
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2011-03-05 18:03:43 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110305180343-its88tucbyvtevjf
Tags: 2.0.8-1
* Imported Upstream version 2.0.8 (Closes: #609789)
* add a watch file
* build for all python2 versions (it can be use as module by other packages)
* change the documentation section to Programming/Python
* use the Recommendes found in the documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
#
3
 
# Copyright © 2009 Pierre Raybaut
4
 
# Licensed under the terms of the MIT License
5
 
# (see spyderlib/__init__.py for details)
6
 
 
7
 
"""Pylint Code Analysis Plugin"""
8
 
 
9
 
# pylint: disable-msg=C0103
10
 
# pylint: disable-msg=R0903
11
 
# pylint: disable-msg=R0911
12
 
# pylint: disable-msg=R0201
13
 
 
14
 
from PyQt4.QtGui import QFontDialog, QInputDialog
15
 
 
16
 
import sys
17
 
 
18
 
# For debugging purpose:
19
 
STDOUT = sys.stdout
20
 
 
21
 
# Local imports
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
26
 
 
27
 
 
28
 
class Pylint(PylintWidget, SpyderPluginMixin):
29
 
    """Python source code analysis based on pylint"""
30
 
    ID = '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)
35
 
 
36
 
        self.set_font(get_font(self.ID))
37
 
        
38
 
    #------ SpyderPluginWidget API ---------------------------------------------    
39
 
    def get_plugin_title(self):
40
 
        """Return widget title"""
41
 
        return self.tr("Pylint")
42
 
    
43
 
    def get_focus_widget(self):
44
 
        """
45
 
        Return the widget to give focus to when
46
 
        this plugin's dockwidget is raised on top-level
47
 
        """
48
 
        return self.treewidget
49
 
    
50
 
    def get_plugin_actions(self):
51
 
        """Setup actions"""
52
 
        # Font
53
 
        history_action = create_action(self, self.tr("History..."),
54
 
                                       None, 'history.png',
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)
61
 
        return (None, None)
62
 
        
63
 
    def refresh_plugin(self):
64
 
        """Refresh pylint widget"""
65
 
        self.remove_obsolete_items()
66
 
        
67
 
    def closing_plugin(self, cancelable=False):
68
 
        """Perform actions before parent main window is closed"""
69
 
        return True
70
 
        
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'),
77
 
                                       10, 10000)
78
 
        if valid:
79
 
            CONF.set(self.ID, 'max_entries', depth)
80
 
        
81
 
    def change_font(self):
82
 
        """Change font"""
83
 
        font, valid = QFontDialog.getFont(get_font(self.ID), self,
84
 
                                          self.tr("Select a new font"))
85
 
        if valid:
86
 
            self.set_font(font)
87
 
            set_font(font, self.ID)
88
 
            
89
 
    def set_font(self, font):
90
 
        """Set pylint widget font"""
91
 
        self.ratelabel.setFont(font)
92
 
        self.treewidget.setFont(font)
93
 
        
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)
101