~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/Checks/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import sys
12
12
import copy
13
13
 
14
 
from qt import *
 
14
from PyQt4.QtCore import QObject, SIGNAL
 
15
from PyQt4.QtGui import QMenu
15
16
 
16
17
from TabnannyDialog import TabnannyDialog
17
18
from SyntaxCheckerDialog import SyntaxCheckerDialog
18
 
from PyLintConfigDialog import PyLintConfigDialog
19
 
from PyLintExecDialog import PyLintExecDialog
 
19
from PyLint import PyLint
20
20
 
21
 
from UI.E3Action import E3Action
 
21
from E4Gui.E4Action import E4Action
22
22
 
23
23
import Utilities
24
24
 
38
38
        self.projectOrBrowser = projectOrBrowser
39
39
        self.actions = []
40
40
        
41
 
        self.pylintDialog = None
42
41
        self.tabnannyDialog = None
43
42
        self.syntaxcheckDialog = None
 
43
        
 
44
        self.pylint = PyLint(projectOrBrowser, parent)
44
45
 
45
46
    def initActions(self):
46
47
        """
47
 
        Private method to initialize the Checkers actions.
 
48
        Public method to initialize the Checkers actions.
48
49
        """
49
50
        self.actions = []
50
51
        
51
 
        self.checkSyntaxAct = E3Action(self.trUtf8('Check Syntax'),
 
52
        self.checkSyntaxAct = E4Action(self.trUtf8('Check Syntax'),
52
53
                self.trUtf8('&Syntax...'),0,0,
53
54
                self,'project_check_syntax')
54
55
        self.checkSyntaxAct.setStatusTip(self.trUtf8('Check syntax.'))
56
57
            """<b>Check Syntax...</b>"""
57
58
            """<p>This checks all Python files for syntax errors.</p>"""
58
59
        ))
59
 
        self.checkSyntaxAct.connectIt(SIGNAL('activated()'),
 
60
        self.checkSyntaxAct.connectIt(SIGNAL('triggered(bool)'),
60
61
            self.projectOrBrowser.handleSyntaxCheck)
61
62
        self.actions.append(self.checkSyntaxAct)
62
 
 
63
 
        self.tabnannyAct = E3Action(self.trUtf8('Check Indentations'),
 
63
        
 
64
        self.tabnannyAct = E4Action(self.trUtf8('Check Indentations'),
64
65
                self.trUtf8('&Indentations...'),0,0,
65
66
                self,'project_check_indentations')
66
67
        self.tabnannyAct.setStatusTip(self.trUtf8('Check indentations using tabnanny.'))
69
70
            """<p>This checks all Python files"""
70
71
            """ for bad indentations using tabnanny.</p>"""
71
72
        ))
