Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
YoannQDQ committed Nov 4, 2024
1 parent 3d7ecb8 commit ac3a01f
Show file tree
Hide file tree
Showing 30 changed files with 344 additions and 228 deletions.
30 changes: 30 additions & 0 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10868,6 +10868,36 @@
"""
# --
Qgis.ColorModel.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DocumentationApi.PyQgis.__doc__ = "PyQgis API documentation"
Qgis.DocumentationApi.PyQgisSearch.__doc__ = "Search in PyQgis API documentation"
Qgis.DocumentationApi.CppQgis.__doc__ = "C++ QGIS API documentation"
Qgis.DocumentationApi.Qt.__doc__ = "Qt API documentation"
Qgis.DocumentationApi.__doc__ = """Documentation Api

.. versionadded:: 3.42

* ``PyQgis``: PyQgis API documentation
* ``PyQgisSearch``: Search in PyQgis API documentation
* ``CppQgis``: C++ QGIS API documentation
* ``Qt``: Qt API documentation

"""
# --
Qgis.DocumentationApi.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DocumentationBrowser.DeveloperToolsPanel.__doc__ = "Embedded webview in the DevTools panel"
Qgis.DocumentationBrowser.SystemWebBrowser.__doc__ = "Default system web browser"
Qgis.DocumentationBrowser.__doc__ = """Documentation API browser

.. versionadded:: 3.42

* ``DeveloperToolsPanel``: Embedded webview in the DevTools panel
* ``SystemWebBrowser``: Default system web browser

