Beispiel #1
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)
Beispiel #2
0
    def __init__(self, size=None, parent=None):
        super(MSequenceFile, self).__init__(parent)
        self.sequence_obj = None
        size = size or dayu_theme.small
        self._file_label = MLineEdit()
        self._file_label.set_dayu_size(size)
        self._file_label.setReadOnly(True)
        self._is_sequence_check_box = MCheckBox(self.tr('Sequence'))
        self._is_sequence_check_box.toggled.connect(functools.partial(self.setProperty, 'sequence'))
        self._is_sequence_check_box.toggled.connect(self.sig_is_sequence_changed)

        self._info_label = MLabel().secondary()
        self._error_label = MLabel().secondary()
        self._error_label.setProperty('error', True)
        self._error_label.setMinimumWidth(100)
        self._error_label.set_elide_mode(Qt.ElideMiddle)

        seq_lay = QHBoxLayout()
        seq_lay.addWidget(self._is_sequence_check_box)
        seq_lay.addWidget(self._info_label)
        seq_lay.addWidget(self._error_label)
        seq_lay.setStretchFactor(self._is_sequence_check_box, 0)
        seq_lay.setStretchFactor(self._info_label, 0)
        seq_lay.setStretchFactor(self._error_label, 100)

        self._main_lay = QVBoxLayout()
        self._main_lay.setContentsMargins(0, 0, 0, 0)
        self._main_lay.addWidget(self._file_label)
        self._main_lay.addLayout(seq_lay)
        self.setLayout(self._main_lay)
        self.set_sequence(True)
Beispiel #3
0
    def __init__(self,
                 text='',
                 orientation=Qt.Horizontal,
                 alignment=Qt.AlignCenter,
                 parent=None):
        super(MDivider, self).__init__(parent)
        self._orient = orientation
        self._text_label = MLabel().secondary()
        self._left_frame = QFrame()
        self._right_frame = QFrame()
        self._main_lay = QHBoxLayout()
        self._main_lay.setContentsMargins(0, 0, 0, 0)
        self._main_lay.setSpacing(0)
        self._main_lay.addWidget(self._left_frame)
        self._main_lay.addWidget(self._text_label)
        self._main_lay.addWidget(self._right_frame)
        self.setLayout(self._main_lay)

        if orientation == Qt.Horizontal:
            self._left_frame.setFrameShape(QFrame.HLine)
            self._left_frame.setFrameShadow(QFrame.Sunken)
            self._right_frame.setFrameShape(QFrame.HLine)
            self._right_frame.setFrameShadow(QFrame.Sunken)
        else:
            self._text_label.setVisible(False)
            self._right_frame.setVisible(False)
            self._left_frame.setFrameShape(QFrame.VLine)
            self._left_frame.setFrameShadow(QFrame.Plain)
            self.setFixedWidth(2)
        self._main_lay.setStretchFactor(self._left_frame,
                                        self._alignment_map.get(alignment, 50))
        self._main_lay.setStretchFactor(
            self._right_frame, 100 - self._alignment_map.get(alignment, 50))
        self._text = None
        self.set_dayu_text(text)
Beispiel #4
0
    def __init__(self, init_color, parent=None):
        super(MColorPaletteDialog, self).__init__(parent)
        self.setWindowTitle('DAYU Color Palette')
        self.primary_color = QColor(init_color)
        self.color_chart = MColorChart()
        self.choose_color_button = QPushButton()
        self.choose_color_button.setFixedSize(QSize(100, 30))
        self.color_label = QLabel()
        self.info_label = MLabel()
        self.info_label.setProperty('error', True)
        color_lay = QHBoxLayout()
        color_lay.addWidget(MLabel('Primary Color:'))
        color_lay.addWidget(self.choose_color_button)
        color_lay.addWidget(self.color_label)
        color_lay.addWidget(self.info_label)
        color_lay.addStretch()
        dialog = QColorDialog(self.primary_color, parent=self)
        dialog.setWindowFlags(Qt.Widget)
        dialog.setOption(QColorDialog.NoButtons)
        dialog.currentColorChanged.connect(self.slot_color_changed)
        setting_lay = QVBoxLayout()
        setting_lay.addLayout(color_lay)
        setting_lay.addWidget(MDivider())
        setting_lay.addWidget(dialog)

        main_lay = QHBoxLayout()
        main_lay.addWidget(self.color_chart)
        main_lay.addLayout(setting_lay)
        self.setLayout(main_lay)
        self.update_color()
