]> Softwares of Agnibho - medscript.git/commitdiff
File input for plugins
authorAgnibho Mondal <mondal@agnibho.com>
Sat, 28 Oct 2023 19:33:22 +0000 (01:03 +0530)
committerAgnibho Mondal <mondal@agnibho.com>
Sat, 28 Oct 2023 19:33:22 +0000 (01:03 +0530)
README
plugin.py

diff --git a/README b/README
index 3884ba2183eda92b28c740f119104b2795ae7773..7857efd85b87de4ad0d3abcf87cffc5bcd85067d 100644 (file)
--- a/README
+++ b/README
@@ -364,6 +364,16 @@ global variable called `name` with the desired name.
 Each function mentioned above may return a string which will be displayed to
 the user by the program.
 
+Plugins may get input from the user by implementing one or more of the
+following functions:
+
+    def input(string text)
+        Get text input from the user.
+    def fileopen(string path)
+        Get file to open. Only called before "run" function.
+    def filesave(string path)
+        Get file to save. Only called before "run" function.
+
 The plugin may implement one or more functions mentioned above, it is not
 necessary to implement all.
 
index a1c4b47f45561c276b510a3c6d9ad3251ca50f61..da9552bc0cbd060d3801ae63f7a04a7c8219aefd 100644 (file)
--- a/plugin.py
+++ b/plugin.py
@@ -6,7 +6,7 @@
 # You should have received a copy of the GNU General Public License along with MedScript. If not, see <https://www.gnu.org/licenses/>.
 
 import os, importlib
-from PyQt6.QtWidgets import QMessageBox, QInputDialog
+from PyQt6.QtWidgets import QMessageBox, QInputDialog, QFileDialog
 from glob import glob
 from config import config
 
@@ -97,6 +97,10 @@ class Plugin():
             if(hasattr(module, "run") and callable(module.run)):
                 if(hasattr(module, "input") and callable(module.input)):
                     module.input(self.input())
+                if(hasattr(module, "fileopen") and callable(module.fileopen)):
+                    module.fileopen(QFileDialog.getOpenFileName()[0])
+                if(hasattr(module, "filesave") and callable(module.filesave)):
+                    module.filesave(QFileDialog.getSaveFileName()[0])
                 msg=module.run(prescription)
                 if(msg):
                     QMessageBox.information(None, "Information", msg)