diff options
Diffstat (limited to 'mainApp.py')
-rw-r--r-- | mainApp.py | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -27,7 +27,9 @@ import datetime from container import Container from Graphics import Graphics import pickle +import threading import os +import ctypes import sys ui,_ = loadUiType('main.ui') @@ -53,6 +55,7 @@ class MainApp(QMainWindow,ui): # Initializing attributes self.zoomcount = 0 + self.thrd = None # Creating instances of classes for the main app self.Container = Container(self.textBrowser) @@ -104,6 +107,7 @@ class MainApp(QMainWindow,ui): # self.actionRedo.triggered.connect(self.undoStack.redo) self.actionSave_2.triggered.connect(self.save) self.actionOpen.triggered.connect(self.open) + self.actionTerminate.triggered.connect(self.terminate) ''' Handles all the buttons of different components. @@ -154,12 +158,30 @@ class MainApp(QMainWindow,ui): selected by the user. ''' def simulate(self,mode): - self.Container.simulate(mode) + self.thrd = threading.Thread(target=self.Container.simulate, args=(mode,)) + self.thrd.start() + # self.Container.simulate(mode) self.dockWidget_2.show() self.res = resdockWidget(self.Container) self.addDockWidget(Qt.LeftDockWidgetArea, self.res) self.res.show() + def terminate(self): + 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____________________') + 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("<span style=\"color:red\">["+str(self.currentTime())+"]<b> Terminating the simulation </b></span>") + print('____________________Simulation thread terminated____________________') + if res > 1: + ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 0) + print('Exception raise (Thread termination) failure') + + ''' Resets the zoom level to default scaling ''' |