Debian Codegraph @

libs/CCAppCommon/QDarkStyleSheet/qdarkstyle/utils/__main__.py

raw
1 # -*- coding: utf-8 -*-
2 """Script to process QRC files (convert .qrc to _rc.py and .rcc).
3
4 The script will attempt to compile the qrc file using the following tools:
5
6 - `pyside6-rcc` for PySide6 and QtPy (Python) (Official)
7 - There is no specific rcc compiler for PyQt6, use `pyside6-rcc` (Python)
8 - `pyrcc5` for PyQt5 (Python)
9 - `pyside2-rcc` for PySide2 (Python)
10 - `rcc` for Qt5/Qt6 (C++)
11
12 Delete the compiled files that you don't want to use manually after
13 running this script.
14
15 Links to understand those tools:
16
17 - `pyside6-rcc`: https://doc.qt.io/qtforpython/tutorials/basictutorial/qrcfiles.html (Official)
18 - `pyrcc5`: http://pyqt.sourceforge.net/Docs/PyQt5/resources.html#pyrcc5
19 - `pyside2-rcc: https://doc.qt.io/qtforpython/overviews/resources.html (Documentation Incomplete)
20 - `rcc` on Qt6: https://doc.qt.io/qt-6/resources.html
21 - `rcc` on Qt5: http://doc.qt.io/qt-5/rcc.html
22
23 """
24
25 # Standard library imports
26 import argparse
27 import logging
28 import sys
29
30 # Third party imports
31 from watchdog.events import FileSystemEventHandler
32 from watchdog.observers import Observer
33
34 # Local imports
35 from qdarkstyle import PACKAGE_PATH
36 from qdarkstyle.dark.palette import DarkPalette
37 from qdarkstyle.light.palette import LightPalette
38 from qdarkstyle.utils import process_palette
39
40 _logger = logging.getLogger(__name__)
41
42
43 class QSSFileHandler(FileSystemEventHandler):
44 """QSS File observer."""
45
46 def __init__(self, parser_args):
47 """QSS File observer."""
48 super(QSSFileHandler, self).__init__()
49 self.args = parser_args
50
51 def on_modified(self, event):
52 """Handle file system events."""
53 if event.src_path.endswith('.qss'):
54 # TODO: needs implementation for new palettes
55 process_palette(compile_for=self.args.create)
56 print('\n')
57
58
59 def main():
60 """Process QRC files."""
61 parser = argparse.ArgumentParser(description=__doc__,
62 formatter_class=argparse.RawDescriptionHelpFormatter)
63 parser.add_argument('--qrc_dir',
64 default=None,
65 type=str,
66 help="QRC file directory, relative to current directory.",)
67 parser.add_argument('--create',
68 default='qtpy',
69 choices=['pyqt5', 'pyqt6', 'pyside2', 'pyside6', 'qtpy', 'pyqtgraph', 'qt', 'qt5', 'all'],
70 type=str,
71 help="Choose which one would be generated.")
72 parser.add_argument('--watch', '-w',
73 action='store_true',
74 help="Watch for file changes.")
75
76 args = parser.parse_args()
77
78 if args.watch:
79 path = PACKAGE_PATH
80 observer = Observer()
81 handler = QSSFileHandler(parser_args=args)
82 observer.schedule(handler, path, recursive=True)
83 try:
84 print('\nWatching QSS file for changes...\nPress Ctrl+C to exit\n')
85 observer.start()
86 except KeyboardInterrupt:
87 observer.stop()
88 observer.join()
89 else:
90 for palette in [DarkPalette, LightPalette]:
91 process_palette(palette=palette, compile_for=args.create)
92
93
94 if __name__ == "__main__":
95 logging.basicConfig(level=logging.DEBUG)
96 sys.exit(main())