Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _apply_application_patches(QCoreApplication, QPalette, QColor):
"""
Apply application level fixes on the QPalette.
The import names args must be passed here because the import is done
inside the load_stylesheet() function, as QtPy is only imported in
that moment for setting reasons.
"""
# See issue #139
color = DarkPalette.COLOR_SELECTION_LIGHT
qcolor = QColor(color)
# Todo: check if it is qcoreapplication indeed
app = QCoreApplication.instance()
_logger.info("Found application patches to be applied.")
if app:
palette = app.palette()
palette.setColor(QPalette.Normal, QPalette.Link, qcolor)
app.setPalette(palette)
else:
_logger.warn("No QCoreApplication instance found. "
"Application patches not applied. "
Returns:
str: stylesheet string (css).
"""
os_fix = ""
if platform.system().lower() == 'darwin':
# See issue #12
os_fix = '''
QDockWidget::title
{{
background-color: {color};
text-align: center;
height: 12px;
}}
'''.format(color=DarkPalette.COLOR_BACKGROUND_NORMAL)
# Only open the QSS file if any patch is needed
if os_fix:
_logger.info("Found OS patches to be applied.")
return os_fix
if os.path.isdir(theme_root_path):
shutil.rmtree(theme_root_path)
shutil.copytree(RC_PATH, theme_rc_path)
# Copy QSS folder and contents
theme_qss_path = os.path.join(theme_root_path, qss_loc)
if os.path.isdir(theme_qss_path):
os.removedirs(theme_qss_path)
shutil.copytree(QSS_PATH, theme_qss_path)
# Create custom palette
custom_palette = type(name, (DarkPalette, ), {})
custom_palette.COLOR_BACKGROUND_LIGHT = color_background_light
custom_palette.COLOR_BACKGROUND_NORMAL = color_background_normal
custom_palette.COLOR_BACKGROUND_DARK = color_background_dark
custom_palette.COLOR_FOREGROUND_LIGHT = color_foreground_light
custom_palette.COLOR_FOREGROUND_NORMAL = color_foreground_normal
custom_palette.COLOR_FOREGROUND_DARK = color_foreground_dark
custom_palette.COLOR_SELECTION_LIGHT = color_selection_light
custom_palette.COLOR_SELECTION_NORMAL = color_selection_normal
custom_palette.COLOR_SELECTION_DARK = color_selection_dark
custom_palette.SIZE_BORDER_RADIUS = border_radius
custom_palette.PATH_RESOURCES = "'{}'".format(theme_root_path)
# Process images and save them to the custom platte rc folder
create_images(rc_path=theme_rc_path, palette=custom_palette)
create_palette_image(path=theme_root_path, palette=custom_palette)
def create_qss(qss_filepath=QSS_FILEPATH, main_scss_filepath=MAIN_SCSS_FILEPATH,
variables_scss_filepath=VARIABLES_SCSS_FILEPATH,
palette=DarkPalette):
"""Create variables files and run qtsass compilation."""
_create_scss_variables(variables_scss_filepath, palette)
stylesheet = _create_qss(main_scss_filepath, qss_filepath)
return stylesheet
def create_palette_image(base_svg_path=SVG_PATH, path=IMAGES_PATH,
palette=DarkPalette):
"""
Create palette image svg and png image on specified path.
"""
# Needed to use QPixmap
_ = QApplication([])
base_palette_svg_path = os.path.join(base_svg_path, 'base_palette.svg')
palette_svg_path = os.path.join(path, 'palette.svg')
palette_png_path = os.path.join(path, 'palette.png')
_logger.info("Creating palette image ...")
_logger.info("Base SVG: %s" % base_palette_svg_path)
_logger.info("To SVG: %s" % palette_svg_path)
_logger.info("To PNG: %s" % palette_png_path)
with open(base_palette_svg_path, 'r') as fh:
def create_images(base_svg_path=SVG_PATH, rc_path=RC_PATH,
palette=DarkPalette):
"""Create resources `rc` png image files from base svg files and palette.
Search all SVG files in `base_svg_path` excluding IMAGE_BLACKLIST,
change its colors using `palette` creating temporary SVG files, for each
state generating PNG images for each size `heights`.
Args:
base_svg_path (str, optional): [description]. Defaults to SVG_PATH.
rc_path (str, optional): [description]. Defaults to RC_PATH.
palette (DarkPalette, optional): Palette . Defaults to DarkPalette.
"""
# Needed to use QPixmap
_ = QApplication([])
temp_dir = tempfile.mkdtemp()