From e518e76814763ee66c02e8c87b642f5e5c1a271b Mon Sep 17 00:00:00 2001 From: brenda-br Date: Thu, 16 Feb 2023 21:46:01 +0530 Subject: Fix #58 Stop Simulation Button added --- Container.py | 35 ++++++++++++++++++++++++----------- Undo.dat | Bin 61657 -> 0 bytes icons/stop.png | Bin 0 -> 5514 bytes main.ui | 18 ++++++++++++++++-- mainApp.py | 11 ++++++----- 5 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 icons/stop.png diff --git a/Container.py b/Container.py index 8bb1b1d..5e6836c 100644 --- a/Container.py +++ b/Container.py @@ -119,12 +119,9 @@ class Container(): self.msg.append(""+stdout+"") def simulate(self,mode): - self.graphicsView.parent().parent().menubar.setProperty('enabled',False) - self.graphicsView.parent().parent().toolBar.setProperty('enabled',False) - self.graphicsView.parent().parent().dockWidget.setProperty('enabled',False) - self.graphicsView.setInteractive(False) - QApplication.instance().setOverrideCursor(QCursor(Qt.WaitCursor)) + self.disableInterfaceforSimulation(True) + for i in self.graphics.scene.items(): if (isinstance(i, NodeItem)): try: @@ -170,13 +167,29 @@ class Container(): no_output_lines = len(i.output[0].out_lines) if(no_input_lines>0): #Checks if material stream is input or output stream if it is output stream it continues i.obj.disableInputDataTab(i.dock_widget) + + self.disableInterfaceforSimulation(False) + + def enableToolbar(self,status): + self.graphicsView.parent().parent().actionNew.setProperty('enabled',status) + self.graphicsView.parent().parent().actionZoomIn.setProperty('enabled',status) + self.graphicsView.parent().parent().actionZoomOut.setProperty('enabled',status) + self.graphicsView.parent().parent().actionResetZoom.setProperty('enabled',status) + self.graphicsView.parent().parent().actionEquationOriented.setProperty('enabled',status) + self.graphicsView.parent().parent().actionTerminate.setProperty('enabled',not status) + self.graphicsView.parent().parent().actionSelectCompounds.setProperty('enabled',status) + + def disableInterfaceforSimulation(self,status): + self.graphicsView.parent().parent().menubar.setProperty('enabled',not status) + self.enableToolbar(not status) + self.graphicsView.parent().parent().dockWidget.setProperty('enabled',not status) + self.graphicsView.setInteractive(not status) + if status: + QApplication.instance().setOverrideCursor(QCursor(Qt.WaitCursor)) + else: + QApplication.instance().restoreOverrideCursor() + QApplication.instance().setOverrideCursor(QCursor(Qt.ArrowCursor)) - self.graphicsView.parent().parent().menubar.setProperty('enabled',True) - self.graphicsView.parent().parent().toolBar.setProperty('enabled',True) - self.graphicsView.parent().parent().dockWidget.setProperty('enabled',True) - self.graphicsView.setInteractive(True) - QApplication.instance().restoreOverrideCursor() - QApplication.instance().setOverrideCursor(QCursor(Qt.ArrowCursor)) def flat_list(lst): flat_lst=[] for sublist in lst: diff --git a/Undo.dat b/Undo.dat index 7cf571d..e69de29 100644 Binary files a/Undo.dat and b/Undo.dat differ diff --git a/icons/stop.png b/icons/stop.png new file mode 100644 index 0000000..d365d34 Binary files /dev/null and b/icons/stop.png differ diff --git a/main.ui b/main.ui index c41747e..9a4f48d 100644 --- a/main.ui +++ b/main.ui @@ -115,7 +115,7 @@ - 0 + 89 150 @@ -2025,6 +2025,8 @@ + + @@ -2075,6 +2077,18 @@ Sequential mode + + + false + + + + Icons/stop.pngIcons/stop.png + + + Stop Simulation + + @@ -2115,7 +2129,7 @@ - Terminate + Stop Simulation diff --git a/mainApp.py b/mainApp.py index 8381000..ea957bd 100644 --- a/mainApp.py +++ b/mainApp.py @@ -173,16 +173,17 @@ class MainApp(QMainWindow,ui): os.chdir(self.container.flowsheet.root_dir) if self.thrd: thread_id = self.thrd.ident - print('____________________Going to terminate simulation thread with Thread ID:',thread_id,'____________________') - print('____________________Going to terminate the new process created for omc____________________') + # print('____________________Going to terminate simulation thread with Thread ID:',thread_id,'____________________') + # print('____________________Going to terminate the new process created for omc____________________') self.container.flowsheet.process.terminate() print('____________________New process created for omc is terminated.____________________') res = ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, ctypes.py_object(SystemExit)) - self.textBrowser.append("["+str(self.current_time())+"] Terminating the simulation ") - print('____________________Simulation thread terminated____________________') + self.textBrowser.append("["+str(self.current_time())+"]Simulation Terminated.") + self.container.disableInterfaceforSimulation(False) + # print('____________________Simulation thread terminated____________________') if res > 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 0) - print('Exception raise (Thread termination) failure') + # print('Exception raise (Thread termination) failure') ''' Resets the zoom level to default scaling -- cgit