예제 #1
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)
예제 #2
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)
예제 #3
0
    def _init_ui(self):
        self.register_field("percent", 20)
        main_lay = QtWidgets.QVBoxLayout()
        main_lay.addWidget(MDivider("different orientation"))
        for orn in [QtCore.Qt.Horizontal, QtCore.Qt.Vertical]:
            line_edit_hor = MSlider(orn)
            line_edit_hor.setRange(1, 100)
            self.bind("percent", line_edit_hor, "value")
            lay = QtWidgets.QVBoxLayout()
            lay.addWidget(line_edit_hor)
            main_lay.addLayout(lay)
        spin_box = MSpinBox()
        spin_box.setRange(1, 100)
        self.bind("percent", spin_box, "value", signal="valueChanged")

        lay3 = QtWidgets.QHBoxLayout()
        button_grp = MPushButtonGroup()
        button_grp.set_button_list(
            [
                {"text": "+", "clicked": functools.partial(self.slot_change_value, 10)},
                {
                    "text": "-",
                    "clicked": functools.partial(self.slot_change_value, -10),
                },
            ]
        )
        lay3.addWidget(spin_box)
        lay3.addWidget(button_grp)
        lay3.addStretch()
        main_lay.addWidget(MDivider("data bind"))
        main_lay.addLayout(lay3)
        main_lay.addStretch()
        self.setLayout(main_lay)
