diff options
Diffstat (limited to 'mainApp.py')
-rw-r--r-- | mainApp.py | 159 |
1 files changed, 80 insertions, 79 deletions
@@ -27,7 +27,7 @@ import os import ctypes import sys -ui,_ = loadUiType('main3.ui') +ui,_ = loadUiType('main.ui') ''' MainApp class is responsible for all the main App Ui operations @@ -46,68 +46,66 @@ class MainApp(QMainWindow,ui): # self.setStyleSheet(style) # Initializing attributes - self.zoomcount = 0 + self.zoom_count = 0 self.thrd = None # Creating instances of classes for the main app - self.container = Container.Container(self.textBrowser) + self.container = Container.Container(self.textBrowser, self.graphicsView) self.comp = ComponentSelector(self) # Setting up interactive canvas - self.scene = self.container.graphics.getScene() ### + self.scene = self.container.graphics.get_scene() ### self.graphicsView.setScene(self.scene) self.graphicsView.setMouseTracking(True) - self.graphicsView.keyPressEvent=self.deleteCall + self.graphicsView.keyPressEvent=self.delete_call self.setDockNestingEnabled(True) self.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea) self.setCorner(Qt.BottomLeftCorner, Qt.LeftDockWidgetArea) self.addDockWidget(Qt.BottomDockWidgetArea,self.dockWidget_2) - # Calling initialisation functions - self.buttonHandler() - self.menuBar() + # Calling initialisation + self.menu_bar() + self.button_handler() self.comp.show() ''' MenuBar function handels all the all the operations of menu bar like new,zoom,comounds selector, simulation options. ''' - def menuBar(self): - self.actionSelect_compounds.triggered.connect(self.selectCompounds) - self.actionSelect_compounds.setShortcut('Ctrl+C') - self.actionZoomIn.triggered.connect(self.zoomIn) + def menu_bar(self): + self.actionSelectCompounds.triggered.connect(self.select_compounds) + self.actionSelectCompounds.setShortcut('Ctrl+C') + self.actionZoomIn.triggered.connect(self.zoom_in) self.actionZoomIn.setShortcut('Ctrl++') self.actionNew.triggered.connect(self.new) self.actionNew.setShortcut('Ctrl+N') - self.actionZoomOut.triggered.connect(self.zoomOut) + self.actionZoomOut.triggered.connect(self.zoom_out) self.actionZoomOut.setShortcut('Ctrl+-') - self.actionResetZoom.triggered.connect(self.zoomReset) + self.actionResetZoom.triggered.connect(self.zoom_reset) self.actionResetZoom.setShortcut('Ctrl+R') self.actionHelp.triggered.connect(self.help) self.actionHelp.setShortcut('Ctrl+H') - self.actionSequential_mode.triggered.connect(partial(self.simulate,'SM')) - self.actionSequential_mode.setShortcut('Ctrl+M') - self.actionEquation_oriented.triggered.connect(partial(self.simulate,'EQN')) - self.actionEquation_oriented.setShortcut('Ctrl+E') + self.actionSequentialMode.triggered.connect(partial(self.simulate,'SM')) + self.actionSequentialMode.setShortcut('Ctrl+M') + self.actionEquationOriented.triggered.connect(partial(self.simulate,'EQN')) + self.actionEquationOriented.setShortcut('Ctrl+E') self.actionUndo.triggered.connect(self.undo) self.actionUndo.setShortcut('Ctrl+Z') self.actionRedo.triggered.connect(self.redo) self.actionRedo.setShortcut('Ctrl+Y') - # self.actionUndo_2.triggered.connect(self.undoStack.undo) - # self.actionRedo.triggered.connect(self.undoStack.redo) - self.actionSave_2.triggered.connect(self.save) - self.actionSave_2.setShortcut('Ctrl+S') + self.actionSave.triggered.connect(self.save) + self.actionSave.setShortcut('Ctrl+S') self.actionOpen.triggered.connect(self.open) self.actionOpen.setShortcut('Ctrl+O') self.actionTerminate.triggered.connect(self.terminate) self.actionTerminate.setShortcut('Ctrl+T') - self.actionBinary_Phase_Envelope.triggered.connect(self.BinPhaseEnv) + self.actionBinaryPhaseEnvelope.triggered.connect(self.bin_phase_env) ''' Handles all the buttons of different components. ''' - def buttonHandler(self): + def button_handler(self): self.pushButton.clicked.connect(partial(self.component,'MaterialStream')) self.pushButton_7.clicked.connect(partial(self.component,'Mixer')) self.pushButton_14.clicked.connect(partial(self.component,'Pump')) @@ -133,27 +131,27 @@ class MainApp(QMainWindow,ui): msgBox.setStandardButtons(QMessageBox.Ok) msgBox.exec_() - def BinPhaseEnv(self): + def bin_phase_env(self): #compounds = self.comp.getComp() - if len(self.comp.getComp())<2: + if len(self.comp.get_compounds())<2: QMessageBox.about(self, 'Important', "Please select at least 2 Compounds first") self.comp.show() #compunds = self.comp.getComp() else: - self.bin_phase = Bin_Phase_env(self.comp) + self.bin_phase = BinPhaseEnv(self.comp) self.bin_phase.show() ''' Shows Compounds Selector Dialog ''' - def selectCompounds(self): + def select_compounds(self): self.comp.show() ''' - Returns currenttime in a required particular format + Returns current time in a required particular format ''' - def currentTime(self): + def current_time(self): now = datetime.datetime.now() time = str(now.hour) + ":" + str(now.minute) + ":" +str(now.second) return time @@ -176,7 +174,7 @@ class MainApp(QMainWindow,ui): 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>") + self.textBrowser.append("<span style=\"color:red\">["+str(self.current_time())+"]<b> Terminating the simulation </b></span>") print('____________________Simulation thread terminated____________________') if res > 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(thread_id, 0) @@ -185,40 +183,40 @@ class MainApp(QMainWindow,ui): ''' Resets the zoom level to default scaling ''' - def zoomReset(self): - if(self.zoomcount>0): - for i in range(self.zoomcount): + def zoom_reset(self): + if(self.zoom_count>0): + for i in range(self.zoom_count): self.zoomout() - elif(self.zoomcount<0): - for i in range(abs(self.zoomcount)): + elif(self.zoom_count<0): + for i in range(abs(self.zoom_count)): self.zoomin() ''' ZoomOut the canvas ''' - def zoomOut(self): + def zoom_out(self): self.graphicsView.scale(1.0/1.15,1.0/1.15) - self.zoomcount -=1 + self.zoom_count -=1 ''' ZoomIn the canvas ''' - def zoomIn(self): + def zoom_in(self): self.graphicsView.scale(1.15,1.15) - self.zoomcount +=1 + self.zoom_count +=1 ''' Instantiate a NodeItem object for selected type of component and added that on canvas/flowsheeting area. ''' - def component(self,unitOpType): - if(self.comp.isCompSelected()): - self.type = unitOpType + def component(self,unit_operation_type): + if(self.comp.is_compound_selected()): + self.type = unit_operation_type if(self.type=="MaterialStream"): - self.obj = MaterialStream(CompNames=compound_selected) + self.obj = MaterialStream(compound_names = compound_selected) else: self.obj = eval(self.type)() - self.container.addUnitOp(self.obj, self.graphicsView) + self.container.add_unit_operation(self.obj) else: QMessageBox.about(self, 'Important', "Please Select Compounds first") @@ -230,13 +228,13 @@ class MainApp(QMainWindow,ui): def new(self): self.undo_redo_helper() self.comp.tableWidget.setRowCount(0) - self.textBrowser.append("<span>[" + str(self.currentTime()) + "] <b>New</b> flowsheet is created ... </span>") - dockWidgetLst.clear() + self.textBrowser.append("<span>[" + str(self.current_time()) + "] <b>New</b> flowsheet is created ... </span>") + dock_widget_lst.clear() ''' Handels all the operations which will happen when delete button is pressed. ''' - def deleteCall(self,event): + def delete_call(self,event): try: if event.key() == QtCore.Qt.Key_Delete: l=self.scene.selectedItems() @@ -250,19 +248,19 @@ class MainApp(QMainWindow,ui): It helps by clearing screen and loading the objects by undo redo methods ''' def undo_redo_helper(self): - for i in self.container.unitOp: + for i in self.container.unit_operations: type(i).counter = 1 del self.container - for i in dockWidgetLst: + for i in dock_widget_lst: i.hide() del i lst.clear() - self.container = Container.Container(self.textBrowser) + self.container = Container.Container(self.textBrowser, self.graphicsView) compound_selected.clear() - self.scene = self.container.graphics.getScene() + self.scene = self.container.graphics.get_scene() self.graphicsView.setScene(self.scene) self.graphicsView.setMouseTracking(True) - self.graphicsView.keyPressEvent=self.deleteCall + self.graphicsView.keyPressEvent=self.delete_call @@ -270,14 +268,14 @@ class MainApp(QMainWindow,ui): Function for undo ''' def undo(self): - redo_data = POP('Undo') + redo_data = pop('Undo') if redo_data is not None: - PUSH('Redo', redo_data) + push('Redo', redo_data) undo_data = get_last_list('Undo') messages = self.textBrowser.toPlainText() try: self.undo_redo_helper() - self.container.graphics.loadCanvas(undo_data) + self.container.graphics.load_canvas(undo_data, self.container) self.textBrowser.setText(messages) except Exception as e: print(e) @@ -285,72 +283,75 @@ class MainApp(QMainWindow,ui): else: messages = self.textBrowser.toPlainText() self.textBrowser.setText(messages) - self.textBrowser.append("<span>[" + str(self.currentTime()) + "] <b>No more undo can be done!</b>... </span>") + self.textBrowser.append("<span>[" + str(self.current_time()) + "] <b>No more undo can be done!</b>... </span>") ''' Function for redo ''' def redo(self): - redo_data = POP('Redo') + redo_data = pop('Redo') if redo_data is not None: - PUSH('Undo', redo_data) + push('Undo', redo_data) messages = self.textBrowser.toPlainText() self.undo_redo_helper() - self.container.graphics.loadCanvas(redo_data) + self.container.graphics.load_canvas(redo_data, self.container) self.textBrowser.setText(messages) else: messages = self.textBrowser.toPlainText() self.textBrowser.setText(messages) - self.textBrowser.append("<span>[" + str(self.currentTime()) + "] <b>No more redo can be done!</b>... </span>") + self.textBrowser.append("<span>[" + str(self.current_time()) + "] <b>No more redo can be done!</b>... </span>") ''' Function for saving the current canvas items and compound_selected ''' def save(self): data = [] - for i in self.container.unitOp: + for i in self.container.unit_operations: data.append(i) print(i.pos) data.append(compound_selected) print(data) - fileFormat = 'sim' - initialPath = QDir.currentPath() + 'untitled.' + fileFormat - fileName, _ = QFileDialog.getSaveFileName(self, "Save As", - initialPath, "%s Files (*.%s);; All Files (*)" % - (fileFormat.upper(), fileFormat)) - if fileName != "": - with open(fileName, 'wb') as f: #'saved_file.sim' + file_format = 'sim' + initial_path = QDir.currentPath() + 'untitled.' + file_format + file_name, _ = QFileDialog.getSaveFileName(self, "Save As", + initial_path, "%s Files (*.%s);; All Files (*)" % + (file_format.upper(), file_format)) + #if file_name != "": + try: + with open(file_name, 'wb') as f: #'saved_file.sim' pickle.dump(data, f, pickle.HIGHEST_PROTOCOL) + except Exception as e: + pass ''' Function for loading previous saved canvas and simulation ''' def open(self): try: - fileFormat = 'sim' - initialPath = QDir.currentPath() + 'untitled.' + fileFormat + file_format = 'sim' + initial_path = QDir.currentPath() + 'untitled.' + file_format - fileName, _ = QFileDialog.getOpenFileName(self, "Open As", - initialPath, "%s Files (*.%s);; All Files (*)" % - (fileFormat.upper(), fileFormat)) + file_name, _ = QFileDialog.getOpenFileName(self, "Open As", + initial_path, "%s Files (*.%s);; All Files (*)" % + (file_format.upper(), file_format)) # if fileName != "": # self.new() self.undo_redo_helper() - with open(fileName, 'rb') as f: + with open(file_name, 'rb') as f: obj = pickle.load(f) - - self.container.graphics.loadCanvas(obj) + print(obj) + self.container.graphics.load_canvas(obj, self.container) except Exception as e: pass def main(): - CLEAN_FILE('Undo') - CLEAN_FILE('Redo') + clean_file('Undo') + clean_file('Redo') app = QApplication(sys.argv) window = MainApp() |