Beispiel #5
0
    def __init__(self, text='', parent=None, flags=0):
        super(MAlert, self).__init__(parent, flags)
        self.setAttribute(Qt.WA_StyledBackground)
        self._icon_label = MAvatar()
        self._icon_label.set_dayu_size(dayu_theme.tiny)
        self._content_label = MLabel().secondary()
        self._close_button = MToolButton().svg(
            'close_line.svg').tiny().icon_only()
        self._close_button.clicked.connect(
            functools.partial(self.setVisible, False))

        self._main_lay = QHBoxLayout()
        self._main_lay.setContentsMargins(8, 8, 8, 8)
        self._main_lay.addWidget(self._icon_label)
        self._main_lay.addWidget(self._content_label)
        self._main_lay.addStretch()
        self._main_lay.addWidget(self._close_button)

        self.setLayout(self._main_lay)

        self.set_show_icon(True)
        self.set_closeable(False)
        self._dayu_type = None
        self._dayu_text = None
        self.set_dayu_type(MAlert.InfoType)
        self.set_dayu_text(text)
Beispiel #6
0
def test_label_dayu_style(qtbot, func, text, attr):
    """Test MLabel with different style"""
    label = MLabel(text)
    getattr(label, func)()
    qtbot.addWidget(label)

    assert label.property(attr)
    assert label.text() == text
Beispiel #7
0
def test_label_dayu_level(qtbot, func, text, attr):
    """Test MLabel with different level"""
    label = MLabel(text)
    getattr(label, func)()
    qtbot.addWidget(label)

    assert label.get_dayu_level() == attr
    assert label.text() == text
Beispiel #8
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
Beispiel #9
0
    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)
Beispiel #10
0
    def _init_ui(self):
        main_lay = QVBoxLayout()

        tab_center = MLineTabWidget()
        tab_center.add_tab(MLabel('test 1 ' * 10),
                           {'text': u'Tab 1', 'svg': 'user_line.svg'})
        tab_center.add_tab(MLabel('test 2 ' * 10), {'svg': 'calendar_line.svg'})
        tab_center.add_tab(MLabel('test 3 ' * 10), u'Tab 3')
        tab_center.tool_button_group.set_dayu_checked(0)

        tab_left = MLineTabWidget(alignment=Qt.AlignLeft)
        tab_left.add_tab(MLabel('test 1 ' * 10), u'Tab 1')
        tab_left.add_tab(MLabel('test 2 ' * 10), u'Tab 2')
        tab_left.add_tab(MLabel('test 3 ' * 10), u'Tab 3')
        tab_left.tool_button_group.set_dayu_checked(0)

        tab_right = MLineTabWidget(alignment=Qt.AlignRight)
        tab_right.add_tab(MLabel('test 1 ' * 10), u'Tab 1')
        tab_right.add_tab(MLabel('test 2 ' * 10), u'Tab 2')
        tab_right.add_tab(MLabel('test 3 ' * 10), u'Tab 3')
        tab_right.tool_button_group.set_dayu_checked(0)

        main_lay.addWidget(MDivider('Center'))
        main_lay.addWidget(tab_center)
        main_lay.addSpacing(20)
        main_lay.addWidget(MDivider('Left'))
        main_lay.addWidget(tab_left)
        main_lay.addSpacing(20)
        main_lay.addWidget(MDivider('Right'))
        main_lay.addWidget(tab_right)
        main_lay.addStretch()
        self.setLayout(main_lay)
