Commit 49a1d94d authored by dmMaze's avatar dmMaze
Browse files

reverse icon color on darkmode

parent 4253378a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -828,5 +828,5 @@ class MainWindow(FramelessWindow):
    def on_darkmode_triggered(self):
        self.config.darkmode = self.titleBar.darkModeAction.isChecked()
        theme = 'eva-dark' if self.config.darkmode else 'eva-light'
        css = parse_stylesheet(theme=theme)
        css = parse_stylesheet(theme=theme, reverse_icon=True)
        self.setStyleSheet(css)
 No newline at end of file
+42 −3
Original line number Diff line number Diff line
import cv2, re, json
import cv2, re, json, os
from pathlib import Path
import numpy as np
import os.path as osp
from typing import Tuple, Union, List, Dict
@@ -389,7 +390,10 @@ def doc_replace_no_shift(doc: QTextDocument, span_list: List, target: str):
        cursor.insertText(target)
    cursor.endEditBlock()

def parse_stylesheet(theme: str = '') -> str:
def parse_stylesheet(theme: str = '', reverse_icon: bool = False) -> str:
    if reverse_icon:
        dark2light = True if theme == 'eva-light' else False
        reverse_icon_color(dark2light)
    with open(STYLESHEET_PATH, "r", encoding='utf-8') as f:
        stylesheet = f.read()
    with open(THEME_PATH, 'r', encoding='utf8') as f:
@@ -401,3 +405,38 @@ def parse_stylesheet(theme: str = '') -> str:
    for key, val in tgt_theme.items():
        stylesheet = stylesheet.replace(key, val)
    return stylesheet


ICON_DIR = 'data/icons'

LIGHTFILL_ACTIVE = "fill=\"#697187\""
LIGHTFILL = "fill=\"#b3b6bf\""
DARKFILL_ACTIVE = "fill=\"#96a4cd\""
DARKFILL = "fill=\"#697186\""

ICONREVERSE_DICT_LIGHT2DARK = {LIGHTFILL_ACTIVE: DARKFILL_ACTIVE, LIGHTFILL: DARKFILL}
ICONREVERSE_DICT_DARK2LIGHT = {DARKFILL_ACTIVE: LIGHTFILL_ACTIVE, DARKFILL: LIGHTFILL}
ICON_LIST = []

def reverse_icon_color(dark2light: bool = False):
    global ICON_LIST
    if not ICON_LIST:
        for filename in os.listdir(ICON_DIR):
            file_suffix = Path(filename).suffix
            if file_suffix.lower() != '.svg':
                continue
            else:
                ICON_LIST.append(osp.join(ICON_DIR, filename))

    if dark2light:
        pattern = re.compile(re.escape(DARKFILL) + '|' + re.escape(DARKFILL_ACTIVE))
        rep_dict = ICONREVERSE_DICT_DARK2LIGHT
    else:
        pattern = re.compile(re.escape(LIGHTFILL) + '|' + re.escape(LIGHTFILL_ACTIVE))
        rep_dict = ICONREVERSE_DICT_LIGHT2DARK
    for svgpath in ICON_LIST:
        with open(svgpath, "r", encoding="utf-8") as f:
            svg_content = f.read()
            svg_content = pattern.sub(lambda m:rep_dict[m.group()], svg_content)
        with open(svgpath, "w", encoding="utf-8") as f:
            f.write(svg_content)
 No newline at end of file