def create_char( cls, char: str, size: int, background: types.ColorType = "black", color: types.ColorType = "white", ): pixmap = cls(size, size) pixmap.fill(QtCore.Qt.transparent) with gui.Painter(pixmap) as painter: painter.setRenderHints(painter.Antialiasing | painter.TextAntialiasing | painter.SmoothPixmapTransform) bg_color = colors.get_color(background) painter.setPen(bg_color) painter.setBrush(bg_color) margin = 1 + size // 16 text_margin = size // 20 rect = QtCore.QRectF(margin, margin, size - 2 * margin, size - 2 * margin) painter.drawRoundedRect(rect, 30.0, 30.0, QtCore.Qt.RelativeSize) painter.setPen(colors.get_color(color)) font = painter.font() # type: QtGui.QFont font.setPixelSize(size - 2 * margin - 2 * text_margin) painter.setFont(font) painter.drawText(rect, QtCore.Qt.AlignCenter, char) return pixmap
def __init__( self, duration: float, color: types.ColorType = "yellow", picture: QtGui.QPixmap | None = None, ): self.duration = duration self.color = colors.get_color(color) # Floating color self.def_color = colors.get_color(color) # DefaultColor self.picture = None if picture is None else picture.scaledToHeight(45) self.start_pos = 0.0 # Initial position self.end_pos = self.duration # End position
def create_checkerboard_pattern(cls, n: int, color_1: types.ColorType, color_2: types.ColorType): """Construct tileable checkerboard pattern for paint events.""" # Brush will be an n×n checkerboard pattern pat = gui.Pixmap(2 * n, 2 * n) bg0 = colors.get_color(color_1) bg1 = colors.get_color(color_2) with gui.Painter(pat) as p: p.setPen(QtCore.Qt.PenStyle.NoPen) # Paint a checkerboard pattern for the color to be overlaid on p.fillRect(pat.rect(), bg0) p.fillRect(0, 0, n, n, bg1) p.fillRect(n, n, 2 * n, 2 * n, bg1) return pat
def highlight_current_line(self, color: types.ColorType = None): if color is None: color = self.get_palette().get_color("highlight") else: color = colors.get_color(color) self.setCaretLineVisible(color is not None) self.setCaretLineBackgroundColor(color)
def set_color(self, color: types.ColorType) -> Label: with self.edit_stylesheet() as ss: if color is None: ss.color.setValue("") else: color = colors.get_color(color) ss.color.setValue(color.name()) return self
def set_background( self, brush_or_color: types.ColorAndBrushType, pattern: constants.PatternStr = "solid", ): if isinstance(brush_or_color, QtGui.QBrush): brush = brush_or_color else: color = colors.get_color(brush_or_color) brush = gui.Brush(color, constants.PATTERN[pattern]) self.setBackground(brush)
def create_dot(cls, color: types.ColorType = "black", size: int = 16) -> Pixmap: col = colors.get_color(color) px = cls(size, size) px.fill(QtCore.Qt.GlobalColor.transparent) # type: ignore px_size = px.rect().adjusted(1, 1, -1, -1) with gui.Painter(px) as painter: painter.use_antialiasing() painter.setBrush(col) pen_color = gui.Color(15, 15, 15) painter.set_pen(color=pen_color, width=1) painter.drawEllipse(px_size) return px
def fill_rect( self, rect: types.RectType | types.RectFType, color: types.ColorType, pattern: constants.PatternStr = "solid", ): if pattern not in constants.PATTERN: raise InvalidParamError(pattern, constants.PATTERN) if isinstance(rect, tuple): rect = core.RectF(*rect) color = colors.get_color(color) if pattern != "solid": color = gui.Brush(color, constants.PATTERN[pattern]) self.fillRect(rect, color)
def highlight_current_line(self, color: types.ColorType = None): if color is None: color = self.get_palette().get_color("highlight") else: color = colors.get_color(color) extra_selections = [] if not self.isReadOnly(): selection = widgets.TextEdit.ExtraSelection() selection.format.setBackground(color) prop = QtGui.QTextFormat.Property.FullWidthSelection selection.format.setProperty(prop, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() extra_selections.append(selection) self.setExtraSelections(extra_selections)
def set_current_color(self, color: types.ColorType): self._current_color = colors.get_color(color) self.lineedit.set_text(self._current_color.name().upper()) icon = iconprovider.for_color(self._current_color) self.button.set_icon(icon)
def set_background_color(self, color: types.ColorType | QtGui.QBrush): if not isinstance(color, QtGui.QBrush): color = colors.get_color(color) self.setBackground(color)
def set_text_color(self, color: types.ColorType) -> None: color = colors.get_color(color) self.setTextColor(color)
def set_background_color(self, color: types.ColorType): color = colors.get_color(color) self.background_color = color
def set_text_color(self, color: types.ColorType): color = colors.get_color(color) self.text_color = color
def set_marker_background_color(self, color: types.ColorType, marker_num): self.setMarkerBackgroundColor(colors.get_color(color), marker_num)
def set_color(self, color: types.ColorType = "black"): self._color = colors.get_color(color)
def set_brush(self, brush: QtGui.QBrush | types.ColorType): if not isinstance(brush, QtGui.QBrush): brush = colors.get_color(brush) self.setBrush(brush)
def change_color(self, color: types.ColorType) -> None: self._color = colors.get_color(color)
def set_brush( self, role: RoleStr, brush: types.ColorAndBrushType, group: GroupStr = "active" ): if not isinstance(brush, QtGui.QBrush): brush = gui.Brush(colors.get_color(brush)) self.setBrush(GROUP[group], ROLE[role], brush)
def set_background_color(self, color: types.ColorType) -> None: col_str = "" if color is None else colors.get_color(color).name() with self.edit_stylesheet() as ss: ss.backgroundColor.setValue(col_str)
def set_margins_background_color(self, color: types.ColorType): self.setMarginsBackgroundColor(colors.get_color(color))
def set_right_color(self, color: types.ColorType): self.gradient_right = colors.get_color(color) self.update()
def set_color(self, color: types.ColorType): color = colors.get_color(color) self.setPen(color)
def set_color( self, role: RoleStr, color: types.ColorType, group: GroupStr = "active" ): color = colors.get_color(color) self.setColor(GROUP[group], ROLE[role], color)
def __init__(self, xml: str, color: types.ColorType = "black") -> None: self._xml = xml self._color = colors.get_color(color) super().__init__()