"""
# --
Qgis.DocumentationBrowser.baseClass = Qgis
try:
Qgis.__attribute_docs__ = {'QGIS_DEV_VERSION': 'The development version', 'DEFAULT_SEARCH_RADIUS_MM': 'Identify search radius in mm', 'DEFAULT_MAPTOPIXEL_THRESHOLD': 'Default threshold between map coordinates and device coordinates for map2pixel simplification', 'DEFAULT_HIGHLIGHT_COLOR': 'Default highlight color. The transparency is expected to only be applied to polygon\nfill. Lines and outlines are rendered opaque.', 'DEFAULT_HIGHLIGHT_BUFFER_MM': 'Default highlight buffer in mm.', 'DEFAULT_HIGHLIGHT_MIN_WIDTH_MM': 'Default highlight line/stroke minimum width in mm.', 'SCALE_PRECISION': 'Fudge factor used to compare two scales. The code is often going from scale to scale\ndenominator. So it looses precision and, when a limit is inclusive, can lead to errors.\nTo avoid that, use this factor instead of using <= or >=.\n\n.. deprecated:: 3.40\n\n No longer used by QGIS and will be removed in QGIS 4.0.', 'DEFAULT_Z_COORDINATE': 'Default Z coordinate value.\nThis value have to be assigned to the Z coordinate for the vertex.', 'DEFAULT_M_COORDINATE': 'Default M coordinate value.\nThis value have to be assigned to the M coordinate for the vertex.\n\n.. versionadded:: 3.20', 'UI_SCALE_FACTOR': 'UI scaling factor. This should be applied to all widget sizes obtained from font metrics,\nto account for differences in the default font sizes across different platforms.', 'DEFAULT_SNAP_TOLERANCE': 'Default snapping distance tolerance.', 'DEFAULT_SNAP_UNITS': 'Default snapping distance units.'}
Qgis.version = staticmethod(Qgis.version)
Expand Down
14 changes: 14 additions & 0 deletions python/PyQt6/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -3169,6 +3169,20 @@ The development version
Cmyk,
};

enum class DocumentationApi /BaseType=IntEnum/
{
PyQgis,
PyQgisSearch,
CppQgis,
Qt,
};

enum class DocumentationBrowser /BaseType=IntEnum/
{
DeveloperToolsPanel,
SystemWebBrowser,
};

static const double DEFAULT_SEARCH_RADIUS_MM;

static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
Expand Down
2 changes: 1 addition & 1 deletion python/PyQt6/gui/auto_additions/qgscodeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
QgsCodeEditor.Flags.baseClass = QgsCodeEditor
Flags = QgsCodeEditor # dirty hack since SIP seems to introduce the flags in module
try:
QgsCodeEditor.__attribute_docs__ = {'SEARCH_RESULT_INDICATOR': 'Indicator index for search results', 'sessionHistoryCleared': 'Emitted when the history of commands run in the current session is cleared.\n\n.. versionadded:: 3.30\n', 'persistentHistoryCleared': 'Emitted when the persistent history of commands run in the editor is cleared.\n\n.. versionadded:: 3.30\n', 'helpRequested': 'Emitted whent the F1 key is pressed while hovering over a word\n\n.. versionadded:: 3.42\n'}
QgsCodeEditor.__attribute_docs__ = {'SEARCH_RESULT_INDICATOR': 'Indicator index for search results', 'sessionHistoryCleared': 'Emitted when the history of commands run in the current session is cleared.\n\n.. versionadded:: 3.30\n', 'persistentHistoryCleared': 'Emitted when the persistent history of commands run in the editor is cleared.\n\n.. versionadded:: 3.30\n', 'helpRequested': 'Emitted when documentation was requested for the specified ``word``.\n\n.. versionadded:: 3.42\n'}
QgsCodeEditor.languageToString = staticmethod(QgsCodeEditor.languageToString)
QgsCodeEditor.defaultColor = staticmethod(QgsCodeEditor.defaultColor)
QgsCodeEditor.color = staticmethod(QgsCodeEditor.color)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,9 @@ Emitted when the persistent history of commands run in the editor is cleared.
%End


void helpRequested( QString word );
void helpRequested( const QString &word );
%Docstring
Emitted whent the F1 key is pressed while hovering over a word
Emitted when documentation was requested for the specified ``word``.

.. versionadded:: 3.42
%End
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Searches the selected text in the official PyQGIS online documentation.

virtual void showApiDocumentation( const QString &item );
%Docstring
Searches the given text in the official APIs (PyQGIS, C++ QGIS or Qt) documentation.
Displays the given text in the official APIs (PyQGIS, C++ QGIS or Qt) documentation.

.. versionadded:: 3.42
%End
Expand Down
8 changes: 4 additions & 4 deletions python/PyQt6/gui/auto_generated/qgisinterface.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1492,14 +1492,14 @@ Unregister a previously registered tool factory from the development/debugging t
.. versionadded:: 3.14
%End

virtual void showApiDocumentation( const QString &api = QStringLiteral( "pyqgis" ), bool embedded = true, const QString &object = QString(), const QString &module = QString() ) = 0;
virtual void showApiDocumentation( Qgis::DocumentationApi api = Qgis::DocumentationApi::PyQgis, Qgis::DocumentationBrowser browser = Qgis::DocumentationBrowser::DeveloperToolsPanel, const QString &object = QString(), const QString &module = QString() ) = 0;
%Docstring
Show a page of the API documentation

:param api: "pyqgis" or "qgis" or "qt" or "pyqgis-search"
:param embedded: If ``True``, the documentation will be opened in the embedded devtools webview. Otherwise, use system web browser
:param api: Which API to display
:param browser: Web browser used to display the API documentation
:param object: object to show in the documentation
:param module: used only if api = "pyqgis"
:param module: used only if api = :py:class:`Qgis`.DocumentationApi.PyQgis

.. versionadded:: 3.42
%End
Expand Down
47 changes: 24 additions & 23 deletions python/console/console_sci.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,46 @@ def __parse_object(object=None):
return 'qt', module, obj
""",
r"""
def _help(object=None, api="pyqgis", embedded=True, force_search=False):
def _help(object=None, api=Qgis.DocumentationApi.PyQgis, force_search=False):
'''
Link to the C++ or PyQGIS API documentation for the given object.
If no object is given, the main PyQGIS API page is opened.
If the object is not part of the QGIS API but is a Qt object the Qt documentation is opened.
'''
pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
browserName = pythonSettingsTreeNode.childSetting('context-help-browser').valueAsVariant()
try:
browser = Qgis.DocumentationBrowser[browserName]
except KeyError:
browser = Qgis.DocumentationBrowser.DeveloperToolsPanel
if not object:
return iface.showApiDocumentation(api, embedded=embedded)
return iface.showApiDocumentation(api, browser=browser)
embedded = browser == Qgis.DocumentationBrowser.DeveloperToolsPanel
if isinstance(object, str):
try:
object = eval(object)
except (SyntaxError, NameError):
if embedded and not force_search:
return iface.showApiDocumentation(api, embedded=True)
return iface.showApiDocumentation(api, browser=browser)
else:
return iface.showApiDocumentation("pyqgis-search", object=object, embedded=False)
return iface.showApiDocumentation(Qgis.DocumentationApi.PyQgisSearch, object=object, browser=Qgis.DocumentationBrowser.SystemWebBrowser)
obj_info = __parse_object(object)
if not obj_info:
if force_search or isinstance(object, str) and not embedded:
return iface.showApiDocumentation("pyqgis-search", object=object, embedded=False)
return iface.showApiDocumentation(Qgis.DocumentationApi.PyQgisSearch, object=object, browser=Qgis.DocumentationBrowser.SystemWebBrowser)
else:
return iface.showApiDocumentation(api, embedded=embedded)
return iface.showApiDocumentation(api, browser=browser)
obj_type, module, class_name = obj_info
if obj_type == "qt":
api = "qt"
api = Qgis.DocumentationApi.Qt
iface.showApiDocumentation(api, embedded=embedded, object=class_name, module=module)
iface.showApiDocumentation(api, browser=browser, object=class_name, module=module)
""",
r"""
Expand All @@ -145,7 +154,7 @@ def _api(object=None):
If no object is given, the main API page is opened.
If the object is not part of the QGIS API but is a Qt object the Qt documentation is opened.
'''
return _help(object, api="qgis")
return _help(object, api=Qgis.DocumentationApi.CppQgis)
""",
r"""
def _pyqgis(object=None):
Expand All @@ -154,7 +163,7 @@ def _pyqgis(object=None):
If no object is given, the main PyQGIS API page is opened.
If the object is not part of the QGIS API but is a Qt object the Qt documentation is opened.
'''
return _help(object, api="pyqgis")
return _help(object, api=Qgis.DocumentationApi.PyQgis)
"""
]

