Skip to content
Permalink
Browse files

Merge pull request #4986 from nyalldawson/console_imports

Import gui, analysis, processing and Qt classes on console startup
  • Loading branch information
nyalldawson committed Aug 6, 2017
2 parents 5f87bd8 + 05a039b commit 771bcebc5e4bce82c55897e9d2265318d4905b7e
Showing with 2 additions and 38 deletions.
  1. +0 −33 python/console/console.py
  2. +2 −2 python/console/console_sci.py
  3. +0 −3 tests/src/python/test_console.py
@@ -325,16 +325,6 @@ def __init__(self, parent=None):
self.optionsButton.setIconVisibleInMenu(True)
self.optionsButton.setToolTip(optionsBt)
self.optionsButton.setText(optionsBt)
# Action menu for class
actionClassBt = QCoreApplication.translate("PythonConsole", "Import Class")
self.actionClass = QAction(self)
self.actionClass.setCheckable(False)
self.actionClass.setEnabled(True)
self.actionClass.setIcon(QgsApplication.getThemeIcon("console/iconClassConsole.png"))
self.actionClass.setMenuRole(QAction.PreferencesRole)
self.actionClass.setIconVisibleInMenu(True)
self.actionClass.setToolTip(actionClassBt)
self.actionClass.setText(actionClassBt)
# Action for Run script
runBt = QCoreApplication.translate("PythonConsole", "Run Command")
self.runButton = QAction(self)
@@ -365,7 +355,6 @@ def __init__(self, parent=None):
self.toolBar.setMovable(False)
self.toolBar.setFloatable(False)
self.toolBar.addAction(self.clearButton)
self.toolBar.addAction(self.actionClass)
self.toolBar.addAction(self.runButton)
self.toolBar.addSeparator()
self.toolBar.addAction(self.showEditorButton)
@@ -400,28 +389,6 @@ def __init__(self, parent=None):
self.toolBarEditor.addSeparator()
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 qgis.PyQt.QtCore import *"],
(QCoreApplication.translate("PythonConsole", "Import PyQt.QtGui Class"),
QgsApplication.getThemeIcon("console/iconQtGuiConsole.png")):
["from qgis.PyQt.QtGui import *", "from qgis.PyQt.QtWidgets import *"]
}

self.classMenu = QMenu()
for (title, icon), commands in list(default_command.items()):
action = self.classMenu.addAction(icon, title)
action.triggered.connect(partial(self.shell.commandConsole, commands))

cM = self.toolBar.widgetForAction(self.actionClass)
cM.setMenu(self.classMenu)
cM.setPopupMode(QToolButton.InstantPopup)

self.widgetButton = QWidget()
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
@@ -36,8 +36,8 @@
from qgis.core import QgsApplication, QgsSettings
from .ui_console_history_dlg import Ui_HistoryDialogPythonConsole

_init_commands = ["from qgis.core import *", "import qgis.utils",
"from qgis.utils import iface"]
_init_commands = ["from qgis.core import *", "from qgis.gui import *", "from qgis.analysis import *", "import processing", "import qgis.utils",
"from qgis.utils import iface", "from qgis.PyQt.QtCore import *", "from qgis.PyQt.QtGui import *", "from qgis.PyQt.QtWidgets import *"]
_historyFile = os.path.join(QgsApplication.qgisSettingsDirPath(), "console_history.txt")


@@ -34,9 +34,6 @@ def test_show_console(self):
my_console = console.show_console()
my_console_widget = my_console.console

for action in my_console_widget.classMenu.actions():
action.trigger()


if __name__ == "__main__":
unittest.main()

0 comments on commit 771bceb

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