72
 
        self.tabnannyAct.connectIt(SIGNAL('activated()'),
 
73
        self.tabnannyAct.connectIt(SIGNAL('triggered(bool)'),
73
74
            self.projectOrBrowser.handleTabnanny)
74
75
        self.actions.append(self.tabnannyAct)
75
 
 
76
 
        self.pylintAct = E3Action(self.trUtf8('Run PyLint'),
77
 
                self.trUtf8('Run &PyLint...'),0,0,
78
 
                self,'project_check_pylint')
79
 
        self.pylintAct.setStatusTip(\
80
 
            self.trUtf8('Check project, packages or modules with pylint.'))
81
 
        self.pylintAct.setWhatsThis(self.trUtf8(
82
 
            """<b>Run PyLint...</b>"""
83
 
            """<p>This checks the project, packages or modules using pylint.</p>"""
84
 
        ))
85
 
        self.pylintAct.connectIt(SIGNAL('activated()'),
86
 
            self.projectOrBrowser.handlePyLint)
87
 
        self.actions.append(self.pylintAct)
88
 
 
89
 
        self.pylintShowAct = E3Action(self.trUtf8('Show PyLint Dialog'),
90
 
                self.trUtf8('Show Py&Lint Dialog...'),0,0,
91
 
                self,'project_check_pylintshow')
92
 
        self.pylintShowAct.setStatusTip(\
93
 
            self.trUtf8('Show the PyLint dialog with the results of the last run.'))
94
 
        self.pylintShowAct.setWhatsThis(self.trUtf8(
95
 
            """<b>Show PyLint Dialog...</b>"""
96
 
            """<p>This shows the PyLint dialog with the results of the last run.</p>"""
97
 
        ))
98
 
        self.pylintShowAct.connectIt(SIGNAL('activated()'),
99
 
            self.handlePyLintShow)
100
 
        self.actions.append(self.pylintShowAct)
101
76
        
 
77
        self.pylint.initActions()
 
78
 
102
79
    def initMenu(self):
103
80
        """
104
 
        Private method called to build the project packagers submenu.
 
81
        Public method called to build the Checkers submenu.
105
82
        
106
83
        @return the menu or None
107
84
        """
108
 
        menu = QPopupMenu(self.parent())
109
 
        menu.insertTearOffHandle()
 
85
        menu = QMenu()
 
86
        menu.setTearOffEnabled(True)
110
87
        
111
88
        self.checkSyntaxAct.addTo(menu)
112
89
        self.tabnannyAct.addTo(menu)
113
 
        menu.insertSeparator()
114
 
        self.pylintAct.addTo(menu)
115
 
        self.pylintShowAct.addTo(menu)
116
90
        
117
 
        # entry for cxfreeze is only activated if it is accessible
118
 
        exe = 'pylint'
119
 
        if sys.platform == "win32":
120
 
            exe += '.bat'
121
 
        self.pylintAct.setEnabled(Utilities.isinpath(exe))
 
91
        self.pylint.initMenu(menu)
122
92
        
123
93
        # connect the aboutToShow signal
124
 
        self.connect(menu, SIGNAL('aboutToShow()'), self.handleShowMenu)
 
94
        self.connect(menu, SIGNAL('aboutToShow()'), self.__showMenu)
125
95
        
126
96
        return menu
127
 
        
 
97
    
128
98
    def getActions(self):
129
99
        """
130
100
        Public method to get a list of all actions.
131
101
        
132
 
        @return list of all actions (list of E3Action)
133
 
        """
134
 
        return self.actions[:]
135
 
 
136
 
    def handleTabnanny(self, files):
137
 
        """
138
 
        Private slot used to check the project files for bad indentations.
 
102
        @return list of all actions (list of E4Action)
 
103
        """
 
104
        return self.actions[:] + self.pylint.getActions()
 
105
 
 
106
    def __showMenu(self):
 
107
        """
 
108
        Private slot to handle the aboutToShow signal of the menu.
 
109
        """
 
110
        self.pylint.checkActions()
 
111
 
 
112
    def closeAllWindows(self):
 
113
        """
 
114
        Public method to close all windows.
 
115
        """
 
116
        self.tabnannyDialog and self.tabnannyDialog.close()
 
117
        self.syntaxcheckDialog and self.syntaxcheckDialog.close()
 
118
        self.pylint.closeAllWindows()
 
119
 
 
120
    def tabnanny(self, files):
 
121
        """
 
122
        Public slot used to check the project files for bad indentations.
139
123
        
140
124
        @param files File or list of files or directory to be checked
141
125
                (string or list of strings)
142
126
        """
143
 
        self.tabnannyDialog = TabnannyDialog(qApp.mainWidget().getViewManager())
 
127
        self.tabnannyDialog = TabnannyDialog()
144
128
        self.tabnannyDialog.show()
145
129
        self.tabnannyDialog.start(files)
146
130
    
147
 
    def handleSyntaxCheck(self, files):
 
131
    def syntaxCheck(self, files):
148
132
        """
149
 
        Private slot used to check the project files for bad syntax.
 
133
        Public slot used to check the project files for bad syntax.
150
134
        
151
135
        @param files File or list of files or directory to be checked
152
136
                (string or list of strings)
153
137
        """
154
 
        self.syntaxcheckDialog = SyntaxCheckerDialog(qApp.mainWidget().getViewManager())
 
138
        self.syntaxcheckDialog = SyntaxCheckerDialog()
155
139
        self.syntaxcheckDialog.show()
156
140
        self.syntaxcheckDialog.start(files)
157
141
 
158
 
    def handlePyLint(self, project, mpName):
 
142
    ############################################################################
 
143
    ## Public interface to PyLint
 
144
    ############################################################################
 
145
    
 
146
    def pyLint(self, project, mpName):
159
147
        """
160
148
        Public method used to perform a PyLint run.
161
149
        
162
150
        @param project reference to the Project object
163
151
        @param mpName name of module or package to be checked (string or QString)
164
152
        """
165
 
        if len(project.pdata['PYLINTPARMS']):
166
 
            parms = copy.deepcopy(project.pdata['PYLINTPARMS'][0])
167
 
        else:
168
 
            parms = None
169
 
        dlg = PyLintConfigDialog(project.ppath, parms)
170
 
        if dlg.exec_loop() == QDialog.Accepted:
171
 
            args, parms = dlg.generateParameters()
172
 
            
173
 
            # test for changes of selected parameters and save the in the project
174
 
            # 1. there were none, now there are
175
 
            if len(project.pdata['PYLINTPARMS']) == 0 and len(parms) > 0:
176
 
                project.pdata['PYLINTPARMS'] = [copy.deepcopy(parms)]
177
 
                project.setDirty(1)
178
 
            # 2. there were some, now there aren't
179
 
            elif len(project.pdata['PYLINTPARMS']) > 0 and len(parms) == 0:
180
 
                project.pdata['PYLINTPARMS'] = []
181
 
                project.setDirty(1)
182
 
            # 3. there were some and still are
183
 
            else:
184
 
                if parms != project.pdata['PYLINTPARMS'][0]:
185
 
                    project.pdata['PYLINTPARMS'] = [copy.deepcopy(parms)]
186
 
                    project.setDirty(1)
187
 
                    
188
 
            # now do the call
189
 
            self.pylintDialog = PyLintExecDialog()
190
 
            try:
191
 
                reportFile = parms['reportFile']
192
 
            except KeyError:
193
 
                reportFile = None
194
 
            res = self.pylintDialog.start(args, mpName, reportFile, project.ppath)
195
 
            if res:
196
 
                self.pylintDialog.show()
197
 
        
198
 
    def handlePyLintShow(self):
199
 
        """
200
 
        Private slot to show the PyLint dialog with the results of the last run.
201
 
        """
202
 
        if self.pylintDialog is not None:
203
 
            self.pylintDialog.show()
204
 
        
205
 
    def handleShowMenu(self):
206
 
        """
207
 
        Private slot to handle the aboutToShow signal of the menu.
208
 
        """
209
 
        self.pylintShowAct.setEnabled(self.pylintDialog is not None)
 
153
        self.pylint.pyLint(project, mpName)