From e19991d1349f7f9d810d239f8625484d112dc406 Mon Sep 17 00:00:00 2001 From: xystudio_u <173288240@qq.com> Date: Thu, 19 Feb 2026 14:08:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=90=8C=E6=AD=A53.2.0.19beta10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gui/main.py | 416 +++++++++++++++++++++--------------------- Gui/res/versions.json | 2 +- 2 files changed, 209 insertions(+), 209 deletions(-) diff --git a/Gui/main.py b/Gui/main.py index 4904839..667d3a4 100644 --- a/Gui/main.py +++ b/Gui/main.py @@ -11,22 +11,22 @@ # TODO: 添加更新设置,使用hashlib.algorithms_available获取支持的hash算法 -# def get_windows_version(): -# '''获取winmdows版本''' -# # 检查系统 -# if sys.platform != 'win32': -# return +def get_windows_version(): + '''获取winmdows版本''' + # 检查系统 + if sys.platform != 'win32': + return -# version = platform.win32_ver()[1] -# major_version = int(version.split('.')[0]) -# build_number = int(version.split('.')[2]) if len(version.split('.')) > 2 else 0 -# if major_version == 10: # win10或win11 -# if build_number >= 22000: # win11初始版本为22000 -# return 11 -# else: -# return 10 -# else: -# return major_version + version = platform.win32_ver()[1] + major_version = int(version.split('.')[0]) + build_number = int(version.split('.')[2]) if len(version.split('.')) > 2 else 0 + if major_version == 10: # win10或win11 + if build_number >= 22000: # win11初始版本为22000 + return 11 + else: + return 10 + else: + return major_version def filter_hotkey(text:str): return text.split('(')[0] @@ -1941,15 +1941,15 @@ def init_ui(self): set_style(title, 'big_text_16') # 按钮 - # update = QPushButton(get_lang('26')) # 更新按钮 - # set_style(update, 'selected') + update = QPushButton(get_lang('26')) # 更新按钮 + set_style(update, 'selected') update_log = QPushButton(get_lang('27')) # 查看更新日志按钮 cancel = QPushButton(get_lang('1f')) # 取消按钮 bottom_layout = QHBoxLayout() # 绑定事件 logger.debug('绑定事件') - # update.clicked.connect(self.on_update) + update.clicked.connect(self.on_update) update_log.clicked.connect(self.on_open_update_log) cancel.clicked.connect(self.close) @@ -1959,7 +1959,7 @@ def init_ui(self): layout.addWidget(version) bottom_layout.addStretch() - # bottom_layout.addWidget(update) + bottom_layout.addWidget(update) bottom_layout.addWidget(update_log) bottom_layout.addWidget(cancel) @@ -1969,35 +1969,35 @@ def init_ui(self): logger.debug('初始化更新窗口完成') - # def on_update(self): - # '''更新''' - # try: - # self.close() - # os.rename('updater', 'updater.old') - # self.down_thread = QtThread(download_file, args=(web_data['down_web'].format(latest_version=result[4]), 'updater.old/clickmouse.7z')) - # self.down_thread.finished.connect(self.on_update_finished) - # self.down_thread.start() - # except: - # trace = format_exc() - # logger.exception('更新安装', trace) - # os.rename('updater.old', 'updater') - # MessageBox.critical(self, get_lang('14'), f'更新安装失败:\n{trace}') + def on_update(self): + '''更新''' + try: + self.close() + os.rename('updater', 'updater.old') + self.down_thread = QtThread(download_file, args=(web_data['down_web'].format(latest_version=result[4]), 'updater.old/clickmouse.7z')) + self.down_thread.finished.connect(self.on_update_finished) + self.down_thread.start() + except: + trace = format_exc() + logger.exception('更新安装', trace) + os.rename('updater.old', 'updater') + MessageBox.critical(self, get_lang('14'), f'更新安装失败:\n{trace}') - # def on_update_finished(self, state): - # '''更新完成''' - # global can_update - # if state[0]: - # hash_info = result[3] - # if get_file_hash('updater.old/clickmouse.7z', hash_info[1]) == hash_info[0]: - # can_update = True - # update_ok = UpdateOKWindow() - # update_ok.show() - # else: - # logger.exception('更新安装', '文件校验失败') - # QMessageBox.critical(self, get_lang('14'), '更新包校验失败') - # else: - # logger.exception('更新安装', state[1]) - # QMessageBox.critical(self, get_lang('14'), f'更新失败:\n{state[1]}') + def on_update_finished(self, state): + '''更新完成''' + global can_update + if state[0]: + hash_info = result[3] + if get_file_hash('updater.old/clickmouse.7z', hash_info[1]) == hash_info[0]: + can_update = True + update_ok = UpdateOKWindow() + update_ok.show() + else: + logger.exception('更新安装', '文件校验失败') + QMessageBox.critical(self, get_lang('14'), '更新包校验失败') + else: + logger.exception('更新安装', state[1]) + QMessageBox.critical(self, get_lang('14'), f'更新失败:\n{state[1]}') def on_open_update_log(self): # 打开更新日志 @@ -2260,22 +2260,22 @@ def __init__(self, values:dict | None = None): self.page_choice_buttons = [get_lang('42'), get_lang('a6'), get_lang('43'), get_lang('44')]# , get_lang('69')] self.last_page = None self.now_page = 0 - # self.values = {} if values is None else values + self.values = {} if values is None else values self.init_ui() - # self.check_values() # 检查设置值 + self.check_values() # 检查设置值 # 连接信号 clicker.started.connect(self.on_clicker_started) logger.debug('初始化设置窗口完成') - # def check_values(self): - # '''检查设置值''' - # # 热键设置 - # if self.values.get('need_restart', False): - # self.on_need_restart_setting_changed(lambda: system_lang, 'select_lang') - # self.values.clear() + def check_values(self): + '''检查设置值''' + # 热键设置 + if self.values.get('need_restart', False): + self.on_need_restart_setting_changed(lambda: system_lang, 'select_lang') + self.values.clear() def create_setting_page(self, title): logger.debug(f'创建设置页面: {title}') @@ -2302,14 +2302,14 @@ def create_horizontal_line(): line.setFrameShape(UFrame.Shape.HLine) # 水平线 return line - # def parse_hotkey(input: UHotkeyLineEdit): - # return input.text().split('+') + def parse_hotkey(input: UHotkeyLineEdit): + return input.text().split('+') self.page_general = self.page_choice_buttons[0] # 默认设置 self.page_style = self.page_choice_buttons[1] # 样式设置 self.page_click = self.page_choice_buttons[2] # 连点器设置 self.page_update = self.page_choice_buttons[3] # 更新设置 - # self.page_hotkey = self.page_choice_buttons[4] # 热键设置 + self.page_hotkey = self.page_choice_buttons[4] # 热键设置 # 主程序 self.app = get_application_instance() @@ -2372,11 +2372,11 @@ def create_horizontal_line(): set_style(delay_layout_text, 'big_text_16') # 重置所有设置 - # repair_layout = QHBoxLayout() # 重置布局 - # self.repair_button = QPushButton(get_lang('5e')) + repair_layout = QHBoxLayout() # 重置布局 + self.repair_button = QPushButton(get_lang('5e')) - # repair_layout.addWidget(self.repair_button) - # repair_layout.addStretch(1) + repair_layout.addWidget(self.repair_button) + repair_layout.addStretch(1) # 布局 layout.addLayout(lang_choice_layout) @@ -2387,7 +2387,7 @@ def create_horizontal_line(): layout.addWidget(delay_layout_text) layout.addWidget(delay_tip_label) layout.addWidget(create_horizontal_line()) - # layout.addLayout(repair_layout) + layout.addLayout(repair_layout) # 绑定事件 self.lang_choice.currentIndexChanged.connect(lambda: self.on_need_restart_setting_changed(self.lang_choice.currentIndex, 'select_lang')) @@ -2395,7 +2395,7 @@ def create_horizontal_line(): tray.checkStateChanged.connect(lambda: self.app.setQuitOnLastWindowClosed(not tray.isChecked())) # 关闭窗口时不退出应用 soft_delay.valueChanged.connect(lambda: self.on_setting_changed(lambda: soft_delay.value() * 10 if soft_delay.value() > 0 else 1, 'soft_delay')) soft_delay.valueChanged.connect(lambda: delay_layout_text.setText(f'{get_lang('b0')}: {soft_delay.value() * 10 if soft_delay.value() > 0 else 1}{get_lang("ms", source=unit_lang)}')) - # self.repair_button.clicked.connect(self.repair_all_settings) + self.repair_button.clicked.connect(self.repair_all_settings) case self.page_click: set_content_label(get_lang('84')) # 选择默认连点器延迟 @@ -2517,17 +2517,17 @@ def create_horizontal_line(): style_use_windows_layout.addWidget(style_choice_use_windows) style_use_windows_layout.addStretch(1) - # theme_layout = QHBoxLayout() # 主题布局 - # theme_tip_window = QLabel(get_lang('4b')) - # set_style(theme_tip_window, 'dest_small') - # theme_combo = QComboBox() - # theme_combo.addItems(QStyleFactory.keys()) - # theme_combo.setCurrentText(settings.get('theme', theme)) + theme_layout = QHBoxLayout() # 主题布局 + theme_tip_window = QLabel(get_lang('4b')) + set_style(theme_tip_window, 'dest_small') + theme_combo = QComboBox() + theme_combo.addItems(QStyleFactory.keys()) + theme_combo.setCurrentText(settings.get('theme', theme)) # 布局 - # theme_layout.addWidget(QLabel(get_lang('23'))) - # theme_layout.addWidget(theme_combo) - # theme_layout.addStretch(1) + theme_layout.addWidget(QLabel(get_lang('23'))) + theme_layout.addWidget(theme_combo) + theme_layout.addStretch(1) # 布局 layout.addLayout(style_layout) @@ -2535,127 +2535,127 @@ def create_horizontal_line(): layout.addLayout(style_use_windows_layout) layout.addWidget(tip_label) layout.addWidget(create_horizontal_line()) - # layout.addLayout(theme_layout) - # layout.addWidget(theme_tip_window) - # layout.addWidget(create_horizontal_line()) + layout.addLayout(theme_layout) + layout.addWidget(theme_tip_window) + layout.addWidget(create_horizontal_line()) # 连接信号 self.style_choice.currentIndexChanged.connect(lambda: self.on_setting_changed(self.style_choice.currentIndex, 'select_style')) style_choice_use_windows.checkStateChanged.connect(lambda: self.on_setting_changed(style_choice_use_windows.isChecked, 'use_windows_color')) - # theme_combo.currentIndexChanged.connect(lambda: self.on_setting_changed(theme_combo.currentText, 'theme')) - # theme_combo.currentIndexChanged.connect(lambda: self.app.setStyle(theme_combo.currentText())) - # case self.page_hotkey: - # set_content_label(get_lang('21')) + theme_combo.currentIndexChanged.connect(lambda: self.on_setting_changed(theme_combo.currentText, 'theme')) + theme_combo.currentIndexChanged.connect(lambda: self.app.setStyle(theme_combo.currentText())) + case self.page_hotkey: + set_content_label(get_lang('21')) - # # 左键连点 - # left_click_layout = QHBoxLayout() # 左键连点布局 - # left_click_input = UHotkeyLineEdit() # 左键连点输入框 - # left_click_input.setText(format_keys(settings.get('left_click_hotkey', ['F2']))) - # left_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + # 左键连点 + left_click_layout = QHBoxLayout() # 左键连点布局 + left_click_input = UHotkeyLineEdit() # 左键连点输入框 + left_click_input.setText(format_keys(settings.get('left_click_hotkey', ['F2']))) + left_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - # # 布局 - # left_click_layout.addWidget(QLabel(f'{get_lang('0c')}: '), 1) # 左键连点提示 - # left_click_layout.addWidget(left_click_input, 6) - # left_click_layout.addWidget(left_repair_button, 2) - # left_click_layout.addStretch() + # 布局 + left_click_layout.addWidget(QLabel(f'{get_lang('0c')}: '), 1) # 左键连点提示 + left_click_layout.addWidget(left_click_input, 6) + left_click_layout.addWidget(left_repair_button, 2) + left_click_layout.addStretch() - # # 右键连点 - # right_click_layout = QHBoxLayout() # 右键连点布局 - # right_click_input = UHotkeyLineEdit() # 右键连点输入框 - # right_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + # 右键连点 + right_click_layout = QHBoxLayout() # 右键连点布局 + right_click_input = UHotkeyLineEdit() # 右键连点输入框 + right_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - # right_click_input.setText(format_keys(settings.get('right_click_hotkey', ['F3']))) + right_click_input.setText(format_keys(settings.get('right_click_hotkey', ['F3']))) - # # 布局 - # right_click_layout.addWidget(QLabel(f'{get_lang('0d')}: '), 1) # 右键连点提示 - # right_click_layout.addWidget(right_click_input, 6) - # right_click_layout.addWidget(right_repair_button, 2) - # right_click_layout.addStretch() + # 布局 + right_click_layout.addWidget(QLabel(f'{get_lang('0d')}: '), 1) # 右键连点提示 + right_click_layout.addWidget(right_click_input, 6) + right_click_layout.addWidget(right_repair_button, 2) + right_click_layout.addStretch() - # # 暂停/重启连点 - # pause_click_layout = QHBoxLayout() # 暂停/重启连点布局 - # pause_click_input = UHotkeyLineEdit() # 暂停/重启连点输入框 - # pause_click_input.setText(format_keys(settings.get('pause_click_hotkey', ['F4']))) - # pause_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + # 暂停/重启连点 + pause_click_layout = QHBoxLayout() # 暂停/重启连点布局 + pause_click_input = UHotkeyLineEdit() # 暂停/重启连点输入框 + pause_click_input.setText(format_keys(settings.get('pause_click_hotkey', ['F4']))) + pause_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - # # 布局 - # pause_click_layout.addWidget(QLabel(f'{get_lang('6b')}: '), 1) # 暂停/重启连点提示 - # pause_click_layout.addWidget(pause_click_input, 6) - # pause_click_layout.addWidget(pause_repair_button, 2) - # pause_click_layout.addStretch() + # 布局 + pause_click_layout.addWidget(QLabel(f'{get_lang('6b')}: '), 1) # 暂停/重启连点提示 + pause_click_layout.addWidget(pause_click_input, 6) + pause_click_layout.addWidget(pause_repair_button, 2) + pause_click_layout.addStretch() - # # 停止连点 - # stop_click_layout = QHBoxLayout() # 停止连点布局 - # stop_click_input = UHotkeyLineEdit() # 停止连点输入框 - # stop_click_input.setText(format_keys(settings.get('stop_click_hotkey', ['F6']))) - # stop_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + # 停止连点 + stop_click_layout = QHBoxLayout() # 停止连点布局 + stop_click_input = UHotkeyLineEdit() # 停止连点输入框 + stop_click_input.setText(format_keys(settings.get('stop_click_hotkey', ['F6']))) + stop_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - # # 布局 - # stop_click_layout.addWidget(QLabel(f'{get_lang('6c')}: '), 1) # 停止连点提示 - # stop_click_layout.addWidget(stop_click_input, 6) - # stop_click_layout.addWidget(stop_repair_button, 2) - # stop_click_layout.addStretch() + # 布局 + stop_click_layout.addWidget(QLabel(f'{get_lang('6c')}: '), 1) # 停止连点提示 + stop_click_layout.addWidget(stop_click_input, 6) + stop_click_layout.addWidget(stop_repair_button, 2) + stop_click_layout.addStretch() - # # 连点属性 - # click_attr_layout = QHBoxLayout() # 连点属性布局 - # click_attr_input = UHotkeyLineEdit() # 连点属性输入框 - # click_attr_input.setText(format_keys(settings.get('click_attr_hotkey', ['Ctrl', 'Alt', 'A']))) - # click_attr_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + # 连点属性 + click_attr_layout = QHBoxLayout() # 连点属性布局 + click_attr_input = UHotkeyLineEdit() # 连点属性输入框 + click_attr_input.setText(format_keys(settings.get('click_attr_hotkey', ['Ctrl', 'Alt', 'A']))) + click_attr_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - # # 布局 - # click_attr_layout.addWidget(QLabel(f'{get_lang('8c')}: '), 1) # 连点属性提示 - # click_attr_layout.addWidget(click_attr_input, 6) - # click_attr_layout.addWidget(click_attr_button, 2) - # click_attr_layout.addStretch() + # 布局 + click_attr_layout.addWidget(QLabel(f'{get_lang('8c')}: '), 1) # 连点属性提示 + click_attr_layout.addWidget(click_attr_input, 6) + click_attr_layout.addWidget(click_attr_button, 2) + click_attr_layout.addStretch() - # # 快速连点 - # fast_click_layout = QHBoxLayout() # 快速连点布局 - # fast_click_input = UHotkeyLineEdit() # 快速连点输入框 - # fast_click_input.setText(format_keys(settings.get('fast_click_hotkey', ['Ctrl', 'Alt', 'F']))) - # fast_click_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + # 快速连点 + fast_click_layout = QHBoxLayout() # 快速连点布局 + fast_click_input = UHotkeyLineEdit() # 快速连点输入框 + fast_click_input.setText(format_keys(settings.get('fast_click_hotkey', ['Ctrl', 'Alt', 'F']))) + fast_click_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - # # 布局 - # fast_click_layout.addWidget(QLabel(f'{get_lang('75')}: '), 1) # 快速连点提示 - # fast_click_layout.addWidget(fast_click_input, 6) - # fast_click_layout.addWidget(fast_click_button, 2) - # fast_click_layout.addStretch() + # 布局 + fast_click_layout.addWidget(QLabel(f'{get_lang('75')}: '), 1) # 快速连点提示 + fast_click_layout.addWidget(fast_click_input, 6) + fast_click_layout.addWidget(fast_click_button, 2) + fast_click_layout.addStretch() - # # 主窗口 - # main_window_layout = QHBoxLayout() # 主窗口布局 - # main_window_input = UHotkeyLineEdit() # 主窗口输入框 - # main_window_input.setText(format_keys(settings.get('main_window_hotkey', ['Ctrl', 'Alt', 'M']))) - # main_window_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - - # # 布局 - # main_window_layout.addWidget(QLabel(f'{get_lang('76')}: '), 1) # 主窗口提示 - # main_window_layout.addWidget(main_window_input, 6) - # main_window_layout.addWidget(main_window_button, 2) - # main_window_layout.addStretch() - - # # 布局 - # layout.addLayout(left_click_layout) - # layout.addLayout(right_click_layout) - # layout.addLayout(pause_click_layout) - # layout.addLayout(stop_click_layout) - # layout.addLayout(click_attr_layout) - # layout.addLayout(fast_click_layout) - # layout.addLayout(main_window_layout) + # 主窗口 + main_window_layout = QHBoxLayout() # 主窗口布局 + main_window_input = UHotkeyLineEdit() # 主窗口输入框 + main_window_input.setText(format_keys(settings.get('main_window_hotkey', ['Ctrl', 'Alt', 'M']))) + main_window_button = QPushButton(get_lang('20')) # 还原默认设置按钮 + + # 布局 + main_window_layout.addWidget(QLabel(f'{get_lang('76')}: '), 1) # 主窗口提示 + main_window_layout.addWidget(main_window_input, 6) + main_window_layout.addWidget(main_window_button, 2) + main_window_layout.addStretch() + + # 布局 + layout.addLayout(left_click_layout) + layout.addLayout(right_click_layout) + layout.addLayout(pause_click_layout) + layout.addLayout(stop_click_layout) + layout.addLayout(click_attr_layout) + layout.addLayout(fast_click_layout) + layout.addLayout(main_window_layout) - # # 连接信号 - # left_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(left_click_input), 'left_click_hotkey')) - # right_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(right_click_input), 'right_click_hotkey')) - # pause_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(pause_click_input), 'pause_click_hotkey')) - # stop_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(stop_click_input),'stop_click_hotkey')) - # click_attr_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(click_attr_input), 'click_attr_hotkey')) - # fast_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(fast_click_input), 'fast_click_hotkey')) + # 连接信号 + left_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(left_click_input), 'left_click_hotkey')) + right_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(right_click_input), 'right_click_hotkey')) + pause_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(pause_click_input), 'pause_click_hotkey')) + stop_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(stop_click_input),'stop_click_hotkey')) + click_attr_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(click_attr_input), 'click_attr_hotkey')) + fast_click_input.textChanged.connect(lambda: self.on_setting_changed(lambda: parse_hotkey(fast_click_input), 'fast_click_hotkey')) - # left_repair_button.clicked.connect(lambda: self.repair_settings('left_click_hotkey')) - # right_repair_button.clicked.connect(lambda: self.repair_settings('right_click_hotkey')) - # pause_repair_button.clicked.connect(lambda: self.repair_settings('pause_click_hotkey')) - # stop_repair_button.clicked.connect(lambda: self.repair_settings('stop_click_hotkey')) - # click_attr_button.clicked.connect(lambda: self.repair_settings('click_attr_hotkey')) - # fast_click_button.clicked.connect(lambda: self.repair_settings('fast_click_hotkey')) - # main_window_button.clicked.connect(lambda: self.repair_settings('main_window_hotkey')) + left_repair_button.clicked.connect(lambda: self.repair_settings('left_click_hotkey')) + right_repair_button.clicked.connect(lambda: self.repair_settings('right_click_hotkey')) + pause_repair_button.clicked.connect(lambda: self.repair_settings('pause_click_hotkey')) + stop_repair_button.clicked.connect(lambda: self.repair_settings('stop_click_hotkey')) + click_attr_button.clicked.connect(lambda: self.repair_settings('click_attr_hotkey')) + fast_click_button.clicked.connect(lambda: self.repair_settings('fast_click_hotkey')) + main_window_button.clicked.connect(lambda: self.repair_settings('main_window_hotkey')) restart_layout = QHBoxLayout() # 重启提示布局 self.restart_button = QPushButton(get_lang('7e')) @@ -2681,26 +2681,26 @@ def showEvent(self, event): new_color_bar(self) return super().showEvent(event) - # def repair_settings(self, key: str): - # '''还原默认设置''' - # global settings - # if MessageBox.warning(self, get_lang('15'), get_lang('22'), MessageButtonTemplate.YESNO) != 2: # 不确认重置 - # return - # settings[key] = default_setting[key] - # save_settings(settings) - # self.window_restarted.emit() + def repair_settings(self, key: str): + '''还原默认设置''' + global settings + if MessageBox.warning(self, get_lang('15'), get_lang('22'), MessageButtonTemplate.YESNO) != 2: # 不确认重置 + return + settings[key] = default_setting[key] + save_settings(settings) + self.window_restarted.emit() - # def repair_all_settings(self): - # global settings - # if MessageBox.warning(self, get_lang('15'), get_lang('22'), MessageButtonTemplate.YESNO) != 2: # 不确认重置 - # return - # settings = default_setting.copy() - # settings['theme'] = default_theme - # settings['select_lang'] = system_lang - # save_settings(settings) - # self.app.setStyle(default_theme) - # self.values.update({'need_restart': True}) # values 用于存储需要重启后还原的内容 - # self.window_restarted.emit() + def repair_all_settings(self): + global settings + if MessageBox.warning(self, get_lang('15'), get_lang('22'), MessageButtonTemplate.YESNO) != 2: # 不确认重置 + return + settings = default_setting.copy() + settings['theme'] = default_theme + settings['select_lang'] = system_lang + save_settings(settings) + self.app.setStyle(default_theme) + self.values.update({'need_restart': True}) # values 用于存储需要重启后还原的内容 + self.window_restarted.emit() def on_auto_start_changed(self, state): '''自启动复选框状态改变''' @@ -3212,22 +3212,22 @@ def on_start(self): result = (None, None, None, None) # 更新检查结果 # 系统版本 - # windows_version = get_windows_version() - # if windows_version is None: # 非windows - # default_theme = 'Fusion' - # elif windows_version < 10: # 低于win10 - # default_theme = 'Windows' - # elif windows_version == 10: # win10 - # default_theme = 'Windows10' - # elif windows_version == 11: # win11 - # default_theme = 'Windows11' - # else: # 未知 - # default_theme = 'Fusion' + windows_version = get_windows_version() + if windows_version is None: # 非windows + default_theme = 'Fusion' + elif windows_version < 10: # 低于win10 + default_theme = 'Windows' + elif windows_version == 10: # win10 + default_theme = 'Windows10' + elif windows_version == 11: # win11 + default_theme = 'Windows11' + else: # 未知 + default_theme = 'Fusion' - # with open(get_resource_path('default_setting.json')) as f: - # default_setting = json.load(f) + with open(get_resource_path('default_setting.json')) as f: + default_setting = json.load(f) - # theme = settings.get('theme', default_theme) + theme = settings.get('theme', default_theme) logger.info('定义资源完成') @@ -3255,5 +3255,5 @@ def on_start(self): setting_window.window_restarted.connect(on_update_setting_window) app = TrayApp() - # app.app.setStyle(theme) + app.app.setStyle(theme) app.run() \ No newline at end of file diff --git a/Gui/res/versions.json b/Gui/res/versions.json index 2541e6e..9739538 100644 --- a/Gui/res/versions.json +++ b/Gui/res/versions.json @@ -1 +1 @@ -{"package_format_version": "1.2.0", "clickmouse":"3.1.3.18"} +{"package_format_version": "1.2.0", "clickmouse":"3.2.0.19beta10"} From 406119f6a6b58081500947e7efc508fcf75aac31 Mon Sep 17 00:00:00 2001 From: xystudio_u <173288240@qq.com> Date: Tue, 24 Feb 2026 21:10:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=94=A7modify=20(clickmouse):=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化代码 - 修改风格,移除按下下拉框的样式 --- Gui/main.py | 315 ++++++++++++++++++++++++--------- Gui/res/defaultsetting.json | 1 + Gui/res/styles/dark.qss | 4 - Gui/res/styles/light.qss | 4 - Gui/res/vars/cleancache.json | 2 +- Gui/res/versions.json | 2 +- Gui/tests/test_property_get.py | 12 ++ 7 files changed, 249 insertions(+), 91 deletions(-) create mode 100644 Gui/res/defaultsetting.json create mode 100644 Gui/tests/test_property_get.py diff --git a/Gui/main.py b/Gui/main.py index a304af8..6d9e7c9 100644 --- a/Gui/main.py +++ b/Gui/main.py @@ -70,7 +70,7 @@ def should_check_update(): last_check_time_stamp = datetime.fromtimestamp(last_check_time) now = datetime.now() - setting_time = settings.get('update_frequency', 1) + setting_time = setting_value.update_frequency time = 9 match setting_time: @@ -348,10 +348,6 @@ def get_hotkey_listener_instance(): hotkey_thread.start() return get_hotkey_listener_instance.instance -def parse_hotkey(hotkey_str: str, default_keys): - '''解析热键字符串''' - return settings.get(hotkey_str + '_hotkey', default_keys) - def revert_update(): '''回滚更新''' logger.info('回滚更新') @@ -374,8 +370,8 @@ def on_input_change(*, type:str ): times_combo = main_window.times_combo delay_combo = main_window.delay_combo total = main_window.total_time_label - delay_num = settings.get('click_delay', '') - time_num = settings.get('click_times', '') + delay_num = setting_value.click_delay + time_num = setting_value.click_times is_error = False elif type =='setting': delay_text = setting_window.default_delay @@ -388,11 +384,11 @@ def on_input_change(*, type:str ): is_inf = False delay = 0 - delay_times.setEnabled(not(times_combo.currentIndex() == latest_index or (settings.get('times_unit', 0) == latest_index) and type == 'main')) + delay_times.setEnabled(not(times_combo.currentIndex() == latest_index or (setting_value.times_unit == latest_index) and type == 'main')) if times_combo.currentIndex() == latest_index or input_times == '0': is_inf = True - if settings.get('times_unit', 0) == latest_index and type == 'main': + if setting_value.times_unit == latest_index and type == 'main': is_inf = True def on_delay_error(error_text=get_lang('14')): @@ -426,15 +422,15 @@ def check_default_var(value): if delay < 1: raise ValueError except ValueError: - if not settings.get('click_delay', '') == '': + if not setting_value.click_delay == '': if input_delay == '': if check_default_var('delay'): - delay = int(settings.get('click_delay', '')) + delay = int(setting_value.click_delay) else: return - elif settings.get('failed_use_default', False): + elif setting_value.delay_error_use_default: if check_default_var('delay'): - delay = int(settings.get('click_delay', '')) + delay = int(setting_value.click_delay) else: return else: @@ -450,18 +446,18 @@ def check_default_var(value): if times < 1: raise ValueError except ValueError: - if settings.get('click_times', '') == '' and settings.get('click_delay', '') == '': + if setting_value.click_times == '' and setting_value.click_delay == '': on_delay_error(get_lang('61')) return else: if input_times == '': if check_default_var('times'): - times = int(settings.get('click_times', '')) + times = int(setting_value.click_times) else: return - elif settings.get('times_failed_use_default', False): + elif setting_value.times_error_use_default: if check_default_var('times'): - times = int(settings.get('click_times', '')) + times = int(setting_value.click_times) else: return else: @@ -476,8 +472,8 @@ def check_default_var(value): main_window.left_click_button.setEnabled(True) is_error = False - if settings.get('click_delay', '') != '' and input_delay == '': - match settings.get('delay_unit', 0): + if setting_value.click_delay != '' and input_delay == '': + match setting_value.delay_unit: case 0: delay_num = delay case 1: @@ -499,8 +495,8 @@ def check_default_var(value): if delay_num == 0: on_delay_error() else: - if settings.get('click_times', '') != '' and input_times == '': - match settings.get('times_unit', 0): + if setting_value.click_times != '' and input_times == '': + match setting_value.times_unit: case 0: time_num = times case 1: @@ -563,7 +559,7 @@ def __init__(self): self.timer = QTimer() self.timer.timeout.connect(self.check_value) - self.timer.start(settings.get('soft_delay', 1)) + self.timer.start(setting_value.soft_delay) def create_reg(self): '''检查是否已启用开机自启动''' @@ -848,7 +844,7 @@ def do_step(self, codes): logger.error(f'步骤{code.__name__}执行失败:{e}') def refresh_title(self): - QTimer.singleShot(settings.get('soft_delay', 100), color_getter.style_changed.emit) + QTimer.singleShot(setting_value.soft_delay, color_getter.style_changed.emit) def left_check(self): if clicker.left_clicked: @@ -895,7 +891,7 @@ def __init__(self): super().__init__() # 记录当前主题 - self.style = settings.get('select_style', 0) + self.style = setting_value.select_style self.current_theme, self.windows_theme, self.windows_color, self.use_windows_color = self.load_theme() try: @@ -917,7 +913,7 @@ def __init__(self): # 使用定时器定期检测主题变化 self.timer = QTimer() self.timer.timeout.connect(self.check_and_apply_theme) - self.timer.start(settings.get('soft_delay', 1)) + self.timer.start(setting_value.soft_delay) def load_theme(self): logger.debug('获取最新的主题') @@ -941,10 +937,10 @@ def load_theme(self): windows_theme = 'light' windows_color = get_windows_accent_color() - use_windows_color = settings.get('use_windows_color', True) + use_windows_color = setting_value.use_windows_color for k, v in maps.items(): - if v == settings.get('select_style', 0): + if v == setting_value.select_style: theme = k return theme, windows_theme, windows_color, use_windows_color @@ -953,7 +949,7 @@ def check_and_apply_theme(self): '''检查主题是否变化,变化则重新应用''' logger.debug('检查主题是否变化') - self.style = settings.get('select_style', 0) + self.style = setting_value.select_style new_theme, new_windows_theme, new_windows_color, new_use_windows_color = self.load_theme() @@ -1023,6 +1019,161 @@ def apply_global_theme(self): app.setStyleSheet(select_styles.css_text) # 全局应用 self.refresh() + +class SettingText: + select_lang = 'select_lang' + show_tray_icon ='show_tray_icon' + soft_delay ='soft_delay' + click_delay = 'click_delay' + click_times = 'click_times' + delay_unit = 'delay_unit' + times_unit = 'times_unit' + delay_error_use_default = 'failed_use_default' + times_error_use_default = 'times_failed_use_default' + update_enabled = 'update_enabled' + update_notify = 'update_notify' + quiet_update = 'quiet_update' + update_ok_notify = 'update_ok_notify' + update_frequency = 'update_frequency' + select_style = 'select_style' + use_windows_color = 'use_windows_color' + theme = 'theme' + left_click_hotkey = 'left_click_hotkey' + right_click_hotkey = 'right_click_hotkey' + pause_click_hotkey = 'pause_click_hotkey' + stop_click_hotkey ='stop_click_hotkey' + click_attr_hotkey = 'click_attr_hotkey' + fast_click_hotkey = 'fast_click_hotkey' + main_window_hotkey = 'main_window_hotkey' + default_doc_link = 'default_doc_link' + lang_doc = 'lang_doc' + update_log_path = 'update_log_path' + +class SettingValue: + def get(self, value): + default_value = default_settings.get(value, None) + if isinstance(default_value, str): + if default_value.startswith('!var '): # 需要加载变量 + var_name = default_value[5:] + default_value = eval(var_name) + return settings.get(value, default_value) + + def __getitem__(self, key): + return self.get(key) + + def __setitem__(self, key, value): + raise ValueError('SettingValue is readonly') + + def __delitem__(self, key): + raise ValueError('SettingValue is readonly') + + @property + def select_lang(self): + return self[SettingText.select_lang] + + @property + def show_tray_icon(self): + return self[SettingText.show_tray_icon] + + @property + def soft_delay(self): + return self[SettingText.soft_delay] + + @property + def click_delay(self): + return self[SettingText.click_delay] + + @property + def click_times(self): + return self[SettingText.click_times] + + @property + def delay_unit(self): + return self[SettingText.delay_unit] + + @property + def times_unit(self): + return self[SettingText.times_unit] + + @property + def delay_error_use_default(self): + return self[SettingText.delay_error_use_default] + + @property + def times_error_use_default(self): + return self[SettingText.times_error_use_default] + + @property + def update_enabled(self): + return self[SettingText.update_enabled] + + @property + def update_notify(self): + return self[SettingText.update_notify] + + @property + def quiet_update(self): + return self[SettingText.quiet_update] + + @property + def update_ok_notify(self): + return self[SettingText.update_ok_notify] + + @property + def update_frequency(self): + return self[SettingText.update_frequency] + + @property + def select_style(self): + return self[SettingText.select_style] + + @property + def use_windows_color(self): + return self[SettingText.use_windows_color] + + @property + def theme(self): + return self[SettingText.theme] + + @property + def left_click_hotkey(self): + return self[SettingText.left_click_hotkey] + + @property + def right_click_hotkey(self): + return self[SettingText.right_click_hotkey] + + @property + def pause_click_hotkey(self): + return self[SettingText.pause_click_hotkey] + + @property + def stop_click_hotkey(self): + return self[SettingText.stop_click_hotkey] + + @property + def click_attr_hotkey(self): + return self[SettingText.click_attr_hotkey] + + @property + def fast_click_hotkey(self): + return self[SettingText.fast_click_hotkey] + + @property + def main_window_hotkey(self): + return self[SettingText.main_window_hotkey] + + @property + def default_doc_link(self): + return self[SettingText.default_doc_link] + + @property + def lang_doc(self): + return self[SettingText.lang_doc] + + @property + def update_log_path(self): + return self[SettingText.update_log_path] class MainWindow(UMainWindow): def __init__(self): @@ -1251,7 +1402,7 @@ def open_doc(self, *, path: str=''): lang_name = langs[select_lang]['lang_system_name'] supported_doc_lang = [i['lang_system_name'] for i in langs if i['supported']] - doc_choice = settings.get('lang_doc', 0) + doc_choice = setting_value.lang_doc if doc_choice == 0: # 软件语言 doc_choice_lang = lang_name elif doc_choice == 1: # 系统语言 @@ -1262,7 +1413,7 @@ def open_doc(self, *, path: str=''): if doc_choice_lang not in supported_doc_lang: # 不受支持的语言包 doc_choice_lang = 'en' # 默认英文 - open_url(settings.get('default_doc_link', 'https://xystudiocode.github.io/clickmouse_docs/{lang}/{path}').format(lang=doc_choice_lang, path=path)) + open_url(f'{setting_value.default_doc_link}/{path}'.format(lang=doc_choice_lang)) def do_extension(self, index): '''执行扩展''' @@ -1347,7 +1498,7 @@ def show_about(self): def show_update_log(self): '''显示更新日志''' logger.info('打开更新日志窗口') - self.open_doc(path=settings.get('update_log_path', 'updatelog')) + self.open_doc(path=setting_value.update_log_path) def show_clean_cache(self): '''清理缓存''' @@ -1361,7 +1512,7 @@ def show_setting(self): def on_check_update(self): # 检查更新 - if settings.get('update_enabled', True): + if setting_value.update_enabled: self.update_checked = True if should_check_update_res: self.check_update_thread = QtThread(check_update, args=(False,)) @@ -1392,7 +1543,7 @@ def on_check_update_result(self, check_data): return # 检查结果处理 - if settings.get('update_notify', True): + if setting_value.update_notify: if result[1] != -1: # -1表示函数出错 self.save() if result[0]: # 检查到需要更新 @@ -1410,7 +1561,7 @@ def on_check_update_result(self, check_data): def on_update(self, judge=False): '''显示更新提示''' if judge: - if settings.get('update_enabled', True): + if setting_value.update_enabled: if result[0]: # 检查到需要更新 self.open_update() else: @@ -2012,7 +2163,7 @@ def init_ui(self): logger.debug('初始化更新窗口完成') def exec(self): - if settings.get('quiet_update', False): + if setting_value.quiet_update: self.close() self.on_update() else: @@ -2042,7 +2193,7 @@ def on_update_finished(self, state): hash_info = result[3] if get_file_hash('updater.old/clickmouse.7z', hash_info[1]) == hash_info[0]: can_update = True - if settings.get('update_ok_notify', True): + if setting_value.update_ok_notify: update_ok_window.show() else: logger.exception('更新安装', '文件校验失败') @@ -2226,7 +2377,7 @@ def __init__(self): # 定义变量 self.timer = QTimer(self) self.timer.timeout.connect(self.update_attr) - self.timer.start(settings.get('soft_delay', 1)) + self.timer.start(setting_value.soft_delay) self.init_ui() @@ -2370,7 +2521,7 @@ def parse_hotkey(input: UHotkeyLineEdit): lang_choice_layout = QHBoxLayout() # 语言选择布局 self.lang_choice = QComboBox() self.lang_choice.addItems([i['lang_name'] for i in langs]) - self.lang_choice.setCurrentIndex(settings.get('select_lang', 0)) + self.lang_choice.setCurrentIndex(setting_value.select_lang) # 布局 lang_choice_layout.addWidget(QLabel(f'{get_lang('45')}{get_lang('b5')}:')) # 选择语言提示 @@ -2380,7 +2531,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 显示托盘图标 tray_layout = QHBoxLayout() # 窗口风格布局 tray = UCheckBox(get_lang('80')) - tray.setChecked(settings.get('show_tray_icon', True)) + tray.setChecked(setting_value.show_tray_icon) tray_layout.addWidget(tray) tray_layout.addStretch(1) @@ -2398,7 +2549,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 延迟 soft_delay_layout = QHBoxLayout() # 颜色延迟布局 - soft_delay_setting = settings.get('soft_delay', 100) + soft_delay_setting = setting_value.soft_delay soft_delay = QSlider(Qt.Horizontal) soft_delay.setMinimum(0) @@ -2450,10 +2601,10 @@ def parse_hotkey(input: UHotkeyLineEdit): layout_delay = QVBoxLayout() # 延迟布局 unit_delay_layout = QHBoxLayout() # 窗口风格布局 self.default_delay = QLineEdit() - self.default_delay.setText(str(settings.get('click_delay', ''))) + self.default_delay.setText(setting_value.click_delay) self.delay_combo = QComboBox() self.delay_combo.addItems([get_lang('ms', source=unit_lang), get_lang('s', source=unit_lang)]) - self.delay_combo.setCurrentIndex(settings.get('delay_unit', 0)) + self.delay_combo.setCurrentIndex(setting_value.delay_unit) unit_delay_layout.addWidget(QLabel(get_lang('46') + ': ')) unit_delay_layout.addWidget(self.default_delay) @@ -2462,7 +2613,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 连点出错时使用默认值 use_default_delay = UCheckBox(get_lang('47')) - use_default_delay.setChecked(settings.get('failed_use_default', False)) + use_default_delay.setChecked(setting_value.delay_error_use_default) if not self.default_delay.text(): use_default_delay.setEnabled(False) @@ -2476,10 +2627,10 @@ def parse_hotkey(input: UHotkeyLineEdit): layout_time = QVBoxLayout() # 次数布局 unit_time_layout = QHBoxLayout() # 窗口风格布局 self.default_time = QLineEdit() - self.default_time.setText(str(settings.get('click_times', ''))) + self.default_time.setText(str(setting_value.click_times)) self.times_combo = QComboBox() self.times_combo.addItems([get_lang('66'), get_lang('2a'), get_lang('2b')]) - self.times_combo.setCurrentIndex(settings.get('times_unit', 0)) + self.times_combo.setCurrentIndex(setting_value.times_unit) unit_time_layout.addWidget(QLabel(get_lang('85') + ': ')) unit_time_layout.addWidget(self.default_time) @@ -2488,7 +2639,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 连点出错时使用默认值 use_default_time = UCheckBox(get_lang('86')) - use_default_time.setChecked(settings.get('times_failed_use_default', False)) + use_default_time.setChecked(setting_value.times_error_use_default) if not self.default_time.text(): use_default_time.setEnabled(False) @@ -2523,21 +2674,21 @@ def parse_hotkey(input: UHotkeyLineEdit): set_content_label(get_lang('87')) # 选择更新检查提示 self.enable_update = UCheckBox(get_lang('48')) # 开启更新 - self.enable_update.setChecked(settings.get('update_enabled', True)) + self.enable_update.setChecked(setting_value.update_enabled) self.update_notify = UCheckBox(get_lang('4a')) # 更新提示 - self.update_notify.setChecked(settings.get('update_notify', True)) + self.update_notify.setChecked(setting_value.update_notify) self.quiet_install = UCheckBox(get_lang('49')) # 静默安装 - self.quiet_install.setChecked(settings.get('quiet_update', False)) + self.quiet_install.setChecked(setting_value.quiet_update) self.update_ok = UCheckBox(get_lang('4c')) # 更新完成弹出提示 - self.update_ok.setChecked(settings.get('update_ok_notify', True)) + self.update_ok.setChecked(setting_value.update_ok_notify) update_frequency_layout = QHBoxLayout() # 更新频率布局 self.update_frequency = QComboBox() # 更新频率 self.update_frequency.addItems([get_lang('bd'), get_lang('be'), get_lang('bf'), get_lang('c0')]) - self.update_frequency.setCurrentIndex(settings.get('update_frequency', 1)) + self.update_frequency.setCurrentIndex(setting_value.update_frequency) update_frequency_layout.addWidget(QLabel(get_lang('c1'))) update_frequency_layout.addWidget(self.update_frequency) update_frequency_layout.addStretch(1) @@ -2566,7 +2717,7 @@ def parse_hotkey(input: UHotkeyLineEdit): items = list(style_indexes[select_lang]['lang_package'].values()) self.style_choice.addItems([get_lang('82')] + items) - self.style_choice.setCurrentIndex(settings.get('select_style', 0)) + self.style_choice.setCurrentIndex(setting_value.select_style) # 布局 style_layout.addWidget(QLabel(get_lang('81'))) # 选择窗口风格提示 @@ -2577,7 +2728,7 @@ def parse_hotkey(input: UHotkeyLineEdit): style_choice_use_windows = UCheckBox(get_lang('a8')) tip_label = QLabel(get_lang('b4')) set_style(tip_label, 'dest_small') - style_choice_use_windows.setChecked(settings.get('use_windows_color', True)) + style_choice_use_windows.setChecked(setting_value.use_windows_color) # 布局 style_use_windows_layout.addWidget(style_choice_use_windows) @@ -2588,7 +2739,7 @@ def parse_hotkey(input: UHotkeyLineEdit): set_style(theme_tip_window, 'dest_small') theme_combo = QComboBox() theme_combo.addItems(QStyleFactory.keys()) - theme_combo.setCurrentText(settings.get('theme', theme)) + theme_combo.setCurrentText(setting_value.theme) # 布局 theme_layout.addWidget(QLabel(get_lang('23'))) @@ -2616,7 +2767,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 左键连点 left_click_layout = QHBoxLayout() # 左键连点布局 left_click_input = UHotkeyLineEdit() # 左键连点输入框 - left_click_input.setText(format_keys(settings.get('left_click_hotkey', ['F2']))) + left_click_input.setText(format_keys(setting_value.left_click_hotkey)) left_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 # 布局 @@ -2630,7 +2781,7 @@ def parse_hotkey(input: UHotkeyLineEdit): right_click_input = UHotkeyLineEdit() # 右键连点输入框 right_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 - right_click_input.setText(format_keys(settings.get('right_click_hotkey', ['F3']))) + right_click_input.setText(format_keys(setting_value.right_click_hotkey)) # 布局 right_click_layout.addWidget(QLabel(f'{get_lang('0d')}: '), 1) # 右键连点提示 @@ -2641,7 +2792,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 暂停/重启连点 pause_click_layout = QHBoxLayout() # 暂停/重启连点布局 pause_click_input = UHotkeyLineEdit() # 暂停/重启连点输入框 - pause_click_input.setText(format_keys(settings.get('pause_click_hotkey', ['F4']))) + pause_click_input.setText(format_keys(setting_value.pause_click_hotkey)) pause_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 # 布局 @@ -2653,7 +2804,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 停止连点 stop_click_layout = QHBoxLayout() # 停止连点布局 stop_click_input = UHotkeyLineEdit() # 停止连点输入框 - stop_click_input.setText(format_keys(settings.get('stop_click_hotkey', ['F6']))) + stop_click_input.setText(format_keys(setting_value.stop_click_hotkey)) stop_repair_button = QPushButton(get_lang('20')) # 还原默认设置按钮 # 布局 @@ -2665,7 +2816,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 连点属性 click_attr_layout = QHBoxLayout() # 连点属性布局 click_attr_input = UHotkeyLineEdit() # 连点属性输入框 - click_attr_input.setText(format_keys(settings.get('click_attr_hotkey', ['Ctrl', 'Alt', 'A']))) + click_attr_input.setText(format_keys(setting_value.click_attr_hotkey)) click_attr_button = QPushButton(get_lang('20')) # 还原默认设置按钮 # 布局 @@ -2677,7 +2828,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 快速连点 fast_click_layout = QHBoxLayout() # 快速连点布局 fast_click_input = UHotkeyLineEdit() # 快速连点输入框 - fast_click_input.setText(format_keys(settings.get('fast_click_hotkey', ['Ctrl', 'Alt', 'F']))) + fast_click_input.setText(format_keys(setting_value.fast_click_hotkey)) fast_click_button = QPushButton(get_lang('20')) # 还原默认设置按钮 # 布局 @@ -2689,7 +2840,7 @@ def parse_hotkey(input: UHotkeyLineEdit): # 主窗口 main_window_layout = QHBoxLayout() # 主窗口布局 main_window_input = UHotkeyLineEdit() # 主窗口输入框 - main_window_input.setText(format_keys(settings.get('main_window_hotkey', ['Ctrl', 'Alt', 'M']))) + main_window_input.setText(format_keys(setting_value.main_window_hotkey)) main_window_button = QPushButton(get_lang('20')) # 还原默认设置按钮 # 布局 @@ -2728,7 +2879,7 @@ def parse_hotkey(input: UHotkeyLineEdit): default_doc_layout = QHBoxLayout() # 默认打开文档布局 default_doc_link = QLineEdit() # 默认打开文档链接 - default_doc_link.setText(settings.get('default_doc_link', 'https://xystudiocode.github.io/clickmouse_docs/{lang}')) + default_doc_link.setText(setting_value.default_doc_link) # 布局 default_doc_layout.addWidget(QLabel(get_lang('c2'))) # 默认打开文档提示 @@ -2737,7 +2888,7 @@ def parse_hotkey(input: UHotkeyLineEdit): default_lang_layout = QHBoxLayout() # 默认文档语言布局 lang_choice = QComboBox() # 语言选择框 lang_choice.addItems([get_lang('c3'), get_lang('c4')] + [i['lang_name'] for i in langs if i['supported']]) - lang_choice.setCurrentIndex(settings.get('lang_doc', 0)) + lang_choice.setCurrentIndex(setting_value.lang_doc) # 布局 default_lang_layout.addWidget(QLabel(get_lang('c5'))) # 默认文档语言提示 @@ -2746,7 +2897,7 @@ def parse_hotkey(input: UHotkeyLineEdit): uppdate_log_path_layout = QHBoxLayout() # 更新日志路径布局 uppdate_log_path_input = QLineEdit() # 更新日志路径输入框 - uppdate_log_path_input.setText(settings.get('update_log_path', 'updatelog')) + uppdate_log_path_input.setText(setting_value.update_log_path) # 布局 uppdate_log_path_layout.addWidget(QLabel(get_lang('c6'))) # 更新日志路径提示 @@ -2819,7 +2970,10 @@ def repair_settings(self, key: str): global settings if MessageBox.warning(self, get_lang('15'), get_lang('22'), MessageButtonTemplate.YESNO) != 2: # 不确认重置 return - del settings[key] + try: + del settings[key] + except KeyError: + pass save_settings(settings) self.window_restarted.emit() @@ -2828,8 +2982,6 @@ def repair_all_settings(self): if MessageBox.warning(self, get_lang('15'), get_lang('22'), MessageButtonTemplate.YESNO) != 2: # 不确认重置 return settings = {} - settings['theme'] = default_theme - settings['select_lang'] = system_lang save_settings(settings) self.app.setStyle(default_theme) self.values.update({'need_restart': True}) # values 用于存储需要重启后还原的内容 @@ -2955,7 +3107,7 @@ def __init__(self): logger.info('加载托盘程序') self.app = get_application_instance() - show_tray_icon = settings.get('show_tray_icon', True) + show_tray_icon = setting_value.show_tray_icon if show_tray_icon: self.app.setQuitOnLastWindowClosed(False) # 关闭窗口时不退出应用 @@ -3155,25 +3307,25 @@ def on_combination_pressed(self, combination): '''处理组合键事件''' combination = format_keys(combination, source=True) - if all_in_list(combination, parse_hotkey('fast_click', ['F', 'Ctrl', 'Alt'])): + if all_in_list(combination, setting_value.fast_click_hotkey): # 处理Ctrl+Alt+F组合键 if clicker.running: self.tray_icon.showMessage(get_lang('14'), get_lang('af'), QSystemTrayIcon.MessageIcon.Critical, 1000) else: self.show_window(fast_click_window) - elif all_in_list(combination, parse_hotkey('main_window', ['Ctrl', 'Alt', 'M'])): + elif all_in_list(combination, setting_value.main_window_hotkey): # 处理Ctrl+Alt+M组合键 self.show_window(main_window) if not main_window.isVisible(): main_window.is_start_from_tray = True - elif all_in_list(combination, parse_hotkey('click_attr', ['Ctrl', 'Alt', 'A'])): + elif all_in_list(combination, setting_value.click_attr_hotkey): # 处理Ctrl+Alt+A组合键 self.show_window(click_attr_window) - elif all_in_list(combination, parse_hotkey('left_click', ['F2'])): + elif all_in_list(combination, setting_value.left_click_hotkey): self.on_start_clicker_tray('left') # 左键 - elif all_in_list(combination, parse_hotkey('right_click', ['F3'])): + elif all_in_list(combination, setting_value.right_click_hotkey): self.on_start_clicker_tray('right') # 右键 - elif all_in_list(combination, parse_hotkey('pause_click', ['F4'])): + elif all_in_list(combination, setting_value.pause_click_hotkey): if clicker.running: clicker.pause_click() if clicker.paused: @@ -3182,7 +3334,7 @@ def on_combination_pressed(self, combination): self.tray_icon.showMessage(get_lang('6e'), get_lang('72'), QSystemTrayIcon.MessageIcon.Information, 1000) else: self.tray_icon.showMessage(get_lang('6e'), get_lang('74'), QSystemTrayIcon.MessageIcon.Warning, 1000) - elif all_in_list(combination, parse_hotkey('stop_click', ['F6'])): + elif all_in_list(combination, setting_value.stop_click_hotkey): if clicker.running: main_window.on_stop() self.tray_icon.showMessage(get_lang('6e'), get_lang('73'), QSystemTrayIcon.MessageIcon.Information, 1000) @@ -3303,8 +3455,11 @@ def on_start(self): logger.info('加载设置') settings = load_settings() + with open(get_resource_path('defaultsetting.json'), 'r', encoding='utf-8') as f: + default_settings: dict = json.load(f) logger.info('加载服务程序') + setting_value = SettingValue() clicker = Click() auto_start_manager = StartManager() color_getter = ColorGetter() @@ -3325,15 +3480,15 @@ def on_start(self): # 创建资源 update_cache = load_update_cache() - should_check_update_res = should_check_update() if settings.get('update_enabled', True) else False + should_check_update_res = should_check_update() if setting_value.update_enabled else False icon = get_icon('icon') - + settings_need_restart = False can_update = False # 单位控制 latest_index = 2 - select_lang = settings.get('select_lang', 0) + select_lang = setting_value.select_lang # 其他 dev_config = parse_dev.parse() # 开发者模式配置 @@ -3353,8 +3508,6 @@ def on_start(self): else: # 未知 default_theme = 'Fusion' - theme = settings.get('theme', default_theme) - logger.info('定义资源完成') logger.info('检查更新注册表') @@ -3385,5 +3538,5 @@ def on_start(self): set_import_extension_window = SetImportExtensionModeWindow() app = TrayApp() - app.app.setStyle(theme) + app.app.setStyle(setting_value.theme) app.run() \ No newline at end of file diff --git a/Gui/res/defaultsetting.json b/Gui/res/defaultsetting.json new file mode 100644 index 0000000..aff7a98 --- /dev/null +++ b/Gui/res/defaultsetting.json @@ -0,0 +1 @@ +{"select_lang": "!var system_lang", "show_tray_icon": true, "soft_delay": 100, "click_delay": "", "click_times": "", "delay_unit": 0, "times_unit": 0, "failed_use_default": false, "times_failed_use_default": false, "update_enabled": true, "update_notify": true, "quiet_update": false, "update_ok_notify": true, "update_frequency": 1, "select_style": 0, "use_windows_color": true, "theme": "!var default_theme", "left_click_hotkey": ["F2"], "right_click_hotkey": ["F3"], "pause_click_hotkey": ["F4"], "stop_click_hotkey": ["F6"], "click_attr_hotkey": ["Ctrl", "Alt", "A"], "fast_click_hotkey": ["Ctrl", "Alt", "F"], "main_window_hotkey": ["Ctrl", "Alt", "M"], "default_doc_link": "https://xystudiocode.github.io/clickmouse_docs/{lang}", "lang_doc": 0, "update_log_path": "updatelog"} \ No newline at end of file diff --git a/Gui/res/styles/dark.qss b/Gui/res/styles/dark.qss index 5b5b37f..618ceba 100644 --- a/Gui/res/styles/dark.qss +++ b/Gui/res/styles/dark.qss @@ -33,10 +33,6 @@ QComboBox:hover { background-color: #505050; } -QComboBox:pressed { - background-color: #353535; -} - QComboBox:disabled { background-color: #252525; color: #505050; diff --git a/Gui/res/styles/light.qss b/Gui/res/styles/light.qss index 21d71f5..e98707a 100644 --- a/Gui/res/styles/light.qss +++ b/Gui/res/styles/light.qss @@ -41,10 +41,6 @@ QComboBox:hover { background-color: lightgray; } -QComboBox:pressed { - background-color: gray; -} - QComboBox QAbstractItemView { background-color: white; } diff --git a/Gui/res/vars/cleancache.json b/Gui/res/vars/cleancache.json index 6723548..fa71c9c 100644 --- a/Gui/res/vars/cleancache.json +++ b/Gui/res/vars/cleancache.json @@ -4,7 +4,7 @@ " 2e" ], " 2f": [ - "update.json;update_log.md", + "update.json", " 30", 4, false diff --git a/Gui/res/versions.json b/Gui/res/versions.json index 9c0d6d9..0165816 100644 --- a/Gui/res/versions.json +++ b/Gui/res/versions.json @@ -1 +1 @@ -{"package_format_version": "1.2.0", "clickmouse":"3.2.0.19rc1"} +{"package_format_version": "1.2.0", "clickmouse":"3.2.0.19rc2"} diff --git a/Gui/tests/test_property_get.py b/Gui/tests/test_property_get.py new file mode 100644 index 0000000..50458d4 --- /dev/null +++ b/Gui/tests/test_property_get.py @@ -0,0 +1,12 @@ +class TestPropertyGet: + @property + def my_property(self): + return "Hello World" + +def test_property_get(): + obj = TestPropertyGet() + print(obj.my_property) + assert obj.my_property == "Hello World" + + print(getattr(obj, "my_property")) + assert getattr(obj, "my_property") == "Hello World" \ No newline at end of file From d0b5cee0394724b3a07911029bc48276b571b454 Mon Sep 17 00:00:00 2001 From: xystudio_u <173288240@qq.com> Date: Tue, 3 Mar 2026 21:54:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=83docs(issue=5Ftemplate):?= =?UTF-8?q?=E4=BF=AE=E6=94=B9issue=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改issue模板 --- .github/ISSUE_TEMPLATE/SPA.yml | 51 ++++++++++++++++++++++++++++++ .github/ISSUE_TEMPLATE/bug.yml | 1 + .github/ISSUE_TEMPLATE/feature.yml | 1 + .github/ISSUE_TEMPLATE/tasks.yml | 1 + 4 files changed, 54 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/SPA.yml diff --git a/.github/ISSUE_TEMPLATE/SPA.yml b/.github/ISSUE_TEMPLATE/SPA.yml new file mode 100644 index 0000000..ef9b93f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/SPA.yml @@ -0,0 +1,51 @@ +name: 🗒️新的标准立项 +description: 将会建议、建立或修改一个标准。 +title: "🗒️[SPA]" +labels: enhancement +type: Feature +body: + - type: markdown + attributes: + value: | + > [!NOTE] + > 为避免造成更多的麻烦,请在报告issue前,先检查是否有其他人已经报告过相同的立项。[检查是否存在重复](https://github.com/xystudiocode/pyclickmouse/issues)😊 + + > [!IMPORTANT] + > 我们不会在gitee上处理issue,请使用github发布。🙋‍♂️ + - type: textarea + attributes: + label: 🧾新增的立项 + placeholder: | + 请在这里输入立项内容。。。 + description: 🧾请详细描述你想要立项的标准。 + validations: + required: true + - type: input + attributes: + label: ℹ️立项施行的clickmouse版本 + placeholder: | + >=X.X.X 或 >=X.X.X.X + description: 🔠反馈大于等于一个三位或四位版本号 + value: | + 下一个clickmouse正式版 + validations: + required: false + - type: textarea + attributes: + label: ❓需要这些功能的原因 + placeholder: | + 解决了什么问题? + 增加了什么功能? + 改进了什么? + 其他原因... + description: ❓为什么需要这个功能? + validations: + required: false + - type: textarea + attributes: + label: ➕其他相关信息 + description: ✉️你了解到的更多内容 + placeholder: | + 更多信息。 + validations: + required: false \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 9afb342..8c52125 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -56,6 +56,7 @@ body: - ⤴️安装更新 - 💠其他扩展 - ♻️清理缓存 + - 🏳️‍🌈主题/样式 - 📄文档 - ❓其他/未知 validations: diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml index d2b8567..3ef203d 100644 --- a/.github/ISSUE_TEMPLATE/feature.yml +++ b/.github/ISSUE_TEMPLATE/feature.yml @@ -37,6 +37,7 @@ body: - 💠其他扩展 - ♻️清理缓存 - 📄文档 + - 🏳️‍🌈主题/样式 - ❓其他/未知 validations: required: true diff --git a/.github/ISSUE_TEMPLATE/tasks.yml b/.github/ISSUE_TEMPLATE/tasks.yml index 7c6eee5..7b6269c 100644 --- a/.github/ISSUE_TEMPLATE/tasks.yml +++ b/.github/ISSUE_TEMPLATE/tasks.yml @@ -34,6 +34,7 @@ body: - 💠其他扩展 - ♻️清理缓存 - 📄文档 + - 🏳️‍🌈主题/样式 - ❓其他/未知 validations: required: true