Skip to content
Permalink
Browse files

[pyqgis-console] move console options to main app options

  • Loading branch information
slarosa authored and nyalldawson committed Oct 2, 2020
1 parent 61a71a4 commit 4fea3ed82278de6866fe90b3e4bb7ceffee14d64
@@ -22,3 +22,4 @@
__copyright__ = '(C) 2012, Salvatore Larosa'

from .console import show_console # NOQA
from .console import init_options_widget
@@ -28,7 +28,7 @@
from .console_sci import ShellScintilla
from .console_output import ShellOutputScintilla
from .console_editor import EditorTabWidget
from .console_settings import optionsDialog
from .console_settings import ConsoleOptionsFactory, settingsWatcher
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.gui import QgsFilterLineEdit, QgsHelp, QgsDockWidget
from functools import partial
@@ -37,6 +37,7 @@
import re

_console = None
_options_factory = ConsoleOptionsFactory()


def show_console():
@@ -72,6 +73,13 @@ def console_displayhook(obj):
_console_output = obj


def init_options_widget():
""" called from QGIS to add the console options widget """
global _options_factory
_options_factory.setTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
iface.registerOptionsWidgetFactory(_options_factory)


class PythonConsole(QgsDockWidget):

def __init__(self, parent=None):
@@ -81,6 +89,7 @@ def __init__(self, parent=None):
# self.setAllowedAreas(Qt.BottomDockWidgetArea)

self.console = PythonConsoleWidget(self)
settingsWatcher.settingsChanged.connect(self.console.updateSettings)
self.setWidget(self.console)
self.setFocusProxy(self.console)

@@ -688,10 +697,12 @@ def openHelpCookbook(self):
QDesktopServices.openUrl(QUrl('https://docs.qgis.org/{}.{}/en/docs/pyqgis_developer_cookbook/index.html'.format(m.group(1), m.group(2))))

def openSettings(self):
if optionsDialog(self).exec_():
self.shell.refreshSettingsShell()
self.shellOut.refreshSettingsOutput()
self.tabEditorWidget.refreshSettingsEditor()
iface.showOptionsDialog(iface.mainWindow(), currentPage='consoleOptions')

def updateSettings(self):
self.shell.refreshSettingsShell()
self.shellOut.refreshSettingsOutput()
self.tabEditorWidget.refreshSettingsEditor()

def callWidgetMessageBar(self, text):
self.shellOut.widgetMessageBar(iface, text)
@@ -19,17 +19,56 @@
Some portions of code were taken from https://code.google.com/p/pydee/
"""

from qgis.PyQt.QtCore import QCoreApplication, QSize, Qt, QUrl
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QTableWidgetItem
from qgis.PyQt.QtCore import QCoreApplication, QSize, QObject, Qt, pyqtSignal
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QTableWidgetItem, QHBoxLayout
from qgis.PyQt.QtGui import QIcon, QFont, QColor, QFontDatabase, QDesktopServices

from qgis.core import QgsSettings
from qgis.core import QgsSettings, QgsApplication
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory

from .console_base import QgsPythonConsoleBase
from .console_compile_apis import PrepareAPIDialog
from .ui_console_settings import Ui_SettingsDialogPythonConsole


class SettingsWatcher(QObject):
settingsChanged = pyqtSignal()


settingsWatcher = SettingsWatcher()


class ConsoleOptionsFactory(QgsOptionsWidgetFactory):

def __init__(self):
super(QgsOptionsWidgetFactory, self).__init__()

def icon(self):
return QgsApplication.getThemeIcon('/console/mIconRunConsole.svg')

def createWidget(self, parent):
return ConsoleOptionsPage(parent)


class ConsoleOptionsPage(QgsOptionsPageWidget):

def __init__(self, parent):
super(ConsoleOptionsPage, self).__init__(parent)
self.options_widget = optionsDialog(parent)
layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setMargin(0)
self.setLayout(layout)
layout.addWidget(self.options_widget)
self.setObjectName('consoleOptions')

def apply(self):
self.config_widget.accept()

def helpKey(self):
return 'plugins/python_console.html'


class optionsDialog(QDialog, Ui_SettingsDialogPythonConsole):

def __init__(self, parent):
@@ -128,6 +167,7 @@ def accept(self):
)
return
self.saveSettings()
settingsWatcher.settingsChanged.emit()
self.listPath = []
QDialog.accept(self)

3 comments on commit 4fea3ed

@nirvn

This comment has been minimized.

Copy link
Contributor

@nirvn nirvn replied Oct 3, 2020

@nyalldawson , @slarosa , I get a python error when closing the options dialog now:

AttributeError: 'ConsoleOptionsPage' object has no attribute 'config_widget'
Traceback (most recent call last):
File "/home/webmaster/apps/share/qgis/python/console/console_settings.py", line 66, in apply
self.config_widget.accept()
AttributeError: 'ConsoleOptionsPage' object has no attribute 'config_widget'

@slarosa

This comment has been minimized.

Copy link
Member Author

@slarosa slarosa replied Oct 3, 2020

@nyalldawson , @slarosa , I get a python error when closing the options dialog now:

AttributeError: 'ConsoleOptionsPage' object has no attribute 'config_widget'
Traceback (most recent call last):
File "/home/webmaster/apps/share/qgis/python/console/console_settings.py", line 66, in apply
self.config_widget.accept()
AttributeError: 'ConsoleOptionsPage' object has no attribute 'config_widget'

my bad, thank you for pointing to me the issue.

@slarosa

This comment has been minimized.

Copy link
Member Author

@slarosa slarosa replied Oct 3, 2020

To https://github.com/qgis/QGIS.git
 ! [remote rejected]       master -> master (protected branch hook declined)

is this anything introduced recently? I cannot anymore do direct push to branch master.
I know it's preferable to do pull request but I just wanted to rename instance attribute to fix attribute error.

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