~ubuntu-branches/debian/experimental/spyder/experimental

« back to all changes in this revision

Viewing changes to spyderplugins/p_pylint.py

  • Committer: Package Import Robot
  • Author(s): Picca Frédéric-Emmanuel
  • Date: 2013-02-27 09:51:28 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20130227095128-wtx1irpvf4vl79lj
Tags: 2.2.0~beta3+dfsg-1
* Imported Upstream version 2.2.0~beta3+dfsg
* debian /patches
  - 0002-feature-forwarded-add-icon-to-desktop-file.patch (deleted)
    this patch was integrated by the upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding:utf-8 -*-
2
 
#
3
 
# Copyright © 2009-2011 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=C0103
10
 
# pylint: disable=R0903
11
 
# pylint: disable=R0911
12
 
# pylint: disable=R0201
13
 
 
14
 
from spyderlib.qt.QtGui import QInputDialog, QVBoxLayout, QGroupBox, QLabel
15
 
from spyderlib.qt.QtCore import SIGNAL, Qt
16
 
 
17
 
# Local imports
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
23
 
 
24
 
from spyderplugins.widgets.pylintgui import PylintWidget, PYLINT_PATH
25
 
 
26
 
 
27
 
class PylintConfigPage(PluginConfigPage):
28
 
    def setup_page(self):
29
 
        settings_group = QGroupBox(_("Settings"))
30
 
        save_box = self.create_checkbox(_("Save script before analyzing it"),
31
 
                                        'save_before', default=True)
32
 
        
33
 
        hist_group = QGroupBox(_("History"))
34
 
        hist_label1 = QLabel(_("The following option will be applied at next "
35
 
                               "startup."))
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)
40
 
 
41
 
        results_group = QGroupBox(_("Results"))
42
 
        results_label1 = QLabel(_("Pylint plugin results are stored here:"))
43
 
        results_label1.setWordWrap(True)
44
 
 
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)
49
 
 
50
 
        results_label2.setTextInteractionFlags(Qt.TextSelectableByMouse)
51
 
        results_label2.setWordWrap(True)
52
 
 
53
 
        settings_layout = QVBoxLayout()
54
 
        settings_layout.addWidget(save_box)
55
 
        settings_group.setLayout(settings_layout)
56
 
 
57
 
        hist_layout = QVBoxLayout()
58
 
        hist_layout.addWidget(hist_label1)
59
 
        hist_layout.addWidget(hist_spin)
60
 
        hist_group.setLayout(hist_layout)
61
 
 
62
 
        results_layout = QVBoxLayout()
63
 
        results_layout.addWidget(results_label1)
64
 
        results_layout.addWidget(results_label2)
65
 
        results_group.setLayout(results_layout)
66
 
 
67
 
        vlayout = QVBoxLayout()
68
 
        vlayout.addWidget(settings_group)
69
 
        vlayout.addWidget(hist_group)
70
 
        vlayout.addWidget(results_group)
71
 
        vlayout.addStretch(1)
72
 
        self.setLayout(vlayout)
73
 
 
74
 
 
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)
83
 
        
84
 
        # Initialize plugin
85
 
        self.initialize_plugin()
86
 
        
87
 
    #------ SpyderPluginWidget API --------------------------------------------
88
 
    def get_plugin_title(self):
89
 
        """Return widget title"""
90
 
        return _("Pylint")
91
 
    
92
 
    def get_plugin_icon(self):
93
 
        """Return widget icon"""
94
 
        return get_icon('pylint.png')
95
 
    
96
 
    def get_focus_widget(self):
97
 
        """
98
 
        Return the widget to give focus to when
99
 
        this plugin's dockwidget is raised on top-level
100
 
        """
101
 
        return self.treewidget
102
 
    
103
 
    def get_plugin_actions(self):
104
 
        """Return a list of actions related to plugin"""
105
 
        # Font
106
 
        history_action = create_action(self, _("History..."),
107
 
                                       None, 'history.png',
108
 
                                       _("Set history maximum entries"),
109
 
                                       triggered=self.change_history_depth)
110
 
        self.treewidget.common_actions += (None, history_action)
111
 
        return []
112
 
    
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)
120
 
        
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")
126
 
        
127
 
        self.main.source_menu_actions += [None, pylint_act]
128
 
        self.main.editor.pythonfile_dependent_actions += [pylint_act]
129
 
                    
130
 
    def refresh_plugin(self):
131
 
        """Refresh pylint widget"""
132
 
        self.remove_obsolete_items()
133
 
        
134
 
    def closing_plugin(self, cancelable=False):
135
 
        """Perform actions before parent main window is closed"""
136
 
        return True
137
 
            
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
142
 
        pass
143
 
        
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'),
150
 
                                       10, 10000)
151
 
        if valid:
152
 
            self.set_option('max_entries', depth)
153
 
        
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():
158
 
            return
159
 
        self.analyze( self.main.editor.get_current_filename() )
