Skip to content

GradientMixin

Subclasses

Class Module Description
Gradient prettyqt.gui.gradient
LinearGradient prettyqt.gui.lineargradient
RadialGradient prettyqt.gui.radialgradient
ConicalGradient prettyqt.gui.conicalgradient

⋔ Inheritance diagram

graph TD
  1473245598256["gui.GradientMixin"]
  140713234304496["builtins.object"]
  140713234304496 --> 1473245598256

🛈 DocStrings

Source code in prettyqt\gui\gradient.py
class GradientMixin:
    def __setitem__(self, key: float, value: datatypes.ColorType):
        self.set_color_at(key, value)

    def serialize(self) -> dict[str, Any]:
        return dict(
            coordinate_mode=self.get_coordinate_mode(),
            spread=self.get_spread(),
            stops=self.get_stops(),
        )

    def set_color_at(self, key: float, color: datatypes.ColorType):
        super().setColorAt(key, colors.get_color(color))

    def set_coordinate_mode(self, mode: CoordinateModeStr | gui.QGradient.CoordinateMode):
        """Set the coordinate mode.

        Args:
            mode: coordinate mode
        """
        self.setCoordinateMode(COORDINATE_MODE.get_enum_value(mode))

    def get_coordinate_mode(self) -> CoordinateModeStr:
        """Return current coordinate mode.

        Returns:
            coordinate mode
        """
        return COORDINATE_MODE.inverse[self.coordinateMode()]

    def set_spread(self, method: SpreadStr | gui.QGradient.Spread):
        """Set the spread method.

        Args:
            method: spread method
        """
        self.setSpread(SPREAD.get_enum_value(method))

    def get_spread(self) -> SpreadStr:
        """Return current spread method.

        Returns:
            spread method
        """
        return SPREAD.inverse[self.spread()]

    def get_type(self) -> TypeStr:
        """Return current gradient type.

        Returns:
            gradient type
        """
        return TYPE.inverse[self.type()]

    def get_stops(self) -> list[tuple[float, gui.Color]]:
        return [(i, gui.Color(j)) for (i, j) in self.stops()]

    @classmethod
    def for_palette(cls, palette: gui.Palette, group: gui.palette.GroupStr = "active"):
        gradient = cls()
        for i, role_name in enumerate(gui.palette.ROLE):
            color = palette.get_color(role_name, group)
            gradient.setColorAt(i / len(gui.palette.ROLE), color)
        return gradient

    def change_brightness(self, factor: float):
        # still need to streamline changing brightness across the framework...
        # color.lighter returns a lighter color when arg is > 100 (same for darker)
        factor = int(factor * 100)
        for pos, color in grad.stops():
            if factor > 0:
                self.setColorAt(pos, color.lighter(factor))
            else:
                self.setColorAt(pos, color.darker(-factor))

get_coordinate_mode() -> CoordinateModeStr

Return current coordinate mode.

Source code in prettyqt\gui\gradient.py
def get_coordinate_mode(self) -> CoordinateModeStr:
    """Return current coordinate mode.

    Returns:
        coordinate mode
    """
    return COORDINATE_MODE.inverse[self.coordinateMode()]

get_spread() -> SpreadStr

Return current spread method.

Source code in prettyqt\gui\gradient.py
def get_spread(self) -> SpreadStr:
    """Return current spread method.

    Returns:
        spread method
    """
    return SPREAD.inverse[self.spread()]

get_type() -> TypeStr

Return current gradient type.

Source code in prettyqt\gui\gradient.py
def get_type(self) -> TypeStr:
    """Return current gradient type.

    Returns:
        gradient type
    """
    return TYPE.inverse[self.type()]

set_coordinate_mode(mode: CoordinateModeStr | gui.QGradient.CoordinateMode)

Set the coordinate mode.

Parameters:

Name Type Description Default
mode CoordinateModeStr | CoordinateMode

coordinate mode

required
Source code in prettyqt\gui\gradient.py
def set_coordinate_mode(self, mode: CoordinateModeStr | gui.QGradient.CoordinateMode):
    """Set the coordinate mode.

    Args:
        mode: coordinate mode
    """
    self.setCoordinateMode(COORDINATE_MODE.get_enum_value(mode))

set_spread(method: SpreadStr | gui.QGradient.Spread)

Set the spread method.

Parameters:

Name Type Description Default
method SpreadStr | Spread

spread method

required
Source code in prettyqt\gui\gradient.py
def set_spread(self, method: SpreadStr | gui.QGradient.Spread):
    """Set the spread method.

    Args:
        method: spread method
    """
    self.setSpread(SPREAD.get_enum_value(method))