| 1 |
# -*- coding: utf-8 -*- |
| 2 |
""" |
| 3 |
Utilities for processing SASS and images from default and custom palette. |
| 4 |
""" |
| 5 |
|
| 6 |
# Standard library imports |
| 7 |
import logging |
| 8 |
import sys |
| 9 |
|
| 10 |
# Local imports |
| 11 |
from qdarkstyle import PACKAGE_PATH, QRC_FILE_SUFFIX |
| 12 |
from qdarkstyle.utils.images import (compile_qrc_file, create_images, |
| 13 |
create_palette_image, generate_qrc_file) |
| 14 |
from qdarkstyle.utils.scss import create_qss |
| 15 |
|
| 16 |
_logger = logging.getLogger(__name__) |
| 17 |
|
| 18 |
|
| 19 |
def process_palette(palette, compile_for='qtpy'): |
| 20 |
"""Process palette class to create a new palette file/folders. |
| 21 |
|
| 22 |
It generates all files below, in this order: |
| 23 |
- Palette files (svg/.png) under docs/images/[palette_id] |
| 24 |
- Image files (.png) under [palette_id]/rc folder. |
| 25 |
- QRC file in [palette_id]/[palette_id]style.qrc (C++). |
| 26 |
- SCSS variables in [palette_id]/_variables.scss file. |
| 27 |
- QSS file in [palette_id]/[palette_id]style.qss. |
| 28 |
- Compiled QRC file in [palette_id]/[palette_id]style_rc.py |
| 29 |
|
| 30 |
TODO: |
| 31 |
- Must generalize to create custom palettes and folder paths. |
| 32 |
- Must create/copy all files under [palette_id], such as main.scss, |
| 33 |
__init__.py, palette.py. |
| 34 |
- Add option or avoid adding the palette under docs for custom palettes. |
| 35 |
|
| 36 |
Args: |
| 37 |
palette (Palette): Palette. |
| 38 |
compile_for (list, optional): Prefix used in resources. |
| 39 |
Defaults to 'qtpy'. Possible values are 'qtpy', 'pyqtgraph', |
| 40 |
'pyqt', 'pyqt5', 'pyqt6', |
| 41 |
'pyside', 'pyside2', 'pyside6', |
| 42 |
'qt', 'qt5', qt6, 'all'. |
| 43 |
""" |
| 44 |
|
| 45 |
if palette is None: |
| 46 |
_logger.error("Please pass a palette class in order to create its " |
| 47 |
"associated images") |
| 48 |
sys.exit(1) |
| 49 |
|
| 50 |
if palette.ID is None: |
| 51 |
_logger.error("A QDarkStyle palette requires an ID!") |
| 52 |
sys.exit(1) |
| 53 |
|
| 54 |
id_ = palette.ID |
| 55 |
print(f"-- PROCESSING THEME: {id_}") |
| 56 |
|
| 57 |
# TODO: delete/remove all files and folders to ensure that old files |
| 58 |
# are not used |
| 59 |
|
| 60 |
print(f"-- GENERATING PALETTE IMAGE FOR: {id_}") |
| 61 |
create_palette_image(palette=palette) |
| 62 |
|
| 63 |
print(f"-- GENERATING IMAGE FILES (.svg > .png) FOR: {id_}") |
| 64 |
create_images(palette=palette) |
| 65 |
|
| 66 |
print(f"-- GENERATING QRC FILE FOR: {id_}") |
| 67 |
generate_qrc_file(palette=palette) |
| 68 |
|
| 69 |
print(f"-- GENERATING QSS FILE (.scss > .qss) FOR: {id_}") |
| 70 |
create_qss(palette=palette) |
| 71 |
|
| 72 |
print(f"-- CONVERTING RESOURCE FILE (. qrc > _rc.py/.rcc) FOR: {id_}") |
| 73 |
compile_qrc_file(compile_for=compile_for, palette=palette) |