修改部分实现,用于兼容Client-Server架构
This commit is contained in:
parent
106985695d
commit
2470a321f0
@ -70,6 +70,9 @@ class EventEngine(object):
|
||||
# 其中每个键对应的值是一个列表,列表中保存了对该事件进行监听的函数功能
|
||||
self.__handlers = defaultdict(list)
|
||||
|
||||
# __generalHandlers是一个列表,用来保存通用回调函数(所有事件均调用)
|
||||
self.__generalHandlers = []
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __run(self):
|
||||
"""引擎运行"""
|
||||
@ -90,7 +93,11 @@ class EventEngine(object):
|
||||
|
||||
# 以上语句为Python列表解析方式的写法,对应的常规循环写法为:
|
||||
#for handler in self.__handlers[event.type_]:
|
||||
#handler(event)
|
||||
#handler(event)
|
||||
|
||||
# 调用通用处理函数进行处理
|
||||
if self.__generalHandlers:
|
||||
[handler(event) for handler in self.__generalHandlers]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __onTimer(self):
|
||||
@ -153,6 +160,19 @@ class EventEngine(object):
|
||||
def put(self, event):
|
||||
"""向事件队列中存入事件"""
|
||||
self.__queue.put(event)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def registerGeneralHandler(self, handler):
|
||||
"""注册通用事件处理函数监听"""
|
||||
if handler not in self.__generalHandlers:
|
||||
self.__generalHandlers.append(handler)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def unregisterGeneralHandler(self, handler):
|
||||
"""注销通用事件处理函数监听"""
|
||||
if handler in self.__generalHandlers:
|
||||
self.__generalHandlers.remove(handler)
|
||||
|
||||
|
||||
|
||||
########################################################################
|
||||
@ -182,6 +202,9 @@ class EventEngine2(object):
|
||||
# 其中每个键对应的值是一个列表,列表中保存了对该事件进行监听的函数功能
|
||||
self.__handlers = defaultdict(list)
|
||||
|
||||
# __generalHandlers是一个列表,用来保存通用回调函数(所有事件均调用)
|
||||
self.__generalHandlers = []
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __run(self):
|
||||
"""引擎运行"""
|
||||
@ -202,7 +225,11 @@ class EventEngine2(object):
|
||||
|
||||
# 以上语句为Python列表解析方式的写法,对应的常规循环写法为:
|
||||
#for handler in self.__handlers[event.type_]:
|
||||
#handler(event)
|
||||
#handler(event)
|
||||
|
||||
# 调用通用处理函数进行处理
|
||||
if self.__generalHandlers:
|
||||
[handler(event) for handler in self.__generalHandlers]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __runTimer(self):
|
||||
@ -272,6 +299,18 @@ class EventEngine2(object):
|
||||
"""向事件队列中存入事件"""
|
||||
self.__queue.put(event)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def registerGeneralHandler(self, handler):
|
||||
"""注册通用事件处理函数监听"""
|
||||
if handler not in self.__generalHandlers:
|
||||
self.__generalHandlers.append(handler)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def unregisterGeneralHandler(self, handler):
|
||||
"""注销通用事件处理函数监听"""
|
||||
if handler in self.__generalHandlers:
|
||||
self.__generalHandlers.remove(handler)
|
||||
|
||||
|
||||
########################################################################
|
||||
class Event:
|
||||
@ -297,7 +336,8 @@ def test():
|
||||
app = QCoreApplication(sys.argv)
|
||||
|
||||
ee = EventEngine2()
|
||||
ee.register(EVENT_TIMER, simpletest)
|
||||
#ee.register(EVENT_TIMER, simpletest)
|
||||
ee.registerGeneralHandler(simpletest)
|
||||
ee.start()
|
||||
|
||||
app.exec_()
|
||||
|
@ -70,6 +70,9 @@ class EventEngine(object):
|
||||
# 其中每个键对应的值是一个列表,列表中保存了对该事件进行监听的函数功能
|
||||
self.__handlers = defaultdict(list)
|
||||
|
||||
# __generalHandlers是一个列表,用来保存通用回调函数(所有事件均调用)
|
||||
self.__generalHandlers = []
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __run(self):
|
||||
"""引擎运行"""
|
||||
@ -90,7 +93,11 @@ class EventEngine(object):
|
||||
|
||||
# 以上语句为Python列表解析方式的写法,对应的常规循环写法为:
|
||||
#for handler in self.__handlers[event.type_]:
|
||||
#handler(event)
|
||||
#handler(event)
|
||||
|
||||
# 调用通用处理函数进行处理
|
||||
if self.__generalHandlers:
|
||||
[handler(event) for handler in self.__generalHandlers]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __onTimer(self):
|
||||
@ -153,6 +160,19 @@ class EventEngine(object):
|
||||
def put(self, event):
|
||||
"""向事件队列中存入事件"""
|
||||
self.__queue.put(event)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def registerGeneralHandler(self, handler):
|
||||
"""注册通用事件处理函数监听"""
|
||||
if handler not in self.__generalHandlers:
|
||||
self.__generalHandlers.append(handler)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def unregisterGeneralHandler(self, handler):
|
||||
"""注销通用事件处理函数监听"""
|
||||
if handler in self.__generalHandlers:
|
||||
self.__generalHandlers.remove(handler)
|
||||
|
||||
|
||||
|
||||
########################################################################
|
||||
@ -182,6 +202,9 @@ class EventEngine2(object):
|
||||
# 其中每个键对应的值是一个列表,列表中保存了对该事件进行监听的函数功能
|
||||
self.__handlers = defaultdict(list)
|
||||
|
||||
# __generalHandlers是一个列表,用来保存通用回调函数(所有事件均调用)
|
||||
self.__generalHandlers = []
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __run(self):
|
||||
"""引擎运行"""
|
||||
@ -202,7 +225,11 @@ class EventEngine2(object):
|
||||
|
||||
# 以上语句为Python列表解析方式的写法,对应的常规循环写法为:
|
||||
#for handler in self.__handlers[event.type_]:
|
||||
#handler(event)
|
||||
#handler(event)
|
||||
|
||||
# 调用通用处理函数进行处理
|
||||
if self.__generalHandlers:
|
||||
[handler(event) for handler in self.__generalHandlers]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __runTimer(self):
|
||||
@ -272,6 +299,18 @@ class EventEngine2(object):
|
||||
"""向事件队列中存入事件"""
|
||||
self.__queue.put(event)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def registerGeneralHandler(self, handler):
|
||||
"""注册通用事件处理函数监听"""
|
||||
if handler not in self.__generalHandlers:
|
||||
self.__generalHandlers.append(handler)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def unregisterGeneralHandler(self, handler):
|
||||
"""注销通用事件处理函数监听"""
|
||||
if handler in self.__generalHandlers:
|
||||
self.__generalHandlers.remove(handler)
|
||||
|
||||
|
||||
########################################################################
|
||||
class Event:
|
||||
@ -297,7 +336,8 @@ def test():
|
||||
app = QCoreApplication(sys.argv)
|
||||
|
||||
ee = EventEngine2()
|
||||
ee.register(EVENT_TIMER, simpletest)
|
||||
#ee.register(EVENT_TIMER, simpletest)
|
||||
ee.registerGeneralHandler(simpletest)
|
||||
ee.start()
|
||||
|
||||
app.exec_()
|
||||
|
@ -685,7 +685,7 @@ class TradingWidget(QtGui.QFrame):
|
||||
self.symbol = ''
|
||||
|
||||
# 添加交易接口
|
||||
self.gatewayList.extend(mainEngine.gatewayDict.keys())
|
||||
self.gatewayList.extend(mainEngine.getAllGatewayNames())
|
||||
|
||||
self.initUi()
|
||||
self.connectSignal()
|
||||
|
@ -296,6 +296,12 @@ class MainEngine(object):
|
||||
"""查询所有的活跃的委托(返回列表)"""
|
||||
return self.dataEngine.getAllWorkingOrders()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getAllGatewayNames(self):
|
||||
"""查询引擎中所有可用接口的名称"""
|
||||
return self.gatewayDict.keys()
|
||||
|
||||
|
||||
|
||||
########################################################################
|
||||
class DataEngine(object):
|
||||
|
Loading…
Reference in New Issue
Block a user