Beispiel #11
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()
Beispiel #12
0
    def __init__(self,
                 title='',
                 expand=False,
                 widget=None,
                 closeable=False,
                 parent=None):
        super(MSectionItem, self).__init__(parent)
        self._central_widget = None
        self.setAttribute(Qt.WA_StyledBackground)
        self.title_label = MLabel(parent=self)
        self.expand_icon = MLabel(parent=self)
        self.expand_icon.setSizePolicy(QSizePolicy.Minimum,
                                       QSizePolicy.Minimum)
        self._close_button = MToolButton().icon_only().tiny().svg(
            'close_line.svg')
        self._close_button.clicked.connect(self.close)

        header_lay = QHBoxLayout()
        header_lay.addWidget(self.expand_icon)
        header_lay.addWidget(self.title_label)
        header_lay.addStretch()
        header_lay.addWidget(self._close_button)
        self.header_widget = QWidget(parent=self)
        self.header_widget.setAttribute(Qt.WA_StyledBackground)
        self.header_widget.setObjectName('title')
        self.header_widget.setLayout(header_lay)
        self.header_widget.setSizePolicy(QSizePolicy.Minimum,
                                         QSizePolicy.Minimum)
        self.header_widget.setCursor(Qt.PointingHandCursor)
        self.title_label.setCursor(Qt.PointingHandCursor)
        self.header_widget.installEventFilter(self)
        self.title_label.installEventFilter(self)

        self.content_widget = QWidget(parent=self)
        self.content_layout = QHBoxLayout()
        self.content_widget.setLayout(self.content_layout)

        self.main_lay = QVBoxLayout()
        self.main_lay.setContentsMargins(0, 0, 0, 0)
        self.main_lay.setSpacing(0)
        self.main_lay.addWidget(self.header_widget)
        self.main_lay.addWidget(self.content_widget)
        self.setLayout(self.main_lay)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.setMouseTracking(True)
        self.set_title(title)
        self.set_closeable(closeable)
        if widget:
            self.set_content(widget)
        self.set_expand(expand)
Beispiel #13
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()
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
0
    def add_item(self, data_dict, index=None):
        """Add a item"""
        button = MToolButton()
        button.setText(data_dict.get('text'))
        if data_dict.get('svg'):
            button.svg(data_dict.get('svg'))
        if data_dict.get('tooltip'):
            button.setProperty('toolTip', data_dict.get('tooltip'))
        if data_dict.get('clicked'):
            button.clicked.connect(data_dict.get('clicked'))
        if data_dict.get('text'):
            if data_dict.get('svg') or data_dict.get('icon'):
                button.text_beside_icon()
            else:
                button.text_only()
        else:
            button.icon_only()

        if self._button_group.buttons():
            separator = MLabel(self._separator).secondary()
            self._label_list.append(separator)
            self._main_layout.insertWidget(self._main_layout.count() - 1,
                                           separator)
        self._main_layout.insertWidget(self._main_layout.count() - 1, button)

        if index is None:
            self._button_group.addButton(button)
        else:
            self._button_group.addButton(button, index)
Beispiel #17
0
class MColorPaletteDialog(QDialog):
    def __init__(self, init_color, parent=None):
        super(MColorPaletteDialog, self).__init__(parent)
        self.setWindowTitle('DAYU Color Palette')
        self.primary_color = QColor(init_color)
        self.color_chart = MColorChart()
        self.choose_color_button = QPushButton()
        self.choose_color_button.setFixedSize(QSize(100, 30))
        self.color_label = QLabel()
        self.info_label = MLabel()
        self.info_label.setProperty('error', True)
        color_lay = QHBoxLayout()
        color_lay.addWidget(MLabel('Primary Color:'))
        color_lay.addWidget(self.choose_color_button)
        color_lay.addWidget(self.color_label)
        color_lay.addWidget(self.info_label)
        color_lay.addStretch()
        dialog = QColorDialog(self.primary_color, parent=self)
        dialog.setWindowFlags(Qt.Widget)
        dialog.setOption(QColorDialog.NoButtons)
        dialog.currentColorChanged.connect(self.slot_color_changed)
        setting_lay = QVBoxLayout()
        setting_lay.addLayout(color_lay)
        setting_lay.addWidget(MDivider())
        setting_lay.addWidget(dialog)

        main_lay = QHBoxLayout()
        main_lay.addWidget(self.color_chart)
        main_lay.addLayout(setting_lay)
        self.setLayout(main_lay)
        self.update_color()

    @Slot(QColor)
    def slot_color_changed(self, color):
        self.primary_color = color
        light = self.primary_color.lightness()
        saturation = self.primary_color.saturation()
        self.info_label.setText('')
        if light <= 70:
            self.info_label.setText(u'亮度建议不低于70(现在 {})'.format(light))
        if saturation <= 70:
            self.info_label.setText(u'饱和度建议不低于70(现在 {})'.format(saturation))

        self.update_color()

    def update_color(self):
        self.choose_color_button.setStyleSheet(
            'border-radius: 0;border: none;border:1px solid gray;'
            'background-color:{};'.format(self.primary_color.name()))
        self.color_label.setText(self.primary_color.name())
        self.color_chart.set_colors([
            utils.generate_color(self.primary_color, index + 1)
            for index in range(10)
        ])