160
 
        
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)
168
 
 
169
 
 
170
 
#==============================================================================
171
 
# The following statements are required to register this 3rd party plugin:
172
 
#==============================================================================
173
 
PLUGIN_CLASS = Pylint
174
 
 
 
1
# -*- coding:utf-8 -*-
 
2
#
 
3
# Copyright © 2009-2011 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=C0103
 
10
# pylint: disable=R0903
 
11
# pylint: disable=R0911
 
12
# pylint: disable=R0201
 
13
 
 
14
from spyderlib.qt.QtGui import QInputDialog, QVBoxLayout, QGroupBox, QLabel
 
15
from spyderlib.qt.QtCore import SIGNAL, Qt
 
16
 
 
17
# Local imports
 
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
 
22
 
 
23
from spyderplugins.widgets.pylintgui import PylintWidget, PYLINT_PATH
 
24
 
 
25
 
 
26
class PylintConfigPage(PluginConfigPage):
 
27
    def setup_page(self):
 
28
        settings_group = QGroupBox(_("Settings"))
 
29
        save_box = self.create_checkbox(_("Save script before analyzing it"),
 
30
                                        'save_before', default=True)
 
31
        
 
32
        hist_group = QGroupBox(_("History"))
 
33
        hist_label1 = QLabel(_("The following option will be applied at next "
 
34
                               "startup."))
 
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)
 
39
 
 
40
        results_group = QGroupBox(_("Results"))
 
41
        results_label1 = QLabel(_("Pylint plugin results are stored here:"))
 
42
        results_label1.setWordWrap(True)
 
43
 
 
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)
 
48
 
 
49
        results_label2.setTextInteractionFlags(Qt.TextSelectableByMouse)
 
50
        results_label2.setWordWrap(True)
 
51
 
 
52
        settings_layout = QVBoxLayout()
 
53
        settings_layout.addWidget(save_box)
 
54
        settings_group.setLayout(settings_layout)
 
55
 
 
56
        hist_layout = QVBoxLayout()
 
57
        hist_layout.addWidget(hist_label1)
 
58
        hist_layout.addWidget(hist_spin)
 
59
        hist_group.setLayout(hist_layout)
 
60
 
 
61
        results_layout = QVBoxLayout()
 
62
        results_layout.addWidget(results_label1)
 
63
        results_layout.addWidget(results_label2)
 
64
        results_group.setLayout(results_layout)
 
65
 
 
66
        vlayout = QVBoxLayout()
 
67
        vlayout.addWidget(settings_group)
 
68
        vlayout.addWidget(hist_group)
 
69
        vlayout.addWidget(results_group)
 
70
        vlayout.addStretch(1)
 
71
        self.setLayout(vlayout)
 
72
 
 
73
 
 
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)
 
82
        
 
83
        # Initialize plugin
 
84
        self.initialize_plugin()
 
85
        
 
86
    #------ SpyderPluginWidget API --------------------------------------------
 
87
    def get_plugin_title(self):
 
88
        """Return widget title"""
 
89
        return _("Pylint")
 
90
    
 
91
    def get_plugin_icon(self):
 
92
        """Return widget icon"""
 
93
        return get_icon('pylint.png')
 
94
    
 
95
    def get_focus_widget(self):
 
96
        """
 
97
        Return the widget to give focus to when
 
98
        this plugin's dockwidget is raised on top-level
 
99
        """
 
100
        return self.treewidget
 
101
    
 
102
    def get_plugin_actions(self):
 
103
        """Return a list of actions related to plugin"""
 
104
        # Font
 
105
        history_action = create_action(self, _("History..."),
 
106
                                       None, 'history.png',
 
107
                                       _("Set history maximum entries"),
 
108
                                       triggered=self.change_history_depth)
 
109
        self.treewidget.common_actions += (None, history_action)
 
110
        return []
 
111
    
 
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)
 
119
        
 
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")
 
125
        
 
126
        self.main.source_menu_actions += [None, pylint_act]
 
127
        self.main.editor.pythonfile_dependent_actions += [pylint_act]
 
128
                    
 
129
    def refresh_plugin(self):
 
130
        """Refresh pylint widget"""
 
131
        self.remove_obsolete_items()
 
132
        
 
133
    def closing_plugin(self, cancelable=False):
 
134
        """Perform actions before parent main window is closed"""
 
135
        return True
 
136
            
 
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
 
141
        pass
 
142
        
 
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'),
 
149
                                       10, 10000)
 
150
        if valid:
 
151
            self.set_option('max_entries', depth)
 
152
        
 
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():
 
157
            return
 
158
        self.analyze( self.main.editor.get_current_filename() )
 
159
        
 
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)
 
167
 
 
168
 
 
169
#==============================================================================
 
170
# The following statements are required to register this 3rd party plugin:
 
171
#==============================================================================
 
172
PLUGIN_CLASS = Pylint
 
173