Skip to content

Commit

Permalink
Fix callbacks file parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
VanDavv committed Nov 20, 2021
1 parent 17ef066 commit c240d82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def onReport(report):
pass


def onSetup(**kwargs):
def onSetup(*args, **kwargs):
pass


def onTeardown(**kwargs):
def onTeardown(*args, **kwargs):
pass


def onIter(**kwargs):
def onIter(*args, **kwargs):
pass
13 changes: 13 additions & 0 deletions depthai_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ def __init__(self, instance, parent, conf, selectedPreview=None):
self.instance = instance
self.parent = parent
self.conf = conf
self.callback_module = loadModule(conf.args.callback)
self.file_callbacks = {
callbackName: getattr(self.callback_module, callbackName)
for callbackName in ["shouldRun", "onNewFrame", "onShowFrame", "onNn", "onReport", "onSetup", "onTeardown", "onIter"]
if callable(getattr(self.callback_module, callbackName, None))
}
self.instance.setCallbacks(**self.file_callbacks)
self.signals = WorkerSignals()
self.signals.exitSignal.connect(self.terminate)
self.signals.updateConfSignal.connect(self.updateConf)
Expand Down Expand Up @@ -544,9 +551,13 @@ def onError(self, ex: Exception):
self.signals.setDataSignal.emit(["restartRequired", True])

def shouldRun(self):
if "shouldRun" in self.file_callbacks:
return self.running and self.file_callbacks["shouldRun"]()
return self.running

def onShowFrame(self, frame, source):
if "onShowFrame" in self.file_callbacks:
self.file_callbacks["onShowFrame"](frame, source)
writerObject = self.parent.window.findChild(QObject, "writer")
w, h = int(writerObject.width()), int(writerObject.height())
if source == self.selectedPreview:
Expand All @@ -558,6 +569,8 @@ def onShowFrame(self, frame, source):
self.signals.updatePreviewSignal.emit(img)

def onSetup(self, instance):
if "onSetup" in self.file_callbacks:
self.file_callbacks["onSetup"](instance)
self.selectedPreview = self.conf.args.show[0]
self.signals.updateConfSignal.emit(list(vars(self.conf.args).items()))
self.signals.setDataSignal.emit(["previewChoices", self.conf.args.show])
Expand Down

0 comments on commit c240d82

Please sign in to comment.