[Add] Add about dialog
This commit is contained in:
parent
1eb26d6151
commit
a89cba984d
@ -3,6 +3,7 @@ Implements main window of VN Trader.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from typing import Callable
|
||||||
|
|
||||||
from PyQt5 import QtWidgets, QtCore, QtGui
|
from PyQt5 import QtWidgets, QtCore, QtGui
|
||||||
|
|
||||||
@ -19,7 +20,8 @@ from .widget import (
|
|||||||
ConnectDialog,
|
ConnectDialog,
|
||||||
TradingWidget,
|
TradingWidget,
|
||||||
ActiveOrderMonitor,
|
ActiveOrderMonitor,
|
||||||
ContractManager
|
ContractManager,
|
||||||
|
AboutDialog
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -70,23 +72,48 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
gateway_names = self.main_engine.get_all_gateway_names()
|
gateway_names = self.main_engine.get_all_gateway_names()
|
||||||
for name in gateway_names:
|
for name in gateway_names:
|
||||||
func = partial(self.connect, name)
|
func = partial(self.connect, name)
|
||||||
icon = QtGui.QIcon(get_icon_path(__file__, "connect.ico"))
|
self.add_menu_action(sys_menu, f"连接{name}", "connect.ico", func)
|
||||||
|
|
||||||
action = QtWidgets.QAction(f"连接{name}", self)
|
sys_menu.addSeparator()
|
||||||
action.triggered.connect(func)
|
|
||||||
action.setIcon(icon)
|
|
||||||
|
|
||||||
sys_menu.addAction(action)
|
self.add_menu_action(sys_menu, "退出", "exit.ico", self.close)
|
||||||
|
|
||||||
# App menu
|
# App menu
|
||||||
|
|
||||||
# Help menu
|
# Help menu
|
||||||
contract_action = QtWidgets.QAction("查询合约", self)
|
self.add_menu_action(
|
||||||
contract_action.triggered.connect(self.open_contract)
|
help_menu,
|
||||||
contract_icon = QtGui.QIcon(get_icon_path(__file__, "contract.ico"))
|
"查询合约",
|
||||||
contract_action.setIcon(contract_icon)
|
"contract.ico",
|
||||||
|
partial(self.open_widget,
|
||||||
|
ContractManager,
|
||||||
|
"contract")
|
||||||
|
)
|
||||||
|
|
||||||
help_menu.addAction(contract_action)
|
self.add_menu_action(
|
||||||
|
help_menu,
|
||||||
|
"关于",
|
||||||
|
"about.ico",
|
||||||
|
partial(self.open_widget,
|
||||||
|
AboutDialog,
|
||||||
|
"about")
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_menu_action(
|
||||||
|
self,
|
||||||
|
menu: QtWidgets.QMenu,
|
||||||
|
action_name: str,
|
||||||
|
icon_name: str,
|
||||||
|
func: Callable
|
||||||
|
):
|
||||||
|
""""""
|
||||||
|
icon = QtGui.QIcon(get_icon_path(__file__, icon_name))
|
||||||
|
|
||||||
|
action = QtWidgets.QAction(action_name, self)
|
||||||
|
action.triggered.connect(func)
|
||||||
|
action.setIcon(icon)
|
||||||
|
|
||||||
|
menu.addAction(action)
|
||||||
|
|
||||||
def create_dock(
|
def create_dock(
|
||||||
self,
|
self,
|
||||||
@ -138,12 +165,16 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
else:
|
else:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
|
|
||||||
def open_contract(self):
|
def open_widget(self, widget_class: QtWidgets.QWidget, name: str):
|
||||||
"""
|
"""
|
||||||
Open contract manager.
|
Open contract manager.
|
||||||
"""
|
"""
|
||||||
widget = self.widgets.get("contract", None)
|
widget = self.widgets.get(name, None)
|
||||||
if not widget:
|
if not widget:
|
||||||
widget = ContractManager(self.main_engine, self.event_engine)
|
widget = widget_class(self.main_engine, self.event_engine)
|
||||||
self.widgets["contract"] = widget
|
self.widgets[name] = widget
|
||||||
widget.show()
|
|
||||||
|
if isinstance(widget, QtWidgets.QDialog):
|
||||||
|
widget.exec()
|
||||||
|
else:
|
||||||
|
widget.show()
|
||||||
|
@ -1061,3 +1061,38 @@ class ContractManager(QtWidgets.QWidget):
|
|||||||
|
|
||||||
self.contract_table.resizeColumnsToContents()
|
self.contract_table.resizeColumnsToContents()
|
||||||
|
|
||||||
|
|
||||||
|
class AboutDialog(QtWidgets.QDialog):
|
||||||
|
"""
|
||||||
|
About VN Trader.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, main_engine: MainEngine, event_engine: EventEngine):
|
||||||
|
""""""
|
||||||
|
super(AboutDialog, self).__init__()
|
||||||
|
|
||||||
|
self.main_engine = main_engine
|
||||||
|
self.event_engine = event_engine
|
||||||
|
|
||||||
|
self.init_ui()
|
||||||
|
|
||||||
|
def init_ui(self):
|
||||||
|
""""""
|
||||||
|
self.setWindowTitle(f"关于VN Trader")
|
||||||
|
|
||||||
|
text = """
|
||||||
|
Developed by Traders, for Traders.
|
||||||
|
License:MIT
|
||||||
|
|
||||||
|
Website:www.vnpy.com
|
||||||
|
Github:www.github.com/vnpy/vnpy
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
label = QtWidgets.QLabel()
|
||||||
|
label.setText(text)
|
||||||
|
label.setMinimumWidth(500)
|
||||||
|
|
||||||
|
vbox = QtWidgets.QVBoxLayout()
|
||||||
|
vbox.addWidget(label)
|
||||||
|
self.setLayout(vbox)
|
||||||
|
Loading…
Reference in New Issue
Block a user