Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
    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 = QFormLayout()
        size_lay.addRow('Huge', MSwitch().huge())
        size_lay.addRow('Large', MSwitch().large())
        size_lay.addRow('Medium', MSwitch().medium())
        size_lay.addRow('Small', MSwitch().small())
        size_lay.addRow('Tiny', MSwitch().tiny())

        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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
    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('windowOpacity')
        self._opacity_ani.setStartValue(0.0)
        self._opacity_ani.setEndValue(0.9)

        self._get_center_position(parent)
        self._fade_int()
Exemplo n.º 6
0
class MCard(QWidget):
    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 get_more_button(self):
        return self._extra_button

    def set_widget(self, widget):
        self._content_layout.addWidget(widget)

    def border(self):
        self.setProperty('border', True)
        self.style().polish(self)
        return self
Exemplo n.º 7
0
    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()
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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() == ''
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    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()
Exemplo n.º 12
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
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
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
Exemplo n.º 18
0
    def _init_ui(self):
        size_lay = QHBoxLayout()
        size_list = [
            ('Huge', MLoading.huge),
            ('Large', MLoading.large),
            ('Medium', MLoading.medium),
            ('Small', MLoading.small),
            ('Tiny', MLoading.tiny),
        ]
        for label, cls in size_list:
            size_lay.addWidget(MLabel(label))
            size_lay.addWidget(cls())
            size_lay.addSpacing(10)

        color_lay = QHBoxLayout()
        color_list = [('cyan', '#13c2c2'), ('green', '#52c41a'),
                      ('magenta', '#eb2f96'), ('red', '#f5222d'),
                      ('yellow', '#fadb14'), ('volcano', '#fa541c')]
        for label, color in color_list:
            color_lay.addWidget(MLabel(label))
            color_lay.addWidget(MLoading.tiny(color=color))
            color_lay.addSpacing(10)

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different size'))
        main_lay.addLayout(size_lay)
        main_lay.addWidget(MDivider('different color'))
        main_lay.addLayout(color_lay)
        main_lay.addWidget(MDivider('loading wrapper'))
        # main_lay.addLayout(wrapper_lay)

        main_lay.addStretch()
        self.setLayout(main_lay)
Exemplo n.º 19
0
    def _init_ui(self):
        page_1 = MPage()
        page_1.set_total(255)

        page_2 = MPage()
        page_2.set_total(100)

        main_lay = QVBoxLayout()
        self.setLayout(main_lay)
        main_lay.addWidget(MDivider())
        main_lay.addWidget(page_1)
        main_lay.addWidget(MDivider())
        main_lay.addWidget(page_2)
        main_lay.addStretch()
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
    def _init_ui(self):
        self.button_grp = MRadioButtonGroup()
        self.button_grp.set_button_list(
            ['top', {
                'text': 'right',
                'checked': True
            }, 'bottom', 'left'])

        open_button_2 = MPushButton('Open').primary()
        open_button_2.clicked.connect(self.slot_open_button_2)
        placement_lay = QHBoxLayout()
        placement_lay.addWidget(self.button_grp)
        placement_lay.addSpacing(20)
        placement_lay.addWidget(open_button_2)
        placement_lay.addStretch()

        new_account_button = MPushButton(text='New account',
                                         icon=MIcon('add_line.svg',
                                                    '#fff')).primary()
        new_account_button.clicked.connect(self.slot_new_account)
        new_account_lay = QHBoxLayout()
        new_account_lay.addWidget(MLabel('Submit form in drawer'))
        new_account_lay.addWidget(new_account_button)
        new_account_lay.addStretch()

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('Custom Placement'))
        main_lay.addLayout(placement_lay)
        main_lay.addWidget(MDivider('Submit form in drawer'))
        main_lay.addLayout(new_account_lay)

        main_lay.addWidget(MDivider('Preview drawer'))
        self.setLayout(main_lay)
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
    def _init_ui(self):
        button3 = MPushButton(text='Normal Message').primary()
        button4 = MPushButton(text='Success Message').success()
        button5 = MPushButton(text='Warning Message').warning()
        button6 = MPushButton(text='Error Message').danger()
        button3.clicked.connect(
            functools.partial(self.slot_show_message, MToast.info,
                              {'text': u'好像没啥用'}))
        button4.clicked.connect(
            functools.partial(self.slot_show_message, MToast.success,
                              {'text': u'领取成功'}))
        button5.clicked.connect(
            functools.partial(self.slot_show_message, MToast.warning,
                              {'text': u'暂不支持'}))
        button6.clicked.connect(
            functools.partial(self.slot_show_message, MToast.error,
                              {'text': u'支付失败,请重试'}))

        sub_lay1 = QHBoxLayout()
        sub_lay1.addWidget(button3)
        sub_lay1.addWidget(button4)
        sub_lay1.addWidget(button5)
        sub_lay1.addWidget(button6)

        loading_button = MPushButton('Loading Toast').primary()
        loading_button.clicked.connect(self.slot_show_loading)

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different type'))
        main_lay.addLayout(sub_lay1)
        main_lay.addWidget(MLabel(u'不同的提示状态:成功、失败、加载中。默认2秒后消失'))
        main_lay.addWidget(loading_button)

        main_lay.addStretch()
        self.setLayout(main_lay)
