Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
     --exclude="ui_*.py,debian/*,python/ext-libs/*" \
     .
  • Loading branch information
jef-n committed Feb 1, 2015
1 parent a016367 commit 956c155
Show file tree
Hide file tree
Showing 487 changed files with 10,363 additions and 11,182 deletions.
1 change: 0 additions & 1 deletion cmake/FindSIP.py
Expand Up @@ -30,7 +30,6 @@
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

import sys
import sipconfig

sipcfg = sipconfig.Configuration()
Expand Down
8 changes: 4 additions & 4 deletions python/__init__.py
Expand Up @@ -42,6 +42,7 @@
# >>> print "Not a null value"
from types import MethodType
from PyQt4.QtCore import QPyNullVariant

def __nonzero__(self):
return False

Expand Down Expand Up @@ -73,10 +74,9 @@ def mapping_feature(feature):
properties = {}
fields = [field.name() for field in feature.fields()]
properties = dict(zip(fields, feature.attributes()))
return {
'type' : 'Feature',
'properties' : properties,
'geometry' : geom.__geo_interface__}
return {'type' : 'Feature',
'properties' : properties,
'geometry' : geom.__geo_interface__}

def mapping_geometry(geometry):
geo = geometry.exportToGeoJSON()
Expand Down
16 changes: 3 additions & 13 deletions python/console/console.py
Expand Up @@ -19,8 +19,8 @@
Some portions of code were taken from https://code.google.com/p/pydee/
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL
from PyQt4.QtGui import QDockWidget, QToolBar, QToolButton, QWidget, QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication
from PyQt4 import pyqtconfig
from qgis.utils import iface
from console_sci import ShellScintilla
Expand All @@ -31,7 +31,6 @@
from qgis.gui import QgsFilterLineEdit

import sys
import os

_console = None

Expand Down Expand Up @@ -374,13 +373,6 @@ def __init__(self, parent=None):
self.toolBar.addAction(self.optionsButton)
self.toolBar.addAction(self.helpButton)

if sys.platform.startswith('win'):
bkgrcolor = ['170', '170', '170']
bordercl = ['125', '125', '125']
else:
bkgrcolor = ['200', '200', '200']
bordercl = ['155', '155', '155']

