From bda448bed6f75a042bba1e4c563da298932d6c9b Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Sun, 29 Oct 2023 01:03:22 +0530 Subject: [PATCH] File input for plugins --- README | 10 ++++++++++ plugin.py | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README b/README index 3884ba2..7857efd 100644 --- 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. diff --git a/plugin.py b/plugin.py index a1c4b47..da9552b 100644 --- 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 . 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) -- 2.39.5