Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python console interactive help (Request in QGIS) #9384

Open
qgis-bot opened this issue Nov 13, 2024 · 1 comment
Open

Python console interactive help (Request in QGIS) #9384

qgis-bot opened this issue Nov 13, 2024 · 1 comment
Labels
3.42 QGIS 3.42 new features Plugins Core plugins, enhancement to handle community plugins Project/Configuration project properties, global options and settings
Milestone

Comments

@qgis-bot
Copy link
Collaborator

Request for documentation

From pull request qgis/QGIS#58962
Author: @YoannQDQ
QGIS version: 3.42

Python console interactive help

PR Description:

  • Fix #36338

Description

Add a shortcut in python editors to open the API

When pressing F1, open the API page matching

  • selected text if any OR
  • word at the mouse position (if enabled in settings, see below) OR
  • word at the text cursor position

Behavior is slighltly different for the Python Console (and editors) and for the others generic QgsCodeEditorPython (e.g Expression Editor).

Generic editors

This PR only improves the already existing "Search in PyQGIS Documentation" action in the context menu to add the F1 shortcut and the word under mouse logic. Besides, if the text hovered matches a Qt class name, the Qt API is opened at the correct page. PyQGIS documentation urls cannot be deduced from the class name only as they also include the module name, so pressing F1 will only search the PyQGIS documentation.

Python console (where the PR truly shines)

Add a widget in the devtools panel to display the API documentation (PyQGIS and Qt)

api_panel

The buttons at the top of the widget access the home pages of the APIs.
The button at the top right opens the current URL in the system web browser

When pressing F1 while hovering a symbol on the Python Console or Editors tab, the object is evaluated to get its class and module. The relevant API (PyQGIS or Qt) is then opened at the correct page. It works for class names, class, or even objects

Consider the following snippet:

myLayer = iface.activeLayer() 
if isinstance(myLayer, QgsRasterLayer):
  print("It is a QgsRasterLayer")
a = QLabel()

Let's say the active layer is a vector layer. With the text cursor at the following words, pressing F1 will

  • myLayer: open the PyQGIS api page for QgsVectorLayer.
  • iface: open the PyQGIS api page for QgisInterface.
  • QLabel: open the Qt api page for QLabel
  • QgsRasterLayer (in the print statement or in the type check): open the Qt api page for QgsRasterLayer

If the symbol is not recognized, open the PyQGIS API home page.

Settings

context_help_settings

  • Open In: how should the API html page be displayed?
    • Embedded Webview
    • Default system Web browser
  • F1 on Hover: whether pressing F1 should trigger the context help for the hovered word or for the word at the textCursor

Demo

console-interactive-help-demo

Commits tagged with [need-docs] or [FEATURE]

@github-actions github-actions bot added the 3.42 QGIS 3.42 new features label Nov 13, 2024
@github-actions github-actions bot added this to the QGIS 3.48 milestone Nov 13, 2024
@DelazJ DelazJ added Project/Configuration project properties, global options and settings Plugins Core plugins, enhancement to handle community plugins and removed PyQGIS Cookbook labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.42 QGIS 3.42 new features Plugins Core plugins, enhancement to handle community plugins Project/Configuration project properties, global options and settings
Projects
None yet
Development

No branches or pull requests

3 participants