Expand Down Expand Up @@ -238,9 +247,9 @@ def execCommandImpl(self, cmd, show_input=True):
if cmd == "?":
self.shell.console_widget.shell_output.insertHelp()
elif cmd == '_pyqgis':
self.shell.showApi("pyqgis")
self.shell.showApi(Qgis.DocumentationApi.PyQgis)
elif cmd == '_api':
self.shell.showApi("qgis")
self.shell.showApi(Qgis.DocumentationApi.CppQgis)
elif cmd == '_cookbook':
webbrowser.open(
"https://docs.qgis.org/{}/en/docs/pyqgis_developer_cookbook/".format(
Expand Down Expand Up @@ -474,18 +483,10 @@ def runFile(self, filename, override_file_name: Optional[str] = None):
QgsProcessingUtils.stringToPythonLiteral(dirname)), False)

def showApiDocumentation(self, text, force_search=False):
self._interpreter.execCommandImpl(f'_help({repr(text)}, api=Qgis.DocumentationApi.PyQgis, force_search={force_search})', show_input=False)

pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")

embedded = pythonSettingsTreeNode.childSetting('context-help-embedded').value()
api = "pyqgis" if pythonSettingsTreeNode.childSetting('context-help-pyqgis').value() else "qgis"

self._interpreter.execCommandImpl(f'_help({repr(text)}, api="{api}", embedded={embedded}, force_search={force_search})', show_input=False)

