class CellBase(Observation, QWidget): def __init__(self, subject, index): Observation.__init__(self, subject) QWidget.__init__(self) self.index = index self.selected = False self._initNameLabel() def _initNameLabel(self): self.nameLabel = QLineEdit(self) self.nameLabel.setWindowFlags(Qt.FramelessWindowHint) self.nameLabel.setStyleSheet("background: transparent; border: none;") self.nameLabel.setMaxLength(30) self.nameLabel.setContextMenuPolicy(Qt.NoContextMenu) self.nameLabel.textChanged.connect(self.onNameChanged) self.nameLabel.editingFinished.connect(self.onEditingNameFinished) def editNameResponder(self, e): if self.selected: self.nameLabel.setFocus() self.nameLabel.selectAll() def onNameChanged(self, name): pass def onEditingNameFinished(self): self.nameLabel.clearFocus() def setSelected(self, value): self.selected = value self.updateStyle() def updateStyle(self): pass def setName(self, name): self.nameLabel.setText(name) def name(self): return self.nameLabel.text() def delete(self): self.unregister() self.setParent(None) self.deleteLater()
def _setupExpression(self, expressionLabel, expressionChangedCB, expressionFinishedCB): expressionWidget = QWidget() expressionLayout = QHBoxLayout() expressionLayout.setContentsMargins(0, 0, 0, 0) expressionLayout.setSpacing(utils.dpiScale(2)) expressionWidget.setLayout(expressionLayout) expression = QLineEdit() tip = maya.stringTable['y_simpleSelector.kExpressionTooltipStr'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr1'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr2'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr3'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr4'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr5'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr6'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr7'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr8'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr9'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr10'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr11'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr12'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr13'] tip += maya.stringTable['y_simpleSelector.kExpressionTooltipStr14'] expression.setToolTip(tip) expression.textChanged.connect(expressionChangedCB) # editingFinished is triggered for both enter key pressed and focused lost. expression.editingFinished.connect(expressionFinishedCB) expression.returnPressed.connect(lambda: expression.clearFocus()) expression.setPlaceholderText(self.CREATE_EXPRESSION_STRING) expressionLayout.addWidget(expression) selectButton = QPushButton(self.SELECT_STRING) selectButton.setToolTip( maya.stringTable['y_simpleSelector.kExpressionSelectTooltipStr']) selectButton.setMinimumWidth(self.EXPRESSION_BUTTON_WIDTH) selectButton.clicked.connect(self.selectIncludeExpression) expressionLayout.addWidget(selectButton) self.addToCollectionGroupBoxLayout.addRow(expressionLabel, expressionWidget) return expressionWidget, expression
class ParameterInteger(QWidget): def check_int(self, s): if s[0] in ("-", "+"): return s[1:].isdigit() return s.isdigit() def clamp(self, value, min_value, max_value): if value < min_value: return min_value elif value > max_value: return max_value else: return value def __init__(self, parent=None, value=0, name="", label_text="", min_value=None, max_value=None, label_width=64, height=22, min_visible=0, max_visible=10, change_callback=None): QWidget.__init__(self, parent) self.VERTICAL_MARGIN = 0 self.HORIZONTAL_MARGIN = 0 self.name = name self.label_text = label_text self.min_value_raw = min_value self.max_value_raw = max_value self.min_value = min_value if min_value is not None else -sys.maxsize self.max_value = max_value if max_value is not None else sys.maxsize self.value = self.clamp(value, self.min_value, self.max_value) self.min_visible = max(self.min_value, min(min_visible, self.value)) self.max_visible = min(self.max_value, max(max_visible, self.value)) self._is_callback_define = False if change_callback is not None: self._change_callback = change_callback self._is_callback_define = True self._last_call = None self.label = QLabel(label_text) self.label.setFixedWidth(label_width) self.label.setFixedHeight(height) self.value_textbox = QLineEdit() self.value_textbox.setFixedWidth(52) self.value_textbox.setFixedHeight(height) self._update_value_label() self.slider = QSlider(Qt.Horizontal) self.slider.setFixedHeight(height) self._update_visible_interval() self.slider.setValue(value) layout = QHBoxLayout() layout.setContentsMargins(self.HORIZONTAL_MARGIN, self.VERTICAL_MARGIN, self.HORIZONTAL_MARGIN, self.VERTICAL_MARGIN) layout.addWidget(self.label) layout.addWidget(self.value_textbox) layout.addWidget(self.slider) self.setLayout(layout) self.slider.valueChanged.connect(self.slider_valueChanged) self.value_textbox.returnPressed.connect(self.textbox_enter) self.value_textbox.editingFinished.connect(self.textbox_enter) self.slider.sliderReleased.connect(self.slider_sliderReleased) def _update_visible_interval(self): self.slider.setRange(self.min_visible, self.max_visible) def _update_value_label(self): self.value_textbox.setText(str(self.value)) def slider_valueChanged(self, value): self.value = value self._update_value_label() self.value_change() def slider_sliderReleased(self): self.try_change_visible(self.value) self.slider.setValue(self.value) def try_change_visible(self, new_value): delta = self.max_visible - self.min_visible # increase visible interval if new value out of the current if new_value <= self.min_visible: self.min_visible = max(self.min_value, new_value - delta) if new_value >= self.max_visible: self.max_visible = min(self.max_value, new_value + delta) self._update_visible_interval() def textbox_enter(self): text = self.value_textbox.text() # check is this text is integer if self.check_int(text): new_value = int(text) # clamp value if new_value < self.min_value: new_value = self.min_value if new_value > self.max_value: new_value = self.max_value self.try_change_visible(new_value) self.slider.setValue(new_value) self._update_value_label() self.value_change() else: self._update_value_label() self.value_textbox.clearFocus() def value_change(self): if self._is_callback_define: if self._last_call is None or self._last_call != self.value: self._last_call = self.value self._change_callback(param_name=self.name, param_value=self.value)