diff --git a/example/example.py b/example/example.py index 899d9b8..c4159d7 100644 --- a/example/example.py +++ b/example/example.py @@ -53,6 +53,8 @@ sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + # Must be in this place, after setting path, to not need to install import qdarkstyle # noqa: E402 +from qdarkstyle.darkpalette import DarkPalette +from qdarkstyle.lightpalette import LightPalette # Set log for debug logging.basicConfig(level=logging.DEBUG) @@ -77,6 +79,11 @@ def main(): help="Reset GUI settings (position, size) then opens.") parser.add_argument('--screenshots', action='store_true', help="Generate screenshots on images folder.") + parser.add_argument('--palette', + default='dark', + choices=['dark', 'light'], + type=str, + help="Palette to display",) # Parsing arguments from command line args = parser.parse_args() @@ -136,7 +143,10 @@ def main(): style = '' if not args.no_dark: - style = qdarkstyle.load_stylesheet() + if args.palette == 'dark': + style = qdarkstyle.load_stylesheet(palette=DarkPalette) + else: + style = qdarkstyle.load_stylesheet(palette=LightPalette) app.setStyleSheet(style) @@ -263,7 +273,7 @@ def main(): # Save screenshots for different displays and quit if args.screenshots: window.showFullScreen() - create_screenshots(app, window, args.no_dark) + create_screenshots(app, window, args) # Do not read settings when taking screenshots - like reset else: _read_settings(window, args.reset, QSettings) @@ -300,13 +310,19 @@ def _read_settings(window, reset, QSettings): window.move(pos) -def create_screenshots(app, window, no_dark): +def create_screenshots(app, window, args): """Save screenshots for different application views and quit.""" from qtpy.QtCore import QCoreApplication from qtpy.QtGui import QGuiApplication from qtpy.QtWidgets import QDockWidget, QTabWidget - theme = 'no_dark' if no_dark else 'dark' + if args.no_dark: + theme = 'no_dark' + elif args.palette == 'dark': + theme = 'dark' + else: + theme = 'light' + print('\nCreating {} screenshots'.format(theme)) docks = window.findChildren(QDockWidget) diff --git a/example/ui/dw_buttons.ui b/example/ui/dw_buttons.ui index 2384038..fee4a4e 100644 --- a/example/ui/dw_buttons.ui +++ b/example/ui/dw_buttons.ui @@ -289,8 +289,8 @@ Icon - - :/qss_icons/rc/window_undock_focus.png:/qss_icons/rc/window_undock_focus.png + + :/qss_icons/${ID}/rc/window_undock_focus.png:/qss_icons/${ID}/rc/window_undock_focus.png @@ -334,8 +334,8 @@ Icon - - :/qss_icons/rc/window_undock_focus.png:/qss_icons/rc/window_undock_focus.png + + :/qss_icons/${ID}/rc/window_undock_focus.png:/qss_icons/${ID}/rc/window_undock_focus.png @@ -368,8 +368,8 @@ Icon Checked - - :/qss_icons/rc/window_undock_focus.png:/qss_icons/rc/window_undock_focus.png + + :/qss_icons/${ID}/rc/window_undock_focus.png:/qss_icons/${ID}/rc/window_undock_focus.png true @@ -407,8 +407,8 @@ Icon Checked - - :/qss_icons/rc/window_undock_focus.png:/qss_icons/rc/window_undock_focus.png + + :/qss_icons/${ID}/rc/window_undock_focus.png:/qss_icons/${ID}/rc/window_undock_focus.png true @@ -1139,7 +1139,7 @@ - + diff --git a/example/ui/dw_inputs_fields.ui b/example/ui/dw_inputs_fields.ui index 93e0b01..9168c30 100644 --- a/example/ui/dw_inputs_fields.ui +++ b/example/ui/dw_inputs_fields.ui @@ -160,8 +160,8 @@ Option 1 With Icon - - :/qss_icons/rc/window_undock.png:/qss_icons/rc/window_undock.png + + :/qss_icons/${ID}/rc/window_undock.png:/qss_icons/${ID}/rc/window_undock.png @@ -169,8 +169,8 @@ Option 2 With Icon - - :/qss_icons/rc/window_undock_focus@2x.png:/qss_icons/rc/window_undock_focus@2x.png + + :/qss_icons/${ID}/rc/window_undock_focus@2x.png:/qss_icons/${ID}/rc/window_undock_focus@2x.png @@ -979,7 +979,7 @@ p, li { white-space: pre-wrap; } - + diff --git a/example/ui/dw_inputs_no_fields.ui b/example/ui/dw_inputs_no_fields.ui index a374877..3371e23 100644 --- a/example/ui/dw_inputs_no_fields.ui +++ b/example/ui/dw_inputs_no_fields.ui @@ -483,8 +483,8 @@ Option 1 With Icon - - :/qss_icons/rc/window_undock.png:/qss_icons/rc/window_undock.png + + :/qss_icons/${ID}/rc/window_undock.png:/qss_icons/${ID}/rc/window_undock.png @@ -492,8 +492,8 @@ Option 2 With Icon - - :/qss_icons/rc/window_undock_focus@2x.png:/qss_icons/rc/window_undock_focus@2x.png + + :/qss_icons/${ID}/rc/window_undock_focus@2x.png:/qss_icons/${ID}/rc/window_undock_focus@2x.png @@ -710,7 +710,7 @@ - + diff --git a/example/ui/mw_menus.ui b/example/ui/mw_menus.ui index a021932..2a0b4a0 100644 --- a/example/ui/mw_menus.ui +++ b/example/ui/mw_menus.ui @@ -488,8 +488,8 @@ false - - :/qss_icons/rc/window_undock_focus.png:/qss_icons/rc/window_undock_focus.png + + :/qss_icons/${ID}/rc/window_undock_focus.png:/qss_icons/${ID}/rc/window_undock_focus.png Action Icon A @@ -500,8 +500,8 @@ true - - :/qss_icons/rc/window_close_focus.png:/qss_icons/rc/window_close_focus.png + + :/qss_icons/${ID}/rc/window_close_focus.png:/qss_icons/${ID}/rc/window_close_focus.png Action IconB @@ -512,8 +512,8 @@ - - :/qss_icons/rc/arrow_right_focus.png:/qss_icons/rc/arrow_right_focus.png + + :/qss_icons/${ID}/rc/arrow_right_focus.png:/qss_icons/${ID}/rc/arrow_right_focus.png Action Icon C @@ -568,7 +568,7 @@ lineEdit_2 - + diff --git a/scripts/process_ui.py b/scripts/process_ui.py index ff64092..1e4d1ee 100755 --- a/scripts/process_ui.py +++ b/scripts/process_ui.py @@ -26,11 +26,17 @@ from subprocess import call import argparse import glob import os +import shutil +import string import sys +import tempfile # Constants HERE = os.path.abspath(os.path.dirname(__file__)) REPO_ROOT = os.path.dirname(HERE) +DEFAULT_EXAMPLE_DIR = os.path.join(REPO_ROOT, 'example') +DEFAULT_UI_DIR = os.path.join(DEFAULT_EXAMPLE_DIR, 'ui') +EXAMPLE_TMP_DIR = os.path.join(tempfile.gettempdir(), 'qdarkstyle_example') def main(arguments): @@ -38,7 +44,7 @@ def main(arguments): parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('--ui_dir', - default=os.path.join(REPO_ROOT, 'example', 'ui'), + default=DEFAULT_UI_DIR, type=str, help="UI files directory, relative to current directory.",) parser.add_argument('--create', @@ -46,15 +52,38 @@ def main(arguments): choices=['pyqt', 'pyqt5', 'pyside', 'pyside2', 'qtpy', 'pyqtgraph', 'all'], type=str, help="Choose which one would be generated.") + parser.add_argument('--palette', + default='dark', + choices=['dark', 'light'], + type=str, + help="Palette to display",) args = parser.parse_args(arguments) - print('Changing directory to: ', args.ui_dir) - os.chdir(args.ui_dir) + if args.ui_dir == DEFAULT_UI_DIR: + shutil.rmtree(EXAMPLE_TMP_DIR, ignore_errors=True) + shutil.copytree(DEFAULT_EXAMPLE_DIR, EXAMPLE_TMP_DIR) + ui_dir = os.path.join(EXAMPLE_TMP_DIR, 'ui') + else: + ui_dir = args.ui_dir + + print('Changing directory to: ', ui_dir) + os.chdir(ui_dir) print('Converting .ui to .py ...') for ui_file in glob.glob('*.ui'): + + # Replace palette identifier placeholders + if args.ui_dir == DEFAULT_UI_DIR: + with open(ui_file, 'r+') as f: + contents = f.read() + template = string.Template(contents) + contents = template.substitute(ID=args.palette) + f.seek(0) + f.write(contents) + f.truncate() + # get name without extension filename = os.path.splitext(ui_file)[0] print(filename, '...') diff --git a/scripts/run_ui_css_edition.py b/scripts/run_ui_css_edition.py index 0290fd1..e2ecce3 100755 --- a/scripts/run_ui_css_edition.py +++ b/scripts/run_ui_css_edition.py @@ -6,17 +6,34 @@ Process qrc, ui, image, and screenshot files, then run example in while loop. # Standard library imports from __future__ import absolute_import, print_function + +import argparse from subprocess import call import os import sys +import tempfile # Constants SCRIPTS_PATH = os.path.abspath(os.path.dirname(__file__)) -REPO_PATH = os.path.dirname(SCRIPTS_PATH) + +# This needs to be the same one defined in process_ui.py +EXAMPLE_TMP_DIR = os.path.join(tempfile.gettempdir(), 'qdarkstyle_example') def main(): """Process qrc and ui files, then run example in while loop.""" + parser = argparse.ArgumentParser(description=__doc__, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('--palette', + default='dark', + choices=['dark', 'light'], + type=str, + help="Palette to display",) + + # Parsing arguments from command line + args = parser.parse_args() + palette = args.palette + dark = None no_dark = None themes = {'Dark': dark, 'No Dark': no_dark} @@ -33,21 +50,17 @@ def main(): print(sys.argv) - # Process images - process_images = os.path.join(SCRIPTS_PATH, 'process_images.py') - call(['python', process_images]) - # Process qrc files process_qrc = os.path.join(SCRIPTS_PATH, 'process_qrc.py') call(['python', process_qrc]) # Process ui files process_ui = os.path.join(SCRIPTS_PATH, 'process_ui.py') - call(['python', process_ui]) + call(['python', process_ui, '--palette', palette]) - # Create screenshots - example = os.path.join(REPO_PATH, 'example', 'example.py') - call(['python', example, '--screenshots']) + # Show window + example = os.path.join(EXAMPLE_TMP_DIR, 'example.py') + call(['python', example, '--screenshots', '--palette', palette]) call(['python', example, '--no_dark', '--screenshots']) # Open dark example