class AreaPage(QWidget): def __init__(self, parent=None): super(AreaPage, self).__init__(parent) name_label = QLabel("Name:") self.name_lineedit = QLineEdit() self.name_lineedit.setReadOnly(True) devicenum_label = QLabel("Number of devices in this relief device area:") self.devicenum_lineedit = QLineEdit() self.devicenum_lineedit.setReadOnly(True) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.addWidget(name_label, 0, 0) layout.addWidget(self.name_lineedit, 0, 1) layout.addWidget(devicenum_label, 1, 0) layout.addWidget(self.devicenum_lineedit, 1, 1) self.setLayout(layout) self.mapper = QDataWidgetMapper() def setModel(self, proxy_model): self.proxy_model = proxy_model self.mapper.setModel(self.proxy_model.sourceModel()) self.mapper.addMapping(self.name_lineedit, 0) self.mapper.addMapping(self.devicenum_lineedit, 2) def setSelection(self, current): model_index = self.proxy_model.mapToSource(current) parent = model_index.parent() self.mapper.setRootIndex(parent) self.mapper.setCurrentModelIndex(model_index)
def __init__(self, parent=None): super(ScenarioPage, self).__init__(parent) reqflow_label = QLabel("Required Flow:") self.reqflow_spinbox = QSpinBox() maxflow_label = QLabel("Maximum Flow:") self.maxflow_spinbox = QSpinBox() type_label = QLabel("Vapor or Liquid?:") self.type_combobox = QComboBox() self.type_combobox.addItems(["Vapor", "Liquid"]) pdropinlet_label = QLabel("% Pressure Drop (Inlet)") self.pdropinlet_spinbox = QSpinBox() pdropoutlet_label = QLabel("% Pressure Drop (Outlet)") self.pdropoutlet_spinbox = QSpinBox() layout = QGridLayout() layout.addWidget(reqflow_label, 0, 0) layout.addWidget(self.reqflow_spinbox, 0, 1) layout.addWidget(maxflow_label, 1, 0) layout.addWidget(self.maxflow_spinbox, 1, 1) layout.addWidget(type_label, 2, 0) layout.addWidget(self.type_combobox, 2, 1) layout.addWidget(pdropinlet_label, 3, 0) layout.addWidget(self.pdropinlet_spinbox, 3, 1) layout.addWidget(pdropoutlet_label, 4, 0) layout.addWidget(self.pdropoutlet_spinbox, 4, 1) self.setLayout(layout) self.mapper = QDataWidgetMapper()
def __init__(self, node, parent=None): super(DevicePage, self).__init__(parent) name_label = QLabel("Name:") self.name_lineedit = QLineEdit() setpressure_label = QLabel("Set Pressure:") #self.setpressure_spinbox = QDoubleSpinBox() self.setpressure_spinbox = CustomDoubleSpinBox(node, parent, setpressure_label.text()) modelnum_label = QLabel("Model Number:") #self.modelnum_lineedit = QLineEdit() self.modelnum_lineedit = CustomLineEdit(node, parent, modelnum_label.text()) orient_label = QLabel("Orientation:") self.orient_combobox = QComboBox() self.orient_combobox.addItems(["Horizontal", "Vertical"]) layout = QGridLayout() layout.addWidget(name_label, 0, 0) layout.addWidget(self.name_lineedit, 0, 1) layout.addWidget(setpressure_label, 1, 0) layout.addWidget(self.setpressure_spinbox, 1, 1) layout.addWidget(modelnum_label, 2, 0) layout.addWidget(self.modelnum_lineedit, 2, 1) layout.addWidget(orient_label, 3, 0) layout.addWidget(self.orient_combobox, 3, 1) self.setLayout(layout) self.mapper = QDataWidgetMapper()
def __init__(self, parent=None): super(AreaPage, self).__init__(parent) name_label = QLabel("Name:") self.name_lineedit = QLineEdit() self.name_lineedit.setReadOnly(True) devicenum_label = QLabel("Number of devices in this relief device area:") self.devicenum_lineedit = QLineEdit() self.devicenum_lineedit.setReadOnly(True) layout = QGridLayout() layout.setAlignment(Qt.AlignTop) layout.addWidget(name_label, 0, 0) layout.addWidget(self.name_lineedit, 0, 1) layout.addWidget(devicenum_label, 1, 0) layout.addWidget(self.devicenum_lineedit, 1, 1) self.setLayout(layout) self.mapper = QDataWidgetMapper()
class ScenarioPage(QWidget): def __init__(self, parent=None): super(ScenarioPage, self).__init__(parent) reqflow_label = QLabel("Required Flow:") self.reqflow_spinbox = QSpinBox() maxflow_label = QLabel("Maximum Flow:") self.maxflow_spinbox = QSpinBox() type_label = QLabel("Vapor or Liquid?:") self.type_combobox = QComboBox() self.type_combobox.addItems(["Vapor", "Liquid"]) pdropinlet_label = QLabel("% Pressure Drop (Inlet)") self.pdropinlet_spinbox = QSpinBox() pdropoutlet_label = QLabel("% Pressure Drop (Outlet)") self.pdropoutlet_spinbox = QSpinBox() layout = QGridLayout() layout.addWidget(reqflow_label, 0, 0) layout.addWidget(self.reqflow_spinbox, 0, 1) layout.addWidget(maxflow_label, 1, 0) layout.addWidget(self.maxflow_spinbox, 1, 1) layout.addWidget(type_label, 2, 0) layout.addWidget(self.type_combobox, 2, 1) layout.addWidget(pdropinlet_label, 3, 0) layout.addWidget(self.pdropinlet_spinbox, 3, 1) layout.addWidget(pdropoutlet_label, 4, 0) layout.addWidget(self.pdropoutlet_spinbox, 4, 1) self.setLayout(layout) self.mapper = QDataWidgetMapper() def setModel(self, proxy_model): self.proxy_model = proxy_model self.mapper.setModel(self.proxy_model.sourceModel()) self.mapper.addMapping(self.reqflow_spinbox, 2) self.mapper.addMapping(self.maxflow_spinbox, 3) self.mapper.addMapping(self.type_combobox, 4, "currentIndex") self.mapper.addMapping(self.pdropinlet_spinbox, 5) self.mapper.addMapping(self.pdropoutlet_spinbox, 6) def setSelection(self, current): current = self.proxy_model.mapToSource(current) parent = current.parent() self.mapper.setRootIndex(parent) self.mapper.setCurrentModelIndex(current)
class DevicePage(QWidget): def __init__(self, node, parent=None): super(DevicePage, self).__init__(parent) name_label = QLabel("Name:") self.name_lineedit = QLineEdit() setpressure_label = QLabel("Set Pressure:") #self.setpressure_spinbox = QDoubleSpinBox() self.setpressure_spinbox = CustomDoubleSpinBox(node, parent, setpressure_label.text()) modelnum_label = QLabel("Model Number:") #self.modelnum_lineedit = QLineEdit() self.modelnum_lineedit = CustomLineEdit(node, parent, modelnum_label.text()) orient_label = QLabel("Orientation:") self.orient_combobox = QComboBox() self.orient_combobox.addItems(["Horizontal", "Vertical"]) layout = QGridLayout() layout.addWidget(name_label, 0, 0) layout.addWidget(self.name_lineedit, 0, 1) layout.addWidget(setpressure_label, 1, 0) layout.addWidget(self.setpressure_spinbox, 1, 1) layout.addWidget(modelnum_label, 2, 0) layout.addWidget(self.modelnum_lineedit, 2, 1) layout.addWidget(orient_label, 3, 0) layout.addWidget(self.orient_combobox, 3, 1) self.setLayout(layout) self.mapper = QDataWidgetMapper() def setModel(self, proxy_model): self.proxy_model = proxy_model self.mapper.setModel(self.proxy_model.sourceModel()) self.mapper.addMapping(self.name_lineedit, 0) self.mapper.addMapping(self.setpressure_spinbox, 2) self.mapper.addMapping(self.modelnum_lineedit, 3) self.mapper.addMapping(self.orient_combobox, 4, "currentIndex") def setSelection(self, current): current = self.proxy_model.mapToSource(current) parent = current.parent() self.mapper.setRootIndex(parent) self.mapper.setCurrentModelIndex(current)
class ObservationDialog(QDialog, Ui_observationDialog): ''' A dialog delegate that handles the displaying of the observation model in a suitable GUI dialog. ''' FIRST, PREV, NEXT, LAST, CURRENT = range(5) ADD, DELETE, SHOW = range(3) def __init__(self, model, index, parent=None): super(ObservationDialog, self).__init__(parent) self.logger = Logger('root.observationDialog') self.logger.debug('Debug set to: %s' % str(parent.logger.debugging)) self.setupUi(self) # self.dateTimeEdit.setDateTime(QDateTime.currentDateTime()) # An observation model is passed to the constructor as a parameter self.model = model # Build a QCompleter that is based on a species model's species name. # This way user can start typing the name in a line edit and the # completion will suggest suitable species names based on the model # TODO: language for the species name completion needs to be handled # TODO: both completers have model column indexes hard coded in, thus # they will break if the model is modified sppCompleter = QCompleter(self) sppCompleter.setModel(self.model.data_model) sppCompleter.setCompletionColumn(4) sppCompleter.setCompletionMode(QCompleter.InlineCompletion) sppCompleter.setCaseSensitivity(Qt.CaseInsensitive) self.sppLineEdit.setCompleter(sppCompleter) # Build a QCompleter that is based on a species model's abbreviation. # This way user can start typing the abbreviation in a line edit and the # completion will suggest suitable species names based on the model abbrCompleter = QCompleter(self) abbrCompleter.setModel(self.model.data_model) abbrCompleter.setCompletionColumn(1) abbrCompleter.setCompletionMode(QCompleter.InlineCompletion) self.abbrLineEdit.setCompleter(abbrCompleter) # The underlying (observation) model is automatically updated through # a QDataWidgetMapper self.mapper = QDataWidgetMapper(self) self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit) self.mapper.setModel(model) # ID is mapped to a disabled dummy label in order to include it in the # WidgetMapper --> not very elegant self.mapper.addMapping(self.idLineEdit, model.ID) self.mapper.addMapping(self.sppLineEdit, model.SPECIES) self.mapper.addMapping(self.abbrLineEdit, model.ABBR) self.mapper.addMapping(self.countSpinBox, model.COUNT) self.mapper.addMapping(self.dateTimeEdit, model.TIME) self.mapper.addMapping(self.locLineEdit, model.LOCATION) self.mapper.addMapping(self.notesTextEdit, model.NOTES) self.mapper.setCurrentModelIndex(index) self.firstButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.FIRST)) self.prevButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.PREV)) self.nextButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.NEXT)) self.lastButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.LAST)) self.saveButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.CURRENT)) self.closeButton.clicked.connect(self.reject) self.sppLineEdit.editingFinished.connect(self.update_fields) def addRecord(self): row = self.model.rowCount() self.model.insertRow(row) now = QDateTime.currentDateTime() self.dateTimeEdit.setDateTime(now) self.sppLineEdit.setFocus() self.mapper.setCurrentIndex(row) def deleteRecord(self): species = self.sppLineEdit.text() obstime = self.dateTimeEdit.dateTime().toString( DATETIME_FORMAT) if (QMessageBox.question(self, "Delete", "Delete observation of <br>%s on %s?" % (species, obstime), QMessageBox.Yes|QMessageBox.No) == QMessageBox.No): return row = self.mapper.currentIndex() self.model.removeRow(row) self.model.submitAll() if row + 1 >= self.model.rowCount(): row = self.model.rowCount() - 1 self.mapper.setCurrentIndex(row) def reject(self): QDialog.reject(self) def accept(self): self.mapper.submit() QDialog.accept(self) def saveRecord(self, where): ''' Method saves the current row in the self.mapper and moves the data model cursor to a given location. ''' if self.sppLineEdit.text() == "": QMessageBox.warning(self, "Warning", "You must enter a species name!", QMessageBox.Ok) return # Get the current index and submit changes to the underlying model row = self.mapper.currentIndex() self.mapper.submit() # Move the data model cursor to a given location if where == ObservationDialog.FIRST: row = 0 elif where == ObservationDialog.PREV: row = 0 if row <= 1 else row - 1 elif where == ObservationDialog.NEXT: row += 1 if row >= self.model.rowCount(): row = self.model.rowCount() - 1 elif where == ObservationDialog.LAST: row = self.model.rowCount() - 1 self.mapper.setCurrentIndex(row) def update_fields(self): '''Called when editing of the sppLineEdit stops, etc. species name input is complete. Species name will be searched from the model and corresponding abbreviation string and ID number will be set.''' item = self.sppLineEdit.text() item = item.capitalize() # Match the user entered name to an abbreviation in the species model matches = self.model.data_model.match(self.model.data_model.index(0, 4), Qt.DisplayRole, item, hits=1, flags=Qt.MatchExactly) if matches: # There should be only one match match_row = matches[0].row() abbreviation = self.model.data_model.index(match_row, self.model.data_model.ABBR).data() # Also get the ID for updating the model id = self.model.data_model.index(match_row, self.model.data_model.ID).data() self.abbrLineEdit.setText(abbreviation)
def __init__(self, model, index, parent=None): super(ObservationDialog, self).__init__(parent) self.logger = Logger('root.observationDialog') self.logger.debug('Debug set to: %s' % str(parent.logger.debugging)) self.setupUi(self) # self.dateTimeEdit.setDateTime(QDateTime.currentDateTime()) # An observation model is passed to the constructor as a parameter self.model = model # Build a QCompleter that is based on a species model's species name. # This way user can start typing the name in a line edit and the # completion will suggest suitable species names based on the model # TODO: language for the species name completion needs to be handled # TODO: both completers have model column indexes hard coded in, thus # they will break if the model is modified sppCompleter = QCompleter(self) sppCompleter.setModel(self.model.data_model) sppCompleter.setCompletionColumn(4) sppCompleter.setCompletionMode(QCompleter.InlineCompletion) sppCompleter.setCaseSensitivity(Qt.CaseInsensitive) self.sppLineEdit.setCompleter(sppCompleter) # Build a QCompleter that is based on a species model's abbreviation. # This way user can start typing the abbreviation in a line edit and the # completion will suggest suitable species names based on the model abbrCompleter = QCompleter(self) abbrCompleter.setModel(self.model.data_model) abbrCompleter.setCompletionColumn(1) abbrCompleter.setCompletionMode(QCompleter.InlineCompletion) self.abbrLineEdit.setCompleter(abbrCompleter) # The underlying (observation) model is automatically updated through # a QDataWidgetMapper self.mapper = QDataWidgetMapper(self) self.mapper.setSubmitPolicy(QDataWidgetMapper.ManualSubmit) self.mapper.setModel(model) # ID is mapped to a disabled dummy label in order to include it in the # WidgetMapper --> not very elegant self.mapper.addMapping(self.idLineEdit, model.ID) self.mapper.addMapping(self.sppLineEdit, model.SPECIES) self.mapper.addMapping(self.abbrLineEdit, model.ABBR) self.mapper.addMapping(self.countSpinBox, model.COUNT) self.mapper.addMapping(self.dateTimeEdit, model.TIME) self.mapper.addMapping(self.locLineEdit, model.LOCATION) self.mapper.addMapping(self.notesTextEdit, model.NOTES) self.mapper.setCurrentModelIndex(index) self.firstButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.FIRST)) self.prevButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.PREV)) self.nextButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.NEXT)) self.lastButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.LAST)) self.saveButton.clicked.connect( lambda: self.saveRecord(ObservationDialog.CURRENT)) self.closeButton.clicked.connect(self.reject) self.sppLineEdit.editingFinished.connect(self.update_fields)
def mapWordModelFields(self): mapper = QDataWidgetMapper() mapper.setModel(self.wordModel) mapper.addMapping(self.ui.leWord, self.wordModel.valueFieldNum) mapper.addMapping(self.ui.teMeaning, self.wordModel.meaningFieldNum) mapper.toFirst()
def mapDictModelFields(self): mapper = QDataWidgetMapper() mapper.setModel(self.dictModel) mapper.addMapping(self.ui.leDictName, self.dictModel.nameFieldName) mapper.toFirst()