def _editNumericalMethods(self, current, ids): """Edit the solver specific properties\n current = ID of the equation set that should be edited""" title = "" for i in range(0, len(self._equationEditor)): title = self._equationEditor[i].tabWidget.tabText(current) break if(title == "General"): sys.stdout.write("No solver controls for 'General' equation options") sys.stdout.flush() return if(current >= len(self._solverParameterEditor)): self._solverParameterEditor.append(solverparameters.SovlerParameterEditor(path_forms)) spe = self._solverParameterEditor[current] spe.setWindowTitle("Solver control for {}".format(title)) spe.solverName = title if(spe.generalOptions == None): spe.generalOptions = dynamiceditor.DynamicEditor() spe.generalOptions.setupTabs(self._elmerDefs, "Solver", current) spe.solverControlTabs.insertTab(0, spe.generalOptions.tabWidget.widget(current), "Solver specific options") for i in range(0, spe.generalOptions.tabWidget.count()): if(spe.generalOptions.tabWidget.tabText(i) == title): spe.solverControlTabs.insertTab(0, spe.generalOptions.tabWidget.widget(i), "Solver specific options") break spe.show()
def _editNumericalMethods(self, current, ids, show=True): """Edit the solver specific properties Args: ----- current: int current tab-index ids: int ID of the equation show: bool flag to show window or not """ title = "" # get active tab in the currently opened equation set for eq in self.equationEditor: if eq.ID == ids: title = eq.tabWidget.tabText(current) break if (title == "General"): sys.stdout.write( "No solver controls for 'General' equation options") sys.stdout.flush() return # if tab is not yet in list, resize list and copy previous items if (current >= len(self.solverParameterEditor)): tmp = (current + 1) * [None] for idx, element in enumerate(self.solverParameterEditor): tmp[idx] = element self.solverParameterEditor = tmp # create a new instane of the Solver settings and put it into storage if not self.solverParameterEditor[current]: self.solverParameterEditor[ current] = solverparameters.SolverParameterEditor( self._path_forms) spe = self.solverParameterEditor[current] spe.setWindowTitle("Solver control for {}".format(title)) spe.solverName = title if (spe.generalOptions is None): spe.generalOptions = dynamiceditor.DynamicEditor() spe.generalOptions.setupTabs(self._elmerDefs, "Solver", current) spe.solverControlTabs.insertTab( 0, spe.generalOptions.tabWidget.widget(current), "Solver specific options") for i in range(0, spe.generalOptions.tabWidget.count()): if (spe.generalOptions.tabWidget.tabText(i) == title): spe.solverControlTabs.insertTab( 0, spe.generalOptions.tabWidget.widget(i), "Solver specific options") break if show: spe.show()
def pdeEditorFinishedSlot(self, signal, ids): """Method for handling the button events in the equation settings. Args: ----- signal: int Type of button clicked ids: int ID of the body force set """ # check if already in the storage and retrieve it for eq in self.equationEditor: temp = eq.ID if temp == ids: ids = self.equationEditor.index(eq) break listview = self._eqWindow.layout().itemAt(0).widget() # check OK-Button or Apply-Button signalOK = False if (signal == dynamiceditor.MatTypes.MAT_OK or signal == dynamiceditor.MatTypes.MAT_APPLY): signalOK = True # OK or Apply if (signalOK): item = listview.item(ids) de = self.equationEditor[ids] equationName = str(de.nameEdit.text()).strip() if not equationName: sys.stdout.write("No equation name\n") sys.stdout.flush() return else: item.setText(equationName) self._eqWindow.setWindowTitle(equationName) # hide window, when OK if signal == dynamiceditor.MatTypes.MAT_OK: self._eqWindow.hide() # New -> create new Equation elif (signal == dynamiceditor.MatTypes.MAT_NEW): # get window and layout window = self._eqWindow layout = window.layout() # new instance of the dynamic editor current = self._eqCurrent de = dynamiceditor.DynamicEditor() # put new instance into storage self.equationEditor.append(de) # populate tabs de.setupTabs(self._elmerDefs, "Equation", current) de.applyButton.setText("Apply") de.discardButton.setText("Delete") de.dynamicEditorReady[int, int].connect(self.pdeEditorFinishedSlot) de.spareButton.setText("Edit Solver Settings") de.spareButton.show() de.dynamicEditorSpareButtonClicked[int, int].connect( self._editNumericalMethods) # clear right side of layout and at the new dynamic editor item = layout.takeAt(1) if item is not None: item.widget().close() layout.addWidget(de, stretch=5) # add item to list item = QtGui.QListWidgetItem() item.setText(de.nameEdit.text()) listview.addItem(item) # set new as selected count = len(self.equationEditor) listview.item(count - 1).setSelected(True) self._eqWindow.setWindowTitle(de.nameEdit.text()) self._eqCurrent += 1 # Delete elif (signal == dynamiceditor.MatTypes.MAT_DELETE): # remove the current equation editor if len(self.equationEditor) > 1: # remove the current equation item = listview.takeItem(ids) del self.equationEditor[ids] # show the previous equation if ids > 0: ids -= 1 listview.item(ids).setSelected(True) layout = self._eqWindow.layout() item = layout.takeAt(1) item.widget().close() de = self.equationEditor[ids] layout.insertWidget(1, de, stretch=5) de.show() self._eqWindow.setWindowTitle(de.nameEdit.text()) else: # remove the current equation del self.equationEditor[ids] self.equationEditor = [] # close the window self._eqWindow.hide()
def _pdeEditorFinishedSlot(self, signal, ids): """Method for handling the button events in the solver settings\n signal = the button hit\n ids = ID of the equation set""" listview = self._listview signalOK = False if(signal == dynamiceditor.MatTypes.MAT_OK or signal == dynamiceditor.MatTypes.MAT_APPLY): signalOK = True if(signalOK): """ToDo""" item = listview.item(ids) de = self._equationEditor[ids] equationName = str(de.nameEdit.text()).strip() if not equationName: sys.stdout.write("No equation name\n") sys.stdout.flush() return else: item.setText(equationName) self._window.setWindowTitle(equationName) if signal == dynamiceditor.MatTypes.MAT_OK: self._window.close() elif(signal == dynamiceditor.MatTypes.MAT_NEW): """Create a new material""" # get window and layout window = self._window layout = window.layout() # new instance of the dynamic editor current = len(self._equationEditor) de = dynamiceditor.DynamicEditor() self._equationEditor.append(de) de.setupTabs(self._elmerDefs, "Equation", current) de.applyButton.setText("Apply") de.discardButton.setText("Delete") de.dynamicEditorReady[int, int].connect(self._pdeEditorFinishedSlot) de.spareButton.setText("Edit Solver Settings") de.spareButton.show() de.dynamicEditorSpareButtonClicked[int, int].connect(self._editNumericalMethods) #clear right side of layout and at the new dynamic editor item = layout.takeAt(1) if item is not None: item.widget().close() layout.addWidget(de) #add item to list item = QtGui.QListWidgetItem() item.setText(de.nameEdit.text()) self._listview.addItem(item) self._window.setWindowTitle(de.nameEdit.text()) elif(signal == dynamiceditor.MatTypes.MAT_DELETE): """Remove the current equation editor from the collection""" if ids > 0: #remove the current equation item = self._listview.takeItem(ids) del self._equationEditor[ids] #show the previous equation self._listview.item(ids-1).setSelected(True) layout = self._window.layout() item = layout.takeAt(1) item.widget().close() de = self._equationEditor[ids - 1] layout.insertWidget(1, de) de.show() self._window.setWindowTitle(de.nameEdit.text()) else: #remove the current equation del self._equationEditor[ids] self._equationEditor = [] self._window.close()