Ejemplo n.º 1
0
 def _update_style(self):
     scale_x, _ = get_scale_factor()
     if self._border:
         self.setStyleSheet(
             self._border_style.substitute(
                 padding_small=3 * scale_x,
                 font_size_base=dayu_theme.font_size_base,
                 font_unit=dayu_theme.font_unit,
                 unit=dayu_theme.unit,
                 background_color=utils.fade_color(self._color, "15%"),
                 border_radius=dayu_theme.border_radius_base,
                 border_color=utils.fade_color(self._color, "35%"),
                 hover_color=utils.generate_color(self._color, 5),
                 text_color=self._color,
             ))
     else:
         self.setStyleSheet(
             self._no_border_style.substitute(
                 padding=4 * scale_x,
                 font_size_base=dayu_theme.font_size_base,
                 font_unit=dayu_theme.font_unit,
                 unit=dayu_theme.unit,
                 background_color=utils.generate_color(self._color, 6),
                 border_radius=dayu_theme.border_radius_base,
                 border_color=utils.generate_color(self._color, 6),
                 hover_color=utils.generate_color(self._color, 5),
                 text_color=dayu_theme.text_color_inverse,
             ))
Ejemplo n.º 2
0
    def _init_ui(self):
        scale_x, _ = get_scale_factor()
        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 = QtWidgets.QHBoxLayout()
        placement_lay.addWidget(self.button_grp)
        placement_lay.addSpacing(20 * scale_x)
        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 = QtWidgets.QHBoxLayout()
        new_account_lay.addWidget(MLabel("Submit form in drawer"))
        new_account_lay.addWidget(new_account_button)
        new_account_lay.addStretch()

        main_lay = QtWidgets.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)
Ejemplo n.º 3
0
    def __init__(self, text="", parent=None, flags=QtCore.Qt.Widget):
        super(MAlert, self).__init__(parent, flags)
        self.setAttribute(QtCore.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))
        scale_x, _ = get_scale_factor()
        margin = 8 * scale_x
        self._main_lay = QtWidgets.QHBoxLayout()
        self._main_lay.setContentsMargins(margin, margin, margin, margin)
        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_closable(False)
        self._dayu_type = None
        self._dayu_text = None
        self.set_dayu_type(MAlert.InfoType)
        self.set_dayu_text(text)
Ejemplo n.º 4
0
    def __init__(self, text="New Tag", parent=None):
        super(MNewTag, self).__init__(parent)
        self.setAttribute(Qt.WA_StyledBackground)
        self._add_button = MToolButton().text_beside_icon().small().svg(
            "add_line.svg")
        self._add_button.setText(text)
        self._add_button.clicked.connect(self._slot_show_edit)
        self._line_edit = MLineEdit().small()
        self._line_edit.returnPressed.connect(self._slot_return_pressed)
        self._line_edit.setVisible(False)
        self._line_edit.installEventFilter(self)

        self._main_lay = QGridLayout()
        self._main_lay.setContentsMargins(3, 3, 3, 3)
        self._main_lay.addWidget(self._add_button, 0, 0)
        self._main_lay.addWidget(self._line_edit, 0, 0)
        self.setLayout(self._main_lay)
        scale_x, _ = get_scale_factor()
        style = QssTemplate("""
            MNewTag{
                border: @border@unit dashed @border_color;
            }
            MNewTag MToolButton:hover{
                border:none;
            }
            """)
        self.setStyleSheet(
            style.substitute(
                border_color=utils.fade_color(dayu_theme.secondary_text_color,
                                              "35%"),
                unit=dayu_theme.unit,
                border=1 * scale_x,
            ))
Ejemplo n.º 5
0
 def __init__(self, orientation=QtCore.Qt.Horizontal, parent=None):
     super(MRadioButtonGroup, self).__init__(orientation=orientation,
                                             parent=parent)
     scale_x, _ = get_scale_factor()
     self.set_spacing(15 * scale_x)
     self._button_group.setExclusive(True)
     self._button_group.buttonClicked[int].connect(self.sig_checked_changed)
Ejemplo n.º 6
0
def get_color_icon(color, size=24):
    scale_x, y = get_scale_factor()
    pix = QtGui.QPixmap(size * scale_x, size * scale_x)
    q_color = color
    if isinstance(color, str):
        if color.startswith("#"):
            q_color = QtGui.QColor(str)
        elif color.count(",") == 2:
            q_color = QtGui.QColor(*tuple(map(int, color.split(","))))
    pix.fill(q_color)
    return QtGui.QIcon(pix)