Beispiel #18
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)
Beispiel #19
0
    def _init_ui(self):
        switch = MSwitch()
        switch.setChecked(True)
        slider = MSlider()
        slider.setRange(1, 10)
        switch_lay = QFormLayout()
        switch_lay.addRow(MLabel('AutoPlay'), switch)
        switch_lay.addRow(MLabel('Interval'), slider)
        test = MCarousel([MPixmap('app-{}.png'.format(a)) for a in ['maya', 'nuke', 'houdini']],
                         width=300,
                         height=300,
                         autoplay=True)
        switch.toggled.connect(test.set_autoplay)
        slider.valueChanged.connect(lambda x: test.set_interval(x * 1000))
        slider.setValue(3)

        main_lay = QVBoxLayout()
        main_lay.addWidget(test)
        main_lay.addLayout(switch_lay)
        main_lay.addStretch()
        self.setLayout(main_lay)
Beispiel #20
0
    def __init__(self, dashboard=False, parent=None):
        super(MProgressCircle, self).__init__(parent)
        self._main_lay = QHBoxLayout()
        self._default_label = MLabel().h3()
        self._default_label.setAlignment(Qt.AlignCenter)
        self._main_lay.addWidget(self._default_label)
        self.setLayout(self._main_lay)
        self._color = None
        self._width = None

        self._start_angle = 90 * 16
        self._max_delta_angle = 360 * 16
        self._height_factor = 1.0
        self._width_factor = 1.0
        if dashboard:
            self._start_angle = 225 * 16
            self._max_delta_angle = 270 * 16
            self._height_factor = (2 + pow(2, 0.5)) / 4 + 0.03

        self.set_dayu_width(120)
        self.set_dayu_color(dayu_theme.primary_color)
    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)
Beispiel #22
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))
Beispiel #23
0
    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()
Beispiel #24
0
    def __init__(self, parent=None):
        super(CheckBoxExample, self).__init__(parent)
        self.setWindowTitle('Example for MCheckBox')
        grid_lay = QGridLayout()

        for index, (text, state) in enumerate([('Unchecked', Qt.Unchecked),
                                               ('Checked', Qt.Checked),
                                               ('Partially',
                                                Qt.PartiallyChecked)]):
            check_box_normal = MCheckBox(text)
            check_box_normal.setCheckState(state)

            check_box_disabled = MCheckBox(text)
            check_box_disabled.setCheckState(state)
            check_box_disabled.setEnabled(False)

            grid_lay.addWidget(check_box_normal, 0, index)
            grid_lay.addWidget(check_box_disabled, 1, index)

        icon_lay = QHBoxLayout()
        for text, icon in [('Maya', MIcon('app-maya.png')),
                           ('Nuke', MIcon('app-nuke.png')),
                           ('Houdini', MIcon('app-houdini.png'))]:
            check_box_icon = MCheckBox(text)
            check_box_icon.setIcon(icon)
            icon_lay.addWidget(check_box_icon)

        check_box_bind = MCheckBox('Data Bind')
        label = MLabel()
        button = MPushButton(text='Change State')
        button.clicked.connect(
            lambda: self.set_field('checked', not self.field('checked')))
        self.register_field('checked', True)
        self.register_field(
            'checked_text', lambda: 'Yes!'
            if self.field('checked') else 'No!!')
        self.bind('checked', check_box_bind, 'checked', signal='stateChanged')
        self.bind('checked_text', label, 'text')

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('Basic'))
        main_lay.addLayout(grid_lay)
        main_lay.addWidget(MDivider('Icon'))
        main_lay.addLayout(icon_lay)
        main_lay.addWidget(MDivider('Data Bind'))
        main_lay.addWidget(check_box_bind)
        main_lay.addWidget(label)
        main_lay.addWidget(button)
        main_lay.addStretch()
        self.setLayout(main_lay)
