diff --git a/tests/trader/run.py b/tests/trader/run.py index f6240f53..9fa44e5f 100644 --- a/tests/trader/run.py +++ b/tests/trader/run.py @@ -15,9 +15,6 @@ def main(): main_window = MainWindow(main_engine, event_engine) main_window.showMaximized() - monitor = TickMonitor(main_engine, event_engine) - monitor.show() - qapp.exec() diff --git a/vnpy/trader/engine.py b/vnpy/trader/engine.py index 7c67863e..135a3fd6 100644 --- a/vnpy/trader/engine.py +++ b/vnpy/trader/engine.py @@ -4,6 +4,7 @@ import logging from datetime import datetime from abc import ABC +from typing import Any from vnpy.event import EventEngine, Event @@ -22,23 +23,6 @@ from .setting import SETTINGS from .gateway import BaseGateway -class BaseEngine(ABC): - """ - Abstract class for implementing an function engine. - """ - - def __init__( - self, - main_engine: MainEngine, - event_engine: EventEngine, - engine_name: str - ): - """""" - self.main_engine = main_engine - self.event_engine = event_engine - self.engine_name = engine_name - - class MainEngine: """ Acts as the core of VN Trader. @@ -58,7 +42,7 @@ class MainEngine: self.init_engines() - def add_engine(self, engine_class: BaseEngine): + def add_engine(self, engine_class: Any): """ Add function engine. """ @@ -149,6 +133,23 @@ class MainEngine: self.event_engine.stop() +class BaseEngine(ABC): + """ + Abstract class for implementing an function engine. + """ + + def __init__( + self, + main_engine: MainEngine, + event_engine: EventEngine, + engine_name: str + ): + """""" + self.main_engine = main_engine + self.event_engine = event_engine + self.engine_name = engine_name + + class LogEngine(BaseEngine): """ Processes log event and output with logging module. @@ -227,7 +228,7 @@ class OmsEngine(BaseEngine): def __init__(self, main_engine: MainEngine, event_engine: EventEngine): """""" - super(OmsEngine, self).__init__(main_engine, event_engine, oms) + super(OmsEngine, self).__init__(main_engine, event_engine, "oms") self.ticks = {} self.orders = {} diff --git a/vnpy/trader/gateway.py b/vnpy/trader/gateway.py index 56711bef..5acb74ed 100644 --- a/vnpy/trader/gateway.py +++ b/vnpy/trader/gateway.py @@ -3,6 +3,7 @@ """ from abc import ABC, abstractmethod +from typing import Any from vnpy.event import EventEngine, Event diff --git a/vnpy/trader/ui/__init__.py b/vnpy/trader/ui/__init__.py index 6bf350d0..6872f76e 100644 --- a/vnpy/trader/ui/__init__.py +++ b/vnpy/trader/ui/__init__.py @@ -1,5 +1,6 @@ import platform import ctypes +from pathlib import Path import qdarkstyle from PyQt5 import QtWidgets, QtGui @@ -7,6 +8,7 @@ from PyQt5 import QtWidgets, QtGui from .mainwindow import MainWindow from ..setting import SETTINGS + def create_qapp(): """ Create Qt Application. @@ -17,8 +19,14 @@ def create_qapp(): font = QtGui.QFont(SETTINGS["font.family"], SETTINGS["font.size"]) qapp.setFont(font) + ui_path = Path(__file__).parent + icon_path = ui_path.joinpath("ico", "vnpy.ico") + icon = QtGui.QIcon(str(icon_path)) + qapp.setWindowIcon(icon) + if 'Windows' in platform.uname(): ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( - 'VN Trader') + 'VN Trader' + ) return qapp \ No newline at end of file diff --git a/vnpy/trader/ui/ico/about.ico b/vnpy/trader/ui/ico/about.ico new file mode 100644 index 00000000..10686551 Binary files /dev/null and b/vnpy/trader/ui/ico/about.ico differ diff --git a/vnpy/trader/ui/ico/connect.ico b/vnpy/trader/ui/ico/connect.ico new file mode 100644 index 00000000..ad638cb4 Binary files /dev/null and b/vnpy/trader/ui/ico/connect.ico differ diff --git a/vnpy/trader/ui/ico/contract.ico b/vnpy/trader/ui/ico/contract.ico new file mode 100644 index 00000000..3f4142a2 Binary files /dev/null and b/vnpy/trader/ui/ico/contract.ico differ diff --git a/vnpy/trader/ui/ico/database.ico b/vnpy/trader/ui/ico/database.ico new file mode 100644 index 00000000..6ad2845e Binary files /dev/null and b/vnpy/trader/ui/ico/database.ico differ diff --git a/vnpy/trader/ui/ico/editor.ico b/vnpy/trader/ui/ico/editor.ico new file mode 100644 index 00000000..e5227376 Binary files /dev/null and b/vnpy/trader/ui/ico/editor.ico differ diff --git a/vnpy/trader/ui/ico/exit.ico b/vnpy/trader/ui/ico/exit.ico new file mode 100644 index 00000000..1ca8be52 Binary files /dev/null and b/vnpy/trader/ui/ico/exit.ico differ diff --git a/vnpy/trader/ui/ico/restore.ico b/vnpy/trader/ui/ico/restore.ico new file mode 100644 index 00000000..be9c6175 Binary files /dev/null and b/vnpy/trader/ui/ico/restore.ico differ diff --git a/vnpy/trader/ui/ico/test.ico b/vnpy/trader/ui/ico/test.ico new file mode 100644 index 00000000..d0492b12 Binary files /dev/null and b/vnpy/trader/ui/ico/test.ico differ diff --git a/vnpy/trader/ui/ico/vnpy.ico b/vnpy/trader/ui/ico/vnpy.ico new file mode 100644 index 00000000..f5146d56 Binary files /dev/null and b/vnpy/trader/ui/ico/vnpy.ico differ diff --git a/vnpy/trader/ui/mainwindow.py b/vnpy/trader/ui/mainwindow.py index dd0f5dbb..28558798 100644 --- a/vnpy/trader/ui/mainwindow.py +++ b/vnpy/trader/ui/mainwindow.py @@ -1,7 +1,15 @@ -from PyQt5 import QtWidgets +from PyQt5 import QtWidgets, QtCore from vnpy.event import EventEngine from ..engine import MainEngine +from .widget import ( + TickMonitor, + OrderMonitor, + TradeMonitor, + PositionMonitor, + AccountMonitor, + LogMonitor +) class MainWindow(QtWidgets.QMainWindow): @@ -15,12 +23,43 @@ class MainWindow(QtWidgets.QMainWindow): self.main_engine = main_engine self.event_engine = event_engine + self.widgets = {} + self.init_ui() def init_ui(self): """""" self.setWindowTitle("VN Trader") + self.init_dock() + self.init_menu() - def register_event(self): + def init_dock(self): """""" - pass \ No newline at end of file + tick_widget, tick_dock = self.create_dock(TickMonitor, "行情", QtCore.Qt.RightDockWidgetArea) + order_widget, order_dock = self.create_dock(OrderMonitor, "委托", QtCore.Qt.RightDockWidgetArea) + trade_widget, trade_dock = self.create_dock(TradeMonitor, "成交", QtCore.Qt.RightDockWidgetArea) + log_widget, log_dock = self.create_dock(LogMonitor, "日志", QtCore.Qt.BottomDockWidgetArea) + account_widget, account_dock = self.create_dock(AccountMonitor, "资金", QtCore.Qt.BottomDockWidgetArea) + position_widget, position_dock = self.create_dock(PositionMonitor, "持仓", QtCore.Qt.BottomDockWidgetArea) + + def init_menu(self): + """""" + pass + + def create_dock( + self, + widget_class: QtWidgets.QWidget, + name: str, + area: int + ): + """ + Initialize a dock widget. + """ + widget = widget_class(self.main_engine, self.event_engine) + + dock = QtWidgets.QDockWidget(name) + dock.setWidget(widget) + dock.setObjectName(name) + dock.setFeatures(dock.DockWidgetFloatable | dock.DockWidgetMovable) + self.addDockWidget(area, dock) + return widget, dock \ No newline at end of file diff --git a/vnpy/trader/ui/widget.py b/vnpy/trader/ui/widget.py index b692a038..ae802ba2 100644 --- a/vnpy/trader/ui/widget.py +++ b/vnpy/trader/ui/widget.py @@ -581,5 +581,10 @@ class AccountMonitor(BaseMonitor): 'display': '可用', 'cell': BaseCell, 'update': True + }, + 'gateway_name': { + 'display': '接口', + 'cell': BaseCell, + 'update': False } } diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index fdeb8374..0cb9a7cf 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -50,4 +50,4 @@ def check_order_active(status: str): if status in ACTIVE_STATUSES: return True else: - return False \ No newline at end of file + return False