Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,8 @@ updater.old/
updaterback/
data/
key.json
gui/dev_list/*
!gui/dev_list/in_dev
res/packages/
Gui/packages.json

dev.dat
*.zip
*.7z
source/
Expand Down Expand Up @@ -743,4 +739,6 @@ vite.config.js.timestamp-*
vite.config.ts.timestamp-*

cache/
source/
source/

demo/
12 changes: 6 additions & 6 deletions Gui/install_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
app = QApplication(sys.argv)
from uiStyles.QUI import *

from uiStyles import PagesUI, UMessageBox, MessageButtonTemplate, styles, maps, UCheckBox
from uiStyles import PagesUI, UMessageBox, MessageButton, styles, maps, UCheckBox
import pyperclip
from sharelibs import (get_lang, settings, get_inst_lang, get_icon, system_lang, parse_system_language_to_lang_id, run_software, get_resource_path, is_admin, get_init_lang, QtThread, mem_id)
import win32com.client
Expand Down Expand Up @@ -143,8 +143,8 @@ def new_msg(parent,
title: str,
text: str,
icon: QMessageBox.Icon,
buttons: MessageButtonTemplate = MessageButtonTemplate.OK,
defaultButton: MessageButtonTemplate = MessageButtonTemplate.OK):
buttons: MessageButton = MessageButton.OK,
defaultButton: MessageButton = MessageButton.OK):

msg_box = UMessageBox.new_msg(parent, title, text, icon, buttons, defaultButton)
new_color_bar(msg_box)
Expand Down Expand Up @@ -216,7 +216,7 @@ def apply_titleBar(self, window: QMainWindow | QDialog):
'''应用标题栏样式'''
hwnd = window.winId().__int__()

if select_styles.css_data['.meta']['mode'] == 'dark':
if select_styles.css_data['.meta']['--mode'] == 'dark':
is_dark_mode = 1
else:
is_dark_mode = 0
Expand Down Expand Up @@ -781,7 +781,7 @@ def on_next(self):
self,
get_ipk_lang('1a'),
get_ipk_lang('24').format('\n'.join(self.changes if self.changes else [get_ipk_lang('2f')])),
MessageButtonTemplate.YESNO,
MessageButton.YESNO,
)

for i in packages_info:
Expand All @@ -793,7 +793,7 @@ def on_next(self):

self.changes = get_list_diff(select_package_id, package_id_list)

if message == 3:
if message == MessageButton.NO:
return
else:
message =QMessageBox.question(
Expand Down
32 changes: 24 additions & 8 deletions Gui/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def remove_old_log(directory_path):
os.remove(file_path)
except Exception as e:
pass

class ExceptionVal:
raise_trace = 0b1
output_msg = 0b10
exit = 0b100
all = raise_trace | output_msg | exit

# 定义日志路径
folder_path = Path("cache/logs")
Expand Down Expand Up @@ -120,7 +126,7 @@ def __init__(self, default_service_id):
self.info(f'logger Started')
remove_old_log(folder_path)

def auto_logger(self, service_id=None, start_extra_text='', end_extra_text='', start_extra=None, end_extra=None, level=logging.INFO):
def auto_logger(self, service_id: str | None=None, parent:list | None=None , start_extra_text: str='', end_extra_text:str='', start_extra:str | None=None, end_extra: str | None=None, level=logging.INFO):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
Expand All @@ -140,19 +146,21 @@ def wrapper(*args, **kwargs):
out_service_id = self.default_service_id if service_id is None else service_id
start_extra_out = {} if start_extra is None else start_extra
end_extra_out = {} if end_extra is None else end_extra
parent_out = [] if parent is None else parent

function_name = '.'.join(parent_out) + ('.' if parent else '') + func.__name__

log_func(f'Running function: {func.__name__} args={args} kwargs={kwargs}', extra={'service_id': out_service_id, **start_extra_out})
log_func(f'Running function: {function_name} args={args} kwargs={kwargs}', extra={'service_id': out_service_id, **start_extra_out})
if start_extra_text:
log_func(start_extra_text, extra={'service_id': out_service_id, **start_extra_out})
try:
result = func(*args, **kwargs)
except Exception as e:
trace = traceback.format_exc()
self.exception(out_service_id, trace, f'Function {func.__name__} raised an unexpected exception', extra={'service_id': out_service_id, **end_extra_out})
QMessageBox.critical(None, 'An unexpected error occurred', f'An unexpected error occurred in {func.__name__}: \n{trace}\nPlease look the log path: {(folder_path / f"{log_id}.log").resolve()} and send me the log file on issue: https://github.com/xystudiocode/pyClickMouse/issues/new/choose')
self.exception(out_service_id, trace, f'Function {function_name} raised an unexpected exception', extra={'service_id': out_service_id, **end_extra_out})
QMessageBox.critical(None, 'An unexpected error occurred', f'An unexpected error occurred in {function_name}: \n{trace}\nPlease look the log path: {(folder_path / f"{log_id}.log").resolve()} and send me the log file on issue: https://github.com/xystudiocode/pyClickMouse/issues/new/choose')
sys.exit(1) # 退出程序
raise e
log_func(f'Function {func.__name__} running successfull, returned: {result}', extra={'service_id': out_service_id, **end_extra_out})
log_func(f'Function {function_name} running successfull, returned: {result}', extra={'service_id': out_service_id, **end_extra_out})
if end_extra_text:
log_func(end_extra_text, extra={'service_id': out_service_id, **end_extra_out})
return result
Expand All @@ -174,5 +182,13 @@ def error(self, msg, extra=None):
def critical(self, msg, extra=None):
self.logger.critical(msg, extra=extra)

def exception(self, service, trace, msg='', extra=None):
self.critical(f'{msg}: An error occurred in {service}\n{trace}', extra=extra)
def exception(self, service, msg='', extra=None, mode: ExceptionVal = ExceptionVal.raise_trace):
if mode & ExceptionVal.raise_trace: # 获取堆栈
trace = '\n' + traceback.format_exc()
else:
trace = ''
self.critical(f'{msg}: An error occurred in {service}:{trace}', extra=extra)
if mode & ExceptionVal.output_msg: # 输出消息
QMessageBox.critical(None, 'An unexpected error occurred', f'An unexpected error occurred: {trace}\nPlease look the log path: {(folder_path / f"{log_id}.log").resolve()} and send me the log file on issue: https://github.com/xystudiocode/pyClickMouse/issues/new/choose')
if mode & ExceptionVal.exit: # 退出程序
sys.exit(1) # 退出程序
Loading
Loading