diff options
author | Cristián Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2023-03-06 13:35:10 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-03-09 16:42:07 +0000 |
commit | 3e31ad891bbe348d6663a681a6e46068eecc227b (patch) | |
tree | ee741d2c3f63c70090d1caf0fd27e7aa715abedb | |
parent | 0ff77d558f0c5126230c3cd9fcf07f994ea6debf (diff) |
doc: add zip file with examples to download
This adds a new functionality to the example gallery tool
to create a ZIP file containing all the example files, and including
a button to download it on each example page.
Change-Id: I703c1d73bf690f2eaafca1012ccce3947e13a245
Task-number: PYSIDE-2246
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 3e0343a214075efe2660ec36359ea09e8435b562)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/doc/_static/css/qt_style.css | 28 | ||||
-rw-r--r-- | tools/example_gallery/main.py | 34 |
2 files changed, 59 insertions, 3 deletions
diff --git a/sources/pyside6/doc/_static/css/qt_style.css b/sources/pyside6/doc/_static/css/qt_style.css index 4ca598916..7a86c0b15 100644 --- a/sources/pyside6/doc/_static/css/qt_style.css +++ b/sources/pyside6/doc/_static/css/qt_style.css @@ -78,3 +78,31 @@ table.docutils td ul > li { position:relative; overflow:visible } + +/* We cannot put a :download:`....` command inside + * a sphinx-panels button, so we add some properties from the button + * to the download class to mimic it */ +code.download { + text-align: center; + color: var(--color-brand-primary); + display: block; + border-color: transparent; + background-color: transparent; + border: 1px solid var(--color-brand-primary) !important; + border-radius: 0.25rem; + font-size: 1rem; + font-weight: 400; + vertical-align: middle; + padding: .375rem .75rem; + user-select: none; + line-height: 1.5; + transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out; +} + +code.download:hover { + color: white; + background-color: var(--color-brand-primary); + border-color: var(--color-brand-primary); + text-decoration: none; + padding: .375rem .75rem; +} diff --git a/tools/example_gallery/main.py b/tools/example_gallery/main.py index 5e9029f27..e976539e8 100644 --- a/tools/example_gallery/main.py +++ b/tools/example_gallery/main.py @@ -15,6 +15,7 @@ since there is no special requirements. import json import math import shutil +import zipfile import sys from argparse import ArgumentParser, RawTextHelpFormatter from pathlib import Path @@ -116,9 +117,37 @@ def remove_licenses(s): return "\n".join(new_s) +def make_zip_archive(zip_name, src, skip_dirs=None): + src_path = Path(src).expanduser().resolve(strict=True) + if skip_dirs is None: + skip_dirs = [] + if not isinstance(skip_dirs, list): + print("Error: A list needs to be passed for 'skip_dirs'") + return + with zipfile.ZipFile(src_path.parents[0] / Path(zip_name), 'w', zipfile.ZIP_DEFLATED) as zf: + for file in src_path.rglob('*'): + skip = False + _parts = file.relative_to(src_path).parts + for sd in skip_dirs: + if sd in _parts: + skip = True + break + if not skip: + zf.write(file, file.relative_to(src_path.parent)) + + def get_code_tabs(files, project_dir): content = "\n" + # Prepare ZIP file, and copy to final destination + zip_name = f"{project_dir.name}.zip" + make_zip_archive(zip_name, project_dir, skip_dirs=["doc"]) + zip_src = f"{project_dir}.zip" + zip_dst = EXAMPLES_DOC / zip_name + shutil.move(zip_src, zip_dst) + + content += f":download:`Download this example <{zip_name}>`\n\n" + for i, project_file in enumerate(files): pfile = Path(project_file) if pfile.suffix in (".jpg", ".pdf", ".png", ".pyc", ".svg", ".svgz"): @@ -305,9 +334,8 @@ if __name__ == "__main__": A collection of examples are provided with |project| to help new users to understand different use cases of the module. - You can find all these examples inside the ``pyside-setup`` on the ``examples`` - directory, or you can access them after installing |pymodname| from ``pip`` - inside the ``site-packages/PySide6/examples`` directory. + You can find all these examples inside the ``pyside-setup`` repository + on the ``examples`` directory. """ ) |