예제 #4
0
    def __init__(self, parent=None):
        super(AlertExample, self).__init__(parent)
        self.setWindowTitle("Example for MAlert")
        main_lay = QtWidgets.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())

        closable_alert = MAlert("Some Message", parent=self).closable()

        main_lay.addWidget(MLabel("不同的提示信息类型"))
        main_lay.addWidget(MDivider("closable"))
        main_lay.addWidget(closable_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_closable(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()
예제 #5
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()
    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 = QtWidgets.QHBoxLayout()
        h_lay.addWidget(button_group_h)
        h_lay.addStretch()

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

        main_lay = QtWidgets.QVBoxLayout()
        main_lay.addWidget(
            MLabel(
                "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)
예제 #7
0
    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()
예제 #8
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, MMessage.info, {"text": "这是一条普通提示"}
            )
        )
        button4.clicked.connect(
            functools.partial(
                self.slot_show_message, MMessage.success, {"text": "恭喜你,成功啦!"}
            )
        )
        button5.clicked.connect(
            functools.partial(
                self.slot_show_message, MMessage.warning, {"text": "我警告你哦!"}
            )
        )
        button6.clicked.connect(
            functools.partial(self.slot_show_message, MMessage.error, {"text": "失败了!"})
        )

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

        button_duration = MPushButton(text="show 5s Message")
        button_duration.clicked.connect(
            functools.partial(
                self.slot_show_message,
                MMessage.info,
                {"text": "该条消息将显示5秒后关闭", "duration": 5},
            )
        )
        button_closable = MPushButton(text="closable Message")
        button_closable.clicked.connect(
            functools.partial(
                self.slot_show_message,
                MMessage.info,
                {"text": "可手动关闭提示", "closable": True},
            )
        )
        main_lay = QtWidgets.QVBoxLayout()
        main_lay.addWidget(MDivider("different type"))
        main_lay.addLayout(sub_lay1)
        main_lay.addWidget(MLabel("不同的提示状态:普通、成功、警告、错误。默认2秒后消失"))
        main_lay.addWidget(MDivider("set duration"))
        main_lay.addWidget(button_duration)
        main_lay.addWidget(MLabel("自定义时长,config中设置duration值,单位为秒"))

        main_lay.addWidget(MDivider("set closable"))
        main_lay.addWidget(button_closable)
        main_lay.addWidget(MLabel("设置是否可关闭,config中设置closable 为 True"))

        button_grp = MPushButtonGroup()
        button_grp.set_button_list(
            [
                {
                    "text": "set duration to 1s",
                    "clicked": functools.partial(
                        self.slot_set_config, MMessage.config, {"duration": 1}
                    ),
                },
                {
                    "text": "set duration to 10s",
                    "clicked": functools.partial(
                        self.slot_set_config, MMessage.config, {"duration": 10}
                    ),
                },
                {
                    "text": "set top to 5",
                    "clicked": functools.partial(
                        self.slot_set_config, MMessage.config, {"top": 5}
                    ),
                },
                {
                    "text": "set top to 50",
                    "clicked": functools.partial(
                        self.slot_set_config, MMessage.config, {"top": 50}
                    ),
                },
            ]
        )
        loading_button = MPushButton("Display a loading indicator")
        loading_button.clicked.connect(self.slot_show_loading)
        main_lay.addWidget(MDivider("set global setting"))
        main_lay.addWidget(button_grp)
        main_lay.addWidget(MLabel("全局设置默认duration(默认2秒);top(离parent顶端的距离,默认24px)"))
        main_lay.addWidget(loading_button)

        main_lay.addStretch()
        self.setLayout(main_lay)
예제 #9
0
    def _init_ui(self):
        main_lay = QtWidgets.QVBoxLayout()
        self.setLayout(main_lay)
        main_lay.addWidget(MDivider("circle"))
        lay1 = QtWidgets.QHBoxLayout()
        circle_1 = MProgressCircle(parent=self)
        circle_1.setFormat("%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("%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 = QtWidgets.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"))

        scale_x, _ = get_scale_factor()
        circle_4 = MProgressCircle(parent=self)
        circle_4.set_dayu_width(100 * scale_x)
        circle_4.setValue(40)
        circle_5 = MProgressCircle(parent=self)
        circle_5.setValue(40)
        circle_6 = MProgressCircle(parent=self)
        circle_6.set_dayu_width(160 * scale_x)
        circle_6.setValue(40)
        lay2 = QtWidgets.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 = QtWidgets.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 = QtWidgets.QWidget()
        custom_layout = QtWidgets.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="消费人群规模").secondary()
        lab3 = MLabel(text="总占人数 75%").secondary()
        lab1.setAlignment(QtCore.Qt.AlignCenter)
        lab2.setAlignment(QtCore.Qt.AlignCenter)
        lab3.setAlignment(QtCore.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 * scale_x)
        custom_circle.setValue(75)
        custom_circle.set_widget(custom_widget)

        main_lay.addWidget(MDivider("custom circle"))
        main_lay.addWidget(custom_circle)
        main_lay.addStretch()
예제 #10
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, MMessage.info,
                              {'text': u'这是一条普通提示'}))
        button4.clicked.connect(
            functools.partial(self.slot_show_message, MMessage.success,
                              {'text': u'恭喜你,成功啦!'}))
        button5.clicked.connect(
            functools.partial(self.slot_show_message, MMessage.warning,
                              {'text': u'我警告你哦!'}))
        button6.clicked.connect(
            functools.partial(self.slot_show_message, MMessage.error,
                              {'text': u'失败了!'}))

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

        button_duration = MPushButton(text='show 5s Message')
        button_duration.clicked.connect(
            functools.partial(self.slot_show_message, MMessage.info, {
                'text': u'该条消息将显示5秒后关闭',
                'duration': 5
            }))
        button_closable = MPushButton(text='closable Message')
        button_closable.clicked.connect(
            functools.partial(self.slot_show_message, MMessage.info, {
                'text': u'可手动关闭提示',
                'closable': True
            }))
        main_lay = QVBoxLayout()
        main_lay.addWidget(MDivider('different type'))
        main_lay.addLayout(sub_lay1)
        main_lay.addWidget(MLabel(u'不同的提示状态:普通、成功、警告、错误。默认2秒后消失'))
        main_lay.addWidget(MDivider('set duration'))
        main_lay.addWidget(button_duration)
        main_lay.addWidget(MLabel(u'自定义时长,config中设置duration值,单位为秒'))

        main_lay.addWidget(MDivider('set closable'))
        main_lay.addWidget(button_closable)
        main_lay.addWidget(MLabel(u'设置是否可关闭,config中设置closable 为 True'))

        button_grp = MPushButtonGroup()
        button_grp.set_button_list([
            {
                'text':
                'set duration to 1s',
                'clicked':
                functools.partial(self.slot_set_config, MMessage.config,
                                  {'duration': 1})
            },
            {
                'text':
                'set duration to 10s',
                'clicked':
                functools.partial(self.slot_set_config, MMessage.config,
                                  {'duration': 10})
            },
            {
                'text':
                'set top to 5',
                'clicked':
                functools.partial(self.slot_set_config, MMessage.config,
                                  {'top': 5})
            },
            {
                'text':
                'set top to 50',
                'clicked':
                functools.partial(self.slot_set_config, MMessage.config,
                                  {'top': 50})
            },
        ])
        loading_button = MPushButton('Display a loading indicator')
        loading_button.clicked.connect(self.slot_show_loading)
        main_lay.addWidget(MDivider('set global setting'))
        main_lay.addWidget(button_grp)
        main_lay.addWidget(
            MLabel(u'全局设置默认duration(默认2秒);top(离parent顶端的距离,默认24px)'))
        main_lay.addWidget(loading_button)

        main_lay.addStretch()
        self.setLayout(main_lay)