Skip to content

Commit

Permalink
[pyqgis-console] move console options to main app options
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa authored and nyalldawson committed Oct 2, 2020
1 parent 61a71a4 commit 4fea3ed
Show file tree
Hide file tree
Showing 6 changed files with 715 additions and 808 deletions.
1 change: 1 addition & 0 deletions python/console/__init__.py
Expand Up @@ -22,3 +22,4 @@
__copyright__ = '(C) 2012, Salvatore Larosa'

from .console import show_console # NOQA
from .console import init_options_widget
21 changes: 16 additions & 5 deletions python/console/console.py
Expand Up @@ -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
Expand All @@ -37,6 +37,7 @@
import re

_console = None
_options_factory = ConsoleOptionsFactory()


def show_console():
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
46 changes: 43 additions & 3 deletions python/console/console_settings.py
Expand Up @@ -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):
Expand Down Expand Up @@ -128,6 +167,7 @@ def accept(self):
)
return
self.saveSettings()
settingsWatcher.settingsChanged.emit()
self.listPath = []
QDialog.accept(self)

Expand Down

3 comments on commit 4fea3ed

@nirvn
Copy link
Contributor

@nirvn nirvn commented on 4fea3ed Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

@slarosa slarosa commented on 4fea3ed Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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
Copy link
Member Author

@slarosa slarosa commented on 4fea3ed Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.