コード例 #1
0
 def __init__(self, develop=False):
     self.drawn_once = False
     self.develop = develop
     self.title_font = f = QFont()
     f.setPointSize(self.TITLE_SIZE)
     f.setBold(True)
     self.title_height = QFontMetrics(f).lineSpacing() + 2
     self.body_font = f = QFont()
     f.setPointSize(self.BODY_SIZE)
     self.line_height = QFontMetrics(f).lineSpacing()
     self.total_height = max(self.LOGO_SIZE,
                             self.title_height + 3 * self.line_height)
     self.num_font = f = QFont()
     f.setPixelSize(self.total_height)
     f.setItalic(True), f.setBold(True)
     f = QFontMetrics(f)
     self.num_ch = str(max(3, numeric_version[0]))
     self.footer_font = f = QFont()
     f.setPointSize(self.FOOTER_SIZE)
     f.setItalic(True)
     self.dpr = QApplication.instance().devicePixelRatio()
     self.pmap = QPixmap(I('library.png', allow_user_override=False))
     self.pmap.setDevicePixelRatio(self.dpr)
     self.pmap = self.pmap.scaled(
         int(self.dpr * self.LOGO_SIZE),
         int(self.dpr * self.LOGO_SIZE),
         transformMode=Qt.TransformationMode.SmoothTransformation)
     self.light_brush = QBrush(QColor('#F6F3E9'))
     self.dark_brush = QBrush(QColor('#39322B'))
     pmap = QPixmap(int(self.WIDTH * self.dpr),
                    int(self.total_height * self.dpr))
     pmap.setDevicePixelRatio(self.dpr)
     pmap.fill(Qt.GlobalColor.transparent)
     QSplashScreen.__init__(self, pmap)
     self.setWindowTitle(__appname__)
コード例 #2
0
 def render_emblems(item, emblems):
     emblems = tuple(emblems)
     if not emblems:
         return
     icon = self.rendered_emblem_cache.get(emblems, None)
     if icon is None:
         pixmaps = []
         for emblem in emblems:
             pm = self.emblem_cache.get(emblem, None)
             if pm is None:
                 pm = self.emblem_cache[emblem] = QIcon(I(emblem)).pixmap(self.iconSize())
             pixmaps.append(pm)
         num = len(pixmaps)
         w, h = pixmaps[0].width(), pixmaps[0].height()
         if num == 1:
             icon = self.rendered_emblem_cache[emblems] = QIcon(pixmaps[0])
         else:
             canvas = QPixmap((num * w) + ((num-1)*2), h)
             canvas.setDevicePixelRatio(pixmaps[0].devicePixelRatio())
             canvas.fill(Qt.GlobalColor.transparent)
             painter = QPainter(canvas)
             for i, pm in enumerate(pixmaps):
                 painter.drawPixmap(int(i * (w + 2)/canvas.devicePixelRatio()), 0, pm)
             painter.end()
             icon = self.rendered_emblem_cache[emblems] = canvas
     item.setData(0, Qt.ItemDataRole.DecorationRole, icon)
コード例 #3
0
class ColorButton(QToolButton):
    def __init__(self, color, parent=None):
        QToolButton.__init__(self, parent)
        self.setIconSize(QSize(50, 25))
        self.pix = QPixmap(self.iconSize())
        self._color = QColor('#' + color)
        self.pix.fill(self._color)
        self.setIcon(QIcon(self.pix))
        self.clicked.connect(self.choose_color)

    @property
    def color(self):
        return self._color.name(QColor.NameFormat.HexRgb)[1:]

    @color.setter
    def color(self, val):
        self._color = QColor('#' + val)

    def update_display(self):
        self.pix.fill(self._color)
        self.setIcon(QIcon(self.pix))

    def choose_color(self):
        c = QColorDialog.getColor(self._color, self, _('Choose color'))
        if c.isValid():
            self._color = c
            self.update_display()
コード例 #4
0
 def color(self, val):
     val = unicode_type(val or '')
     col = QColor(val)
     orig = self._color
     if col.isValid():
         self._color = val
         self.setText(val)
         p = QPixmap(self.iconSize())
         p.fill(col)
         self.setIcon(QIcon(p))
     else:
         self._color = None
         self.setText(self.choose_text)
         self.setIcon(QIcon())
     if orig != col:
         self.color_changed.emit(self._color)
コード例 #5
0
class ColorButton(QPushButton):

    changed = pyqtSignal()

    def __init__(self, data, name, text, parent):
        QPushButton.__init__(self, text, parent)
        self.ic = QPixmap(self.iconSize())
        color = data[name]
        self.data, self.name = data, name
        if color is not None:
            self.current_color = read_color(color).color()
            self.ic.fill(self.current_color)
        else:
            self.ic.fill(Qt.GlobalColor.transparent)
            self.current_color = color
        self.update_tooltip()
        self.setIcon(QIcon(self.ic))
        self.clicked.connect(self.choose_color)

    def clear(self):
        self.current_color = None
        self.update_tooltip()
        self.ic.fill(Qt.GlobalColor.transparent)
        self.setIcon(QIcon(self.ic))
        self.data[self.name] = self.value
        self.changed.emit()

    def choose_color(self):
        col = QColorDialog.getColor(self.current_color or Qt.GlobalColor.black,
                                    self, _('Choose color'))
        if col.isValid():
            self.current_color = col
            self.update_tooltip()
            self.ic.fill(col)
            self.setIcon(QIcon(self.ic))
            self.data[self.name] = self.value
            self.changed.emit()

    def update_tooltip(self):
        self.setToolTip(
            _('Red: {0} Green: {1} Blue: {2}').format(
                *self.current_color.getRgb()[:3]) if self.
            current_color else _('No color'))

    @property
    def value(self):
        if self.current_color is None:
            return None
        return col_to_string(self.current_color)