修复一些问题

This commit is contained in:
2025-09-29 11:26:29 +08:00
parent 943130b875
commit ed947743fc
8 changed files with 130 additions and 69 deletions

View File

@@ -16,7 +16,7 @@ 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
def delete_files_in_directory(directory):
path = Path(directory)
if path.exists() and path.is_dir():

View File

@@ -1,7 +1,7 @@
import sqlite3
import time
from inspect import currentframe
from functools import singledispatch
from functools import singledispatch, wraps
from codes.common import clibs
@@ -45,7 +45,9 @@ def db_init():
conn.close()
def db_lock(func):
@wraps(func)
def wrapper(*args, **kwargs):
clibs.caller_frame = currentframe().f_back
try:
clibs.lock.acquire(True)
ret = func(*args, **kwargs)
@@ -93,11 +95,11 @@ def db_close():
@db_lock
def db_write_logs(content, module="", level="info"):
if module == "":
frame = currentframe().f_back
module_name = frame.f_globals["__name__"]
line_no = frame.f_lineno
module = f"{module_name}.{line_no}"
if module == "" and clibs.caller_frame is not None:
module_name = clibs.caller_frame.f_globals["__name__"].split(".")[-1] #
func_name = clibs.caller_frame.f_code.co_name
line_no = clibs.caller_frame.f_lineno
module = f"{module_name}-{func_name}:{line_no}"
if level.lower() not in ["info", "warning", "error", "exception"]:
level = "unknown"

View File

@@ -1,19 +1,28 @@
from functools import wraps
from codes.common import db_operation
from inspect import getfile
from pathlib import Path
from inspect import currentframe
import traceback
def handle_exception(stop: bool = False):
def exceptions(func):
module = Path(getfile(func)).stem
func_name = func.__name__
@wraps(func)
def wrapper(*args, **kwargs):
real_frame = currentframe().f_back
try:
return func(*args, **kwargs)
except Exception as e:
db_operation.db_write_logs(str(e), "@".join([func_name, module]), "exception")
for frame, lineno in traceback.walk_tb(e.__traceback__):
if frame.f_code.co_name == func.__name__:
real_frame = frame
break
tb = traceback.format_exc() # 完整堆栈
module_name = real_frame.f_globals["__name__"].split(".")[-1]
func_name = real_frame.f_code.co_name
line_no = real_frame.f_lineno
module = f"{module_name}-{func_name}:{line_no}"
db_operation.db_write_logs(tb, module, "exception")
if stop:
raise e
return wrapper

View File

@@ -1,28 +0,0 @@
import subprocess
import sys
from codes.common import clibs
from pathlib import Path
UIC_CMD = "pyside6-uic"
def single_uic(ui_path: str, py_path: str):
for file in Path(ui_path).rglob("*.ui"):
file_name = file.stem
ui_file = file
py_file = Path(py_path) / f"{file_name}.py"
cmd = [UIC_CMD, "-o", py_file, ui_file]
print(f"Processing {ui_file} -> {py_file}")
try:
subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
print(f"转换失败: {ui_file}\n{e.stderr}", file=sys.stderr)
def main():
ui_path = clibs.base_path / "assets" / "ui"
py_path = clibs.base_path / "codes" / "ui"
single_uic(str(ui_path), str(py_path))
if __name__ == "__main__":
main()