def showApi(self, api):
pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
embedded = pythonSettingsTreeNode.childSetting('context-help-embedded').value()
self._interpreter.execCommandImpl(f'_help(api="{api}", embedded={embedded})', show_input=False)
def showApi(self, api: Qgis.DocumentationApi):
self._interpreter.execCommandImpl(f'_help(api=Qgis.DocumentationApi.{api.name})', show_input=False)

def populateContextMenu(self, menu):

Expand Down
28 changes: 21 additions & 7 deletions python/console/console_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from qgis.PyQt.QtWidgets import QWidget, QFileDialog, QMessageBox, QTableWidgetItem, QHBoxLayout
from qgis.PyQt.QtGui import QIcon, QDesktopServices

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

from .console_compile_apis import PrepareAPIDialog
Expand Down Expand Up @@ -76,6 +76,10 @@ def __init__(self, parent):
self.parent = parent
self.setupUi(self)

# Populate the documentation Browser combobox
self.contextHelpBrowser.addItem(QCoreApplication.translate("PythonConsole", "Embedded Webview (developer tools)"), Qgis.DocumentationBrowser.DeveloperToolsPanel)
self.contextHelpBrowser.addItem(QCoreApplication.translate("PythonConsole", "Default system web browser"), Qgis.DocumentationBrowser.SystemWebBrowser)

self.autopep8Level.setClearValue(1)
self.maxLineLength.setClearValue(80)

Expand Down Expand Up @@ -211,15 +215,17 @@ def saveSettings(self):

settings.setValue("pythonConsole/formatOnSave", self.formatOnSave.isChecked())

pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
codeEditorTreeNode = QgsSettingsTree.node("gui").childNode("code-editor")
pythonSettingsTreeNode = codeEditorTreeNode.childNode("python")
pythonSettingsTreeNode.childSetting("sort-imports").setValue(self.sortImports.isChecked())
pythonSettingsTreeNode.childSetting("formatter").setValue(self.formatter.currentText())
pythonSettingsTreeNode.childSetting("autopep8-level").setValue(self.autopep8Level.value())
pythonSettingsTreeNode.childSetting("black-normalize-quotes").setValue(self.blackNormalizeQuotes.isChecked())
pythonSettingsTreeNode.childSetting("max-line-length").setValue(self.maxLineLength.value())
pythonSettingsTreeNode.childSetting('external-editor').setValue(self.externalEditor.text())
pythonSettingsTreeNode.childSetting('context-help-embedded').setValue(self.contextHelpBrowser.currentIndex() == 0)
pythonSettingsTreeNode.childSetting('context-help-pyqgis').setValue(self.contextHelpApi.currentIndex() == 0)
pythonSettingsTreeNode.childSetting('context-help-browser').setVariantValue(self.contextHelpBrowser.currentData().name)

codeEditorTreeNode.childSetting('context-help-hover').setValue(self.contextHelpHover.isChecked())

def restoreSettings(self):
settings = QgsSettings()
Expand All @@ -245,16 +251,24 @@ def restoreSettings(self):
self.autoSurround.setChecked(settings.value("pythonConsole/autoSurround", True, type=bool))
self.autoInsertImport.setChecked(settings.value("pythonConsole/autoInsertImport", False, type=bool))

pythonSettingsTreeNode = QgsSettingsTree.node("gui").childNode("code-editor").childNode("python")
codeEditorTreeNode = QgsSettingsTree.node("gui").childNode("code-editor")
pythonSettingsTreeNode = codeEditorTreeNode.childNode("python")

