[Add] Add monitor into mainwindow

This commit is contained in:
vn.py 2019-01-09 22:36:48 +08:00
parent 712fad6288
commit 84eaeb8733
16 changed files with 78 additions and 27 deletions

View File

@ -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()

View File

@ -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 = {}

View File

@ -3,6 +3,7 @@
"""
from abc import ABC, abstractmethod
from typing import Any
from vnpy.event import EventEngine, Event

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
vnpy/trader/ui/ico/exit.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
vnpy/trader/ui/ico/test.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
vnpy/trader/ui/ico/vnpy.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

View File

@ -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
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

View File

@ -581,5 +581,10 @@ class AccountMonitor(BaseMonitor):
'display': '可用',
'cell': BaseCell,
'update': True
},
'gateway_name': {
'display': '接口',
'cell': BaseCell,
'update': False
}
}

View File

@ -50,4 +50,4 @@ def check_order_active(status: str):
if status in ACTIVE_STATUSES:
return True
else:
return False
return False