class NameCommentCell(CellItem): def __init__(self, controller, parent=None, state=None): CellItem.__init__(self, controller, parent, state) self.le = QLineEdit(self.state) self.le.returnPressed.connect(self.on_return_pressed) self.le.editingFinished.connect(self.on_return_pressed) self.widgets.append(self.le) self.set_layout() self.setMaximumWidth(130) def reloadstate(self): text = str(self.le.text()) if not text == self.state: self.cellChanged.emit(self) def on_return_pressed(self): self.cellChanged.emit(self) def value(self): return self.le.text() def setValue(self, val): self.le.setText(val) self.state = val def mouseDoubleClickEvent(self, e): CellItem.mouseDoubleClick(self, e) if e.button() == Qt.LeftButton: self.le.setFocus() e.accept()
def _queryDetails(self): dlg = QDialog(self) dlg.setWindowTitle('Login details for ticket tracker required') layout = QGridLayout() layout.addWidget( QLabel( 'Please enter details for the ticket tracker. ' 'You can contact the instrument control group ' 'for help.', dlg)) layout.addWidget(QLabel('Instrument name:', dlg)) instrBox = QLineEdit(self.instrument, dlg) instrBox.setEnabled(self.instrument != 'none') layout.addWidget(instrBox) noinstrBox = QCheckBox('No instrument', dlg) noinstrBox.setChecked(self.instrument == 'none') noinstrBox.toggled.connect(lambda c: instrBox.setEnabled(not c)) layout.addWidget(noinstrBox) layout.addWidget(QLabel('Username:'******'Password:'******'Login successful. Your API key has been stored ' 'for further reports.') settings = CompatSettings('nicos', 'secrets') settings.beginGroup('Redmine') if noinstrBox.isChecked(): self.instrument = 'none' else: self.instrument = instrBox.text() self.apikey = apikey self.username = userBox.text() settings.setValue('instrument', self.instrument) settings.setValue('apikey', self.apikey) settings.setValue('username', self.username) if not self.instrument or not self.apikey: return False self.titleLabel.setText( 'Submit a ticket for instrument "%s" (as user %s)' % (self.instrument, self.username)) return True
class TimeEditWidget(QWidget): units = ('s', 'm', 'h', 'd') returnPressed = pyqtSignal() def __init__(self, parent=None): QWidget.__init__(self, parent) self.setLayout(QHBoxLayout()) self.layout().setContentsMargins(0.1, 0.1, 0.1, 0.1) self.layout().setSpacing(1) self.val = QLineEdit() self.val.setValidator(QDoubleValidator(0, 1000000, 2)) self.layout().addWidget(self.val) self.unit = QComboBox() self.unit.insertItems(0, self.units) self.layout().addWidget(self.unit) self.setValue(1) self.val.returnPressed.connect(self.on_returnPressed) self.val.editingFinished.connect(self.on_returnPressed) self.unit.currentIndexChanged.connect(self.recalcValue) def value(self): val = float(self.val.text()) current_unit_index = self.unit.currentIndex() if current_unit_index == 1: # minutes val *= 60. elif current_unit_index == 2: # hours val *= 3600. elif current_unit_index == 3: # days val *= 86400. return int(val) def setValue(self, val): fmt = '%%.%df' % self.val.validator().decimals() self.val.setText(fmt % float(val)) self.unit.setCurrentIndex(0) self.currentUnit = 0 def recalcValue(self, idx): # adjust widget value to unit unit_index_current = self.currentUnit unit_index_next = idx if unit_index_next > unit_index_current: start = unit_index_current end = unit_index_next elif unit_index_next < unit_index_current: start = unit_index_next end = unit_index_current val = float(self.val.text()) factor = 1. for i in range(start, end): if self.units[i + 1] == 'd': factor *= 24. else: factor *= 60. if unit_index_next - unit_index_current > 0: factor = 1. / factor next_value = val * factor self.val.setText('%s' % next_value) self.currentUnit = idx def on_returnPressed(self): self.returnPressed.emit()
class BaseDev(QWidget): base_address = 0 has_target = False has_status = False offset = 1 def __init__(self, model, name, index, addr, has_status=False, target=None, value_offset=1): QWidget.__init__(self) self.index = index self.name = name self.model = model self.offset = value_offset self.has_status = has_status self.has_target = target is not None self.base_address = addr self._namelabel = QLabel(name) self._namelabel.setMinimumWidth(120) self._namelabel.setMaximumWidth(120) # self._groupbox = QGroupBox(name) self._groupbox = QFrame() # self._groupbox.setFlat(False) # self._groupbox.setCheckable(False) self._hlayout = QHBoxLayout() self._hlayout.addWidget(self._namelabel) self._hlayout.addWidget(self._groupbox) self._hlayout.setSpacing(0) # inside of the groupbox there is a vbox with 1 or 2 hboxes self._inner_vbox = QVBoxLayout() self._groupbox.setLayout(self._inner_vbox) # upper inner hbox self._inner_hbox1 = QHBoxLayout() self._inner_vbox.addLayout(self._inner_hbox1) # fill upper hbox self.valueWidget = QLineEdit('0b123456789abcdef0') self.valueWidget.setMaximumWidth(120) self._inner_hbox1.addWidget(self.valueWidget) if self.has_target: self.targetWidget = QLineEdit() self.targetWidget.setPlaceholderText(target) self.targetWidget.setMaximumWidth(120) self.targetWidget.returnPressed.connect(lambda *a: model.targeter( index, (self.targetWidget.text(), self.targetWidget.setText(''))[0])) self._inner_hbox1.addWidget(self.targetWidget) self.goButton = QPushButton('Go') self.goButton.clicked.connect(lambda *a: model.targeter( index, (self.targetWidget.text(), self.targetWidget.setText(''))[0])) self._inner_hbox1.addWidget(self.goButton) self.stopButton = QPushButton('Stop') self.stopButton.clicked.connect(lambda *a: model.stopper(index)) self._inner_hbox1.addWidget(self.stopButton) # now (conditionally) the second hbox if has_status: self._inner_hbox2 = QHBoxLayout() self._inner_vbox.addLayout(self._inner_hbox2) self.statvalueWidget = QLineEdit('statval') self.statvalueWidget.setMaximumWidth(120) self._inner_hbox2.addWidget(self.statvalueWidget) self.statusWidget = QLineEdit('Statusstring if available') self.statusWidget.setMaximumWidth(10000) self._inner_hbox2.addWidget(self.statusWidget) self.resetButton = QPushButton('Reset') self.resetButton.clicked.connect(lambda *a: model.resetter(index)) self._inner_hbox1.addWidget(self.resetButton) # self._inner_hbox2.addStretch(0.1) # allow space for resizing self._inner_hbox1.addStretch(1) self._inner_vbox.setSpacing(0) self._inner_vbox.setContentsMargins(0, 0, 0, 0) self._hlayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self._hlayout) self.show()
def text(self): if self._shadowed: return '' return QLineEdit.text(self)
class BaseDev(QWidget): has_target = False has_status = False def __init__(self, model, name, addr): super(BaseDev, self).__init__() self.name = name self.model = model self.addr = addr self._namelabel = QLabel(name) self._namelabel.setMinimumWidth(120) self._namelabel.setMaximumWidth(120) # self._groupbox = QGroupBox(name) self._groupbox = QFrame() # self._groupbox.setFlat(False) # self._groupbox.setCheckable(False) self._hlayout = QHBoxLayout() self._hlayout.addWidget(self._namelabel) self._hlayout.addWidget(self._groupbox) self._hlayout.setSpacing(0) # inside of the groupbox there is a vbox with 1 or 2 hboxes self._inner_vbox = QVBoxLayout() self._groupbox.setLayout(self._inner_vbox) # upper inner hbox self._inner_hbox1 = QHBoxLayout() self._inner_vbox.addLayout(self._inner_hbox1) # fill upper hbox self.valueWidget = QLineEdit('0b123456789abcdef0') self.valueWidget.setMaximumWidth(120) self._inner_hbox1.addWidget(self.valueWidget) if self.has_target: self.targetWidget = QLineEdit() self.targetWidget.setPlaceholderText('') self.targetWidget.setMaximumWidth(120) self.targetWidget.returnPressed.connect(self._go_clicked) self._inner_hbox1.addWidget(self.targetWidget) self.goButton = QPushButton('Go') self.goButton.clicked.connect(self._go_clicked) self._inner_hbox1.addWidget(self.goButton) self.stopButton = QPushButton('Stop') self.stopButton.clicked.connect(self._stop_clicked) self._inner_hbox1.addWidget(self.stopButton) # now (conditionally) the second hbox if self.has_status: self._inner_hbox2 = QHBoxLayout() self._inner_vbox.addLayout(self._inner_hbox2) self.statvalueWidget = QLineEdit('statval') self.statvalueWidget.setMaximumWidth(120) self._inner_hbox2.addWidget(self.statvalueWidget) self.statusWidget = QLineEdit('Statusstring if available') self.statusWidget.setMaximumWidth(10000) self._inner_hbox2.addWidget(self.statusWidget) self.resetButton = QPushButton('Reset') self.resetButton.clicked.connect(self._reset_clicked) self._inner_hbox1.addWidget(self.resetButton) # self._inner_hbox2.addStretch(0.1) # allow space for resizing self._inner_hbox1.addStretch(1) self._inner_vbox.setSpacing(0) self._inner_vbox.setContentsMargins(0, 0, 0, 0) self._hlayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self._hlayout) self.show() def _go_clicked(self): self.model.targeter(self.index, self.targetWidget.text()) self.targetWidget.setText('') def _stop_clicked(self): self.model.stopper(self.index) def _reset_clicked(self): self.resetter(self.index) def _update(self): pass def _str2bin(self, value): return int(value) def _bin2str(self, value): return str(value) def _status(self, value): return "no status decoder implemented"