From: Agnibho Mondal Date: Tue, 14 Nov 2023 19:36:05 +0000 (+0530) Subject: Plugins may close web app window after finishing. X-Git-Tag: v0.5~2 X-Git-Url: https://code.agnibho.com/repo?a=commitdiff_plain;h=f6cfcc63afe8d31486e7cf319e57c6eed8ac38a5;p=medscript.git Plugins may close web app window after finishing. --- diff --git a/README b/README index ccc9019..27cb539 100644 --- a/README +++ b/README @@ -439,7 +439,8 @@ The web app itself must include the `qtwebchannel.js` from PyQt6 `js` to the web app. The web app may access the data from the plugin by using the `js.get()` function. The web app may return data to the plugin by calling the `run` function of the exposed `js` object with the return data as the -argument. +argument. The web app window may be closed by calling the `close` function of +the `js` object. Template Development -------------------- diff --git a/plugin.py b/plugin.py index b127b0f..fd59694 100644 --- a/plugin.py +++ b/plugin.py @@ -181,10 +181,12 @@ class WebApp(QMainWindow): self.channel.registerObject("js", self.js) self.webview.page().setWebChannel(self.channel) self.js.done.connect(lambda: self.done.emit()) + self.js.hide.connect(lambda: self.close()) class JS(QObject): done=pyqtSignal() + hide=pyqtSignal() def __init__(self, module, prescription, data): super().__init__() @@ -209,6 +211,10 @@ class JS(QObject): def get(self): return self.data + @pyqtSlot() + def close(self): + self.hide.emit() + class Worker(QThread): pluginComplete=pyqtSignal(str, int)