Skip to content
Permalink
Browse files

[pyqgis-console] fix import statement

  • Loading branch information
slarosa committed Mar 31, 2016
1 parent ab5f06b commit 20ce2343cb765a91a5766ffbfa47e630f6bb577a
Showing with 21 additions and 57 deletions.
  1. +17 −45 python/console/console.py
  2. +4 −12 python/console/console_sci.py
@@ -328,36 +328,6 @@ def __init__(self, parent=None):
self.actionClass.setIconVisibleInMenu(True)
self.actionClass.setToolTip(actionClassBt)
self.actionClass.setText(actionClassBt)
## Import Processing class
loadProcessingBt = QCoreApplication.translate("PythonConsole", "Import Processing Class")
self.loadProcessingButton = QAction(self)
self.loadProcessingButton.setCheckable(False)
self.loadProcessingButton.setEnabled(True)
self.loadProcessingButton.setIcon(QgsApplication.getThemeIcon("console/iconProcessingConsole.png"))
self.loadProcessingButton.setMenuRole(QAction.PreferencesRole)
self.loadProcessingButton.setIconVisibleInMenu(True)
self.loadProcessingButton.setToolTip(loadProcessingBt)
self.loadProcessingButton.setText(loadProcessingBt)
## Import QtCore class
loadQtCoreBt = QCoreApplication.translate("PythonConsole", "Import PyQt.QtCore Class")
self.loadQtCoreButton = QAction(self)
self.loadQtCoreButton.setCheckable(False)
self.loadQtCoreButton.setEnabled(True)
self.loadQtCoreButton.setIcon(QgsApplication.getThemeIcon("console/iconQtCoreConsole.png"))
self.loadQtCoreButton.setMenuRole(QAction.PreferencesRole)
self.loadQtCoreButton.setIconVisibleInMenu(True)
self.loadQtCoreButton.setToolTip(loadQtCoreBt)
self.loadQtCoreButton.setText(loadQtCoreBt)
## Import QtGui class
loadQtGuiBt = QCoreApplication.translate("PythonConsole", "Import PyQt.QtGui Class")
self.loadQtGuiButton = QAction(self)
self.loadQtGuiButton.setCheckable(False)
self.loadQtGuiButton.setEnabled(True)
self.loadQtGuiButton.setIcon(QgsApplication.getThemeIcon("console/iconQtGuiConsole.png"))
self.loadQtGuiButton.setMenuRole(QAction.PreferencesRole)
self.loadQtGuiButton.setIconVisibleInMenu(True)
self.loadQtGuiButton.setToolTip(loadQtGuiBt)
self.loadQtGuiButton.setText(loadQtGuiBt)
## Action for Run script
runBt = QCoreApplication.translate("PythonConsole", "Run Command")
self.runButton = QAction(self)
@@ -424,10 +394,24 @@ def __init__(self, parent=None):
self.toolBarEditor.addAction(self.objectListButton)

## Menu Import Class
default_command = {
(QCoreApplication.translate("PythonConsole", "Import Processing Class"),
QgsApplication.getThemeIcon("console/iconProcessingConsole.png")):
["import processing"],
(QCoreApplication.translate("PythonConsole", "Import PyQt.QtCore Class"),
QgsApplication.getThemeIcon("console/iconQtCoreConsole.png")):
["from PyQt.QtCore import *"],
(QCoreApplication.translate("PythonConsole", "Import PyQt.QtGui Class"),
QgsApplication.getThemeIcon("console/iconQtGuiConsole.png")):
["from PyQt.QtGui import *", "from PyQt.QtWidgets import *"]
}

self.classMenu = QMenu()
self.classMenu.addAction(self.loadProcessingButton)
self.classMenu.addAction(self.loadQtCoreButton)
self.classMenu.addAction(self.loadQtGuiButton)
for (title, icon), commands in default_command.iteritems():
action = self.classMenu.addAction(icon, title)
action.triggered[()].connect(
lambda commands=commands: self.shell.commandConsole(commands))

cM = self.toolBar.widgetForAction(self.actionClass)
cM.setMenu(self.classMenu)
cM.setPopupMode(QToolButton.InstantPopup)
@@ -528,9 +512,6 @@ def __init__(self, parent=None):
self.showEditorButton.toggled.connect(self.toggleEditor)
self.clearButton.triggered.connect(self.shellOut.clearConsole)
self.optionsButton.triggered.connect(self.openSettings)
self.loadProcessingButton.triggered.connect(self.processing)
self.loadQtCoreButton.triggered.connect(self.qtCore)
self.loadQtGuiButton.triggered.connect(self.qtGui)
self.runButton.triggered.connect(self.shell.entered)
self.openFileButton.triggered.connect(self.openScriptFile)
self.openInEditorButton.triggered.connect(self.openScriptFileExtEditor)
@@ -577,15 +558,6 @@ def onClickGoToLine(self, item, column):
objName = itemName
tabEditor.goToLine(objName, linenr)

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

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

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

def toggleEditor(self, checked):
self.splitterObj.show() if checked else self.splitterObj.hide()
if not self.tabEditorWidget:
@@ -160,24 +160,16 @@ def autoCompleteKeyBinding(self):
elif radioButtonSource == 'fromDocAPI':
self.autoCompleteFromAll()

def commandConsole(self, command):
def commandConsole(self, commands):
if not self.is_cursor_on_last_line():
self.move_cursor_to_end()
line, pos = self.getCursorPosition()
selCmdLenght = len(self.text(line))
self.setSelection(line, 4, line, selCmdLenght)
self.removeSelectedText()
if command == "processing":
# import Processing class
self.append('import processing')
elif command == "qtCore":
# import QtCore class
self.append('from PyQt.QtCore import *')
elif command == "qtGui":
# import QtGui class
self.append('from PyQt.QtGui import *')
self.append('from PyQt.QtWidgets import *')
self.entered()
for cmd in commands:
self.append(cmd)
self.entered()
self.move_cursor_to_end()
self.setFocus()

0 comments on commit 20ce234

Please sign in to comment.
You can’t perform that action at this time.