self.toolBarEditor = QToolBar()
# self.toolBarEditor.setStyleSheet('QToolBar{background-color: rgb(%s, %s, %s' % tuple(bkgrcolor) + ');\
# border-right: 1px solid rgb(%s, %s, %s' % tuple(bordercl) + ');}')
Expand Down Expand Up @@ -616,7 +608,7 @@ def openScriptFile(self):
lastDirPath = self.settings.value("pythonConsole/lastDirPath", "")
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
fileList = QFileDialog.getOpenFileNames(
self, openFileTr, lastDirPath, "Script file (*.py)")
self, openFileTr, lastDirPath, "Script file (*.py)")
if fileList:
for pyFile in fileList:
for i in range(self.tabEditorWidget.count()):
Expand All @@ -637,7 +629,6 @@ def saveScriptFile(self):
try:
tabWidget.save()
except (IOError, OSError), error:
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
Expand All @@ -661,7 +652,6 @@ def saveAsScriptFile(self, index=None):
try:
tabWidget.save(filename)
except (IOError, OSError), error:
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
Expand Down
16 changes: 6 additions & 10 deletions python/console/console_compile_apis.py
Expand Up @@ -19,15 +19,11 @@
Portions of this file contain code from Eric4 APIsManager module.
"""

import sys
import os
import shutil
import fnmatch
import glob

from PyQt4.Qsci import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.Qsci import QsciAPIs
from PyQt4.QtGui import QDialog, QDialogButtonBox
from PyQt4.QtCore import QCoreApplication

from ui_console_compile_apis import Ui_APIsDialogPythonConsole

Expand All @@ -47,7 +43,7 @@ def __init__(self, api_lexer, api_files, pap_file, parent=None):
self._pap_file = pap_file

def _clearLexer(self):
# self.ui.textEdit_Qsci.setLexer(0)
# self.ui.textEdit_Qsci.setLexer(0)
self.qlexer = None

def _stopPreparation(self):
Expand All @@ -74,9 +70,9 @@ def _preparationFinished(self):
self.adjustSize()

def prepareAPI(self):
# self.ui.textEdit_Qsci.setLexer(0)
# self.ui.textEdit_Qsci.setLexer(0)
exec u'self.qlexer = {0}(self.ui.textEdit_Qsci)'.format(self._api_lexer)
# self.ui.textEdit_Qsci.setLexer(self.qlexer)
# self.ui.textEdit_Qsci.setLexer(self.qlexer)
self._api = QsciAPIs(self.qlexer)
self._api.apiPreparationFinished.connect(self._preparationFinished)
for api_file in self._api_files:
Expand Down
110 changes: 54 additions & 56 deletions python/console/console_editor.py
Expand Up @@ -19,10 +19,9 @@
Some portions of code were taken from https://code.google.com/p/pydee/
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, SIGNAL
from PyQt4.QtGui import QFont, QFontMetrics, QColor, QShortcut, QKeySequence, QMenu, QApplication, QCursor, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
from PyQt4.Qsci import (QsciScintilla,
QsciScintillaBase,
QsciLexerPython,
QsciAPIs,
QsciStyle)
Expand All @@ -44,6 +43,7 @@ class KeyFilter(QObject):
("Control", "M"): lambda w, t: t.save(),
("Control", "W"): lambda w, t: t.close()
}

def __init__(self, window, tab, *args):
QObject.__init__(self, *args)
self.window = window
Expand Down Expand Up @@ -77,6 +77,7 @@ def eventFilter(self, obj, event):

class Editor(QsciScintilla):
MARKER_NUM = 6

def __init__(self, parent=None):
super(Editor,self).__init__(parent)
self.parent = parent
Expand Down Expand Up @@ -297,31 +298,31 @@ def contextMenuEvent(self, e):
iconCut = QgsApplication.getThemeIcon("console/iconCutEditorConsole.png")
iconCopy = QgsApplication.getThemeIcon("console/iconCopyEditorConsole.png")
iconPaste = QgsApplication.getThemeIcon("console/iconPasteEditorConsole.png")
hideEditorAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Hide Editor"),
self.hideEditor)
menu.addAction(
QCoreApplication.translate("PythonConsole", "Hide Editor"),
self.hideEditor)
menu.addSeparator() # ------------------------------
syntaxCheck = menu.addAction(iconSyntaxCk,
QCoreApplication.translate("PythonConsole", "Check Syntax"),
self.syntaxCheck, 'Ctrl+4')
QCoreApplication.translate("PythonConsole", "Check Syntax"),
self.syntaxCheck, 'Ctrl+4')
menu.addSeparator()
runSelected = menu.addAction(iconRun,
QCoreApplication.translate("PythonConsole", "Run selected"),
self.runSelectedCode, 'Ctrl+E')
runScript = menu.addAction(iconRunScript,
QCoreApplication.translate("PythonConsole", "Run Script"),
self.runScriptCode, 'Shift+Ctrl+E')
menu.addAction(iconRunScript,
QCoreApplication.translate("PythonConsole", "Run Script"),
self.runScriptCode, 'Shift+Ctrl+E')
menu.addSeparator()
undoAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Undo"),
self.undo, QKeySequence.Undo)
QCoreApplication.translate("PythonConsole", "Undo"),
self.undo, QKeySequence.Undo)
redoAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Redo"),
self.redo, 'Ctrl+Shift+Z')
QCoreApplication.translate("PythonConsole", "Redo"),
self.redo, 'Ctrl+Shift+Z')
menu.addSeparator()
findAction = menu.addAction(iconFind,
QCoreApplication.translate("PythonConsole", "Find Text"),
self.showFindWidget)
menu.addAction(iconFind,
QCoreApplication.translate("PythonConsole", "Find Text"),
self.showFindWidget)
menu.addSeparator()
cutAction = menu.addAction(iconCut,
QCoreApplication.translate("PythonConsole", "Cut"),
Expand All @@ -333,12 +334,12 @@ def contextMenuEvent(self, e):
QCoreApplication.translate("PythonConsole", "Paste"),
self.paste, QKeySequence.Paste)
menu.addSeparator()
commentCodeAction = menu.addAction(iconCommentEditor,
QCoreApplication.translate("PythonConsole", "Comment"),
self.parent.pc.commentCode, 'Ctrl+3')
uncommentCodeAction = menu.addAction(iconUncommentEditor,
QCoreApplication.translate("PythonConsole", "Uncomment"),
self.parent.pc.uncommentCode, 'Shift+Ctrl+3')
menu.addAction(iconCommentEditor,
QCoreApplication.translate("PythonConsole", "Comment"),
self.parent.pc.commentCode, 'Ctrl+3')
menu.addAction(iconUncommentEditor,
QCoreApplication.translate("PythonConsole", "Uncomment"),
self.parent.pc.uncommentCode, 'Shift+Ctrl+3')
menu.addSeparator()
codePadAction = menu.addAction(iconCodePad,
QCoreApplication.translate("PythonConsole", "Share on codepad"),
Expand All @@ -349,12 +350,12 @@ def contextMenuEvent(self, e):
self.objectListEditor)
menu.addSeparator()
selectAllAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Select All"),
self.selectAll, QKeySequence.SelectAll)
QCoreApplication.translate("PythonConsole", "Select All"),
self.selectAll, QKeySequence.SelectAll)
menu.addSeparator()
settingsDialog = menu.addAction(iconSettings,
QCoreApplication.translate("PythonConsole", "Settings"),
self.parent.pc.openSettings)
menu.addAction(iconSettings,
QCoreApplication.translate("PythonConsole", "Settings"),
self.parent.pc.openSettings)
syntaxCheck.setEnabled(False)
pasteAction.setEnabled(False)
codePadAction.setEnabled(False)
Expand All @@ -380,9 +381,9 @@ def contextMenuEvent(self, e):
if QApplication.clipboard().text():
pasteAction.setEnabled(True)
if self.settings.value("pythonConsole/enableObjectInsp",
False, type=bool):
False, type=bool):
showCodeInspection.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))
menu.exec_(self.mapToGlobal(e.pos()))

def findText(self, forward):
lineFrom, indexFrom, lineTo, indexTo = self.getSelection()
Expand Down Expand Up @@ -421,7 +422,8 @@ def objectListEditor(self):
self.parent.pc.objectListButton.setChecked(True)

def codepad(self):
import urllib2, urllib
import urllib2
import urllib
listText = self.selectedText().split('\n')
getCmd = []
for strLine in listText:
Expand Down Expand Up @@ -622,12 +624,10 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):
filename = filename.encode('utf-8')
compile(source, str(filename), 'exec')
except SyntaxError, detail:
s = traceback.format_exception_only(SyntaxError, detail)
fn = detail.filename
eline = detail.lineno and detail.lineno or 1
ecolumn = detail.offset and detail.offset or 1
edescr = detail.msg
if eline != None:
if eline is not None:
eline -= 1
for markerLine in self.bufferMarkerLine:
self.markerDelete(markerLine)
Expand Down Expand Up @@ -678,8 +678,7 @@ def keyPressEvent(self, e):
self.setCursorPosition(endLine, endPos+3)
self.endUndoAction()
return
elif t == '(' and (re.match(r'^[ \t]*def \w+$', txt) \
or re.match(r'^[ \t]*class \w+$', txt)):
elif t == '(' and (re.match(r'^[ \t]*def \w+$', txt) or re.match(r'^[ \t]*class \w+$', txt)):
self.insert('):')
else:
self.insert(self.closing[i])
Expand Down Expand Up @@ -956,26 +955,26 @@ def contextMenuEvent(self, e):
cW = self.widget(self.idx)
menu = QMenu(self)
menu.addSeparator()
newTabAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "New Editor"),
self.newTabEditor)
menu.addAction(
QCoreApplication.translate("PythonConsole", "New Editor"),
self.newTabEditor)
menu.addSeparator()
closeTabAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Close Tab"),
cW.close)
QCoreApplication.translate("PythonConsole", "Close Tab"),
cW.close)
closeAllTabAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Close All"),
self.closeAll)
QCoreApplication.translate("PythonConsole", "Close All"),
self.closeAll)
closeOthersTabAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Close Others"),
self.closeOthers)
QCoreApplication.translate("PythonConsole", "Close Others"),
self.closeOthers)
menu.addSeparator()
saveAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Save"),
cW.save)
saveAsAction = menu.addAction(
QCoreApplication.translate("PythonConsole", "Save As"),
self.saveAs)
QCoreApplication.translate("PythonConsole", "Save"),
cW.save)
menu.addAction(
QCoreApplication.translate("PythonConsole", "Save As"),
self.saveAs)
closeTabAction.setEnabled(False)
closeAllTabAction.setEnabled(False)
closeOthersTabAction.setEnabled(False)
Expand All @@ -986,7 +985,7 @@ def contextMenuEvent(self, e):
closeOthersTabAction.setEnabled(True)
if self.widget(self.idx).newEditor.isModified():
saveAction.setEnabled(True)
action = menu.exec_(self.mapToGlobal(e.pos()))
menu.exec_(self.mapToGlobal(e.pos()))

def closeOthers(self):
idx = self.idx
Expand All @@ -996,7 +995,6 @@ def closeOthers(self):

def closeAll(self):
countTab = self.count()
cI = self.currentIndex()
for i in range(countTab - 1, 0, -1):
self._removeTab(i)
self.newTabEditor(tabName='Untitled-0')
Expand All @@ -1023,7 +1021,7 @@ def newTabEditor(self, tabName=None, filename=None):
readOnly = not QFileInfo(filename).isWritable()
try:
fn = codecs.open(unicode(filename), "rb", encoding='utf-8')
txt = fn.read()
fn.read()
fn.close()
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
Expand Down Expand Up @@ -1128,7 +1126,7 @@ def restoreTabs(self):
else:
errOnRestore = QCoreApplication.translate("PythonConsole",
"Unable to restore the file: \n{0}\n").format(pathFile)
print '## Error: '
print '## Error: '
s = errOnRestore
sys.stderr.write(s)
self.parent.updateTabListScript(pathFile, action='remove')
Expand Down Expand Up @@ -1212,7 +1210,7 @@ def listObject(self, tab):
self.parent.listClassMethod.addTopLevelItem(classItem)
for func_name, data in sorted(readModuleFunction.items(), key=lambda x:x[1].lineno):
if isinstance(data, pyclbr.Function) and \
os.path.normpath(str(data.file)) == os.path.normpath(str(tabWidget.path)):
os.path.normpath(str(data.file)) == os.path.normpath(str(tabWidget.path)):
funcItem = QTreeWidgetItem()
funcItem.setText(0, func_name + ' ')
funcItem.setText(1, str(data.lineno))
Expand Down

0 comments on commit 956c155

Please sign in to comment.