Beispiel #25
0
    def __init__(self, parent=None):
        super(RadioButtonExample, self).__init__(parent)
        self.setWindowTitle('Example for MRadioButton')
        widget_1 = QWidget()
        lay_1 = QHBoxLayout()
        lay_1.addWidget(MRadioButton('Maya'))
        lay_1.addWidget(MRadioButton('Nuke'))
        lay_1.addWidget(MRadioButton('Houdini'))
        widget_1.setLayout(lay_1)

        check_box_icon_1 = MRadioButton('Folder')
        check_box_icon_1.setIcon(MIcon('folder_fill.svg'))
        check_box_icon_2 = MRadioButton('Media')
        check_box_icon_2.setIcon(MIcon('media_fill.svg'))
        check_box_icon_3 = MRadioButton('User')
        check_box_icon_3.setIcon(MIcon('user_fill.svg'))
        check_box_icon_2.setChecked(True)
        widget_2 = QWidget()
        lay_2 = QHBoxLayout()
        lay_2.addWidget(check_box_icon_1)
        lay_2.addWidget(check_box_icon_2)
        lay_2.addWidget(check_box_icon_3)
        widget_2.setLayout(lay_2)

        check_box_single = MRadioButton(u'支付宝')
        check_box_single.setChecked(True)
        check_box_single.setEnabled(False)

        check_box_bind = MRadioButton('Data Bind')
        label = MLabel()
        button = MPushButton(text='Change State')
        button.clicked.connect(lambda: self.set_field('checked', not self.field('checked')))
        self.register_field('checked', True)
        self.register_field('checked_text', lambda: 'Yes!' if self.field('checked') else 'No!!')
        self.bind('checked', check_box_bind, 'checked', signal='toggled')
        self.bind('checked_text', label, 'text')

        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('Basic'))
        main_lay.addWidget(widget_1)
        main_lay.addWidget(check_box_single)
        main_lay.addWidget(MDivider('Icon'))
        main_lay.addWidget(widget_2)
        main_lay.addWidget(MDivider('Data Bind'))
        main_lay.addWidget(check_box_bind)
        main_lay.addWidget(label)
        main_lay.addWidget(button)
        main_lay.addStretch()
        self.setLayout(main_lay)
Beispiel #26
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()
Beispiel #27
0
    def _init_ui(self):
        button_config_list = [
            {
                'text': 'Add',
                'icon': MIcon('add_line.svg', '#fff'),
                'type': MPushButton.PrimaryType
            },
            {
                'text': 'Edit',
                'icon': MIcon('edit_fill.svg', '#fff'),
                'type': MPushButton.WarningType
            },
            {
                'text': 'Delete',
                'icon': MIcon('trash_line.svg', '#fff'),
                'type': MPushButton.DangerType
            },
        ]
        button_group_h = MPushButtonGroup()
        button_group_h.set_dayu_size(dayu_theme.large)
        button_group_h.set_button_list(button_config_list)
        h_lay = QHBoxLayout()
        h_lay.addWidget(button_group_h)
        h_lay.addStretch()

        button_group_v = MPushButtonGroup(orientation=Qt.Vertical)
        button_group_v.set_button_list(button_config_list)
        h_lay_2 = QHBoxLayout()
        h_lay_2.addWidget(button_group_v)
        h_lay_2.addStretch()

        main_lay = QVBoxLayout()
        main_lay.addWidget(
            MLabel(
                u'MPushButtonGroup is MPushButton collection. they are not exclusive.'
            ))
        main_lay.addWidget(
            MDivider('MPushButton group: Horizontal & Small Size'))
        main_lay.addLayout(h_lay)
        main_lay.addWidget(
            MDivider('MPushButton group: Vertical & Default Size'))
        main_lay.addLayout(h_lay_2)
        main_lay.addStretch()
        self.setLayout(main_lay)
