Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
indentation update (now including autopep8)
  • Loading branch information
jef-n committed Aug 22, 2015
1 parent 93d45a0 commit b39055b
Show file tree
Hide file tree
Showing 548 changed files with 18,328 additions and 17,778 deletions.
7 changes: 4 additions & 3 deletions python/__init__.py
Expand Up @@ -41,9 +41,10 @@ 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
74 changes: 40 additions & 34 deletions python/console/console.py
Expand Up @@ -38,46 +38,51 @@

_console = None


def show_console():
""" called from QGIS to open the console """
global _console
if _console is None:
parent = iface.mainWindow() if iface else None
_console = PythonConsole( parent )
_console.show() # force show even if it was restored as hidden
# set focus to the console so the user can start typing
# defer the set focus event so it works also whether the console not visible yet
QTimer.singleShot(0, _console.activate)
else:
_console.setVisible(not _console.isVisible())
# set focus to the console so the user can start typing
if _console.isVisible():
_console.activate()
## Shows help on first launch of the console
settings = QSettings()
if settings.value('pythonConsole/contextHelpOnFirstLaunch', True, type=bool):
QgsContextHelp.run( "PythonConsole" )
settings.setValue('pythonConsole/contextHelpOnFirstLaunch', False)
""" called from QGIS to open the console """
global _console
if _console is None:
parent = iface.mainWindow() if iface else None
_console = PythonConsole(parent)
_console.show() # force show even if it was restored as hidden
# set focus to the console so the user can start typing
# defer the set focus event so it works also whether the console not visible yet
QTimer.singleShot(0, _console.activate)
else:
_console.setVisible(not _console.isVisible())
# set focus to the console so the user can start typing
if _console.isVisible():
_console.activate()
## Shows help on first launch of the console
settings = QSettings()
if settings.value('pythonConsole/contextHelpOnFirstLaunch', True, type=bool):
QgsContextHelp.run("PythonConsole")
settings.setValue('pythonConsole/contextHelpOnFirstLaunch', False)

_old_stdout = sys.stdout
_console_output = None

# hook for python console so all output will be redirected
# and then shown in console


def console_displayhook(obj):
global _console_output
_console_output = obj


class PythonConsole(QDockWidget):

def __init__(self, parent=None):
QDockWidget.__init__(self, parent)
self.setObjectName("PythonConsole")
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
#self.setAllowedAreas(Qt.BottomDockWidgetArea)

self.console = PythonConsoleWidget(self)
self.setWidget( self.console )
self.setFocusProxy( self.console )
self.setWidget(self.console)
self.setFocusProxy(self.console)

# try to restore position from stored main window state
if iface and not iface.mainWindow().restoreDockWidget(self):
Expand All @@ -92,7 +97,9 @@ def closeEvent(self, event):
self.console.saveSettingsConsole()
QWidget.closeEvent(self, event)


class PythonConsoleWidget(QWidget):

def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
Expand All @@ -113,7 +120,7 @@ def __init__(self, parent=None):

self.shellOutWidget = QWidget(self)
self.shellOutWidget.setLayout(QVBoxLayout())
self.shellOutWidget.layout().setContentsMargins(0,0,0,0)
self.shellOutWidget.layout().setContentsMargins(0, 0, 0, 0)
self.shellOutWidget.layout().addWidget(self.shellOut)

self.splitter = QSplitter(self.splitterEditor)
Expand Down Expand Up @@ -141,7 +148,6 @@ def __init__(self, parent=None):
self.listClassMethod.setColumnHidden(1, True)
self.listClassMethod.setAlternatingRowColors(True)


#self.splitterEditor.addWidget(self.widgetEditor)
#self.splitterObj.addWidget(self.listClassMethod)
#self.splitterObj.addWidget(self.widgetEditor)
Expand Down Expand Up @@ -477,9 +483,9 @@ def __init__(self, parent=None):
placeHolderTxt = QCoreApplication.translate("PythonConsole", "Enter text to find...")

if pyqtconfig.Configuration().qt_version >= 0x40700:
self.lineEditFind.setPlaceholderText(placeHolderTxt)
self.lineEditFind.setPlaceholderText(placeHolderTxt)
else:
self.lineEditFind.setToolTip(placeHolderTxt)
self.lineEditFind.setToolTip(placeHolderTxt)
self.findNextButton = QToolButton()
self.findNextButton.setEnabled(False)
toolTipfindNext = QCoreApplication.translate("PythonConsole", "Find Next")
Expand Down Expand Up @@ -579,13 +585,13 @@ def onClickGoToLine(self, item, column):
tabEditor.goToLine(objName, linenr)

