mirror of
https://github.com/ColinDuquesnoy/QDarkStyleSheet.git
synced 2026-08-29 16:40:31 +08:00
Make process_ui.py and run_ui_css_edition.py run for both palettes
This commit is contained in:
committed by
juanis2112
parent
4587b03f45
commit
a62daeb8b1
+20
-4
@@ -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)
|
||||
|
||||
@@ -289,8 +289,8 @@
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus.png</normaloff>:/qss_icons/rc/window_undock_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -334,8 +334,8 @@
|
||||
<string>Icon</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus.png</normaloff>:/qss_icons/rc/window_undock_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -368,8 +368,8 @@
|
||||
<string>Icon Checked</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus.png</normaloff>:/qss_icons/rc/window_undock_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
@@ -407,8 +407,8 @@
|
||||
<string>Icon Checked</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus.png</normaloff>:/qss_icons/rc/window_undock_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
@@ -1139,7 +1139,7 @@
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../qdarkstyle/style.qrc"/>
|
||||
<include location="../../qdarkstyle/${ID}/style.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -160,8 +160,8 @@
|
||||
<string>Option 1 With Icon</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock.png</normaloff>:/qss_icons/rc/window_undock.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock.png</normaloff>:/qss_icons/${ID}/rc/window_undock.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
@@ -169,8 +169,8 @@
|
||||
<string>Option 2 With Icon</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus@2x.png</normaloff>:/qss_icons/rc/window_undock_focus@2x.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus@2x.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus@2x.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
@@ -979,7 +979,7 @@ p, li { white-space: pre-wrap; }
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../qdarkstyle/style.qrc"/>
|
||||
<include location="../../qdarkstyle/${ID}/style.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -483,8 +483,8 @@
|
||||
<string>Option 1 With Icon</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock.png</normaloff>:/qss_icons/rc/window_undock.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock.png</normaloff>:/qss_icons/${ID}/rc/window_undock.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
@@ -492,8 +492,8 @@
|
||||
<string>Option 2 With Icon</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus@2x.png</normaloff>:/qss_icons/rc/window_undock_focus@2x.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus@2x.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus@2x.png</iconset>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
@@ -710,7 +710,7 @@
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../../qdarkstyle/style.qrc"/>
|
||||
<include location="../../qdarkstyle/${ID}/style.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -488,8 +488,8 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_undock_focus.png</normaloff>:/qss_icons/rc/window_undock_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</normaloff>:/qss_icons/${ID}/rc/window_undock_focus.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Action Icon A</string>
|
||||
@@ -500,8 +500,8 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/window_close_focus.png</normaloff>:/qss_icons/rc/window_close_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/window_close_focus.png</normaloff>:/qss_icons/${ID}/rc/window_close_focus.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Action IconB</string>
|
||||
@@ -512,8 +512,8 @@
|
||||
</action>
|
||||
<action name="actionActionIconC">
|
||||
<property name="icon">
|
||||
<iconset resource="../../qdarkstyle/style.qrc">
|
||||
<normaloff>:/qss_icons/rc/arrow_right_focus.png</normaloff>:/qss_icons/rc/arrow_right_focus.png</iconset>
|
||||
<iconset resource="../../qdarkstyle/${ID}/style.qrc">
|
||||
<normaloff>:/qss_icons/${ID}/rc/arrow_right_focus.png</normaloff>:/qss_icons/${ID}/rc/arrow_right_focus.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Action Icon C</string>
|
||||
@@ -568,7 +568,7 @@
|
||||
<tabstop>lineEdit_2</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../qdarkstyle/style.qrc"/>
|
||||
<include location="../../qdarkstyle/${ID}/style.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
+32
-3
@@ -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, '...')
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user