aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2021-04-16 21:39:19 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-18 19:48:55 +0000
commit13502071406fff7593a7c95e5d5e2ddca8059252 (patch)
tree5f08c965a281177497da9f36e6ec7deabe60f53b
parent2e8ab79a7ddd5809ec8f47006a5fd44e3d672bd6 (diff)
tools: display screenshot in example gallery
Adding the option to display a screenshot on the example gallery. First, the script will look for an image with the same name as the example, otherwise it will just get the first in alphabetical order. Fixes: PYSIDE-1490 Change-Id: Ia0328c84206a3d66854197abe5ecad8d1d28abc5 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit d5dcdf2de980ef252aabaa56d5a9465453a1c9b2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tools/example_gallery/main.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/tools/example_gallery/main.py b/tools/example_gallery/main.py
index 2970180fe..332f2a2f5 100644
--- a/tools/example_gallery/main.py
+++ b/tools/example_gallery/main.py
@@ -96,22 +96,32 @@ def get_module_gallery(examples):
gallery = (
".. panels::\n"
f"{ind(1)}:container: container-lg pb-3\n"
- f"{ind(1)}:column: col-lg-3 col-md-4 col-sm-6 col-xs-12 p-2\n\n"
+ f"{ind(1)}:column: col-lg-4 col-md-4 col-sm-6 col-xs-12 p-2\n\n"
)
+
# Iteration per rows
for i in range(math.ceil(len(examples))):
e = examples[i]
url = e["rst"].replace(".rst", ".html")
name = e["example"]
underline = f'{e["module"]}'
+
+
if e["extra"]:
underline += f'/{e["extra"]}'
if i > 0:
gallery += f"{ind(1)}---\n"
+ elif e["img_doc"]:
+ gallery += f"{ind(1)}---\n"
+
+ if e["img_doc"]:
+ gallery += f"{ind(1)}:img-top: {e['img_doc'].name}\n\n"
+ else:
+ gallery += "\n"
+
gallery += f"{ind(1)}`{name} <{url}>`_\n"
- # TODO: Use the body to add the screenshot
gallery += f"{ind(1)}+++\n"
gallery += f"{ind(1)}{underline}\n"
@@ -202,11 +212,26 @@ if __name__ == "__main__":
rst_file = f"example_{module_name}_{extra_names}_{example_name}.rst"
+ def check_img_ext(i):
+ EXT = (".png", ".jpg", ".jpeg")
+ if i.suffix in EXT:
+ return True
+ return False
+
# Check for a 'doc' directory inside the example
has_doc = False
+ img_doc = None
original_doc_dir = Path(f_path.parent / "doc")
if original_doc_dir.is_dir():
has_doc = True
+ images = [i for i in original_doc_dir.glob("*") if i.is_file() and check_img_ext(i)]
+ if len(images) > 0:
+ # We look for an image with the same example_name first, if not, we select the first
+ image_path = [i for i in images if example_name in str(i)]
+ if not image_path:
+ image_path = images[0]
+ else:
+ img_doc = image_path[0]
if module_name not in examples:
examples[module_name] = []
@@ -219,6 +244,7 @@ if __name__ == "__main__":
"rst": rst_file,
"abs_path": str(f_path),
"has_doc": has_doc,
+ "img_doc": img_doc,
}
)