def processing(self):
self.shell.commandConsole('processing')
self.shell.commandConsole('processing')

def qtCore(self):
self.shell.commandConsole('qtCore')
self.shell.commandConsole('qtCore')

def qtGui(self):
self.shell.commandConsole('qtGui')
self.shell.commandConsole('qtGui')

def toggleEditor(self, checked):
self.splitterObj.show() if checked else self.splitterObj.hide()
Expand Down Expand Up @@ -650,7 +656,7 @@ def saveScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget()
try:
tabWidget.save()
except (IOError, OSError), error:
except (IOError, OSError) as error:
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
Expand All @@ -663,19 +669,19 @@ def saveAsScriptFile(self, index=None):
if not tabWidget.path:
fileName = self.tabEditorWidget.tabText(index) + '.py'
folder = self.settings.value("pythonConsole/lastDirPath", QDir.home())
pathFileName = os.path.join(folder,fileName)
pathFileName = os.path.join(folder, fileName)
fileNone = True
else:
pathFileName = tabWidget.path
fileNone = False
saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As")
filename = QFileDialog.getSaveFileName(self,
saveAsFileTr,
pathFileName, "Script file (*.py)")
saveAsFileTr,
pathFileName, "Script file (*.py)")
if filename:
try:
tabWidget.save(filename)
except (IOError, OSError), error:
except (IOError, OSError) as error:
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
Expand All @@ -690,7 +696,7 @@ def saveAsScriptFile(self, index=None):
self.updateTabListScript(pathFileName, action='remove')

def openHelp(self):
QgsContextHelp.run( "PythonConsole" )
QgsContextHelp.run("PythonConsole")

def openSettings(self):
if optionsDialog(self).exec_():
Expand Down
16 changes: 9 additions & 7 deletions python/console/console_compile_apis.py
Expand Up @@ -27,12 +27,14 @@

from ui_console_compile_apis import Ui_APIsDialogPythonConsole


class PrepareAPIDialog(QDialog):

def __init__(self, api_lexer, api_files, pap_file, parent=None):
QDialog.__init__(self, parent)
self.ui = Ui_APIsDialogPythonConsole()
self.ui.setupUi(self)
self.setWindowTitle(QCoreApplication.translate("PythonConsole","Compile APIs"))
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Compile APIs"))
self.ui.plainTextEdit.setVisible(False)
self.ui.textEdit_Qsci.setVisible(False)
self.adjustSize()
Expand All @@ -57,32 +59,32 @@ def _preparationFinished(self):
self._clearLexer()
if os.path.exists(self._pap_file):
os.remove(self._pap_file)
self.ui.label.setText(QCoreApplication.translate("PythonConsole","Saving prepared file..."))
self.ui.label.setText(QCoreApplication.translate("PythonConsole", "Saving prepared file..."))
prepd = self._api.savePrepared(unicode(self._pap_file))
rslt = self.trUtf8("Error")
if prepd:
rslt = QCoreApplication.translate("PythonConsole","Saved")
rslt = QCoreApplication.translate("PythonConsole", "Saved")
self.ui.label.setText(u'{0} {1}'.format(self.ui.label.text(), rslt))
self._api = None
self.ui.progressBar.setVisible(False)
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setText(
QCoreApplication.translate("PythonConsole","Done"))
QCoreApplication.translate("PythonConsole", "Done"))
self.adjustSize()

def prepareAPI(self):
# self.ui.textEdit_Qsci.setLexer(0)
exec u'self.qlexer = {0}(self.ui.textEdit_Qsci)'.format(self._api_lexer)
exec(u'self.qlexer = {0}(self.ui.textEdit_Qsci)'.format(self._api_lexer))
# 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:
self._api.load(unicode(api_file))
try:
self._api.prepare()
except Exception, err:
except Exception as err:
self._api = None
self._clearLexer()
self.ui.label.setText(QCoreApplication.translate("PythonConsole","Error preparing file..."))
self.ui.label.setText(QCoreApplication.translate("PythonConsole", "Error preparing file..."))
self.ui.progressBar.setVisible(False)
self.ui.plainTextEdit.setVisible(True)
self.ui.plainTextEdit.insertPlainText(err)
Expand Down

0 comments on commit b39055b

Please sign in to comment.