Exemplo n.º 24
0
    def __init__(self,
                 cover=None,
                 avatar=None,
                 title=None,
                 description=None,
                 extra=False,
                 parent=None):
        super(MMeta, self).__init__(parent)
        self.setAttribute(Qt.WA_StyledBackground)
        self._cover_label = QLabel()
        self._avatar = MAvatar()
        self._title_label = MLabel().h4()
        self._description_label = MLabel().secondary()
        self._description_label.setWordWrap(True)
        self._description_label.set_elide_mode(Qt.ElideRight)
        self._title_layout = QHBoxLayout()
        self._title_layout.addWidget(self._title_label)
        self._title_layout.addStretch()
        self._extra_button = MToolButton(
            parent=self).icon_only().svg('more.svg')
        self._title_layout.addWidget(self._extra_button)
        self._extra_button.setVisible(extra)

        content_lay = QFormLayout()
        content_lay.setContentsMargins(5, 5, 5, 5)
        content_lay.addRow(self._avatar, self._title_layout)
        content_lay.addRow(self._description_label)

        self._button_layout = QHBoxLayout()

        main_lay = QVBoxLayout()
        main_lay.setSpacing(0)
        main_lay.setContentsMargins(1, 1, 1, 1)
        main_lay.addWidget(self._cover_label)
        main_lay.addLayout(content_lay)
        main_lay.addLayout(self._button_layout)
        main_lay.addStretch()
        self.setLayout(main_lay)
        self._cover_label.setFixedSize(QSize(200, 200))
Exemplo n.º 25
0
    def __init__(self, parent=None):
        super(PushButtonExample, self).__init__(parent)
        self.setWindowTitle('Example for MPushButton')

        sub_lay1 = QHBoxLayout()
        sub_lay1.addWidget(MPushButton('Default'))
        sub_lay1.addWidget(MPushButton('Primary').primary())
        sub_lay1.addWidget(MPushButton('Success').success())
        sub_lay1.addWidget(MPushButton('Warning').warning())
        sub_lay1.addWidget(MPushButton('Danger').danger())

        sub_lay2 = QHBoxLayout()
        sub_lay2.addWidget(MPushButton('Upload', MIcon('cloud_line.svg')))
        sub_lay2.addWidget(
            MPushButton('Submit', MIcon('folder_line.svg', '#ddd')).primary())
        sub_lay2.addWidget(
            MPushButton('Submit', MIcon('success_line.svg', '#ddd')).success())
        sub_lay2.addWidget(
            MPushButton('Edit', MIcon('edit_line.svg', '#ddd')).warning())
        sub_lay2.addWidget(
            MPushButton('Delete', MIcon('trash_line.svg', '#ddd')).danger())

        sub_lay3 = QHBoxLayout()
        sub_lay3.addWidget(MPushButton('Large').large().primary())
        sub_lay3.addWidget(MPushButton('Medium').medium().primary())
        sub_lay3.addWidget(MPushButton('Small').small().primary())

        disabled_button = MPushButton('Disabled')
        disabled_button.setEnabled(False)

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different type'))
        main_lay.addLayout(sub_lay1)
        main_lay.addLayout(sub_lay2)
        main_lay.addWidget(MDivider('different size'))
        main_lay.addLayout(sub_lay3)
        main_lay.addWidget(MDivider('disabled'))
        main_lay.addWidget(disabled_button)
        main_lay.addStretch()
        self.setLayout(main_lay)