Beispiel #28
0
    def __init__(self, parent=None):
        super(FieldMixinExample, self).__init__(parent)
        self.register_field('my_name', 'xiaoming')
        self.register_field('thumbnail_path', '')
        self.register_field('is_enable', True)
        self.register_field('status', 'waiting')
        self.register_field('str_enable', self.computed_str_enable)
        self.register_field('thumbnail_pix_map',
                            self.computed_thumbnail_pix_map)
        self.register_field('email', self.computed_email)

        name2_label = MLabel()
        email_label = MLabel()
        thumbnail_label = MLabel()
        enable_button = MPushButton().primary()
        self.bind('my_name', name2_label, 'dayu_text')
        self.bind('email', email_label, 'dayu_text')
        self.bind('is_enable', enable_button, 'enabled')
        self.bind('thumbnail_pix_map', thumbnail_label, 'pixmap')
        self.bind('str_enable', enable_button, 'text')

        button = MPushButton(text='Change Data').primary()
        button.clicked.connect(self.slot_change_data)
        main_lay = QGridLayout()
        main_lay.addWidget(MLabel('Avatar:'), 0, 0)
        main_lay.addWidget(thumbnail_label, 0, 1)
        main_lay.addWidget(MLabel('Name:'), 1, 0)
        main_lay.addWidget(
            self.bind('my_name', MLineEdit(), 'text', signal='textEdited'), 1,
            1)
        main_lay.addWidget(MLabel('Email:'), 2, 0)
        main_lay.addWidget(email_label, 2, 1)
        main_lay.addWidget(MLabel('Enabled:'), 3, 0)
        main_lay.addWidget(enable_button, 3, 1)
        # for index, i in enumerate(self.field('my_name')):
        #     main_lay.addRow('name{}:'.format(index), self.bind('my_name', QLabel(), 'text', index=index))
        main_lay.addWidget(button, 4, 1)

        temp_lay = QVBoxLayout()
        temp_lay.addLayout(main_lay)
        temp_lay.addStretch()
        self.setLayout(temp_lay)
Beispiel #29
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)
Beispiel #30
0
    def _init_ui(self):
        div1 = MDivider()
        div2 = MDivider('With Text')
        div3 = MDivider.left('Left Text')
        div4 = MDivider.center('Center Text')
        div5 = MDivider.right('Right Text')
        div6 = MDivider.vertical()
        div7 = MDivider.vertical()
        div8 = MDivider.left('orientation=Qt.Vertical')
        label1 = MLabel('Maya').strong()
        label2 = MLabel('Nuke').underline()
        label3 = MLabel('Houdini').mark()
        sub_lay = QHBoxLayout()
        sub_lay.addWidget(label1)
        sub_lay.addWidget(div6)
        sub_lay.addWidget(label2)
        sub_lay.addWidget(div7)
        sub_lay.addWidget(label3)
        sub_lay.addStretch()

        some_text = 'Steven Paul Jobs was an American entrepreneur and business magnate.'
        main_lay = QVBoxLayout()
        main_lay.addWidget(MLabel(some_text))
        main_lay.addWidget(div1)
        main_lay.addWidget(MLabel(some_text))
        main_lay.addWidget(div2)
        main_lay.addWidget(MLabel(some_text))
        main_lay.addWidget(div3)
        main_lay.addWidget(MLabel(some_text))
        main_lay.addWidget(div4)
        main_lay.addWidget(MLabel(some_text))
        main_lay.addWidget(div5)
        main_lay.addLayout(sub_lay)
        main_lay.addWidget(div8)
        main_lay.addStretch()
        self.setLayout(main_lay)