qss
This commit is contained in:
@@ -1,22 +1,33 @@
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
import atexit
|
||||
|
||||
|
||||
base_path = Path(__file__).resolve().parent.parent.parent
|
||||
db_file = base_path / "assets/database/toolbox.db"
|
||||
lock = Lock()
|
||||
config = None
|
||||
code_dict = [4, 11, 4, 31, 22, 12, 19, 23, 7, 16, 7, 23, 1, 8, 7, 18, 27, 32, 28, 25, 7, 32, 9, 15, 2, 32, 0, 12, 26, 15, 14, 17]
|
||||
username, password = "", ""
|
||||
avatar = f"{base_path}/assets/media/avatar.jpg"
|
||||
proverb = "佛曰:Time will say~"
|
||||
bg = f"{base_path}/assets/media/bg.jpg"
|
||||
win_width, win_height = 1100, 500
|
||||
conn, cursor = None, None
|
||||
listW_items = {"实用工具": "w10_practical", "效率提升": "w20_efficiency", "财务分析": "w30_financial"}
|
||||
icon = f"{base_path}/assets/media/icon.ico"
|
||||
caller_frame = None
|
||||
|
||||
base_path = Path(__file__).resolve().parent.parent.parent
|
||||
db_file = base_path / "assets/database/toolbox.db"
|
||||
bg = f"{base_path}/assets/media/bg.jpg"
|
||||
avatar = f"{base_path}/assets/media/avatar.jpg"
|
||||
icon = f"{base_path}/assets/media/icon.ico"
|
||||
logo = f"{base_path}/assets/media/logo.png"
|
||||
on_icon = f"{base_path}/assets/media/switch_on.png"
|
||||
off_icon = f"{base_path}/assets/media/switch_off.png"
|
||||
|
||||
qss_home_overlay = f"{base_path}/assets/conf/qss/home_overlay.qss"
|
||||
qss_list_widget = f"{base_path}/assets/conf/qss/list_widget.qss"
|
||||
qss_toolbar = f"{base_path}/assets/conf/qss/toolbar.qss"
|
||||
qss_statusbar = f"{base_path}/assets/conf/qss/statusbar.qss"
|
||||
qss_w08_log = f"{base_path}/assets/conf/qss/w08_log.qss"
|
||||
|
||||
|
||||
def delete_files_in_directory(directory):
|
||||
path = Path(directory)
|
||||
if path.exists() and path.is_dir():
|
||||
|
||||
@@ -108,7 +108,7 @@ def db_write_logs(content, module="", level="info"):
|
||||
|
||||
@singledispatch
|
||||
@db_lock
|
||||
def db_query_logs(dummy: bool = True):
|
||||
def db_query_logs(dummy: object = None):
|
||||
clibs.cursor.execute(f"SELECT * FROM logs")
|
||||
records = clibs.cursor.fetchall()
|
||||
len_records = len(records)
|
||||
|
||||
41
toolbox/codes/common/qss_reloader.py
Normal file
41
toolbox/codes/common/qss_reloader.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QObject, QFileSystemWatcher
|
||||
|
||||
|
||||
class QssReloader(QObject):
|
||||
instance = None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls.instance is None:
|
||||
cls.instance = super().__new__(cls)
|
||||
return cls.instance
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.path2objs = {}
|
||||
self.watcher = QFileSystemWatcher(self)
|
||||
self.watcher.fileChanged.connect(self.on_file_changed)
|
||||
|
||||
def register(self, qss_path: str, ui_obj):
|
||||
path = str(Path(qss_path).resolve())
|
||||
obj_list = self.path2objs.setdefault(path, [])
|
||||
if ui_obj not in obj_list:
|
||||
obj_list.append(ui_obj)
|
||||
if path not in self.watcher.files():
|
||||
self.watcher.addPath(path)
|
||||
self.apply_one(path, ui_obj)
|
||||
|
||||
def on_file_changed(self, path: str):
|
||||
for obj in self.path2objs.get(path, []):
|
||||
self.apply_one(path, obj)
|
||||
if path not in self.watcher.files():
|
||||
self.watcher.addPath(path)
|
||||
|
||||
@staticmethod
|
||||
def apply_one(path: str, obj):
|
||||
qss = Path(path).read_text(encoding="utf-8")
|
||||
obj.setStyleSheet(qss)
|
||||
|
||||
|
||||
qss_reloader = QssReloader()
|
||||
Reference in New Issue
Block a user