Skip to content
Permalink
Browse files

[python console] Add help links to the PyQGIS API and Cookbook pages

  • Loading branch information
nirvn committed Jun 3, 2020
1 parent 296fc6c commit 2f36e18d1102d52d8136c5a3bc0ee1be297c8b7d
Showing with 37 additions and 10 deletions.
  1. +37 −10 python/console/console.py
@@ -29,11 +29,12 @@
from .console_output import ShellOutputScintilla
from .console_editor import EditorTabWidget
from .console_settings import optionsDialog
from qgis.core import QgsApplication, QgsSettings
from qgis.core import Qgis, QgsApplication, QgsSettings
from qgis.gui import QgsFilterLineEdit, QgsHelp, QgsDockWidget
from functools import partial

import sys
import re

_console = None

@@ -336,16 +337,30 @@ def __init__(self, parent=None):
self.runButton.setIconVisibleInMenu(True)
self.runButton.setToolTip(runBt)
self.runButton.setText(runBt)
# Help action

# Help button
self.helpConsoleAction = QAction(self)
self.helpConsoleAction.setEnabled(True)
self.helpConsoleAction.setText(QCoreApplication.translate("PythonConsole", "Python Console Help"))
self.helpAPIAction = QAction(self)
self.helpAPIAction.setEnabled(True)
self.helpAPIAction.setText(QCoreApplication.translate("PythonConsole", "PyQGIS API Documentation"))
self.helpCookbookAction = QAction(self)
self.helpCookbookAction.setEnabled(True)
self.helpCookbookAction.setText(QCoreApplication.translate("PythonConsole", "PyQGIS Cookbook"))

self.helpMenu = QMenu(self)
self.helpMenu.addAction(self.helpConsoleAction)
self.helpMenu.addAction(self.helpAPIAction)
self.helpMenu.addAction(self.helpCookbookAction)

helpBt = QCoreApplication.translate("PythonConsole", "Help…")
self.helpButton = QAction(self)
self.helpButton.setCheckable(False)
self.helpButton = QToolButton(self)
self.helpButton.setPopupMode(QToolButton.InstantPopup)
self.helpButton.setEnabled(True)
self.helpButton.setIcon(QgsApplication.getThemeIcon("console/iconHelpConsole.svg"))
self.helpButton.setMenuRole(QAction.PreferencesRole)
self.helpButton.setIconVisibleInMenu(True)
self.helpButton.setToolTip(helpBt)
self.helpButton.setText(helpBt)
self.helpButton.setMenu(self.helpMenu)

self.toolBar = QToolBar()
self.toolBar.setEnabled(True)
@@ -361,7 +376,7 @@ def __init__(self, parent=None):
self.toolBar.addAction(self.showEditorButton)
self.toolBar.addSeparator()
self.toolBar.addAction(self.optionsButton)
self.toolBar.addAction(self.helpButton)
self.toolBar.addWidget(self.helpButton)

self.toolBarEditor = QToolBar()
self.toolBarEditor.setEnabled(False)
@@ -492,7 +507,9 @@ def __init__(self, parent=None):
self.openInEditorButton.triggered.connect(self.openScriptFileExtEditor)
self.saveFileButton.triggered.connect(self.saveScriptFile)
self.saveAsFileButton.triggered.connect(self.saveAsScriptFile)
self.helpButton.triggered.connect(self.openHelp)
self.helpConsoleAction.triggered.connect(self.openHelpConsole)
self.helpAPIAction.triggered.connect(self.openHelpAPI)
self.helpCookbookAction.triggered.connect(self.openHelpCookbook)
self.listClassMethod.itemClicked.connect(self.onClickGoToLine)
self.lineEditFind.returnPressed.connect(self._findNext)
self.findNextButton.triggered.connect(self._findNext)
@@ -656,9 +673,19 @@ def saveAsScriptFile(self, index=None):
if not fileNone:
self.updateTabListScript(pathFileName, action='remove')

def openHelp(self):
def openHelpConsole(self):
QgsHelp.openHelp("plugins/python_console.html")

def openHelpAPI(self):
m = re.search(r'^([0-9]+)\.([0-9]+)\.', Qgis.QGIS_VERSION)
if m:
QDesktopServices.openUrl(QUrl('https://qgis.org/pyqgis/{}.{}/'.format(m.group(1), m.group(2))))

def openHelpCookbook(self):
m = re.search(r'^([0-9]+)\.([0-9]+)\.', Qgis.QGIS_VERSION)
if m:
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()

0 comments on commit 2f36e18

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