add method for custom event handing
This commit is contained in:
parent
8e292aab8f
commit
df834ca372
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user