def test_progress_circle_widget(qtbot):
    label = QLabel('text')
    circle = MProgressCircle()
    circle.set_widget(label)
    qtbot.addWidget(circle)
    circle.show()
    circle.repaint()
    assert not circle.isTextVisible()
    assert not circle._default_label.isVisible()
    assert label.isVisible()
def test_progress_circle_widget(qtbot):
    label = QtWidgets.QLabel("text")
    circle = MProgressCircle()
    circle.set_widget(label)
    qtbot.addWidget(circle)
    circle.show()
    circle.repaint()

    def check():
        assert not circle.isTextVisible()
        assert not circle._default_label.isVisible()
        assert label.isVisible()

    qtbot.waitUntil(check)
def test_progress_circle_class_method(qtbot):
    circle = MProgressCircle.dashboard()
    qtbot.addWidget(circle)
    assert circle.width() > circle.height()
def test_progress_circle_init(qtbot):
    circle = MProgressCircle()
    circle.setRange(0, 10)
    circle.setValue(5)
    qtbot.addWidget(circle)
    assert circle.text() == '50%'
def test_progress_circle_color(qtbot, color, result):
    circle = MProgressCircle()
    circle.set_dayu_color(color)
    qtbot.addWidget(circle)
    circle.show()
    assert circle.get_dayu_color() == result
    circle.set_dayu_color('#0f0')
    assert circle.get_dayu_color() == '#0f0'
    circle.setValue(20)
    assert circle.text() == '20%'
def test_progress_circle_width(qtbot, width, result):
    circle = MProgressCircle()
    circle.set_dayu_width(width)
    dashboard = MProgressCircle(dashboard=True)
    dashboard.set_dayu_width(width)
    qtbot.addWidget(circle)
    qtbot.addWidget(dashboard)
    assert circle.width() == result
    assert circle.height() == result
    assert circle.get_dayu_width() == result

    assert dashboard.width() == result
    assert dashboard.height() < result
    assert dashboard.get_dayu_width() == result
    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()
Example #8
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()