def __init__(self, size=None, parent=None): super(MSequenceFile, self).__init__(parent) self.sequence_obj = None size = size or dayu_theme.small self._file_label = MLineEdit() self._file_label.set_dayu_size(size) self._file_label.setReadOnly(True) self._is_sequence_check_box = MCheckBox(self.tr('Sequence')) self._is_sequence_check_box.toggled.connect( functools.partial(self.setProperty, 'sequence')) self._is_sequence_check_box.toggled.connect( self.sig_is_sequence_changed) self._info_label = MLabel().secondary() self._error_label = MLabel().secondary() self._error_label.setProperty('error', True) self._error_label.setMinimumWidth(100) self._error_label.set_elide_mode(Qt.ElideMiddle) seq_lay = QHBoxLayout() seq_lay.addWidget(self._is_sequence_check_box) seq_lay.addWidget(self._info_label) seq_lay.addWidget(self._error_label) seq_lay.setStretchFactor(self._is_sequence_check_box, 0) seq_lay.setStretchFactor(self._info_label, 0) seq_lay.setStretchFactor(self._error_label, 100) self._main_lay = QVBoxLayout() self._main_lay.setContentsMargins(0, 0, 0, 0) self._main_lay.addWidget(self._file_label) self._main_lay.addLayout(seq_lay) self.setLayout(self._main_lay) self.set_sequence(True)
def test_radio_button_init(qtbot): radio_1 = MCheckBox('test') radio_2 = MCheckBox('') qtbot.addWidget(radio_1) qtbot.addWidget(radio_2) assert radio_1.text() == 'test' assert radio_2.text() == ''
def test_radio_button_init(qtbot): radio_1 = MCheckBox("test") radio_2 = MCheckBox("") qtbot.addWidget(radio_1) qtbot.addWidget(radio_2) assert radio_1.text() == "test" assert radio_2.text() == ""
def _init_ui(self): form_lay = QtWidgets.QFormLayout() form_lay.setLabelAlignment(QtCore.Qt.AlignRight) gender_grp = MRadioButtonGroup() gender_grp.set_button_list([ { "text": "Female", "icon": MIcon("female.svg") }, { "text": "Male", "icon": MIcon("male.svg") }, ]) country_combo_box = MComboBox().small() country_combo_box.addItems(["China", "France", "Japan", "US"]) date_edit = MDateEdit().small() date_edit.setCalendarPopup(True) form_lay.addRow("Name:", MLineEdit().small()) form_lay.addRow("Gender:", gender_grp) form_lay.addRow("Age:", MSpinBox().small()) form_lay.addRow("Password:"******"Country:", country_combo_box) form_lay.addRow("Birthday:", date_edit) switch = MSwitch() switch.setChecked(True) form_lay.addRow("Switch:", switch) slider = MSlider() slider.setValue(30) form_lay.addRow("Slider:", slider) button_lay = QtWidgets.QHBoxLayout() button_lay.addStretch() button_lay.addWidget(MPushButton(text="Submit").primary()) button_lay.addWidget(MPushButton(text="Cancel")) main_lay = QtWidgets.QVBoxLayout() main_lay.addLayout(form_lay) main_lay.addWidget(MCheckBox("I accept the terms and conditions")) main_lay.addStretch() main_lay.addWidget(MDivider()) main_lay.addLayout(button_lay) self.setLayout(main_lay)
def _init_ui(self): form_lay = QFormLayout() form_lay.setLabelAlignment(Qt.AlignRight) gender_grp = MRadioButtonGroup() gender_grp.set_button_list([{ 'text': 'Female', 'icon': MIcon('female.svg') }, { 'text': 'Male', 'icon': MIcon('male.svg') }]) country_combo_box = MComboBox().small() country_combo_box.addItems(['China', 'France', 'Japan', 'US']) date_edit = MDateEdit().small() date_edit.setCalendarPopup(True) form_lay.addRow('Name:', MLineEdit().small()) form_lay.addRow('Gender:', gender_grp) form_lay.addRow('Age:', MSpinBox().small()) form_lay.addRow('Password:'******'Country:', country_combo_box) form_lay.addRow('Birthday:', date_edit) switch = MSwitch() switch.setChecked(True) form_lay.addRow('Switch:', switch) slider = MSlider() slider.setValue(30) form_lay.addRow('Slider:', slider) button_lay = QHBoxLayout() button_lay.addStretch() button_lay.addWidget(MPushButton(text='Submit').primary()) button_lay.addWidget(MPushButton(text='Cancel')) main_lay = QVBoxLayout() main_lay.addLayout(form_lay) main_lay.addWidget(MCheckBox('I accept the terms and conditions')) main_lay.addStretch() main_lay.addWidget(MDivider()) main_lay.addLayout(button_lay) self.setLayout(main_lay)
def create_button(self, data_dict): return MCheckBox()
class MSequenceFile(QWidget, MFieldMixin): ''' 这个类必须依赖 DayuPath props: path: six.string_types sequence: bool ''' sig_is_sequence_changed = Signal(bool) def __init__(self, size=None, parent=None): super(MSequenceFile, self).__init__(parent) self.sequence_obj = None size = size or dayu_theme.small self._file_label = MLineEdit() self._file_label.set_dayu_size(size) self._file_label.setReadOnly(True) self._is_sequence_check_box = MCheckBox(self.tr('Sequence')) self._is_sequence_check_box.toggled.connect( functools.partial(self.setProperty, 'sequence')) self._is_sequence_check_box.toggled.connect( self.sig_is_sequence_changed) self._info_label = MLabel().secondary() self._error_label = MLabel().secondary() self._error_label.setProperty('error', True) self._error_label.setMinimumWidth(100) self._error_label.set_elide_mode(Qt.ElideMiddle) seq_lay = QHBoxLayout() seq_lay.addWidget(self._is_sequence_check_box) seq_lay.addWidget(self._info_label) seq_lay.addWidget(self._error_label) seq_lay.setStretchFactor(self._is_sequence_check_box, 0) seq_lay.setStretchFactor(self._info_label, 0) seq_lay.setStretchFactor(self._error_label, 100) self._main_lay = QVBoxLayout() self._main_lay.setContentsMargins(0, 0, 0, 0) self._main_lay.addWidget(self._file_label) self._main_lay.addLayout(seq_lay) self.setLayout(self._main_lay) self.set_sequence(True) def _set_path(self, value): path = DayuPath(value) for seq_obj in path.scan(): self.sequence_obj = seq_obj self._update_info() def set_path(self, value): self.setProperty('path', value) def set_sequence(self, value): assert isinstance(value, bool) self.setProperty('sequence', value) def _set_sequence(self, value): if value != self._is_sequence_check_box.isChecked(): # 更新来自代码 self._is_sequence_check_box.setChecked(value) self.sig_is_sequence_changed.emit(value) self._update_info() def _update_info(self): self._file_label.setProperty( 'text', self.sequence_obj if self.property('sequence') else self.property('path')) if self.sequence_obj: self._info_label.setText(u'Format: {ext} ' u'Total: {count} ' u'Range: {start}-{end}'.format( ext=self.sequence_obj.ext, count=len(self.sequence_obj.frames), start=self.sequence_obj.frames[0] if self.sequence_obj.frames else '/', end=self.sequence_obj.frames[-1] if self.sequence_obj.frames else '/')) error_info = u'Missing: {}'.format( self.sequence_obj.missing) if self.sequence_obj.missing else '' self._error_label.setText(error_info) self._error_label.setToolTip(error_info) self._info_label.setVisible(self.property('sequence')) self._error_label.setVisible(self.property('sequence'))
def __init__(self, parent=None): super(CheckBoxExample, self).__init__(parent) self.setWindowTitle("Example for MCheckBox") grid_lay = QtWidgets.QGridLayout() for index, (text, state) in enumerate([ ("Unchecked", QtCore.Qt.Unchecked), ("Checked", QtCore.Qt.Checked), ("Partially", QtCore.Qt.PartiallyChecked), ]): check_box_normal = MCheckBox(text) check_box_normal.setCheckState(state) check_box_disabled = MCheckBox(text) check_box_disabled.setCheckState(state) check_box_disabled.setEnabled(False) grid_lay.addWidget(check_box_normal, 0, index) grid_lay.addWidget(check_box_disabled, 1, index) icon_lay = QtWidgets.QHBoxLayout() for text, icon in [ ("Maya", MIcon("app-maya.png")), ("Nuke", MIcon("app-nuke.png")), ("Houdini", MIcon("app-houdini.png")), ]: check_box_icon = MCheckBox(text) check_box_icon.setIcon(icon) icon_lay.addWidget(check_box_icon) check_box_bind = MCheckBox("Data Bind") label = MLabel() button = MPushButton(text="Change State") button.clicked.connect( lambda: self.set_field("checked", not self.field("checked"))) self.register_field("checked", True) self.register_field( "checked_text", lambda: "Yes!" if self.field("checked") else "No!!") self.bind("checked", check_box_bind, "checked", signal="stateChanged") self.bind("checked_text", label, "text") main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("Basic")) main_lay.addLayout(grid_lay) main_lay.addWidget(MDivider("Icon")) main_lay.addLayout(icon_lay) main_lay.addWidget(MDivider("Data Bind")) main_lay.addWidget(check_box_bind) main_lay.addWidget(label) main_lay.addWidget(button) main_lay.addStretch() self.setLayout(main_lay)
def __init__(self, parent=None): super(CheckBoxExample, self).__init__(parent) self.setWindowTitle('Example for MCheckBox') grid_lay = QGridLayout() for index, (text, state) in enumerate([('Unchecked', Qt.Unchecked), ('Checked', Qt.Checked), ('Partially', Qt.PartiallyChecked)]): check_box_normal = MCheckBox(text) check_box_normal.setCheckState(state) check_box_disabled = MCheckBox(text) check_box_disabled.setCheckState(state) check_box_disabled.setEnabled(False) grid_lay.addWidget(check_box_normal, 0, index) grid_lay.addWidget(check_box_disabled, 1, index) icon_lay = QHBoxLayout() for text, icon in [('Maya', MIcon('app-maya.png')), ('Nuke', MIcon('app-nuke.png')), ('Houdini', MIcon('app-houdini.png'))]: check_box_icon = MCheckBox(text) check_box_icon.setIcon(icon) icon_lay.addWidget(check_box_icon) check_box_bind = MCheckBox('Data Bind') label = MLabel() button = MPushButton(text='Change State') button.clicked.connect( lambda: self.set_field('checked', not self.field('checked'))) self.register_field('checked', True) self.register_field( 'checked_text', lambda: 'Yes!' if self.field('checked') else 'No!!') self.bind('checked', check_box_bind, 'checked', signal='stateChanged') self.bind('checked_text', label, 'text') main_lay = QVBoxLayout() main_lay.addWidget(MDivider('Basic')) main_lay.addLayout(grid_lay) main_lay.addWidget(MDivider('Icon')) main_lay.addLayout(icon_lay) main_lay.addWidget(MDivider('Data Bind')) main_lay.addWidget(check_box_bind) main_lay.addWidget(label) main_lay.addWidget(button) main_lay.addStretch() self.setLayout(main_lay)