From 92c5fa0dfbaa2c224ea87ed4803d09af2a769c96 Mon Sep 17 00:00:00 2001 From: KenanZhu <3471685733@qq.com> Date: Fri, 26 Jun 2026 09:16:23 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=B8=8E=E5=AF=BC=E5=85=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/MsgBase.py | 4 ++-- src/boot/AppInitializer.py | 3 ++- src/gui/ALMainWindow.py | 10 +++----- src/managers/bulletin/BulletinManager.py | 18 +++++++------- src/managers/config/ConfigManager.py | 8 +++---- src/managers/log/LogManager.py | 5 ---- src/managers/theme/ThemeManager.py | 30 ++++++++++++++---------- 7 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/base/MsgBase.py b/src/base/MsgBase.py index 68c9ae0..7e10ebf 100644 --- a/src/base/MsgBase.py +++ b/src/base/MsgBase.py @@ -11,7 +11,7 @@ import logging import queue import datetime -import managers.log.LogManager as LogManager +from managers.log.LogManager import getLogger class MsgBase: @@ -54,7 +54,7 @@ class MsgBase: self._input_queue = input_queue self._output_queue = output_queue try: - self._logger = LogManager.getLogger(self._class_name) + self._logger = getLogger(self._class_name) except RuntimeError: self._logger = None diff --git a/src/boot/AppInitializer.py b/src/boot/AppInitializer.py index 039a163..365df4c 100644 --- a/src/boot/AppInitializer.py +++ b/src/boot/AppInitializer.py @@ -73,6 +73,8 @@ def _initializeWebDriverManager( def _initializeAppearance( ): + logger = logInstance().getLogger("AppInitializer") + app = QApplication.instance() if not app: return @@ -82,7 +84,6 @@ def _initializeAppearance( saved_custom_theme = cfg.get(CfgKey.GLOBAL.APPEARANCE.CUSTOM_THEME, "") app.setStyle(saved_style) setActiveStyle(saved_style) - logger = logInstance().getLogger("AppInitializer") if saved_custom_theme: try: themeInstance().applyTheme(saved_custom_theme) diff --git a/src/gui/ALMainWindow.py b/src/gui/ALMainWindow.py index 6de44dc..1cf0587 100644 --- a/src/gui/ALMainWindow.py +++ b/src/gui/ALMainWindow.py @@ -77,11 +77,9 @@ class ALMainWindow(MsgBase, QMainWindow, Ui_ALMainWindow): self.connectSignals() self.startMsgPolling() self.startTimerTaskPolling() - self.__bulletin_poller.start() if bulletinInstance().autoFetch(): QTimer.singleShot(1000, self.__bulletin_poller.fetchNow) - self._showLog("主窗口初始化完成") def modifyUi( @@ -182,9 +180,7 @@ class ALMainWindow(MsgBase, QMainWindow, Ui_ALMainWindow): self.StopButton.clicked.connect(self.onStopButtonClicked) self.SendButton.clicked.connect(self.onSendButtonClicked) self.MessageEdit.returnPressed.connect(self.onSendButtonClicked) - self.__bulletin_poller.newBulletinsDetected.connect( - self._onBulletinPollerNewBulletins - ) + self.__bulletin_poller.newBulletinsDetected.connect(self.onBulletinPollerNewBulletins) def closeEvent( self, @@ -365,12 +361,12 @@ class ALMainWindow(MsgBase, QMainWindow, Ui_ALMainWindow): self.__bulletin_poller.setDialogOpen(False) @Slot(int) - def _onBulletinPollerNewBulletins( + def onBulletinPollerNewBulletins( self, count: int ): - if not hasattr(self, 'TrayIcon'): + if not hasattr(self, "TrayIcon"): return self.TrayIcon.showMessage( "公告栏 - AutoLibrary", diff --git a/src/managers/bulletin/BulletinManager.py b/src/managers/bulletin/BulletinManager.py index 49a75c2..dba14bb 100644 --- a/src/managers/bulletin/BulletinManager.py +++ b/src/managers/bulletin/BulletinManager.py @@ -223,24 +223,24 @@ class BulletinManager: try: if self.isFirstSync(): start_date = now - timedelta(days=7) - range_hour = str(24 * 8) + range_hour = str(24*8) elif self.shouldFullSync(): with self.__lock: bulletins = self.bulletins() earliest = min(bulletins, key=self._parseBulletinDateTime) start_date = self._parseBulletinDateTime(earliest) diff = now - start_date - range_hour = str(int(diff.total_seconds() / 3600) + 1) + range_hour = str(int(diff.total_seconds()/3600) + 1) else: with self.__lock: bulletins = self.bulletins() latest = max(bulletins, key=self._parseBulletinDateTime) start_date = self._parseBulletinDateTime(latest) diff = now - start_date - range_hour = str(int(diff.total_seconds() / 3600) + 1) + range_hour = str(int(diff.total_seconds()/3600) + 1) except (ValueError, TypeError, KeyError): start_date = now - timedelta(days=7) - range_hour = str(24 * 8) + range_hour = str(24*8) return { "date": start_date.strftime("%Y-%m-%d"), @@ -256,9 +256,10 @@ class BulletinManager: """ Merge incoming bulletins into the cache. - New bulletins are added with isNew=True. Existing bulletins - keep their current isNew state. Entries listed in delete_ids - are removed. Bulletins missing an "id" field are skipped. + - New bulletins are added with isNew=True. + - Existing bulletins keep their current isNew state. + - Entries listed in delete_ids are removed. + - Bulletins missing an "id" field are skipped. Args: new_bulletins (list[dict]): Incoming bulletin list. @@ -275,7 +276,6 @@ class BulletinManager: bid = b.get("id") if bid is not None: bulletins_dict[str(bid)] = b - for bulletin in new_bulletins: bid = bulletin.get("id") if bid is None: @@ -290,10 +290,8 @@ class BulletinManager: else bulletins_dict[bid].get("isNew", True) ) bulletins_dict[bid] = bulletin - for bid in delete_set: bulletins_dict.pop(bid, None) - result = list(bulletins_dict.values()) result.sort(key=lambda x: str(x.get("id", ""))) self.setBulletins(result) diff --git a/src/managers/config/ConfigManager.py b/src/managers/config/ConfigManager.py index c26b7bf..0b152e1 100644 --- a/src/managers/config/ConfigManager.py +++ b/src/managers/config/ConfigManager.py @@ -18,7 +18,7 @@ from interfaces.ConfigProvider import ConfigType, ConfigPath # This config manager class only responsible for global and other -# unconfigurable config files. +# config files. NOT include run and user config files. class ConfigTemplate: @@ -87,8 +87,8 @@ class ConfigManager: ): self.__config_dir = os.path.abspath(config_dir) - self.__config_lock = threading.Lock() self.__config_data = {} + self.__lock = threading.Lock() self.initialize() @@ -121,7 +121,7 @@ class ConfigManager: default: Optional[Any] = None ) -> Any: - with self.__config_lock: + with self.__lock: config_data = self.__config_data[key.config_type.value] if key.key == "": return config_data @@ -138,7 +138,7 @@ class ConfigManager: value: Any = None ): - with self.__config_lock: + with self.__lock: root_data = self.__config_data[key.config_type.value] if key.key == "": self.__config_data[key.config_type.value] = value diff --git a/src/managers/log/LogManager.py b/src/managers/log/LogManager.py index 767a951..8e5b075 100644 --- a/src/managers/log/LogManager.py +++ b/src/managers/log/LogManager.py @@ -99,17 +99,14 @@ class LogManager: self.__logger = logging.getLogger("AutoLibrary") self.__logger.setLevel(logging.DEBUG) self.__logger.handlers.clear() - formatter = CallerInfoFormatter( '[%(asctime)s] - [%(name)s] - [%(levelname)s] - [%(filename)s:%(lineno)s] - %(message)s', datefmt='%Y-%m-%d %H:%M:%S' ) - console_handler = logging.StreamHandler() console_handler.setLevel(logging.INFO) console_handler.setFormatter(formatter) self.__logger.addHandler(console_handler) - all_log_file = os.path.join(self.__log_dir, "all.log") file_handler_all = TimedRotatingFileHandler( all_log_file, @@ -122,7 +119,6 @@ class LogManager: file_handler_all.setLevel(logging.DEBUG) file_handler_all.setFormatter(formatter) self.__logger.addHandler(file_handler_all) - error_log_file = os.path.join(self.__log_dir, "error.log") file_handler_error = TimedRotatingFileHandler( error_log_file, @@ -135,7 +131,6 @@ class LogManager: file_handler_error.setLevel(logging.ERROR) file_handler_error.setFormatter(formatter) self.__logger.addHandler(file_handler_error) - self.__initialized = True def getLogger( diff --git a/src/managers/theme/ThemeManager.py b/src/managers/theme/ThemeManager.py index 755c67b..957fb45 100644 --- a/src/managers/theme/ThemeManager.py +++ b/src/managers/theme/ThemeManager.py @@ -28,6 +28,8 @@ from utils.ThemeUtils import ( ) +# we use Fusion as the default active style name +# because it's cross-platform. _active_style_name = "Fusion" @@ -61,8 +63,10 @@ class ThemeManager: ): self.__themes_dir = os.path.abspath(themes_dir) - self.__lock = threading.Lock() self.__current_theme_name = "" + self.__lock = threading.Lock() + + # directory must exist os.makedirs(self.__themes_dir, exist_ok=True) @staticmethod @@ -144,18 +148,6 @@ class ThemeManager: ) return alt_path - def themesDir( - self - ) -> str: - """ - Get the themes directory path. - - Returns: - str: The absolute path to the themes storage directory. - """ - - return self.__themes_dir - def importTheme( self, source_path: str @@ -321,6 +313,18 @@ class ThemeManager: ) app.setStyle(QStyleFactory.create(_active_style_name)) + def themesDir( + self + ) -> str: + """ + Get the themes directory path. + + Returns: + str: The absolute path to the themes storage directory. + """ + + return self.__themes_dir + # ThemeManager singleton instance. _theme_manager_instance = None