def __init__(self, attr_name, attr_val, parent=None): super(Attribute, self).__init__(parent) # The label with the attribute's name label = QLabel(attr_name) # Now create the editing element, initialized with the attribute's # value. # First, if the value is an integer, use a spinbox if type(attr_val) is int: value = QSpinBox() value.setMaximum(1E9) value.setValue(attr_val) # Second, if the value is a float, use a doublespinbox, with some # customizations for certain attributes. elif type(attr_val) is float: # We want to display the sensitivities in useful units, which should # simulate scientific notation. The attribute value is the # sensitivity's index in the SENSVECTOR. if "Sens" in attr_name: value = QSpinBox() value.setMaximum(1E10) value.setMinimum(1) attr_val = SENSVECTOR[int(attr_val)] # Figure out which units to use for ex in [(1E-3, 'mV'), (1E-6, 'uV'), (1E-9, 'nV')]: if attr_val / ex[0] > 1 and attr_val / ex[0] < 1000: value.setValue(attr_val / ex[0]) value.setSuffix(' {units}'.format(units=ex[1])) # If the value is a float, but not a sensitivity, just use a normal # doublespinbox else: value = QDoubleSpinBox() value.setMaximum(1E9) value.setMinimum(-1E9) value.setValue(attr_val) # Third, if the value is a datetime, dispaly it in a datetimeedit # element. elif type(attr_val) is datetime: value = QDateTimeEdit() value.setDateTime(attr_val) # Finally, for everything else just display it in a lineedit element. else: value = QLineEdit() value.setText(str(attr_val)) layout = QHBoxLayout() layout.addWidget(label) layout.addWidget(value) self.setLayout(layout)