From a4e1b588ad0f6c8403ceb51eb5b0f1af7380613a Mon Sep 17 00:00:00 2001 From: Agnibho Mondal Date: Wed, 8 Nov 2023 22:05:01 +0530 Subject: [PATCH] Updated index view, copy --- index.py | 18 +++++++++++++++++- renderbox.py | 11 +++++++++-- window.py | 17 +++++++---------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/index.py b/index.py index 4e71ca4..efa80c0 100644 --- a/index.py +++ b/index.py @@ -11,6 +11,7 @@ from PyQt6.QtCore import Qt, pyqtSignal, QSortFilterProxyModel from glob import glob from zipfile import ZipFile from config import config +from renderbox import UnrenderBox import logging, os, json class Index(QMainWindow): @@ -33,6 +34,7 @@ class Index(QMainWindow): self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) self.table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection) self.table.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) + self.table.doubleClicked.connect(self.cmd_view) layout2=QFormLayout() self.input_pid=QLineEdit() self.input_pid.returnPressed.connect(self.cmd_filter_pid) @@ -44,16 +46,21 @@ class Index(QMainWindow): layout2.addRow("Filter by ID:", self.input_id) layout2.addRow("Filter by Name:", self.input_name) layout3=QHBoxLayout() + button_view=QPushButton("View Prescription") + button_view.clicked.connect(self.cmd_view) button_open=QPushButton("Open Original") button_open.clicked.connect(self.cmd_open) - button_copy=QPushButton("New Prescription") + button_copy=QPushButton("Create Copy") button_copy.clicked.connect(self.cmd_copy) + layout3.addWidget(button_view) layout3.addWidget(button_open) layout3.addWidget(button_copy) layout.addLayout(layout2) layout.addLayout(layout3) layout.addWidget(self.table) + self.unrenderbox=UnrenderBox() + self.setCentralWidget(widget) self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico"))) @@ -81,6 +88,15 @@ class Index(QMainWindow): self.proxymodel.setFilterKeyColumn(2) self.proxymodel.setFilterFixedString(self.input_name.text()) + def cmd_view(self): + try: + with ZipFile(self.getSelectedFile()) as zf: + with zf.open("prescription.json") as pf: + prescription=json.loads(pf.read()) + self.unrenderbox.show(prescription).exec() + except Exception as e: + logging.warning(e) + def cmd_open(self): try: self.signal_open.emit(self.getSelectedFile()) diff --git a/renderbox.py b/renderbox.py index b5c87f8..dfd1a1c 100644 --- a/renderbox.py +++ b/renderbox.py @@ -94,12 +94,19 @@ class UnrenderBox(QDialog): self.setWindowIcon(QIcon(os.path.join("resource", "icon_medscript.ico"))) def show(self, prescription): + if(type(prescription) is not dict): + prescription=prescription.__dict__ + prescription["prescriber"]=prescription["prescriber"].__dict__ + self.load(prescription) + return(self) + + def load(self, prescription): text="" - for attr, value in prescription.prescriber.__dict__.items(): + for attr, value in prescription["prescriber"].items(): if(attr not in ["properties"] and len(value)>0): text=text+""+value.upper()+"
" text=text+"
" - for attr, value in prescription.__dict__.items(): + for attr, value in prescription.items(): if(attr not in ["prescriber", "custom", "properties", "file"] and len(str(value))>0): text=text+""+attr.upper()+"
" text=text+str(value)+"
" diff --git a/window.py b/window.py index f721eab..28186ad 100644 --- a/window.py +++ b/window.py @@ -69,12 +69,11 @@ class MainWindow(QMainWindow): def cmd_copy(self, data): self.cmd_new() - self.prescription.name=data["name"] - self.prescription.age=data["age"] - self.prescription.sex=data["sex"] - self.prescription.address=data["address"] - self.prescription.contact=data["contact"] + self.prescription.set_data_from_json(data) + self.prescription.id="" + self.prescription.date=None self.load_interface_from_instance() + self.refresh() def cmd_save(self, save_as=False): self.update_instance() @@ -115,9 +114,6 @@ class MainWindow(QMainWindow): self.cmd_save(save_as=True) def cmd_refresh(self): - self.update_instance() - self.plugin.refresh(self.prescription) - self.load_interface_from_instance() self.refresh() def cmd_quit(self): @@ -125,8 +121,7 @@ class MainWindow(QMainWindow): sys.exit() def cmd_unrender(self): - self.unrenderbox.show(self.prescription) - self.unrenderbox.exec() + self.unrenderbox.show(self.prescription).exec() def cmd_render(self): self.refresh() @@ -464,6 +459,7 @@ class MainWindow(QMainWindow): def refresh(self): self.update_instance() + self.plugin.refresh(self.prescription) self.load_interface_from_instance() def add_attachment(self): @@ -591,6 +587,7 @@ class MainWindow(QMainWindow): action_tabular.triggered.connect(self.cmd_tabular) action_index=QAction("Show Index", self) action_index.triggered.connect(self.cmd_index) + action_index.setShortcut("Ctrl+I") action_update=QAction("Check Update", self) action_update.triggered.connect(self.cmd_update) action_about=QAction("About MedScript", self) -- 2.39.5