示例#1
0
        def paintEvent(self, event):
            if self.text() != self._default_label.text():
                self._default_label.setText(self.text())
            if self.isTextVisible() != self._default_label.isVisible():
                self._default_label.setVisible(self.isTextVisible())

            percent = utils.get_percent(self.value(), self.minimum(),
                                        self.maximum())
            total_width = self._width
            pen_width = int(3 * total_width / 50.0)
            radius = total_width - pen_width - 1

            painter = QtGui.QPainter(self)
            painter.setRenderHints(QtGui.QPainter.Antialiasing)

            # draw background circle
            pen_background = QtGui.QPen()
            pen_background.setWidth(pen_width)
            pen_background.setColor(QtGui.QColor(80, 120, 110))
            pen_background.setCapStyle(QtCore.Qt.RoundCap)
            painter.setPen(pen_background)
            painter.drawArc(pen_width / 2.0 + 1, pen_width / 2.0 + 1, radius,
                            radius, self._start_angle, -self._max_delta_angle)

            # draw foreground circle
            pen_foreground = QtGui.QPen()
            pen_foreground.setWidth(pen_width)
            pen_foreground.setColor(self._color)
            pen_foreground.setCapStyle(QtCore.Qt.RoundCap)
            painter.setPen(pen_foreground)
            painter.drawArc(pen_width / 2.0 + 1, pen_width / 2.0 + 1, radius,
                            radius, self._start_angle,
                            -percent * 0.01 * self._max_delta_angle)
            painter.end()
示例#2
0
        def __init__(self, parent=None, **kwargs):
            super(ProgressCricle, self).__init__(parent)

            self._infinite = False
            self._timer = QtCore.QTimer(self)
            self._timer.timeout.connect(self._on_increase_value)

            self._main_layout = QtWidgets.QHBoxLayout()
            self._default_label = QtWidgets.QLabel()
            self._default_label.setAlignment(QtCore.Qt.AlignCenter)
            self._main_layout.addWidget(self._default_label)
            self.setLayout(self._main_layout)
            self._color = QtGui.QColor(221, 235, 230)
            self._width = kwargs.get('width', 140)

            self.setTextDirection(self.Direction.BottomToTop)

            self._start_angle = 90 * 16
            self._max_delta_angle = 360 * 16
            self._height_factor = 1.0
            self._width_factor = 1.0

            self.setFixedSize(
                QtCore.QSize(self._width * self._width_factor,
                             self._width * self._height_factor))
示例#3
0
def generate_color(primary_color, index):
    """
    Generates a new color from the given one and with given index (between 1 and 10)
    https://github.com/phenom-films/dayu_widgets/blob/master/dayu_widgets/utils.py
    :param primary_color: base color (RRGGBB)
    :param index: color step from 1 (light) to 10 (dark)
    :return: out color Color
    """

    hue_step = 2
    saturation_step = 16
    saturation_step2 = 5
    brightness_step1 = 5
    brightness_step2 = 15
    light_color_count = 5
    dark_color_count = 4

    def _get_hue(color, i, is_light):
        h_comp = color.hue()
        if 60 <= h_comp <= 240:
            hue = h_comp - hue_step * i if is_light else h_comp + hue_step * i
        else:
            hue = h_comp + hue_step * i if is_light else h_comp - hue_step * i
        if hue < 0:
            hue += 359
        elif hue >= 359:
            hue -= 359
        return hue / 359.0

    def _get_saturation(color, i, is_light):
        s_comp = color.saturationF() * 100
        if is_light:
            saturation = s_comp - saturation_step * i
        elif i == dark_color_count:
            saturation = s_comp + saturation_step
        else:
            saturation = s_comp + saturation_step2 * i
        saturation = min(100.0, saturation)
        if is_light and i == light_color_count and saturation > 10:
            saturation = 10
        saturation = max(6.0, saturation)
        return round(saturation * 10) / 1000.0

    def _get_value(color, i, is_light):
        v_comp = color.valueF()
        if is_light:
            return min((v_comp * 100 + brightness_step1 * i) / 100, 1.0)
        return max((v_comp * 100 - brightness_step2 * i) / 100, 0.0)

    light = index <= 6
    hsv_color = QtGui.QColor(primary_color) if isinstance(primary_color, str) else primary_color
    index = light_color_count + 1 - index if light else index - light_color_count - 1
    return QtGui.QColor.fromHsvF(
        _get_hue(hsv_color, index, light),
        _get_saturation(hsv_color, index, light),
        _get_value(hsv_color, index, light)
    ).name()
示例#4
0
def fade_color(color, alpha):
    """
    Internal function that fades given color
    :param color: QColor
    :param alpha: float
    :return:
    """

    qt_color = QtGui.QColor(color)
    return 'rgba({}, {}, {}, {})'.format(qt_color.red(), qt_color.green(), qt_color.blue(), alpha)
示例#5
0
def from_string(text_color):
    """
    Returns a (int, int, int, int) format color from a string format color
    :param text_color: str, string format color to parse
    :param alpha: int, alpha of the color
    :return: (int, int, int, int)
    """

    a = 255
    if string_is_hex(text_color):
        r, g, b = rgb_from_hex(text_color)
    else:
        try:
            if text_color.startswith('rgba'):
                r, g, b, a = text_color.replace('rgba(', '').replace(')', '').split(',')
            else:
                r, g, b, a = text_color.replace('rgb(', '').replace(')', '').split(',')
        except ValueError:
            if text_color.startswith('rgba'):
                r, g, b = text_color.replace('rgba(', '').replace(')', '').split(',')
            else:
                r, g, b = text_color.replace('rgb(', '').replace(')', '').split(',')

    return QtGui.QColor(int(r), int(g), int(b), int(a))
示例#6
0
    def setup_ui(self):
        super(SplashDialog, self).setup_ui()

        self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint
                            | QtCore.Qt.WA_DeleteOnClose)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

        splash_pixmap = resource.pixmap('artella_splash')
        splash = SplashScreen(splash_pixmap)
        splash.setMask(splash_pixmap.mask())
        self._splash_layout = QtWidgets.QVBoxLayout()
        self._splash_layout.setAlignment(QtCore.Qt.AlignBottom)
        splash.setLayout(self._splash_layout)
        self.main_layout.addWidget(splash)

        size_width = splash_pixmap.size().width() + 20
        size_height = splash_pixmap.size().height() + 20
        self.setFixedSize(QtCore.QSize(size_width, size_height))

        shadow_effect = QtWidgets.QGraphicsDropShadowEffect(self)
        shadow_effect.setBlurRadius(qtutils.dpi_scale(15))
        shadow_effect.setColor(QtGui.QColor(0, 0, 0, 150))
        shadow_effect.setOffset(qtutils.dpi_scale(0))
        self.setGraphicsEffect(shadow_effect)