self.formatOnSave.setChecked(settings.value("pythonConsole/formatOnSave", False, type=bool))
self.sortImports.setChecked(pythonSettingsTreeNode.childSetting("sort-imports").value())
self.formatter.setCurrentText(pythonSettingsTreeNode.childSetting("formatter").value())
self.autopep8Level.setValue(pythonSettingsTreeNode.childSetting("autopep8-level").value())
self.blackNormalizeQuotes.setChecked(pythonSettingsTreeNode.childSetting("black-normalize-quotes").value())
self.maxLineLength.setValue(pythonSettingsTreeNode.childSetting("max-line-length").value())
self.contextHelpBrowser.setCurrentIndex(0 if pythonSettingsTreeNode.childSetting('context-help-embedded').value() else 1)
self.contextHelpApi.setCurrentIndex(0 if pythonSettingsTreeNode.childSetting('context-help-pyqgis').value() else 1)

browserName = pythonSettingsTreeNode.childSetting('context-help-browser').valueAsVariant()
try:
browser = Qgis.DocumentationBrowser[browserName]
except KeyError:
browser = Qgis.DocumentationBrowser.DeveloperToolsPanel

self.contextHelpBrowser.setCurrentIndex(self.contextHelpBrowser.findData(browser))
self.contextHelpHover.setChecked(codeEditorTreeNode.childSetting('context-help-hover').value())

if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
self.autoCompFromDoc.setChecked(True)
Expand Down
36 changes: 5 additions & 31 deletions python/console/console_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<x>0</x>
<y>0</y>
<width>739</width>
<height>1242</height>
<height>1240</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -606,40 +606,15 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="contextHelpBrowser">
<item>
<property name="text">
<string>Embedded Webview (developer tools)</string>
</property>
</item>
<item>
<property name="text">
<string>Default system web browser</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="contextHelpBrowser"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="contextHelpHover">
<property name="text">
<string>API</string>
<string>F1 works on hovered words</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="contextHelpApi">
<item>
<property name="text">
<string>PyQGIS</string>
</property>
</item>
<item>
<property name="text">
<string>C++ QGIS</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -677,7 +652,6 @@
<tabstop>autoSurround</tabstop>
<tabstop>autoInsertImport</tabstop>
<tabstop>contextHelpBrowser</tabstop>
<tabstop>contextHelpApi</tabstop>
<tabstop>formatOnSave</tabstop>
<tabstop>sortImports</tabstop>
<tabstop>maxLineLength</tabstop>
Expand Down
30 changes: 30 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10779,6 +10779,36 @@
"""
# --
Qgis.ColorModel.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DocumentationApi.PyQgis.__doc__ = "PyQgis API documentation"
Qgis.DocumentationApi.PyQgisSearch.__doc__ = "Search in PyQgis API documentation"
Qgis.DocumentationApi.CppQgis.__doc__ = "C++ QGIS API documentation"
Qgis.DocumentationApi.Qt.__doc__ = "Qt API documentation"
Qgis.DocumentationApi.__doc__ = """Documentation Api

.. versionadded:: 3.42

* ``PyQgis``: PyQgis API documentation
* ``PyQgisSearch``: Search in PyQgis API documentation
* ``CppQgis``: C++ QGIS API documentation
* ``Qt``: Qt API documentation

"""
# --
Qgis.DocumentationApi.baseClass = Qgis
# monkey patching scoped based enum
Qgis.DocumentationBrowser.DeveloperToolsPanel.__doc__ = "Embedded webview in the DevTools panel"
Qgis.DocumentationBrowser.SystemWebBrowser.__doc__ = "Default system web browser"
Qgis.DocumentationBrowser.__doc__ = """Documentation API browser

.. versionadded:: 3.42

* ``DeveloperToolsPanel``: Embedded webview in the DevTools panel
* ``SystemWebBrowser``: Default system web browser

"""
# --
Qgis.DocumentationBrowser.baseClass = Qgis
from enum import Enum


Expand Down
Loading

0 comments on commit ac3a01f

Please sign in to comment.