From 70adba7637b051a59a83e31a2503f9f8c7dbd628 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 11 Apr 2019 00:43:46 -0400 Subject: [PATCH 1/2] =?UTF-8?q?[Mod]=20=E6=94=B9=E5=8F=98Singleton?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/engine.py | 4 +--- vnpy/trader/utility.py | 7 ++++--- 2 files changed, 5 insertions(+), 6 deletions(-) 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/utility.py b/vnpy/trader/utility.py index 9951e1f1..c221277a 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 = {} From 95df49c54c7aefee9c49dee9ae234000c24345f0 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 11 Apr 2019 00:45:15 -0400 Subject: [PATCH 2/2] =?UTF-8?q?[Mod]=20=E6=94=B9=E5=8F=98=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0=E7=9A=84=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/ui/mainwindow.py | 4 ++-- vnpy/trader/utility.py | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) 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 c221277a..6f023259 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -31,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. """ @@ -54,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 @@ -395,5 +395,3 @@ def virtual(func: "callable"): that can be (re)implemented by subclasses. """ return func - -