def _init_ui(self): self.register_field('percent', 20) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('different orientation')) for orn in [Qt.Horizontal, Qt.Vertical]: line_edit_hor = MSlider(orn) line_edit_hor.setRange(1, 100) self.bind('percent', line_edit_hor, 'value') lay = QVBoxLayout() lay.addWidget(line_edit_hor) main_lay.addLayout(lay) spin_box = MSpinBox() spin_box.setRange(1, 100) self.bind('percent', spin_box, 'value', signal='valueChanged') lay3 = QHBoxLayout() button_grp = MPushButtonGroup() button_grp.set_button_list([ { 'text': '+', 'clicked': functools.partial(self.slot_change_value, 10) }, { 'text': '-', 'clicked': functools.partial(self.slot_change_value, -10) }, ]) lay3.addWidget(spin_box) lay3.addWidget(button_grp) lay3.addStretch() main_lay.addWidget(MDivider('data bind')) main_lay.addLayout(lay3) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): self.register_field("percent", 20) main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("different orientation")) for orn in [QtCore.Qt.Horizontal, QtCore.Qt.Vertical]: line_edit_hor = MSlider(orn) line_edit_hor.setRange(1, 100) self.bind("percent", line_edit_hor, "value") lay = QtWidgets.QVBoxLayout() lay.addWidget(line_edit_hor) main_lay.addLayout(lay) spin_box = MSpinBox() spin_box.setRange(1, 100) self.bind("percent", spin_box, "value", signal="valueChanged") lay3 = QtWidgets.QHBoxLayout() button_grp = MPushButtonGroup() button_grp.set_button_list( [ {"text": "+", "clicked": functools.partial(self.slot_change_value, 10)}, { "text": "-", "clicked": functools.partial(self.slot_change_value, -10), }, ] ) lay3.addWidget(spin_box) lay3.addWidget(button_grp) lay3.addStretch() main_lay.addWidget(MDivider("data bind")) main_lay.addLayout(lay3) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): standalone_lay = QHBoxLayout() standalone_lay.addWidget(MBadge.count(0)) standalone_lay.addWidget(MBadge.count(20)) standalone_lay.addWidget(MBadge.count(100)) standalone_lay.addWidget(MBadge.dot(True)) standalone_lay.addWidget(MBadge.text('new')) standalone_lay.addStretch() button = MToolButton().svg('trash_line.svg') avatar = MAvatar.large(MPixmap('avatar.png')) button_alert = MToolButton().svg('alert_fill.svg').large() badge_1 = MBadge.dot(True, widget=button) badge_2 = MBadge.dot(True, widget=avatar) badge_3 = MBadge.dot(True, widget=button_alert) button.clicked.connect(lambda: badge_1.set_dayu_dot(False)) spin_box = MSpinBox() spin_box.setRange(0, 9999) spin_box.valueChanged.connect(badge_3.set_dayu_count) spin_box.setValue(1) self.register_field('button1_selected', u'北京') menu1 = MMenu() menu1.set_data([u'北京', u'上海', u'广州', u'深圳']) select1 = MComboBox() select1.set_menu(menu1) self.bind('button1_selected', select1, 'value', signal='sig_value_changed') badge_hot = MBadge.text('hot', widget=MLabel(u'你的理想城市 ')) sub_lay1 = QHBoxLayout() sub_lay1.addWidget(badge_1) sub_lay1.addWidget(badge_2) sub_lay1.addWidget(badge_3) sub_lay1.addStretch() sub_lay2 = QHBoxLayout() sub_lay2.addWidget(badge_hot) sub_lay2.addWidget(select1) sub_lay2.addStretch() main_lay = QVBoxLayout() main_lay.addWidget(MDivider('use standalone')) main_lay.addLayout(standalone_lay) main_lay.addWidget(MDivider('different type')) main_lay.addLayout(sub_lay1) main_lay.addWidget(spin_box) main_lay.addWidget(MDivider('different type')) main_lay.addLayout(sub_lay2) 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 slot_new_account(self): custom_widget = QtWidgets.QWidget() custom_lay = QtWidgets.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_widget_to_bottom(MPushButton("Cancel")) drawer.add_widget_to_bottom(submit_button) scale_x, _ = get_scale_factor() drawer.setFixedWidth(300 * scale_x) drawer.set_widget(custom_widget) drawer.show()
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): standalone_lay = QtWidgets.QHBoxLayout() standalone_lay.addWidget(MBadge.count(0)) standalone_lay.addWidget(MBadge.count(20)) standalone_lay.addWidget(MBadge.count(100)) standalone_lay.addWidget(MBadge.dot(True)) standalone_lay.addWidget(MBadge.text("new")) standalone_lay.addStretch() button = MToolButton().svg("trash_line.svg") avatar = MAvatar.large(MPixmap("avatar.png")) button_alert = MToolButton().svg("alert_fill.svg").large() badge_1 = MBadge.dot(True, widget=button) badge_2 = MBadge.dot(True, widget=avatar) badge_3 = MBadge.dot(True, widget=button_alert) button.clicked.connect(lambda: badge_1.set_dayu_dot(False)) spin_box = MSpinBox() spin_box.setRange(0, 9999) spin_box.valueChanged.connect(badge_3.set_dayu_count) spin_box.setValue(1) self.register_field("button1_selected", "北京") menu1 = MMenu(parent=self) menu1.set_data(["北京", "上海", "广州", "深圳"]) select1 = MComboBox() select1.set_menu(menu1) self.bind("button1_selected", select1, "value", signal="sig_value_changed") badge_hot = MBadge.text("hot", widget=MLabel("你的理想城市 ")) sub_lay1 = QtWidgets.QHBoxLayout() sub_lay1.addWidget(badge_1) sub_lay1.addWidget(badge_2) sub_lay1.addWidget(badge_3) sub_lay1.addStretch() sub_lay2 = QtWidgets.QHBoxLayout() sub_lay2.addWidget(badge_hot) sub_lay2.addWidget(select1) sub_lay2.addStretch() main_lay = QtWidgets.QVBoxLayout() main_lay.addWidget(MDivider("use standalone")) main_lay.addLayout(standalone_lay) main_lay.addWidget(MDivider("different type")) main_lay.addLayout(sub_lay1) main_lay.addWidget(spin_box) main_lay.addWidget(MDivider("different type")) main_lay.addLayout(sub_lay2) 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__(self, parent=None): super(MPage, self).__init__(parent) self.register_field('page_size_selected', 25) self.register_field('page_size_list', [{'label': '25 - Fastest', 'value': 25}, {'label': '50 - Fast', 'value': 50}, {'label': '75 - Medium', 'value': 75}, {'label': '100 - Slow', 'value': 100}]) self.register_field('total', 0) self.register_field('current_page', 0) self.register_field('total_page', lambda: utils.get_total_page(self.field('total'), self.field('page_size_selected'))) self.register_field('total_page_text', lambda: str(self.field('total_page'))) self.register_field('display_text', lambda: utils.get_page_display_string(self.field('current_page'), self.field('page_size_selected'), self.field('total'))) self.register_field('can_pre', lambda: self.field('current_page') > 1) self.register_field('can_next', lambda: self.field('current_page') < self.field('total_page')) page_setting_menu = MMenu(parent=self) self._display_label = MLabel() self._display_label.setAlignment(Qt.AlignCenter) self._change_page_size_button = MComboBox().small() self._change_page_size_button.setFixedWidth(110) self._change_page_size_button.set_menu(page_setting_menu) self._change_page_size_button.set_formatter(lambda x: u'{} per page'.format(x)) self._change_page_size_button.sig_value_changed.connect(self._emit_page_changed) self._pre_button = MToolButton().icon_only().svg('left_fill.svg').small() self._pre_button.clicked.connect(functools.partial(self._slot_change_current_page, -1)) self._next_button = MToolButton().small().icon_only().svg('right_fill.svg') self._next_button.clicked.connect(functools.partial(self._slot_change_current_page, 1)) self._current_page_spin_box = MSpinBox() self._current_page_spin_box.setMinimum(1) self._current_page_spin_box.set_dayu_size(dayu_theme.small) self._current_page_spin_box.valueChanged.connect(self._emit_page_changed) self._total_page_label = MLabel() self.bind('page_size_list', page_setting_menu, 'data') self.bind('page_size_selected', page_setting_menu, 'value', signal='sig_value_changed') self.bind('page_size_selected', self._change_page_size_button, 'value', signal='sig_value_changed') self.bind('current_page', self._current_page_spin_box, 'value', signal='valueChanged') self.bind('total_page', self._current_page_spin_box, 'maximum') self.bind('total_page_text', self._total_page_label, 'dayu_text') self.bind('display_text', self._display_label, 'dayu_text') self.bind('can_pre', self._pre_button, 'enabled') self.bind('can_next', self._next_button, 'enabled') main_lay = QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(2) main_lay.addStretch() main_lay.addWidget(self._display_label) main_lay.addStretch() main_lay.addWidget(MLabel('|').secondary()) main_lay.addWidget(self._change_page_size_button) main_lay.addWidget(MLabel('|').secondary()) main_lay.addWidget(self._pre_button) main_lay.addWidget(MLabel('Page')) main_lay.addWidget(self._current_page_spin_box) main_lay.addWidget(MLabel('/')) main_lay.addWidget(self._total_page_label) main_lay.addWidget(self._next_button) self.setLayout(main_lay)
class MPage(QWidget, MFieldMixin): """ MPage A long list can be divided into several pages by MPage, and only one page will be loaded at a time. """ sig_page_changed = Signal(int, int) def __init__(self, parent=None): super(MPage, self).__init__(parent) self.register_field('page_size_selected', 25) self.register_field('page_size_list', [{'label': '25 - Fastest', 'value': 25}, {'label': '50 - Fast', 'value': 50}, {'label': '75 - Medium', 'value': 75}, {'label': '100 - Slow', 'value': 100}]) self.register_field('total', 0) self.register_field('current_page', 0) self.register_field('total_page', lambda: utils.get_total_page(self.field('total'), self.field('page_size_selected'))) self.register_field('total_page_text', lambda: str(self.field('total_page'))) self.register_field('display_text', lambda: utils.get_page_display_string(self.field('current_page'), self.field('page_size_selected'), self.field('total'))) self.register_field('can_pre', lambda: self.field('current_page') > 1) self.register_field('can_next', lambda: self.field('current_page') < self.field('total_page')) page_setting_menu = MMenu(parent=self) self._display_label = MLabel() self._display_label.setAlignment(Qt.AlignCenter) self._change_page_size_button = MComboBox().small() self._change_page_size_button.setFixedWidth(110) self._change_page_size_button.set_menu(page_setting_menu) self._change_page_size_button.set_formatter(lambda x: u'{} per page'.format(x)) self._change_page_size_button.sig_value_changed.connect(self._emit_page_changed) self._pre_button = MToolButton().icon_only().svg('left_fill.svg').small() self._pre_button.clicked.connect(functools.partial(self._slot_change_current_page, -1)) self._next_button = MToolButton().small().icon_only().svg('right_fill.svg') self._next_button.clicked.connect(functools.partial(self._slot_change_current_page, 1)) self._current_page_spin_box = MSpinBox() self._current_page_spin_box.setMinimum(1) self._current_page_spin_box.set_dayu_size(dayu_theme.small) self._current_page_spin_box.valueChanged.connect(self._emit_page_changed) self._total_page_label = MLabel() self.bind('page_size_list', page_setting_menu, 'data') self.bind('page_size_selected', page_setting_menu, 'value', signal='sig_value_changed') self.bind('page_size_selected', self._change_page_size_button, 'value', signal='sig_value_changed') self.bind('current_page', self._current_page_spin_box, 'value', signal='valueChanged') self.bind('total_page', self._current_page_spin_box, 'maximum') self.bind('total_page_text', self._total_page_label, 'dayu_text') self.bind('display_text', self._display_label, 'dayu_text') self.bind('can_pre', self._pre_button, 'enabled') self.bind('can_next', self._next_button, 'enabled') main_lay = QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(2) main_lay.addStretch() main_lay.addWidget(self._display_label) main_lay.addStretch() main_lay.addWidget(MLabel('|').secondary()) main_lay.addWidget(self._change_page_size_button) main_lay.addWidget(MLabel('|').secondary()) main_lay.addWidget(self._pre_button) main_lay.addWidget(MLabel('Page')) main_lay.addWidget(self._current_page_spin_box) main_lay.addWidget(MLabel('/')) main_lay.addWidget(self._total_page_label) main_lay.addWidget(self._next_button) self.setLayout(main_lay) def set_total(self, value): """Set page component total count.""" self.set_field('total', value) self.set_field('current_page', 1) def _slot_change_current_page(self, offset): self.set_field('current_page', self.field('current_page') + offset) self._emit_page_changed() def set_page_config(self, data_list): """Set page component per page settings.""" self.set_field('page_size_list', [{'label': str(data), 'value': data} if isinstance(data, int) else data for data in data_list]) def _emit_page_changed(self): self.sig_page_changed.emit(self.field('page_size_selected'), self.field('current_page'))
def __init__(self, parent=None): super(MPage, self).__init__(parent) self.register_field("page_size_selected", 25) self.register_field( "page_size_list", [ { "label": "25 - Fastest", "value": 25 }, { "label": "50 - Fast", "value": 50 }, { "label": "75 - Medium", "value": 75 }, { "label": "100 - Slow", "value": 100 }, ], ) self.register_field("total", 0) self.register_field("current_page", 0) self.register_field( "total_page", lambda: utils.get_total_page(self.field("total"), self.field("page_size_selected")), ) self.register_field("total_page_text", lambda: str(self.field("total_page"))) self.register_field( "display_text", lambda: utils.get_page_display_string( self.field("current_page"), self.field("page_size_selected"), self.field("total"), ), ) self.register_field("can_pre", lambda: self.field("current_page") > 1) self.register_field( "can_next", lambda: self.field("current_page") < self.field("total_page")) page_setting_menu = MMenu(parent=self) self._display_label = MLabel() self._display_label.setAlignment(QtCore.Qt.AlignCenter) self._change_page_size_button = MComboBox().small() self._change_page_size_button.set_menu(page_setting_menu) self._change_page_size_button.set_formatter( lambda x: "{} per page".format(x)) self._change_page_size_button.sig_value_changed.connect( self._emit_page_changed) self._pre_button = MToolButton().icon_only().svg( "left_fill.svg").small() self._pre_button.clicked.connect( functools.partial(self._slot_change_current_page, -1)) self._next_button = MToolButton().small().icon_only().svg( "right_fill.svg") self._next_button.clicked.connect( functools.partial(self._slot_change_current_page, 1)) self._current_page_spin_box = MSpinBox() self._current_page_spin_box.setMinimum(1) self._current_page_spin_box.set_dayu_size(dayu_theme.small) self._current_page_spin_box.valueChanged.connect( self._emit_page_changed) self._total_page_label = MLabel() self.bind("page_size_list", page_setting_menu, "data") self.bind("page_size_selected", page_setting_menu, "value", signal="sig_value_changed") self.bind( "page_size_selected", self._change_page_size_button, "value", signal="sig_value_changed", ) self.bind("current_page", self._current_page_spin_box, "value", signal="valueChanged") self.bind("total_page", self._current_page_spin_box, "maximum") self.bind("total_page_text", self._total_page_label, "dayu_text") self.bind("display_text", self._display_label, "dayu_text") self.bind("can_pre", self._pre_button, "enabled") self.bind("can_next", self._next_button, "enabled") main_lay = QtWidgets.QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(2) main_lay.addStretch() main_lay.addWidget(self._display_label) main_lay.addStretch() main_lay.addWidget(MLabel("|").secondary()) main_lay.addWidget(self._change_page_size_button) main_lay.addWidget(MLabel("|").secondary()) main_lay.addWidget(self._pre_button) main_lay.addWidget(MLabel("Page")) main_lay.addWidget(self._current_page_spin_box) main_lay.addWidget(MLabel("/")) main_lay.addWidget(self._total_page_label) main_lay.addWidget(self._next_button) self.setLayout(main_lay)
class MPage(QtWidgets.QWidget, MFieldMixin): """ MPage A long list can be divided into several pages by MPage, and only one page will be loaded at a time. """ sig_page_changed = QtCore.Signal(int, int) def __init__(self, parent=None): super(MPage, self).__init__(parent) self.register_field("page_size_selected", 25) self.register_field( "page_size_list", [ { "label": "25 - Fastest", "value": 25 }, { "label": "50 - Fast", "value": 50 }, { "label": "75 - Medium", "value": 75 }, { "label": "100 - Slow", "value": 100 }, ], ) self.register_field("total", 0) self.register_field("current_page", 0) self.register_field( "total_page", lambda: utils.get_total_page(self.field("total"), self.field("page_size_selected")), ) self.register_field("total_page_text", lambda: str(self.field("total_page"))) self.register_field( "display_text", lambda: utils.get_page_display_string( self.field("current_page"), self.field("page_size_selected"), self.field("total"), ), ) self.register_field("can_pre", lambda: self.field("current_page") > 1) self.register_field( "can_next", lambda: self.field("current_page") < self.field("total_page")) page_setting_menu = MMenu(parent=self) self._display_label = MLabel() self._display_label.setAlignment(QtCore.Qt.AlignCenter) self._change_page_size_button = MComboBox().small() self._change_page_size_button.set_menu(page_setting_menu) self._change_page_size_button.set_formatter( lambda x: "{} per page".format(x)) self._change_page_size_button.sig_value_changed.connect( self._emit_page_changed) self._pre_button = MToolButton().icon_only().svg( "left_fill.svg").small() self._pre_button.clicked.connect( functools.partial(self._slot_change_current_page, -1)) self._next_button = MToolButton().small().icon_only().svg( "right_fill.svg") self._next_button.clicked.connect( functools.partial(self._slot_change_current_page, 1)) self._current_page_spin_box = MSpinBox() self._current_page_spin_box.setMinimum(1) self._current_page_spin_box.set_dayu_size(dayu_theme.small) self._current_page_spin_box.valueChanged.connect( self._emit_page_changed) self._total_page_label = MLabel() self.bind("page_size_list", page_setting_menu, "data") self.bind("page_size_selected", page_setting_menu, "value", signal="sig_value_changed") self.bind( "page_size_selected", self._change_page_size_button, "value", signal="sig_value_changed", ) self.bind("current_page", self._current_page_spin_box, "value", signal="valueChanged") self.bind("total_page", self._current_page_spin_box, "maximum") self.bind("total_page_text", self._total_page_label, "dayu_text") self.bind("display_text", self._display_label, "dayu_text") self.bind("can_pre", self._pre_button, "enabled") self.bind("can_next", self._next_button, "enabled") main_lay = QtWidgets.QHBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(2) main_lay.addStretch() main_lay.addWidget(self._display_label) main_lay.addStretch() main_lay.addWidget(MLabel("|").secondary()) main_lay.addWidget(self._change_page_size_button) main_lay.addWidget(MLabel("|").secondary()) main_lay.addWidget(self._pre_button) main_lay.addWidget(MLabel("Page")) main_lay.addWidget(self._current_page_spin_box) main_lay.addWidget(MLabel("/")) main_lay.addWidget(self._total_page_label) main_lay.addWidget(self._next_button) self.setLayout(main_lay) def set_total(self, value): """Set page component total count.""" self.set_field("total", value) self.set_field("current_page", 1) def _slot_change_current_page(self, offset): self.set_field("current_page", self.field("current_page") + offset) self._emit_page_changed() def set_page_config(self, data_list): """Set page component per page settings.""" self.set_field( "page_size_list", [{ "label": str(data), "value": data } if isinstance(data, int) else data for data in data_list], ) def _emit_page_changed(self): self.sig_page_changed.emit(self.field("page_size_selected"), self.field("current_page"))