diff --git a/callbacks.py b/callbacks.py index 6bd347a74..527901602 100644 --- a/callbacks.py +++ b/callbacks.py @@ -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 diff --git a/depthai_demo.py b/depthai_demo.py index 1333044ea..af55ffd97 100755 --- a/depthai_demo.py +++ b/depthai_demo.py @@ -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) @@ -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: @@ -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])