diff --git a/vnpy/trader/engine.py b/vnpy/trader/engine.py index a2e098ee..af136dab 100644 --- a/vnpy/trader/engine.py +++ b/vnpy/trader/engine.py @@ -197,13 +197,11 @@ class BaseEngine(ABC): pass -class LogEngine(BaseEngine): +class LogEngine(BaseEngine, metaclass=Singleton): """ Processes log event and output with logging module. """ - __metaclass__ = Singleton - def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" super(LogEngine, self).__init__(main_engine, event_engine, "log") diff --git a/vnpy/trader/ui/mainwindow.py b/vnpy/trader/ui/mainwindow.py index d8c6280b..b1972f42 100644 --- a/vnpy/trader/ui/mainwindow.py +++ b/vnpy/trader/ui/mainwindow.py @@ -24,7 +24,7 @@ from .widget import ( AboutDialog, ) from ..engine import MainEngine -from ..utility import get_icon_path, TRADER_PATH +from ..utility import get_icon_path, TRADER_DIR class MainWindow(QtWidgets.QMainWindow): @@ -38,7 +38,7 @@ class MainWindow(QtWidgets.QMainWindow): self.main_engine = main_engine self.event_engine = event_engine - self.window_title = f"VN Trader [{TRADER_PATH}]" + self.window_title = f"VN Trader [{TRADER_DIR}]" self.connect_dialogs = {} self.widgets = {} diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index 89c412a1..6f023259 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -14,10 +14,11 @@ from .object import BarData, TickData class Singleton(type): """ - Singleton metaclass, + Singleton metaclass, - class A: - __metaclass__ = Singleton + usage: + class A(metaclass=Singleton): + ... """ _instances = {} @@ -30,7 +31,7 @@ class Singleton(type): return cls._instances[cls] -def get_path(temp_name: str): +def _get_trader_dir(temp_name: str): """ Get path where trader is running in. """ @@ -53,21 +54,21 @@ def get_path(temp_name: str): return home_path, temp_path -TRADER_PATH, TEMP_PATH = get_path(".vntrader") +TRADER_DIR, TEMP_DIR = _get_trader_dir(".vntrader") def get_file_path(filename: str): """ Get path for temp file with filename. """ - return TEMP_PATH.joinpath(filename) + return TEMP_DIR.joinpath(filename) def get_folder_path(folder_name: str): """ Get path for temp folder with folder name. """ - folder_path = TEMP_PATH.joinpath(folder_name) + folder_path = TEMP_DIR.joinpath(folder_name) if not folder_path.exists(): folder_path.mkdir() return folder_path