Exemplo n.º 26
0
    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)
Exemplo n.º 27
0
    def __init__(self, parent=None):
        super(AvatarExample, self).__init__(parent)
        self.setWindowTitle('Example for MAvatar')
        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different size'))

        size_list = [('Huge', MAvatar.huge), ('Large', MAvatar.large),
                     ('Medium', MAvatar.medium), ('Small', MAvatar.small),
                     ('Tiny', MAvatar.tiny)]

        self.pix_map_list = [
            None,
            MPixmap('avatar.png'),
            MPixmap('app-maya.png'),
            MPixmap('app-nuke.png'),
            MPixmap('app-houdini.png')
        ]
        form_lay = QFormLayout()
        form_lay.setLabelAlignment(Qt.AlignRight)

        for label, cls in size_list:
            h_lay = QHBoxLayout()
            for image in self.pix_map_list:
                avatar_tmp = cls(image)
                h_lay.addWidget(avatar_tmp)
            h_lay.addStretch()
            form_lay.addRow(MLabel(label), h_lay)
        main_lay.addLayout(form_lay)
        self.register_field('image', None)
        main_lay.addWidget(MDivider('different image'))
        avatar = MAvatar()
        self.bind('image', avatar, 'dayu_image')
        button = MPushButton(text='Change Avatar Image').primary()
        button.clicked.connect(self.slot_change_image)

        main_lay.addWidget(avatar)
        main_lay.addWidget(button)
        main_lay.addStretch()
        self.setLayout(main_lay)
Exemplo n.º 28
0
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
Exemplo n.º 29
0
    def _init_ui(self):
        progress_1 = MProgressBar()
        progress_1.setValue(10)
        progress_1.setAlignment(Qt.AlignCenter)
        progress_2 = MProgressBar()
        progress_2.setValue(80)

        progress_normal = MProgressBar()
        progress_normal.setValue(30)
        progress_success = MProgressBar().success()
        progress_success.setValue(100)
        progress_error = MProgressBar().error()
        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)

        self.progress_count = 0
        self.timer = QTimer()
        self.timer.setInterval(10)
        self.timer.timeout.connect(self.slot_timeout)
        run_button = MPushButton(text='Run Something')
        run_button.clicked.connect(self.slot_run)
        self.auto_color_progress = MProgressBar().auto_color()
        auto_color_lay = QVBoxLayout()
        auto_color_lay.addWidget(run_button)
        auto_color_lay.addWidget(self.auto_color_progress)

        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.addWidget(MDivider('auto color'))
        main_lay.addLayout(auto_color_lay)
        main_lay.addStretch()
        self.setLayout(main_lay)