Ejemplo n.º 7
0
    def __init__(self, orientation=QtCore.Qt.Horizontal, parent=None):
        super(MCheckBoxGroup, self).__init__(orientation=orientation,
                                             parent=parent)
        scale_x, _ = get_scale_factor()
        self.set_spacing(15 * scale_x)
        self._button_group.setExclusive(False)

        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._slot_context_menu)

        self._button_group.buttonClicked[int].connect(self._slot_map_signal)
        self._dayu_checked = []
Ejemplo n.º 8
0
    def slot_open_button(self):
        custom_widget = QtWidgets.QWidget()
        custom_lay = QtWidgets.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()
        scale_x, _ = get_scale_factor()
        drawer.setFixedWidth(300 * scale_x)
        drawer.set_widget(custom_widget)
        drawer.show()
Ejemplo n.º 9
0
 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
     scale_x, _ = get_scale_factor()
     if value in [MDrawer.BottomPos, MDrawer.TopPos]:
         self.setFixedHeight(200 * scale_x)
     else:
         self.setFixedWidth(200 * scale_x)
Ejemplo n.º 10
0
 def __init__(self, text, parent=None):
     super(MCheckableTag, self).__init__(text, parent)
     scale_x, x = get_scale_factor()
     self.setCheckable(True)
     style = QssTemplate("""
         MCheckableTag{
             spacing: @spaceing@unit;
             padding-top: @padding@unit;
             padding-bottom: @padding@unit;
             padding-right: @spaceing@unit;
             border-radius: @border_radius_base@unit;
             font-size: @font_size_base@font_unit;
         }
         MCheckableTag::indicator{
             width: 0;
             height: 0;
             background: transparent;
         }
         MCheckableTag:pressed{
             background-color: @primary_7;
         }
         MCheckableTag:checked{
             color: @text_color_inverse;
             background-color: @primary_color;
         }
         MCheckableTag:checked:hover{
             background-color: @primary_5;
         }
         MCheckableTag:unchecked{
             color: @secondary_text_color;
             background-color: transparent;
         }
         MCheckableTag:unchecked:hover{
             color: @primary_5;
         }
         """)
     self.setStyleSheet(
         style.substitute(
             spaceing=8 * scale_x,
             padding=4 * scale_x,
             border_radius_base=dayu_theme.border_radius_base,
             unit=dayu_theme.unit,
             font_unit=dayu_theme.font_unit,
             font_size_base=dayu_theme.font_size_base,
             primary_5=dayu_theme.primary_5,
             primary_7=dayu_theme.primary_7,
             primary_color=dayu_theme.primary_color,
             secondary_text_color=dayu_theme.secondary_text_color,
             text_color_inverse=dayu_theme.text_color_inverse,
         ))
Ejemplo n.º 11
0
def convert_to_round_pixmap(orig_pix):
    scale_x, _ = get_scale_factor()
    w = min(orig_pix.width(), orig_pix.height())
    pix_map = QtGui.QPixmap(w, w)
    pix_map.fill(QtCore.Qt.transparent)

    painter = QtGui.QPainter(pix_map)
    painter.setRenderHints(QtGui.QPainter.Antialiasing
                           | QtGui.QPainter.SmoothPixmapTransform)

    path = QtGui.QPainterPath()
    path.addEllipse(0, 0, w, w)
    painter.setClipPath(path)
    painter.drawPixmap(0, 0, w, w, orig_pix)
    return pix_map
Ejemplo n.º 12
0
def set_header_list(self, header_list):
    scale_x, _ = get_scale_factor()
    self.header_list = header_list
    if self.header_view:
        self.header_view.setSortIndicator(-1, QtCore.Qt.AscendingOrder)
        for index, i in enumerate(header_list):
            self.header_view.setSectionHidden(index, i.get("hide", False))
            self.header_view.resizeSection(index,
                                           i.get("width", 100) * scale_x)
            if i.get("order", None) is not None:
                self.header_view.setSortIndicator(index, i.get("order"))
            if i.get("selectable", False):
                delegate = MOptionDelegate(parent=self)
                delegate.set_exclusive(i.get("exclusive", True))
                self.setItemDelegateForColumn(index, delegate)
            elif self.itemDelegateForColumn(index):
                self.setItemDelegateForColumn(index, None)
Ejemplo n.º 13
0
    def slot_open_button_2(self):
        custom_widget = QtWidgets.QWidget()
        custom_lay = QtWidgets.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()
        )

        scale_x, _ = get_scale_factor()
        drawer.setFixedWidth(300 * scale_x)
        drawer.set_widget(custom_widget)
        drawer.show()
