Пример #1
0
class MRadioButton(MShape):
    def __init__(self):
        MShape.__init__(self)

        self.max_height = 20
        self.max_width = 20
        self.width = self.max_width
        self.height = self.max_height
        self.setFixedSize(self.width, self.height)
        self.innerCircle = None
        self.outerRing = OuterRing()
        self.add_layout_item(self.outerRing, 0, 0)
        self.setLayout(self.layout)
        self.__checked = False
        self.__reveal = MCircularReveal()
        self.__reveal.duration = 300
        self.__fade = MFadeOut()
        self.__fade.duration = 200
        self.__bounding_rect = QRect(self.x() + self.margin_x / 2, self.y() + self.margin_y / 2,
                                     self.width - self.margin_x, self.height - self.margin_y)

    def mousePressEvent(self, event):
        if self.__checked:
            self.__reveal.remove_target(self.innerCircle)
            self.__fade.add_target(self.innerCircle)
            self.__fade.end_signal.connect(self.on_fade_end)
            self.__fade.start()
        else:
            self.innerCircle = InnerCircle()
            self.add_layout_item(self.innerCircle, 0, 0)
            self.__reveal.add_target(self.innerCircle)
            self.__reveal.start()
            self.__checked = True

    def on_fade_end(self):
        self.__fade.remove_target(self.innerCircle)
        self.__fade.end_signal.disconnect(self.on_fade_end)
        self.remove_layout_item(self.innerCircle)
        self.__checked = False
Пример #2
0
class MCheckBox(MShape):
    def __init__(self):
        MShape.__init__(self)

        self.max_height = 20
        self.max_width = 20
        self.width = self.max_width
        self.height = self.max_height
        self.setFixedSize(self.width, self.height)
        self.__border = CheckboxBorder()
        self.__area = None
        self.add_layout_item(self.__border, 0, 0)
        self.__reveal = MCircularReveal()
        self.__reveal.duration = 300
        self.__fade = MFadeOut()
        self.__fade.duration = 200
        self.setLayout(self.layout)
        self.__checked = False

    def mousePressEvent(self, event):
        if self.__checked:
            self.__reveal.remove_target(self.__area)
            self.__fade.add_target(self.__area)
            self.__fade.end_signal.connect(self.on_fade_end)
            self.__fade.start()
        else:
            self.__area = CheckboxArea()
            self.add_layout_item(self.__area, 0, 0)
            self.__reveal.add_target(self.__area)
            self.__reveal.start()
            self.__checked = True

    def on_fade_end(self):
        self.__fade.remove_target(self.__area)
        self.__fade.end_signal.disconnect(self.on_fade_end)
        self.remove_layout_item(self.__area)
        self.__checked = False