Skip to content

Commit 68be076

Browse files
committed
Refactor script to capture widget gallery img
1 parent 7d85090 commit 68be076

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ jobs:
4747
- name: Capture WidgetGallery img
4848
run: >-
4949
poetry run python ./tools/capture.py
50-
-i ${{runner.os}}-py${{matrix.py}}-${{matrix.qt}}
51-
-d dist
50+
--name ${{runner.os}}-py${{matrix.py}}-${{matrix.qt}}
5251
5352
- uses: actions/upload-artifact@v3
5453
with:
55-
path: ./dist/*.png
54+
path: ./*.png
5655

5756
pytest-without-qt:
5857
strategy:

tools/capture.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import platform
77
import sys
8-
from pathlib import Path
98

109
import qdarktheme
1110
from qdarktheme.qtpy.QtCore import Qt, QTimer, Slot
@@ -16,27 +15,14 @@
1615

1716
def _parse_args() -> argparse.Namespace:
1817
parser = argparse.ArgumentParser(description="This program capture images of WidgetGallery.")
19-
parser.add_argument(
20-
"-d",
21-
"--dir",
22-
help="Output dir path",
23-
)
24-
parser.add_argument(
25-
"-i",
26-
"--identifier",
27-
help="Image identifier",
28-
)
18+
parser.add_argument("--name", help="Image name")
2919
return parser.parse_args()
3020

3121

3222
class _Application(QApplication):
33-
def __init__(self, img_dir_path: str | None, img_identifier: str | None) -> None:
23+
def __init__(self, img_name: str) -> None:
3424
super().__init__(sys.argv)
35-
self._img_dir_path = Path("dist" if img_dir_path is None else img_dir_path)
36-
self._img_dir_path.mkdir(exist_ok=True)
37-
if img_identifier is not None:
38-
img_identifier = img_identifier.replace("~=", "-")
39-
self._img_identifier = img_identifier
25+
self._img_name = img_name.replace("~=", "-")
4026

4127
if hasattr(Qt.ApplicationAttribute, "AA_UseHighDpiPixmaps"):
4228
self.setAttribute(Qt.ApplicationAttribute.AA_UseHighDpiPixmaps) # type: ignore
@@ -48,21 +34,14 @@ def __init__(self, img_dir_path: str | None, img_identifier: str | None) -> None
4834
def _capture_window_img(self) -> None:
4935
for theme in qdarktheme.get_themes():
5036
self.setStyleSheet(qdarktheme.load_stylesheet(theme))
51-
save_file_name = (
52-
f"{self._img_identifier}-{theme}.png" if self._img_identifier else f"{theme}.png"
53-
)
54-
5537
self._gallery.setGeometry(QGuiApplication.primaryScreen().geometry())
56-
img_path = self._img_dir_path / save_file_name
57-
self._gallery.grab().save(img_path.as_posix())
38+
self._gallery.grab().save(f"{self._img_name}-{theme}.png")
5839
self.exit()
5940

6041

6142
if __name__ == "__main__":
6243
if platform.system() == "Linux":
6344
os.environ["QT_QPA_PLATFORM"] = "offscreen"
64-
args = _parse_args()
65-
66-
app = _Application(args.dir, args.identifier)
45+
app = _Application(_parse_args().name)
6746
QTimer.singleShot(10, app._capture_window_img)
6847
app.exec()

0 commit comments

Comments
 (0)