def __init__(self, parent, target, feat): super().__init__(parent) self._feat = feat layout = QHBoxLayout(self) if feat.keys: wid = QComboBox() if isinstance(feat.keys, dict): self._keys = list(feat.keys.keys()) else: self._keys = list(feat.keys) wid.addItems([str(key) for key in self._keys]) wid.currentIndexChanged.connect(self._combobox_changed) else: wid = QLineEdit() wid.textChanged.connect(self._lineedit_changed) layout.addWidget(wid) self._key_widget = wid wid = WidgetMixin.from_feat(feat) wid.bind_feat(feat) wid.feat_key = self._keys[0] wid.lantz_target = target layout.addWidget(wid) self._value_widget = wid
def __init__(self, parent, target): super().__init__(parent) self._lantz_target = target layout = QVBoxLayout(self) label = QLabel() label.setText(str(target)) layout.addWidget(label) recall = QPushButton() recall.setText('Refresh') recall.clicked.connect(lambda x: target.refresh()) update = QPushButton() update.setText('Update') update.clicked.connect( lambda x: target.update(self.widgets_values_as_dict())) auto = QCheckBox() auto.setText('Update on change') auto.setChecked(True) auto.stateChanged.connect(self.update_on_change) hlayout = QHBoxLayout() hlayout.addWidget(recall) hlayout.addWidget(update) hlayout.addWidget(auto) layout.addLayout(hlayout) self.writable_widgets = [] self.widgets = [] # Feat for feat_name, feat in sorted(target.feats.items()): try: feat_widget = LabeledFeatWidget(self, target, feat) self.widgets.append(feat_widget) if feat_widget.writable: self.writable_widgets.append(feat_widget) layout.addWidget(feat_widget) except Exception as ex: logger.debug('Could not create control for {}: {}'.format( feat_name, ex)) #import traceback #traceback.print_exc() # Actions line = QFrame(self) #self.line.setGeometry(QtCore.QRect(110, 80, 351, 31)) line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout.addWidget(line) actions_label = QLabel(self) actions_label.setText('Actions:') actions_label.setFixedWidth(120) self.actions_combo = QComboBox(self) self.actions_combo.addItems(list(target.actions.keys())) actions_button = QPushButton(self) actions_button.setFixedWidth(60) actions_button.setText('Run') actions_button.clicked.connect(self.on_run_clicked) alayout = QHBoxLayout() alayout.addWidget(actions_label) alayout.addWidget(self.actions_combo) alayout.addWidget(actions_button) layout.addLayout(alayout)
class DriverTestWidget(QWidget): """Widget that is automatically filled to control all Feats of a given driver. :param parent: parent widget. :param target: driver object to map. """ def __init__(self, parent, target): super().__init__(parent) self._lantz_target = target layout = QVBoxLayout(self) label = QLabel() label.setText(str(target)) layout.addWidget(label) recall = QPushButton() recall.setText('Refresh') recall.clicked.connect(lambda x: target.refresh()) update = QPushButton() update.setText('Update') update.clicked.connect( lambda x: target.update(self.widgets_values_as_dict())) auto = QCheckBox() auto.setText('Update on change') auto.setChecked(True) auto.stateChanged.connect(self.update_on_change) hlayout = QHBoxLayout() hlayout.addWidget(recall) hlayout.addWidget(update) hlayout.addWidget(auto) layout.addLayout(hlayout) self.writable_widgets = [] self.widgets = [] # Feat for feat_name, feat in sorted(target.feats.items()): try: feat_widget = LabeledFeatWidget(self, target, feat) self.widgets.append(feat_widget) if feat_widget.writable: self.writable_widgets.append(feat_widget) layout.addWidget(feat_widget) except Exception as ex: logger.debug('Could not create control for {}: {}'.format( feat_name, ex)) #import traceback #traceback.print_exc() # Actions line = QFrame(self) #self.line.setGeometry(QtCore.QRect(110, 80, 351, 31)) line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout.addWidget(line) actions_label = QLabel(self) actions_label.setText('Actions:') actions_label.setFixedWidth(120) self.actions_combo = QComboBox(self) self.actions_combo.addItems(list(target.actions.keys())) actions_button = QPushButton(self) actions_button.setFixedWidth(60) actions_button.setText('Run') actions_button.clicked.connect(self.on_run_clicked) alayout = QHBoxLayout() alayout.addWidget(actions_label) alayout.addWidget(self.actions_combo) alayout.addWidget(actions_button) layout.addLayout(alayout) @Slot() def on_run_clicked(self): ArgumentsInputDialog.run( getattr(self._lantz_target, self.actions_combo.currentText()), self) def update_on_change(self, new_state): """Set the 'update_on_change' flag to new_state in each writable widget within this widget. If True, the driver will be updated after each change. """ for widget in self.writable_widgets: widget._widget._update_on_change = new_state def widgets_values_as_dict(self): """Return a dictionary mapping each writable feat name to the current value of the widget. """ return { widget._feat.name: widget._widget.value() for widget in self.writable_widgets } @property def lantz_target(self): """Driver connected to this widget. """ return self._lantz_target @lantz_target.setter def lantz_target(self, driver): self._lantz_target = driver for widget in self.widgets: widget.lantz_target = driver
def __init__(self, parent, target): super().__init__(parent) self._lantz_target = target layout = QVBoxLayout(self) label = QLabel() label.setText(str(target)) layout.addWidget(label) recall = QPushButton() recall.setText('Refresh') recall.clicked.connect(lambda x: target.refresh()) update = QPushButton() update.setText('Update') update.clicked.connect(lambda x: target.update(self.widgets_values_as_dict())) auto = QCheckBox() auto.setText('Update on change') auto.setChecked(True) auto.stateChanged.connect(self.update_on_change) hlayout = QHBoxLayout() hlayout.addWidget(recall) hlayout.addWidget(update) hlayout.addWidget(auto) layout.addLayout(hlayout) self.writable_widgets = [] self.widgets = [] # Feat for feat_name, feat in sorted(target.feats.items()): try: feat_widget = LabeledFeatWidget(self, target, feat) self.widgets.append(feat_widget) if feat_widget.writable: self.writable_widgets.append(feat_widget) layout.addWidget(feat_widget) except Exception as ex: logger.debug('Could not create control for {}: {}'.format(feat_name, ex)) #import traceback #traceback.print_exc() # Actions line = QFrame(self) #self.line.setGeometry(QtCore.QRect(110, 80, 351, 31)) line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout.addWidget(line) actions_label = QLabel(self) actions_label.setText('Actions:') actions_label.setFixedWidth(120) self.actions_combo = QComboBox(self) self.actions_combo.addItems(list(target.actions.keys())) actions_button = QPushButton(self) actions_button.setFixedWidth(60) actions_button.setText('Run') actions_button.clicked.connect(self.on_run_clicked) alayout = QHBoxLayout() alayout.addWidget(actions_label) alayout.addWidget(self.actions_combo) alayout.addWidget(actions_button) layout.addLayout(alayout)
class DriverTestWidget(QWidget): """Widget that is automatically filled to control all Feats of a given driver. :param parent: parent widget. :param target: driver object to map. """ def __init__(self, parent, target): super().__init__(parent) self._lantz_target = target layout = QVBoxLayout(self) label = QLabel() label.setText(str(target)) layout.addWidget(label) recall = QPushButton() recall.setText('Refresh') recall.clicked.connect(lambda x: target.refresh()) update = QPushButton() update.setText('Update') update.clicked.connect(lambda x: target.update(self.widgets_values_as_dict())) auto = QCheckBox() auto.setText('Update on change') auto.setChecked(True) auto.stateChanged.connect(self.update_on_change) hlayout = QHBoxLayout() hlayout.addWidget(recall) hlayout.addWidget(update) hlayout.addWidget(auto) layout.addLayout(hlayout) self.writable_widgets = [] self.widgets = [] # Feat for feat_name, feat in sorted(target.feats.items()): try: feat_widget = LabeledFeatWidget(self, target, feat) self.widgets.append(feat_widget) if feat_widget.writable: self.writable_widgets.append(feat_widget) layout.addWidget(feat_widget) except Exception as ex: logger.debug('Could not create control for {}: {}'.format(feat_name, ex)) #import traceback #traceback.print_exc() # Actions line = QFrame(self) #self.line.setGeometry(QtCore.QRect(110, 80, 351, 31)) line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout.addWidget(line) actions_label = QLabel(self) actions_label.setText('Actions:') actions_label.setFixedWidth(120) self.actions_combo = QComboBox(self) self.actions_combo.addItems(list(target.actions.keys())) actions_button = QPushButton(self) actions_button.setFixedWidth(60) actions_button.setText('Run') actions_button.clicked.connect(self.on_run_clicked) alayout = QHBoxLayout() alayout.addWidget(actions_label) alayout.addWidget(self.actions_combo) alayout.addWidget(actions_button) layout.addLayout(alayout) @Slot(QVariant) def on_run_clicked(self): ArgumentsInputDialog.run(getattr(self._lantz_target, self.actions_combo.currentText()), self) def update_on_change(self, new_state): """Set the 'update_on_change' flag to new_state in each writable widget within this widget. If True, the driver will be updated after each change. """ for widget in self.writable_widgets: widget._widget._update_on_change = new_state def widgets_values_as_dict(self): """Return a dictionary mapping each writable feat name to the current value of the widget. """ return {widget._feat.name: widget._widget.value() for widget in self.writable_widgets} @property def lantz_target(self): """Driver connected to this widget. """ return self._lantz_target @lantz_target.setter def lantz_target(self, driver): self._lantz_target = driver for widget in self.widgets: widget.lantz_target = driver