add method for custom event handing

This commit is contained in:
Chrys 2017-06-12 17:28:20 +02:00
parent 8e292aab8f
commit df834ca372

View File

@ -76,9 +76,14 @@ class eventManager():
if Force: if Force:
self._mainLoopRunning.value = False self._mainLoopRunning.value = False
self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None}) self._eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
def addEventThread(self, event, function): def addCustomEventThread(self, function):
self._mainLoopRunning.value = True self._mainLoopRunning.value = True
t = Process(target=self.eventWorkerThread, args=(event, function)) t = Process(target=self.eventWorkerThread, args=(q, function))
self._eventProcesses.append(t)
t.start()
def addSimpleEventThread(self, event, function):
self._mainLoopRunning.value = True
t = Process(target=self.SimpleEventWorkerThread, args=(event, function))
self._eventProcesses.append(t) self._eventProcesses.append(t)
t.start() t.start()
def cleanEventQueue(self): def cleanEventQueue(self):
@ -94,7 +99,18 @@ class eventManager():
return False return False
self._eventQueue.put({"Type":event,"Data":data}) self._eventQueue.put({"Type":event,"Data":data})
return True return True
def eventWorkerThread(self, event, function): def customEventWorkerThread(self, eventQueue, function):
if not isinstance(eventQueue, Queue):
return
if not callable(function):
return
while self._mainLoopRunning.value:
try:
function(eventQueue)
except Exception as e:
print(e)
def simpleEventWorkerThread(self, event, function):
if not isinstance(event, fenrirEventType): if not isinstance(event, fenrirEventType):
return return
if not callable(function): if not callable(function):