Exemplo n.º 30
0
class MDrawer(QWidget):
    """
    A panel which slides in from the edge of the screen.
    """
    LeftPos = 'left'
    RightPos = 'right'
    TopPos = 'top'
    BottomPos = 'bottom'

    sig_closed = Signal()

    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('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('windowOpacity')
        self._opacity_ani.setStartValue(0.0)
        self._opacity_ani.setEndValue(1.0)
        # self._shadow_effect = QGraphicsDropShadowEffect(self)
        # color = dayu_theme.red
        # self._shadow_effect.setColor(color)
        # self._shadow_effect.setOffset(0, 0)
        # self._shadow_effect.setBlurRadius(5)
        # self._shadow_effect.setEnabled(False)
        # self.setGraphicsEffect(self._shadow_effect)

    def set_widget(self, widget):
        self._scroll_area.setWidget(widget)

    def add_button(self, button):
        self._button_lay.addWidget(button)

    def _fade_out(self):
        self._pos_ani.setDirection(QAbstractAnimation.Backward)
        self._pos_ani.start()
        self._opacity_ani.setDirection(QAbstractAnimation.Backward)
        self._opacity_ani.start()

    def _fade_int(self):
        self._pos_ani.start()
        self._opacity_ani.start()

    def _set_proper_position(self):
        parent = self.parent()
        parent_geo = parent.geometry()
        if self._position == MDrawer.LeftPos:
            pos = parent_geo.topLeft(
            ) if parent.parent() is None else parent.mapToGlobal(
                parent_geo.topLeft())
            target_x = pos.x()
            target_y = pos.y()
            self.setFixedHeight(parent_geo.height())
            self._pos_ani.setStartValue(
                QPoint(target_x - self.width(), target_y))
            self._pos_ani.setEndValue(QPoint(target_x, target_y))
        if self._position == MDrawer.RightPos:
            pos = parent_geo.topRight(
            ) if parent.parent() is None else parent.mapToGlobal(
                parent_geo.topRight())
            self.setFixedHeight(parent_geo.height())
            target_x = pos.x() - self.width()
            target_y = pos.y()
            self._pos_ani.setStartValue(
                QPoint(target_x + self.width(), target_y))
            self._pos_ani.setEndValue(QPoint(target_x, target_y))
        if self._position == MDrawer.TopPos:
            pos = parent_geo.topLeft(
            ) if parent.parent() is None else parent.mapToGlobal(
                parent_geo.topLeft())
            self.setFixedWidth(parent_geo.width())
            target_x = pos.x()
            target_y = pos.y()
            self._pos_ani.setStartValue(
                QPoint(target_x, target_y - self.height()))
            self._pos_ani.setEndValue(QPoint(target_x, target_y))
        if self._position == MDrawer.BottomPos:
            pos = parent_geo.bottomLeft(
            ) if parent.parent() is None else parent.mapToGlobal(
                parent_geo.bottomLeft())
            self.setFixedWidth(parent_geo.width())
            target_x = pos.x()
            target_y = pos.y() - self.height()
            self._pos_ani.setStartValue(
                QPoint(target_x, target_y + self.height()))
            self._pos_ani.setEndValue(QPoint(target_x, target_y))

    def set_dayu_position(self, value):
        """
        Set the placement of the MDrawer.
        top/right/bottom/left, default is right
        :param value: str
        :return: None
        """
        self._position = value
        if value in [MDrawer.BottomPos, MDrawer.TopPos]:
            self.setFixedHeight(200)
        else:
            self.setFixedWidth(200)

    def get_dayu_position(self):
        """
        Get the placement of the MDrawer
        :return: str
        """
        return self._position

    dayu_position = Property(str, get_dayu_position, set_dayu_position)

    def left(self):
        """Set drawer's placement to left"""
        self.set_dayu_position(MDrawer.LeftPos)
        return self

    def right(self):
        """Set drawer's placement to right"""
        self.set_dayu_position(MDrawer.RightPos)
        return self

    def top(self):
        """Set drawer's placement to top"""
        self.set_dayu_position(MDrawer.TopPos)
        return self

    def bottom(self):
        """Set drawer's placement to bottom"""
        self.set_dayu_position(MDrawer.BottomPos)
        return self

    def show(self):
        self._set_proper_position()
        self._fade_int()
        return super(MDrawer, self).show()

    def closeEvent(self, event):
        if self._is_first_close:
            self._is_first_close = False
            self._close_timer.start()
            self._fade_out()
            event.ignore()
        else:
            event.accept()