def test_badge_count(qtbot, num, text, visible): """Test MBadge init.""" label = QLabel('test') badge_1 = MBadge.count(count=num, widget=label) badge_2 = MBadge.count(num) main_widget = QWidget() main_lay = QVBoxLayout() main_widget.setLayout(main_lay) main_lay.addWidget(badge_1) main_lay.addWidget(badge_2) qtbot.addWidget(main_widget) main_widget.show() assert badge_1._badge_button.text() == text assert badge_1._badge_button.isVisible() == visible assert badge_2._badge_button.text() == text assert badge_2._badge_button.isVisible() == visible assert badge_1.get_dayu_dot() is None assert badge_2.get_dayu_dot() is None assert badge_1.get_dayu_text() is None assert badge_2.get_dayu_text() is None assert badge_1.get_dayu_count() == num assert badge_2.get_dayu_count() == num assert badge_1.get_dayu_overflow() == 99 assert badge_2.get_dayu_overflow() == 99
def __init__(self, parent=None): super(Colorful, self).__init__(parent) preset_color_lay = MFlowLayout() for index, (text, color) in enumerate([ ('magenta', dayu_theme.magenta), ('red', dayu_theme.red), ('volcano', dayu_theme.volcano), ('orange', dayu_theme.orange), ('gold', dayu_theme.gold), ('lime', dayu_theme.lime), ('green', dayu_theme.green), ('cyan', dayu_theme.cyan), ('blue', dayu_theme.blue), ('geekblue', dayu_theme.geekblue), ('purple', dayu_theme.purple), ]): tag = MTag(text) tag.set_dayu_color(color) if index > 5: tag.no_border() preset_color_lay.addWidget(tag) custom_color_lay = MFlowLayout() custom_color_lay.addWidget(MTag('#f00').coloring('#f00')) custom_color_lay.addWidget(MTag('#f66').coloring('#f66')) custom_color_lay.addWidget(MTag('#f0f').coloring('#f0f').no_border()) main_lay = QVBoxLayout() main_lay.addLayout(preset_color_lay) main_lay.addLayout(custom_color_lay) self.setLayout(main_lay)
def test_divider_class_method(qtbot, text, visible_text): """Test MDivider class methods.""" main_widget = QWidget() main_lay = QVBoxLayout() main_widget.setLayout(main_lay) divider_left = MDivider.left(text) divider_center = MDivider.center(text) divider_right = MDivider.right(text) divider_ver = MDivider.vertical() main_lay.addWidget(divider_left) main_lay.addWidget(divider_center) main_lay.addWidget(divider_right) main_lay.addWidget(divider_ver) qtbot.addWidget(main_widget) main_widget.show() _asset_divider_perform(divider_left, True and visible_text, Qt.AlignLeft) _asset_divider_perform(divider_right, True and visible_text, Qt.AlignRight) _asset_divider_perform(divider_center, True and visible_text, Qt.AlignCenter) _asset_divider_perform(divider_ver, False, Qt.AlignCenter) assert divider_left.get_dayu_text() == text assert divider_right.get_dayu_text() == text assert divider_center.get_dayu_text() == text assert divider_ver.get_dayu_text() == ''
def __init__(self, view_type=None, parent=None): super(MItemViewSet, self).__init__(parent) self._main_lay = QVBoxLayout() self._main_lay.setSpacing(5) self._main_lay.setContentsMargins(0, 0, 0, 0) self.sort_filter_model = MSortFilterModel() self.source_model = MTableModel() self.sort_filter_model.setSourceModel(self.source_model) view_class = view_type or MItemViewSet.TableViewType self.item_view = view_class() self.item_view.doubleClicked.connect(self.sig_double_clicked) self.item_view.pressed.connect(self.slot_left_clicked) self.item_view.setModel(self.sort_filter_model) 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) _search_lay = QHBoxLayout() _search_lay.setContentsMargins(0, 0, 0, 0) _search_lay.addStretch() _search_lay.addWidget(self._search_line_edit) self._main_lay.addLayout(_search_lay) self._main_lay.addWidget(self.item_view) self.setLayout(self._main_lay)
def __init__(self, title, position='right', closable=True, parent=None): super(MDrawer, self).__init__(parent) self.setObjectName('message') self.setWindowFlags(Qt.Popup) # self.setWindowFlags( # Qt.FramelessWindowHint | Qt.Popup | Qt.WA_TranslucentBackground) self.setAttribute(Qt.WA_StyledBackground) self._title_label = MLabel(parent=self).h4() # self._title_label.set_elide_mode(Qt.ElideRight) self._title_label.setText(title) self._close_button = MToolButton( parent=self).icon_only().svg('close_line.svg').small() self._close_button.clicked.connect(self.close) self._close_button.setVisible(closable or False) _title_lay = QHBoxLayout() _title_lay.addWidget(self._title_label) _title_lay.addStretch() _title_lay.addWidget(self._close_button) self._button_lay = QHBoxLayout() self._button_lay.addStretch() self._scroll_area = QScrollArea() self._main_lay = QVBoxLayout() self._main_lay.addLayout(_title_lay) self._main_lay.addWidget(MDivider()) self._main_lay.addWidget(self._scroll_area) self._main_lay.addWidget(MDivider()) self._main_lay.addLayout(self._button_lay) self.setLayout(self._main_lay) self._position = position self._close_timer = QTimer(self) self._close_timer.setSingleShot(True) self._close_timer.timeout.connect(self.close) self._close_timer.timeout.connect(self.sig_closed) self._close_timer.setInterval(300) self._is_first_close = True self._pos_ani = QPropertyAnimation(self) self._pos_ani.setTargetObject(self) self._pos_ani.setEasingCurve(QEasingCurve.OutCubic) self._pos_ani.setDuration(300) self._pos_ani.setPropertyName(b'pos') self._opacity_ani = QPropertyAnimation() self._opacity_ani.setTargetObject(self) self._opacity_ani.setDuration(300) self._opacity_ani.setEasingCurve(QEasingCurve.OutCubic) self._opacity_ani.setPropertyName(b'windowOpacity') self._opacity_ani.setStartValue(0.0) self._opacity_ani.setEndValue(1.0)
def test_badge_overflow(qtbot, num, text, overflow): """Test MBadge init.""" badge = MBadge.count(num) badge.set_dayu_overflow(overflow) main_widget = QWidget() main_lay = QVBoxLayout() main_widget.setLayout(main_lay) main_lay.addWidget(badge) qtbot.addWidget(main_widget) main_widget.show() assert badge._badge_button.text() == text assert badge.get_dayu_dot() is None assert badge.get_dayu_text() is None assert badge.get_dayu_count() == num assert badge.get_dayu_overflow() == overflow
def __init__(self, title=None, image=None, size=None, extra=None, type=None, parent=None): super(MCard, self).__init__(parent=parent) self.setAttribute(Qt.WA_StyledBackground) self.setProperty('border', False) size = size or dayu_theme.default_size map_label = { dayu_theme.large: (MLabel.H2Level, 20), dayu_theme.medium: (MLabel.H3Level, 15), dayu_theme.small: (MLabel.H4Level, 10), } self._title_label = MLabel(text=title) self._title_label.set_dayu_level(map_label.get(size)[0]) padding = map_label.get(size)[-1] self._title_layout = QHBoxLayout() self._title_layout.setContentsMargins(padding, padding, padding, padding) if image: self._title_icon = MAvatar() self._title_icon.set_dayu_image(image) self._title_icon.set_dayu_size(size) self._title_layout.addWidget(self._title_icon) self._title_layout.addWidget(self._title_label) self._title_layout.addStretch() if extra: self._extra_button = MToolButton().icon_only().svg('more.svg') self._title_layout.addWidget(self._extra_button) self._content_layout = QVBoxLayout() self._main_lay = QVBoxLayout() self._main_lay.setSpacing(0) self._main_lay.setContentsMargins(1, 1, 1, 1) if title: self._main_lay.addLayout(self._title_layout) self._main_lay.addWidget(MDivider()) self._main_lay.addLayout(self._content_layout) self.setLayout(self._main_lay)
def __init__(self, parent=None): super(MMenuTabWidget, self).__init__(parent=parent) self.tool_button_group = MBlockButtonGroup() self._bar_layout = QHBoxLayout() self._bar_layout.setContentsMargins(10, 0, 10, 0) self._bar_layout.addWidget(self.tool_button_group) self._bar_layout.addStretch() bar_widget = QWidget() bar_widget.setObjectName('bar_widget') bar_widget.setLayout(self._bar_layout) bar_widget.setAttribute(Qt.WA_StyledBackground) main_lay = QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(0) main_lay.addWidget(bar_widget) main_lay.addWidget(MDivider()) main_lay.addSpacing(5) self.setLayout(main_lay) self.setFixedHeight(dayu_theme.large + 10)
def __init__(self, layout=None, parent=None): super(MForm, self).__init__(parent) layout = layout or MForm.Horizontal if layout == MForm.Inline: self._main_layout = QHBoxLayout() elif layout == MForm.Vertical: self._main_layout = QVBoxLayout() else: self._main_layout = QFormLayout() self._model = None self._label_list = []
def test_badge_dot(qtbot, show, visible): """Test MBadge init.""" label = QLabel('test') badge_1 = MBadge.dot(show=show, widget=label) badge_2 = MBadge.dot(show) main_widget = QWidget() main_lay = QVBoxLayout() main_widget.setLayout(main_lay) main_lay.addWidget(badge_1) main_lay.addWidget(badge_2) qtbot.addWidget(main_widget) main_widget.show() assert badge_1._badge_button.isVisible() == visible assert badge_2._badge_button.isVisible() == visible assert badge_1.get_dayu_dot() == show assert badge_2.get_dayu_dot() == show assert badge_1.get_dayu_text() is None assert badge_2.get_dayu_text() is None assert badge_1.get_dayu_count() is None assert badge_2.get_dayu_count() is None
def __init__(self, parent=None): super(Login, self).__init__(parent) self.setWindowTitle('Login') self.resize(250, 150) main_layout = QVBoxLayout() name_layout = QHBoxLayout() password_layout = QHBoxLayout() name_layout.addWidget(MLabel('Name:'), 1, 0) name_layout.addWidget(MLineEdit()) password_layout.addWidget(MLabel('Password:'******'Query').primary() main_layout.addWidget(query_button) self.setLayout(main_layout)
def test_cursor_mixin(qtbot): @mixin.cursor_mixin class _TestClass(QPushButton): def __init__(self, parent=None): super(_TestClass, self).__init__(parent) geo = QApplication.desktop().screenGeometry() self.setGeometry(geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2) main_widget = QWidget() button_test = _TestClass() button_normal = QPushButton() test_lay = QVBoxLayout() test_lay.addWidget(button_test) test_lay.addWidget(button_normal) main_widget.setLayout(test_lay) qtbot.addWidget(main_widget) main_widget.show() button_test.setEnabled(False) assert QApplication.overrideCursor() is None # Not override cursor qtbot.mouseMove(button_test) # mouse enter def check_cursor(): assert QApplication.overrideCursor() is not None assert QApplication.overrideCursor().shape() == Qt.ForbiddenCursor qtbot.waitUntil(check_cursor) qtbot.mouseMove(button_normal) # mouse leave def check_cursor(): assert QApplication.overrideCursor() is None # Restore override cursor qtbot.waitUntil(check_cursor) button_test.setEnabled(True) qtbot.mouseMove(button_test) # mouse enter def check_cursor(): assert QApplication.overrideCursor() is not None assert QApplication.overrideCursor().shape() == Qt.PointingHandCursor qtbot.waitUntil(check_cursor) qtbot.mouseMove(button_normal) # mouse leave def check_cursor(): assert QApplication.overrideCursor() is None # Restore override cursor qtbot.waitUntil(check_cursor)
def slot_open_button(self): custom_widget = QWidget() custom_lay = QVBoxLayout() custom_lay.addWidget(MLabel('Some contents...')) custom_lay.addWidget(MLabel('Some contents...')) custom_lay.addWidget(MLabel('Some contents...')) custom_widget.setLayout(custom_lay) drawer = MDrawer('Basic Drawer', parent=self).left() drawer.setFixedWidth(200) drawer.set_widget(custom_widget) drawer.show()
def _init_ui(self): item_list = [ { 'text': 'Overview', 'svg': 'home_line.svg', 'clicked': functools.partial(MMessage.info, u'首页', parent=self) }, { 'text': u'我的', 'svg': 'user_line.svg', 'clicked': functools.partial(MMessage.info, u'编辑账户', parent=self) }, { 'text': u'Notice', 'svg': 'alert_line.svg', 'clicked': functools.partial(MMessage.info, u'查看通知', parent=self) }, ] tool_bar = MMenuTabWidget() tool_bar.tool_bar_insert_widget( MLabel('DaYu').h4().secondary().strong()) tool_bar.tool_bar_append_widget( MBadge.dot( show=True, widget=MToolButton().icon_only().svg('user_fill.svg').large())) self.content_widget = MLabel() for index, data_dict in enumerate(item_list): tool_bar.add_menu(data_dict, index) tool_bar.tool_button_group.set_dayu_checked(0) main_lay = QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.addWidget(tool_bar) main_lay.addWidget(self.content_widget) self.setLayout(main_lay)
def test_hover_shadow_mixin(qtbot): @mixin.hover_shadow_mixin class _TestClass(QPushButton): def __init__(self, parent=None): super(_TestClass, self).__init__(parent) geo = QApplication.desktop().screenGeometry() self.setGeometry(geo.width() / 4, geo.height() / 4, geo.width() / 2, geo.height() / 2) main_widget = QWidget() button_test = _TestClass() button_normal = QPushButton() test_lay = QVBoxLayout() test_lay.addWidget(button_test) test_lay.addWidget(button_normal) main_widget.setLayout(test_lay) qtbot.addWidget(main_widget) assert button_test.graphicsEffect() is None main_widget.show() qtbot.mouseMove(button_test) # mouse in def check_effect(): graphics_effect = button_test.graphicsEffect() assert graphics_effect is not None assert graphics_effect.isEnabled() assert isinstance(graphics_effect, QGraphicsDropShadowEffect) qtbot.waitUntil(check_effect) qtbot.mouseMove(button_normal) # mouse out def check_effect(): assert button_test.graphicsEffect() is not None assert not button_test.graphicsEffect().isEnabled() qtbot.waitUntil(check_effect) qtbot.mouseMove(button_test) # mouse in def check_effect(): assert button_test.graphicsEffect() is not None assert button_test.graphicsEffect().isEnabled() qtbot.waitUntil(check_effect)
def slot_open_button_2(self): custom_widget = QWidget() custom_lay = QVBoxLayout() custom_lay.addWidget(MLabel('Some contents...')) custom_lay.addWidget(MLabel('Some contents...')) custom_lay.addWidget(MLabel('Some contents...')) custom_widget.setLayout(custom_lay) drawer = MDrawer('Basic Drawer', parent=self) drawer.set_dayu_position( self.button_grp.get_button_group().checkedButton().text()) drawer.setFixedWidth(200) drawer.set_widget(custom_widget) drawer.show()
def test_label_elide_mode(qtbot, text, elide): """Test MLabel elide mode""" main_widget = QWidget() main_widget.setGeometry(0, 0, 30, 200) main_lay = QVBoxLayout() main_widget.setLayout(main_lay) label_left = MLabel() label_left.set_elide_mode(Qt.ElideLeft) label_left.setText(text) label_right = MLabel() label_right.set_elide_mode(Qt.ElideRight) label_right.setText(text) label_center = MLabel(text) label_center.set_elide_mode(Qt.ElideMiddle) label_center.setText(text) main_lay.addWidget(label_left) main_lay.addWidget(label_right) main_lay.addWidget(label_center) qtbot.addWidget(main_widget) main_widget.show() ellipsis = u'…' if elide: assert label_left.property('text').startswith(ellipsis) assert label_right.property('text').endswith(ellipsis) center_text = label_center.property('text') assert center_text.count(ellipsis) \ and not center_text.endswith(ellipsis) else: assert label_left.property('text') == label_left.text() assert label_right.property('text') == label_right.text() assert label_center.property('text') == label_center.text() assert label_left.get_elide_mode() == Qt.ElideLeft assert label_right.get_elide_mode() == Qt.ElideRight assert label_center.get_elide_mode() == Qt.ElideMiddle
def _init_ui(self): self.resize(250, 350) self.button_login = MToolButton().svg( 'user_line.svg').text_beside_icon() self.button_login.setText('Login') self.button_login.clicked.connect(self.onclick) button_lay = QVBoxLayout() button_lay.addWidget(self.button_login) self.tree = QTreeWidget() self.tree.setColumnCount(1) self.tree.setHeaderHidden(1) self.tree.setGeometry(QRect(1, 1, 250, 500)) self.tree.itemClicked.connect(self.testt) new_widget_1 = QTreeWidgetItem(self.tree) new_widget_1.setText(0, u'技能培训') new_widget_2 = QTreeWidgetItem(self.tree) new_widget_2.setText(0, u'企业培训') new_widget_3 = QTreeWidgetItem(self.tree) new_widget_3.setText(0, u'职业技能培训') new_widget_3_1 = QTreeWidgetItem(new_widget_3) new_widget_3_1.setText(0, u'餐饮厨艺') new_widget_3_2 = QTreeWidgetItem(new_widget_3) new_widget_3_2.setText(0, u'家庭服务') new_widget_3_3 = QTreeWidgetItem(new_widget_3) new_widget_3_3.setText(0, u'运输与物流') new_widget_3_3_1 = QTreeWidgetItem(new_widget_3_3) new_widget_3_3_1.setText(0, u'运输与物流第一章') tree_layout = QVBoxLayout() tree_layout.addWidget(self.tree) main_lay = QVBoxLayout() main_lay.addLayout(button_lay) main_lay.addLayout(tree_layout) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): basic_card_lay = MFlowLayout() basic_card_lay.setSpacing(20) for setting in [{ 'title': '', }, { 'title': 'Card Title', 'size': dayu_theme.small }, { 'title': 'Card Title', 'image': MPixmap('app-houdini.png') }, { 'title': 'Card Title', 'extra': 'More', 'image': MPixmap('app-houdini.png') }, { 'title': 'Card Title', 'extra': 'More', }]: card_0 = MCard(**setting) content_widget_0 = QWidget() content_lay_0 = QVBoxLayout() content_lay_0.setContentsMargins(15, 15, 15, 15) content_widget_0.setLayout(content_lay_0) for i in range(4): content_lay_0.addWidget(MLabel('Card Content {}'.format(i + 1))) card_0.set_widget(content_widget_0) basic_card_lay.addWidget(card_0) meta_card_lay = MFlowLayout() meta_card_lay.setSpacing(20) for setting in [ { 'title': u'Houdini', 'description': u'Side Effects Software的旗舰级产品,是创建高级视觉效果的有效工具', 'avatar': MPixmap('user_line.svg'), 'cover': MPixmap('app-houdini.png') }, { 'title': u'Autodesk Maya', 'description': u'3D 数字动画和视觉效果的世界领先软件应用程序', 'cover': MPixmap('app-maya.png') }, ]: meta_card = MMeta() meta_card.setup_data(setting) meta_card_lay.addWidget(meta_card) task_card_lay = QVBoxLayout() # task_card_lay.setSpacing(10) for setting in [ { 'title': u'Task A', 'description': u'demo pl_0010 Animation \n2019/04/01 - 2019/04/09', 'avatar': MPixmap('success_line.svg', dayu_theme.success_color), }, { 'title': u'Task B', 'description': u'#2 closed by xiao hua.', 'avatar': MPixmap('error_line.svg', dayu_theme.error_color) }, { 'title': u'Task C', 'description': u'#3 closed by xiao hua.', 'avatar': MPixmap('warning_line.svg', dayu_theme.warning_color) } ] * 5: meta_card = MMeta(extra=True) meta_card.setup_data(setting) task_card_lay.addWidget(meta_card) left_lay = QVBoxLayout() left_lay.addWidget(MDivider('Basic')) left_lay.addLayout(basic_card_lay) left_lay.addWidget(MDivider('Meta E-Commerce Example')) left_lay.addLayout(meta_card_lay) left_lay.addStretch() left_widget = QWidget() left_widget.setLayout(left_lay) right_lay = QVBoxLayout() right_lay.addWidget(MDivider('Meta Task Item Example')) scroll = QScrollArea() scroll.setWidgetResizable(True) task_widget = QWidget() task_widget.setLayout(task_card_lay) scroll.setWidget(task_widget) right_lay.addWidget(scroll) right_widget = QWidget() right_widget.setLayout(right_lay) splitter = QSplitter() splitter.addWidget(left_widget) splitter.addWidget(right_widget) splitter.setStretchFactor(0, 80) splitter.setStretchFactor(1, 20) main_lay = QVBoxLayout() main_lay.addWidget(splitter) self.setLayout(main_lay)
def __init__(self, parent=None): super(SpinBoxExample, self).__init__(parent) self.setWindowTitle('Examples for Spin Box') main_lay = QVBoxLayout() class_list = [ MSpinBox, MDoubleSpinBox, MDateTimeEdit, MDateEdit, MTimeEdit ] for cls in class_list: main_lay.addWidget(MDivider(cls.__name__)) lay = QHBoxLayout() lay.addWidget(cls().large()) lay.addWidget(cls().medium()) lay.addWidget(cls().small()) main_lay.addLayout(lay) main_lay.addWidget(MDivider('Pop Calendar Widget')) date_time_edit = MDateTimeEdit() date_time_edit.setCalendarPopup(True) date_edit = MDateEdit() date_edit.setCalendarPopup(True) time_edit = MTimeEdit() time_edit.setCalendarPopup(True) date_lay = QHBoxLayout() date_lay.addWidget(date_time_edit) date_lay.addWidget(date_edit) date_lay.addWidget(time_edit) main_lay.addLayout(date_lay) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): progress_1 = MProgressBar() progress_1.setValue(1) progress_1.setAlignment(Qt.AlignCenter) progress_2 = MProgressBar() progress_2.setValue(80) progress_normal = MProgressBar() progress_normal.setValue(30) progress_success = MProgressBar(status=MProgressBar.SuccessStatus) progress_success.setValue(100) progress_error = MProgressBar(status=MProgressBar.ErrorStatus) progress_error.setValue(50) form_lay = QFormLayout() form_lay.addRow('Primary:', progress_normal) form_lay.addRow('Success:', progress_success) form_lay.addRow('Error:', progress_error) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('Basic')) main_lay.addWidget(progress_1) main_lay.addWidget(progress_2) main_lay.addWidget(MDivider('different type')) main_lay.addLayout(form_lay) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): size_lay = QVBoxLayout() sub_lay1 = QHBoxLayout() sub_lay1.addWidget(MToolButton().svg('left_line.svg').icon_only()) sub_lay1.addWidget(MToolButton().svg('right_line.svg').icon_only()) sub_lay1.addWidget(MToolButton().svg('up_line.svg').icon_only()) sub_lay1.addWidget(MToolButton().svg('down_line.svg').icon_only()) sub_lay1.addStretch() size_lay.addLayout(sub_lay1) button2 = MToolButton().svg('detail_line.svg').icon_only() button2.setEnabled(False) button7 = MToolButton().svg('trash_line.svg').icon_only() button7.setCheckable(True) state_lay = QHBoxLayout() state_lay.addWidget(button2) state_lay.addWidget(button7) state_lay.addStretch() button_trash = MToolButton().svg('trash_line.svg').text_beside_icon() button_trash.setText('Delete') button_login = MToolButton().svg('user_line.svg').text_beside_icon() button_login.setText('Login') button_lay = QHBoxLayout() button_lay.addWidget(button_trash) button_lay.addWidget(button_login) sub_lay2 = QHBoxLayout() sub_lay2.addWidget(button2) sub_lay2.addWidget(button7) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('different button_size')) main_lay.addLayout(size_lay) main_lay.addWidget(MDivider('disabled & checkable')) main_lay.addLayout(state_lay) main_lay.addWidget(MDivider('type=normal')) main_lay.addLayout(button_lay) 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): browser_1 = MClickBrowserFilePushButton( text='Browser File PushButton').primary() browser_2 = MClickBrowserFolderPushButton( text='Browser Folder PushButton') browser_2.setIcon(MIcon('upload_line.svg')) browser_3 = MClickBrowserFilePushButton(text='Browser Multi Files', multiple=True).primary() lay_1 = QHBoxLayout() lay_1.addWidget(browser_1) lay_1.addWidget(browser_2) lay_1.addWidget(browser_3) browser_4 = MClickBrowserFileToolButton().huge() label_4 = MLabel() label_4.set_elide_mode(Qt.ElideMiddle) browser_4.sig_file_changed.connect(label_4.setText) browser_5 = MClickBrowserFolderToolButton().huge() label_5 = MLabel() label_5.set_elide_mode(Qt.ElideMiddle) browser_5.sig_folder_changed.connect(label_5.setText) lay_2 = QHBoxLayout() lay_2.addWidget(label_4) lay_2.addWidget(browser_4) lay_2.addWidget(label_5) lay_2.addWidget(browser_5) browser_6 = MDragFileButton(text='Click or drag file here') browser_6.set_dayu_svg('attachment_line.svg') label_6 = MLabel() label_6.set_elide_mode(Qt.ElideMiddle) browser_6.sig_file_changed.connect(label_6.setText) browser_7 = MDragFolderButton() label_7 = MLabel() label_7.set_elide_mode(Qt.ElideRight) browser_7.sig_folder_changed.connect(label_7.setText) lay_3 = QGridLayout() lay_3.addWidget(browser_6, 2, 0) lay_3.addWidget(browser_7, 2, 1) lay_3.addWidget(label_6, 3, 0) lay_3.addWidget(label_7, 3, 1) browser_8 = MDragFileButton(text='Click or drag media file here', multiple=False) browser_8.set_dayu_svg('media_line.svg') browser_8.set_dayu_filters(['.mov', '.mp4']) browser_8_label = MLabel() browser_8_label.set_elide_mode(Qt.ElideRight) self.register_field('current_file', '') self.bind('current_file', browser_8, 'dayu_path', signal='sig_file_changed') self.bind('current_file', browser_8_label, 'text') main_lay = QVBoxLayout() main_lay.addWidget(MDivider('MClickBrowser*PushButton')) main_lay.addLayout(lay_1) main_lay.addWidget(MDivider('MClickBrowser*ToolButton')) main_lay.addLayout(lay_2) main_lay.addWidget(MDivider('MDragBrowser*ToolButton')) main_lay.addLayout(lay_3) main_lay.addWidget(MDivider('data bind')) main_lay.addWidget(browser_8) main_lay.addWidget(browser_8_label) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): check_box_1 = MSwitch() check_box_1.setChecked(True) check_box_2 = MSwitch() check_box_3 = MSwitch() check_box_3.setEnabled(False) lay = QHBoxLayout() lay.addWidget(check_box_1) lay.addWidget(check_box_2) lay.addWidget(check_box_3) size_lay = QVBoxLayout() size_list = [ ('Huge', MSwitch.huge), ('Large', MSwitch.large), ('Medium', MSwitch.medium), ('Small', MSwitch.small), ('Tiny', MSwitch.tiny), ] for label, cls in size_list: lay2 = QHBoxLayout() lay2.addWidget(MLabel(label)) lay2.addWidget(cls()) size_lay.addLayout(lay2) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('Basic')) main_lay.addLayout(lay) main_lay.addWidget(MDivider('different size')) main_lay.addLayout(size_lay) main_lay.addStretch() self.setLayout(main_lay)
def _init_ui(self): MMessage.config(duration=1) entity_list = [ { 'clicked': functools.partial(self.slot_show_message, MMessage.info, 'Go to "Home Page"'), 'svg': 'home_line.svg'}, { 'text': 'pl', 'clicked': functools.partial(self.slot_show_message, MMessage.info, 'Go to "pl"'), 'svg': 'user_line.svg'}, { 'text': 'pl_0010', 'clicked': functools.partial(self.slot_show_message, MMessage.info, 'Go to "pl_0010"'), } ] no_icon_eg = MBreadcrumb() no_icon_eg.set_item_list(entity_list) separator_eg = MBreadcrumb(separator='=>') separator_eg.set_item_list(entity_list) main_lay = QVBoxLayout() main_lay.addWidget(MDivider('normal')) main_lay.addWidget(no_icon_eg) main_lay.addWidget(MDivider('separator: =>')) main_lay.addWidget(separator_eg) main_lay.addStretch() self.setLayout(main_lay)
def __init__(self, parent=None): super(AlertExample, self).__init__(parent) self.setWindowTitle('Example for MAlert') main_lay = QVBoxLayout() self.setLayout(main_lay) main_lay.addWidget(MDivider('different type')) main_lay.addWidget( MAlert(text='Information Message', parent=self).info()) main_lay.addWidget( MAlert(text='Success Message', parent=self).success()) main_lay.addWidget( MAlert(text='Warning Message', parent=self).warning()) main_lay.addWidget(MAlert(text='Error Message', parent=self).error()) closeable_alert = MAlert('Some Message', parent=self).closable() main_lay.addWidget(MLabel(u'不同的提示信息类型')) main_lay.addWidget(MDivider('closable')) main_lay.addWidget(closeable_alert) main_lay.addWidget(MDivider('data bind')) self.register_field('msg', '') self.register_field('msg_type', MAlert.InfoType) data_bind_alert = MAlert(parent=self) data_bind_alert.set_closeable(True) self.bind('msg', data_bind_alert, 'dayu_text') self.bind('msg_type', data_bind_alert, 'dayu_type') button_grp = MPushButtonGroup() button_grp.set_button_list([{ 'text': 'error', 'clicked': functools.partial(self.slot_change_alert, 'password is wrong', MAlert.ErrorType) }, { 'text': 'success', 'clicked': functools.partial(self.slot_change_alert, 'login success', MAlert.SuccessType) }, { 'text': 'no more error', 'clicked': functools.partial(self.slot_change_alert, '', MAlert.InfoType) }]) main_lay.addWidget(button_grp) main_lay.addWidget(data_bind_alert) main_lay.addStretch()
def __init__(self, alignment=Qt.AlignCenter, parent=None): super(MLineTabWidget, self).__init__(parent=parent) self.tool_button_group = MUnderlineButtonGroup() self.bar_layout = QHBoxLayout() self.bar_layout.setContentsMargins(0, 0, 0, 0) if alignment == Qt.AlignCenter: self.bar_layout.addStretch() self.bar_layout.addWidget(self.tool_button_group) self.bar_layout.addStretch() elif alignment == Qt.AlignLeft: self.bar_layout.addWidget(self.tool_button_group) self.bar_layout.addStretch() elif alignment == Qt.AlignRight: self.bar_layout.addStretch() self.bar_layout.addWidget(self.tool_button_group) self.stack_widget = MStackedWidget() self.tool_button_group.sig_checked_changed.connect( self.stack_widget.setCurrentIndex) main_lay = QVBoxLayout() main_lay.setContentsMargins(0, 0, 0, 0) main_lay.setSpacing(0) main_lay.addLayout(self.bar_layout) main_lay.addWidget(MDivider()) main_lay.addSpacing(5) main_lay.addWidget(self.stack_widget) self.setLayout(main_lay)
def _init_ui(self): main_lay = QVBoxLayout() self.setLayout(main_lay) main_lay.addWidget(MDivider('circle')) lay1 = QHBoxLayout() circle_1 = MProgressCircle(parent=self) circle_1.setFormat(u'%p Days') circle_1.setValue(80) circle_2 = MProgressCircle(parent=self) circle_2.set_dayu_color(dayu_theme.success_color) circle_2.setValue(100) circle_3 = MProgressCircle(parent=self) circle_3.set_dayu_color(dayu_theme.error_color) circle_3.setValue(40) dashboard_1 = MProgressCircle.dashboard(parent=self) dashboard_1.setFormat(u'%p Days') dashboard_1.setValue(80) dashboard_2 = MProgressCircle.dashboard(parent=self) dashboard_2.set_dayu_color(dayu_theme.success_color) dashboard_2.setValue(100) dashboard_3 = MProgressCircle.dashboard(parent=self) dashboard_3.set_dayu_color(dayu_theme.error_color) dashboard_3.setValue(40) lay1.addWidget(circle_1) lay1.addWidget(circle_2) lay1.addWidget(circle_3) dashboard_lay = QHBoxLayout() dashboard_lay.addWidget(dashboard_1) dashboard_lay.addWidget(dashboard_2) dashboard_lay.addWidget(dashboard_3) main_lay.addLayout(lay1) main_lay.addWidget(MDivider('dashboard')) main_lay.addLayout(dashboard_lay) main_lay.addWidget(MDivider('different radius')) circle_4 = MProgressCircle(parent=self) circle_4.set_dayu_width(100) circle_4.setValue(40) circle_5 = MProgressCircle(parent=self) circle_5.setValue(40) circle_6 = MProgressCircle(parent=self) circle_6.set_dayu_width(160) circle_6.setValue(40) lay2 = QHBoxLayout() lay2.addWidget(circle_4) lay2.addWidget(circle_5) lay2.addWidget(circle_6) main_lay.addLayout(lay2) main_lay.addWidget(MDivider('data bind')) self.register_field('percent', 0) self.register_field('color', self.get_color) self.register_field('format', self.get_format) circle = MProgressCircle(parent=self) self.bind('percent', circle, 'value') self.bind('color', circle, 'dayu_color') self.bind('format', circle, 'format') lay3 = QHBoxLayout() button_grp = MPushButtonGroup() button_grp.set_dayu_type(MPushButton.DefaultType) button_grp.set_button_list([ {'text': '+', 'clicked': functools.partial(self.slot_change_percent, 10)}, {'text': '-', 'clicked': functools.partial(self.slot_change_percent, -10)}, ]) lay3.addWidget(circle) lay3.addWidget(button_grp) lay3.addStretch() main_lay.addLayout(lay3) custom_widget = QWidget() custom_layout = QVBoxLayout() custom_layout.setContentsMargins(20, 20, 20, 20) custom_layout.addStretch() custom_widget.setLayout(custom_layout) lab1 = MLabel(text='42,001,776').h3() lab2 = MLabel(text=u'消费人群规模').secondary() lab3 = MLabel(text=u'总占人数 75%').secondary() lab1.setAlignment(Qt.AlignCenter) lab2.setAlignment(Qt.AlignCenter) lab3.setAlignment(Qt.AlignCenter) custom_layout.addWidget(lab1) custom_layout.addWidget(lab2) custom_layout.addWidget(MDivider()) custom_layout.addWidget(lab3) custom_layout.addStretch() custom_circle = MProgressCircle() custom_circle.set_dayu_width(180) custom_circle.setValue(75) custom_circle.set_widget(custom_widget) main_lay.addWidget(MDivider('custom circle')) main_lay.addWidget(custom_circle) main_lay.addStretch()
def __init__(self, text, duration=None, dayu_type=None, parent=None): super(MToast, self).__init__(parent) self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog | Qt.WA_TranslucentBackground | Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_StyledBackground) _icon_lay = QHBoxLayout() _icon_lay.addStretch() if dayu_type == MToast.LoadingType: _icon_lay.addWidget( MLoading(size=dayu_theme.huge, color=dayu_theme.text_color_inverse)) else: _icon_label = MAvatar() _icon_label.set_dayu_size(60) _icon_label.set_dayu_image( MPixmap('{}_line.svg'.format(dayu_type or MToast.InfoType), dayu_theme.text_color_inverse)) _icon_lay.addWidget(_icon_label) _icon_lay.addStretch() _content_label = MLabel() _content_label.setText(text) _content_label.setAlignment(Qt.AlignCenter) _main_lay = QVBoxLayout() _main_lay.setContentsMargins(0, 0, 0, 0) _main_lay.addStretch() _main_lay.addLayout(_icon_lay) _main_lay.addSpacing(10) _main_lay.addWidget(_content_label) _main_lay.addStretch() self.setLayout(_main_lay) self.setFixedSize(QSize(120, 120)) _close_timer = QTimer(self) _close_timer.setSingleShot(True) _close_timer.timeout.connect(self.close) _close_timer.timeout.connect(self.sig_closed) _close_timer.setInterval( (duration or self.default_config.get('duration')) * 1000) _ani_timer = QTimer(self) _ani_timer.timeout.connect(self._fade_out) _ani_timer.setInterval( (duration or self.default_config.get('duration')) * 1000 - 300) _close_timer.start() _ani_timer.start() self._opacity_ani = QPropertyAnimation() self._opacity_ani.setTargetObject(self) self._opacity_ani.setDuration(300) self._opacity_ani.setEasingCurve(QEasingCurve.OutCubic) self._opacity_ani.setPropertyName(b'windowOpacity') self._opacity_ani.setStartValue(0.0) self._opacity_ani.setEndValue(0.9) self._get_center_position(parent) self._fade_int()