Ejemplo n.º 14
0
    def slot_new_account(self):
        custom_widget = QtWidgets.QWidget()
        custom_lay = QtWidgets.QFormLayout()
        custom_lay.addRow("Name", MLineEdit())
        custom_lay.addRow("Age", MSpinBox())
        custom_lay.addRow("Birth", MDateEdit())
        custom_widget.setLayout(custom_lay)

        drawer = MDrawer("New account", parent=self)
        submit_button = MPushButton("Submit").primary()
        submit_button.clicked.connect(drawer.close)
        drawer.add_widget_to_bottom(MPushButton("Cancel"))
        drawer.add_widget_to_bottom(submit_button)
        scale_x, _ = get_scale_factor()
        drawer.setFixedWidth(300 * scale_x)
        drawer.set_widget(custom_widget)
        drawer.show()
Ejemplo n.º 15
0
def get_theme_size():
    scale_factor_x, scale_factor_y = get_scale_factor()
    return {
        "border_radius_large": int(6 * scale_factor_x),
        "border_radius_base": int(4 * scale_factor_x),
        "border_radius_small": int(2 * scale_factor_x),
        "huge": int(48 * scale_factor_x),
        "large": int(40 * scale_factor_x),
        "medium": int(32 * scale_factor_x),
        "small": int(24 * scale_factor_x),
        "tiny": int(18 * scale_factor_x),
        "huge_icon": int((48 - 20) * scale_factor_x),
        "large_icon": int((40 - 16) * scale_factor_x),
        "medium_icon": int((32 - 12) * scale_factor_x),
        "small_icon": int((24 - 10) * scale_factor_x),
        "tiny_icon": int((18 - 8) * scale_factor_x),
        "default_size": int(32 * scale_factor_x),
        "badge_width_radius": int(8 * scale_factor_x),
        "badge_width": int(16 * scale_factor_x),
        "badge_dot": int(8 * scale_factor_x),
        "badge_dot_radius": int(4 * scale_factor_x),
        "drop_down_huge": int(20 * scale_factor_x),
        "drop_down_large": int(16 * scale_factor_x),
        "drop_down_medium": int(14 * scale_factor_x),
        "drop_down_small": int(10 * scale_factor_x),
        "drop_down_tiny": int(8 * scale_factor_x),
        "spin_box_huge": int(28 * scale_factor_x),
        "spin_box_large": int(26 * scale_factor_x),
        "spin_box_medium": int(24 * scale_factor_x),
        "spin_box_small": int(20 * scale_factor_x),
        "spin_box_tiny": int(18 * scale_factor_x),
        "spin_box_icon_huge": int(14 * scale_factor_x),
        "spin_box_icon_large": int(12 * scale_factor_x),
        "spin_box_icon_medium": int(10 * scale_factor_x),
        "spin_box_icon_small": int(8 * scale_factor_x),
        "spin_box_icon_tiny": int(6 * scale_factor_x),
        "drag_border": int(2 * scale_factor_x),
        "drag_border_radius": int(10 * scale_factor_x),
        "drag_padding_x": int(20 * scale_factor_x),
        "drag_padding_y": int(40 * scale_factor_x),
        "drag_size": int(60 * scale_factor_x),
        "switch_width_huge": int(58 * scale_factor_x),
        "switch_height_huge": int(30 * scale_factor_x),
        "switch_radius_huge": int(15 * scale_factor_x),
        "switch_width_large": int(48 * scale_factor_x),
        "switch_height_large": int(24 * scale_factor_x),
        "switch_radius_large": int(12 * scale_factor_x),
        "switch_width_medium": int(38 * scale_factor_x),
        "switch_height_medium": int(19 * scale_factor_x),
        "switch_radius_medium": int(9 * scale_factor_x),
        "switch_width_small": int(28 * scale_factor_x),
        "switch_height_small": int(14 * scale_factor_x),
        "switch_radius_small": int(7 * scale_factor_x),
        "switch_width_tiny": int(18 * scale_factor_x),
        "switch_height_tiny": int(10 * scale_factor_x),
        "switch_radius_tiny": int(5 * scale_factor_x),
        "check_box_size": int(13 * scale_factor_x),
        "check_box_spacing": int(4 * scale_factor_x),
        "radio_size": int(14 * scale_factor_x),
        "radio_radius": int(14 * scale_factor_x) / 2.0,
        "radio_spacing": int(4 * scale_factor_x),
        "slider_height": int(4 * scale_factor_x),
        "slider_radius": int(3 * scale_factor_x),
        "slider_handle_size": int(8 * scale_factor_x),
        "slider_handle_radius": int(8 * scale_factor_x) / 1.5,
        "progress_circle_default_radius": int(120 * scale_factor_x),
        "progress_bar_size": int(12 * scale_factor_x),
        "progress_bar_radius": int(12 * scale_factor_x) / 2.0,
        "toast_size": int(120 * scale_factor_x),
        "toast_icon_size": int(60 * scale_factor_x),
    }
Ejemplo n.º 16
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()