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 _init_ui(self): table_small = MListView(size=dayu_theme.small) table_default = MListView() table_large = MListView(size=dayu_theme.large) model_1 = MTableModel() model_1.set_header_list(mock.header_list) model_sort = MSortFilterModel() model_sort.setSourceModel(model_1) table_small.setModel(model_sort) table_default.setModel(model_sort) table_large.setModel(model_sort) model_sort.set_header_list(mock.header_list) table_small.set_header_list(mock.header_list) table_default.set_header_list(mock.header_list) table_large.set_header_list(mock.header_list) model_1.set_data_list(mock.data_list) line_edit = MLineEdit().search().small() line_edit.textChanged.connect(model_sort.set_search_pattern) main_lay = QVBoxLayout() main_lay.addWidget(line_edit) main_lay.addWidget(MDivider('Small Size')) main_lay.addWidget(table_small) main_lay.addWidget(MDivider('Default Size')) main_lay.addWidget(table_default) main_lay.addWidget(MDivider('Large Size')) main_lay.addWidget(table_large) main_lay.addStretch() 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 _init_ui(self): model_1 = MTableModel() model_1.set_header_list(mock.header_list) model_sort = MSortFilterModel() model_sort.setSourceModel(model_1) table_small = MTableView(size=dayu_theme.small, show_row_count=True) table_grid = MTableView(size=dayu_theme.small, show_row_count=True) table_grid.setShowGrid(True) table_default = MTableView(size=dayu_theme.medium, show_row_count=True) thread = MFetchDataThread(self) self.loading_wrapper = MLoadingWrapper(widget=table_default, loading=False) thread.started.connect(functools.partial(self.loading_wrapper.set_dayu_loading, True)) thread.finished.connect(functools.partial(self.loading_wrapper.set_dayu_loading, False)) thread.finished.connect(functools.partial(table_default.setModel, model_sort)) button = MPushButton(text='Get Data: 4s') button.clicked.connect(thread.start) switch_lay = QHBoxLayout() switch_lay.addWidget(button) switch_lay.addStretch() table_large = MTableView(size=dayu_theme.large, show_row_count=False) table_small.setModel(model_sort) table_grid.setModel(model_sort) table_large.setModel(model_sort) model_sort.set_header_list(mock.header_list) table_small.set_header_list(mock.header_list) table_grid.set_header_list(mock.header_list) table_default.set_header_list(mock.header_list) table_large.set_header_list(mock.header_list) model_1.set_data_list(mock.data_list) line_edit = MLineEdit().search().small() line_edit.textChanged.connect(model_sort.set_search_pattern) main_lay = QVBoxLayout() main_lay.addWidget(line_edit) main_lay.addWidget(MDivider('Small Size')) main_lay.addWidget(table_small) main_lay.addWidget(MDivider('Default Size')) main_lay.addLayout(switch_lay) main_lay.addWidget(self.loading_wrapper) main_lay.addWidget(MDivider('Large Size (Hide Row Count)')) main_lay.addWidget(table_large) main_lay.addWidget(MDivider('With Grid')) main_lay.addWidget(table_grid) main_lay.addStretch() self.setLayout(main_lay)
def slot_new_account(self): custom_widget = QWidget() custom_lay = QFormLayout() custom_lay.addRow('Name', MLineEdit()) custom_lay.addRow('Age', MSpinBox()) custom_lay.addRow('Birth', MDateEdit()) custom_widget.setLayout(custom_lay) drawer = MDrawer('New account', parent=self) submit_button = MPushButton('Submit').primary() submit_button.clicked.connect(drawer.close) drawer.add_button(MPushButton('Cancel')) drawer.add_button(submit_button) drawer.setFixedWidth(200) drawer.set_widget(custom_widget) drawer.show()
def __init__(self, parent=None): super(FieldMixinExample, self).__init__(parent) self.register_field('my_name', 'xiaoming') self.register_field('thumbnail_path', '') self.register_field('is_enable', True) self.register_field('status', 'waiting') self.register_field('str_enable', self.computed_str_enable) self.register_field('thumbnail_pix_map', self.computed_thumbnail_pix_map) self.register_field('email', self.computed_email) name2_label = MLabel() email_label = MLabel() thumbnail_label = MLabel() enable_button = MPushButton().primary() self.bind('my_name', name2_label, 'dayu_text') self.bind('email', email_label, 'dayu_text') self.bind('is_enable', enable_button, 'enabled') self.bind('thumbnail_pix_map', thumbnail_label, 'pixmap') self.bind('str_enable', enable_button, 'text') button = MPushButton(text='Change Data').primary() button.clicked.connect(self.slot_change_data) main_lay = QGridLayout() main_lay.addWidget(MLabel('Avatar:'), 0, 0) main_lay.addWidget(thumbnail_label, 0, 1) main_lay.addWidget(MLabel('Name:'), 1, 0) main_lay.addWidget( self.bind('my_name', MLineEdit(), 'text', signal='textEdited'), 1, 1) main_lay.addWidget(MLabel('Email:'), 2, 0) main_lay.addWidget(email_label, 2, 1) main_lay.addWidget(MLabel('Enabled:'), 3, 0) main_lay.addWidget(enable_button, 3, 1) # for index, i in enumerate(self.field('my_name')): # main_lay.addRow('name{}:'.format(index), self.bind('my_name', QLabel(), 'text', index=index)) main_lay.addWidget(button, 4, 1) temp_lay = QVBoxLayout() temp_lay.addLayout(main_lay) temp_lay.addStretch() self.setLayout(temp_lay)
class MSequenceFile(QWidget, MFieldMixin): ''' 这个类必须依赖 DayuPath props: path: basestring 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, table_view=True, big_view=False, parent=None): super(MItemViewFullSet, self).__init__(parent) self.sort_filter_model = MSortFilterModel() self.source_model = MTableModel() self.sort_filter_model.setSourceModel(self.source_model) self.stack_widget = QStackedWidget() self.view_button_grp = MToolButtonGroup(exclusive=True) data_group = [] if table_view: self.table_view = MTableView(show_row_count=True) self.table_view.doubleClicked.connect(self.sig_double_clicked) self.table_view.pressed.connect(self.slot_left_clicked) self.table_view.setModel(self.sort_filter_model) self.stack_widget.addWidget(self.table_view) data_group.append({ 'svg': 'table_view.svg', 'checkable': True, 'tooltip': u'Table View' }) if big_view: self.big_view = MBigView() self.big_view.doubleClicked.connect(self.sig_double_clicked) self.big_view.pressed.connect(self.slot_left_clicked) self.big_view.setModel(self.sort_filter_model) self.stack_widget.addWidget(self.big_view) data_group.append({ 'svg': 'big_view.svg', 'checkable': True, 'tooltip': u'Big View' }) # 设置多个view 共享 MItemSelectionModel leader_view = self.stack_widget.widget(0) self.selection_model = leader_view.selectionModel() for index in range(self.stack_widget.count()): if index == 0: continue other_view = self.stack_widget.widget(index) other_view.setSelectionModel(self.selection_model) self.selection_model.currentChanged.connect(self.sig_current_changed) self.selection_model.currentRowChanged.connect( self.sig_current_row_changed) self.selection_model.currentColumnChanged.connect( self.sig_current_column_changed) self.selection_model.selectionChanged.connect( self.sig_selection_changed) self.tool_bar = QWidget() self.top_lay = QHBoxLayout() self.top_lay.setContentsMargins(0, 0, 0, 0) if data_group and len(data_group) > 1: self.view_button_grp.sig_checked_changed.connect( self.stack_widget.setCurrentIndex) self.view_button_grp.set_button_list(data_group) self.view_button_grp.set_dayu_checked(0) self.top_lay.addWidget(self.view_button_grp) self.search_line_edit = MLineEdit().search().small() self.search_attr_button = MToolButton().icon_only().svg( 'down_fill.svg').small() self.search_line_edit.set_prefix_widget(self.search_attr_button) self.search_line_edit.textChanged.connect( self.sort_filter_model.set_search_pattern) self.search_line_edit.setVisible(False) self.top_lay.addStretch() self.top_lay.addWidget(self.search_line_edit) self.tool_bar.setLayout(self.top_lay) self.page_set = MPage() self.main_lay = QVBoxLayout() self.main_lay.setSpacing(5) self.main_lay.setContentsMargins(0, 0, 0, 0) self.main_lay.addWidget(self.tool_bar) self.main_lay.addWidget(self.stack_widget) self.main_lay.addWidget(self.page_set) self.setLayout(self.main_lay)
class MItemViewFullSet(QWidget): sig_double_clicked = Signal(QModelIndex) sig_left_clicked = Signal(QModelIndex) sig_current_changed = Signal(QModelIndex, QModelIndex) sig_current_row_changed = Signal(QModelIndex, QModelIndex) sig_current_column_changed = Signal(QModelIndex, QModelIndex) sig_selection_changed = Signal(QItemSelection, QItemSelection) sig_context_menu = Signal(object) def __init__(self, table_view=True, big_view=False, parent=None): super(MItemViewFullSet, self).__init__(parent) self.sort_filter_model = MSortFilterModel() self.source_model = MTableModel() self.sort_filter_model.setSourceModel(self.source_model) self.stack_widget = QStackedWidget() self.view_button_grp = MToolButtonGroup(exclusive=True) data_group = [] if table_view: self.table_view = MTableView(show_row_count=True) self.table_view.doubleClicked.connect(self.sig_double_clicked) self.table_view.pressed.connect(self.slot_left_clicked) self.table_view.setModel(self.sort_filter_model) self.stack_widget.addWidget(self.table_view) data_group.append({ 'svg': 'table_view.svg', 'checkable': True, 'tooltip': u'Table View' }) if big_view: self.big_view = MBigView() self.big_view.doubleClicked.connect(self.sig_double_clicked) self.big_view.pressed.connect(self.slot_left_clicked) self.big_view.setModel(self.sort_filter_model) self.stack_widget.addWidget(self.big_view) data_group.append({ 'svg': 'big_view.svg', 'checkable': True, 'tooltip': u'Big View' }) # 设置多个view 共享 MItemSelectionModel leader_view = self.stack_widget.widget(0) self.selection_model = leader_view.selectionModel() for index in range(self.stack_widget.count()): if index == 0: continue other_view = self.stack_widget.widget(index) other_view.setSelectionModel(self.selection_model) self.selection_model.currentChanged.connect(self.sig_current_changed) self.selection_model.currentRowChanged.connect( self.sig_current_row_changed) self.selection_model.currentColumnChanged.connect( self.sig_current_column_changed) self.selection_model.selectionChanged.connect( self.sig_selection_changed) self.tool_bar = QWidget() self.top_lay = QHBoxLayout() self.top_lay.setContentsMargins(0, 0, 0, 0) if data_group and len(data_group) > 1: self.view_button_grp.sig_checked_changed.connect( self.stack_widget.setCurrentIndex) self.view_button_grp.set_button_list(data_group) self.view_button_grp.set_dayu_checked(0) self.top_lay.addWidget(self.view_button_grp) self.search_line_edit = MLineEdit().search().small() self.search_attr_button = MToolButton().icon_only().svg( 'down_fill.svg').small() self.search_line_edit.set_prefix_widget(self.search_attr_button) self.search_line_edit.textChanged.connect( self.sort_filter_model.set_search_pattern) self.search_line_edit.setVisible(False) self.top_lay.addStretch() self.top_lay.addWidget(self.search_line_edit) self.tool_bar.setLayout(self.top_lay) self.page_set = MPage() self.main_lay = QVBoxLayout() self.main_lay.setSpacing(5) self.main_lay.setContentsMargins(0, 0, 0, 0) self.main_lay.addWidget(self.tool_bar) self.main_lay.addWidget(self.stack_widget) self.main_lay.addWidget(self.page_set) self.setLayout(self.main_lay) def enable_context_menu(self): for index in range(self.stack_widget.count()): view = self.stack_widget.widget(index) view.enable_context_menu(True) view.sig_context_menu.connect(self.sig_context_menu) def set_no_data_text(self, text): for index in range(self.stack_widget.count()): view = self.stack_widget.widget(index) view.set_no_data_text(text) def set_selection_mode(self, mode): for index in range(self.stack_widget.count()): view = self.stack_widget.widget(index) view.setSelectionMode(mode) def tool_bar_visible(self, flag): self.tool_bar.setVisible(flag) @Slot(QModelIndex) def slot_left_clicked(self, start_index): button = QApplication.mouseButtons() if button == Qt.LeftButton: real_index = self.sort_filter_model.mapToSource(start_index) self.sig_left_clicked.emit(real_index) def set_header_list(self, header_list): self.source_model.set_header_list(header_list) self.sort_filter_model.set_header_list(header_list) self.sort_filter_model.setSourceModel(self.source_model) for index in range(self.stack_widget.count()): view = self.stack_widget.widget(index) view.set_header_list(header_list) def tool_bar_append_widget(self, widget): self.top_lay.addWidget(widget) def tool_bar_insert_widget(self, widget): self.top_lay.insertWidget(0, widget) @Slot() def setup_data(self, data_list): self.source_model.clear() if data_list: self.source_model.set_data_list(data_list) self.set_record_count(len(data_list)) @Slot(int) def set_record_count(self, total): self.page_set.set_total(total) def get_data(self): return self.source_model.get_data_list() def searchable(self): """Enable search line edit visible.""" self.search_line_edit.setVisible(True) return self
def _init_ui(self): size_lay = QHBoxLayout() line_edit_l = MLineEdit().large() line_edit_l.setPlaceholderText('large size') line_edit_m = MLineEdit().medium() line_edit_m.setPlaceholderText('default size') line_edit_s = MLineEdit().small() line_edit_s.setPlaceholderText('small size') size_lay.addWidget(line_edit_l) size_lay.addWidget(line_edit_m) size_lay.addWidget(line_edit_s) line_edit_tool_button = MLineEdit(text='MToolButton') line_edit_tool_button.set_prefix_widget(MToolButton().svg('user_line.svg').icon_only()) line_edit_label = MLineEdit(text='MLabel') tool_button = MLabel(text='User').mark().secondary() tool_button.setAlignment(Qt.AlignCenter) tool_button.setFixedWidth(80) line_edit_label.set_prefix_widget(tool_button) line_edit_push_button = MLineEdit(text='MPushButton') push_button = MPushButton(text='Go').primary() push_button.setFixedWidth(40) line_edit_push_button.set_suffix_widget(push_button) search_engine_line_edit = MLineEdit().search_engine().large() search_engine_line_edit.returnPressed.connect(self.slot_search) line_edit_options = MLineEdit() combobox = MComboBox() option_menu = MMenu() option_menu.set_separator('|') option_menu.set_data([r'http://', r'https://']) combobox.set_menu(option_menu) combobox.set_value('http://') combobox.setFixedWidth(90) line_edit_options.set_prefix_widget(combobox) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('different size')) main_lay.addLayout(size_lay) main_lay.addWidget(MDivider('custom prefix and suffix widget')) main_lay.addWidget(line_edit_tool_button) main_lay.addWidget(line_edit_label) main_lay.addWidget(line_edit_push_button) main_lay.addWidget(MDivider('preset')) main_lay.addWidget(MLabel('error')) main_lay.addWidget(MLineEdit(text='waring: file d:/ddd/ccc.jpg not exists.').error()) main_lay.addWidget(MLabel('search')) main_lay.addWidget(MLineEdit().search().small()) main_lay.addWidget(MLabel('search_engine')) main_lay.addWidget(search_engine_line_edit) main_lay.addWidget(MLabel('file')) main_lay.addWidget(MLineEdit().file().small()) main_lay.addWidget(MLabel('folder')) main_lay.addWidget(MLineEdit().folder().small()) main_lay.addWidget(MLabel('MLineEdit.options()')) main_lay.addWidget(line_edit_options) main_lay.addStretch() self.setLayout(main_lay)