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

QEP 333: Add screenshots to PyQGIS reference documentation #333

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nyalldawson
Copy link
Contributor

@nyalldawson nyalldawson commented Feb 28, 2025

Thanks to a concentrated effort over the last couple of years, the PyQGIS reference documentation has improved substantially. It's now a valuable, Python-developer friendly, reference, presented in a modern, sleek format.

That said, there's still much room for further improvements in the documentation!

A previously valuable resource for PyQGIS developers was the (unofficial) "PyQGIS samples" site at https://webgeodatavore.github.io/pyqgis-samples/index.html. This site included some great content, including screenshots and example code for many PyQGIS classes.

Unfortunately, this site is outdated and has not been updated for either QGIS 3.x or Qt 5, and accordingly is no longer a valuable resource. This is a shame, as the example screenshots helped PyQGIS developers find the right GUI classes for their code, and
the example code was a fantastic starting point for working with each class.

This proposal seeks to partially port the content from the webgeodatavore site over to the official PyQGIS Reference Guide, specifically the screenshot component only.

(Rendered version with screenshots at https://github.com/qgis/QGIS-Enhancement-Proposals/blob/132a86ad650144d2430afade453bdb43a1eee981/qep_333_pyqgis_screenshots.md )

@nyalldawson nyalldawson added In Discussion QEPs currently in discussion stage Project A proposal which concerns a project, eg new functionality Grant-2025 labels Feb 28, 2025
@nyalldawson nyalldawson changed the title QEP 334: Add screenshots to PyQGIS reference documentation QEP 333: Add screenshots to PyQGIS reference documentation Feb 28, 2025
Copy link
Member

@3nids 3nids left a comment

Choose a reason for hiding this comment

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

Really nice!

It reminded me of a reverted work I did in the past: qgis/QGIS#8041
Generally I would try to keep in mind a potential usage for the user documentation too at some point.

im.save((dest_path / 'color_box_hue.png').as_posix())

return ("\nQgsColorBox using the QgsColorWidget.ColorComponent.Value component:\n\n.. image:: color_box_value.png\n" +
"\nQgsColorBox using the QgsColorWidget.ColorComponent.Hue component:\n\n.. image:: color_box_hue.png\n")
Copy link
Member

Choose a reason for hiding this comment

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

I think the return value should be code agnostic, a dict with file name and label.
This is more futureproof and flexible for other usage.
The sphinx part should be then generated in the sphinx code

The ``generate_screenshot`` method must have the signature:

``` py
def generate_screenshot(dest_path: Path) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

make this "private" using double underscores?

@Guts
Copy link

Guts commented Feb 28, 2025

cc @ThomasG77 the guy behind Webgeodatavore 😉

@nicogodet
Copy link
Member

It would be very valuable!

Would it be possible to display with a "Show snippet code" or a spoiler the code behind the screenshot ?

@nyalldawson
Copy link
Contributor Author

@nicogodet

Would it be possible to display with a "Show snippet code" or a spoiler the code behind the screenshot ?

I'd prefer not -- I think there'll be a moderate amount of "not best practice" code required here, in order to get things looking nice for a screenshot alone with the minimum maintenance burden. (Eg in the QgsMapLayerComboBox code above I'm just using invalid dummy memory layers, as those are sufficient to appear as a normal layer in the combo).

For a future grant funding round I plan on porting the example code from the Webgeodatavore site, so at that stage we would get best-practice sample code in the documentation (all unit-tested, of course!)

@nyalldawson
Copy link
Contributor Author

@3nids

Generally I would try to keep in mind a potential usage for the user documentation too at some point.

Good point! I think a lot of the work/value here will be in fleshing out the ScreenshotUtils class. Eg for my proof of concept tests it was quite a bit of work getting a capture_combobox_with_dropdown method working nicely. I'm also thinking of methods which make it easy to do things like include a cursor in the screenshot, and even potentially making animated gifs when that's useful to show the widget operation.

This class will be kept generic and independent from the PyQGIS logic, so we could rely on it for some future documentation screenshot generation.

@DelazJ
Copy link
Contributor

DelazJ commented Mar 4, 2025

It reminded me of a reverted work I did in the past: qgis/QGIS#8041

@3nids The tool is still there (qgis --help). I even gave it a shot a few weeks ago, with Selma. Screenshots are generated but unfortunately still wrongly resized.

Generally I would try to keep in mind a potential usage for the user documentation too at some point.

+1.
And I would suggest we also consider a potential usage for the software translation. The current process without devs notes or screenshot is quite suboptimal. I didn't explore the subject and don't know how compatible it currently is with our "pricing" (unclear to me what it actually is), but Transifex allows addition of screenshot. Weblate also does it (in a more efficient way ?). And this will bring back a strength of Qt Linguist.
Keeping that need somehow in the loop might be good.
Thanks @nyalldawson.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Grant-2025 In Discussion QEPs currently in discussion stage Project A proposal which concerns a project, eg new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants