Example #1
0
    def add_ellipse(self,
                    x: NumberType,
                    y: NumberType,
                    rx: NumberType,
                    ry: NumberType,
                    color: ColorType,
                    filled: bool,
                    prev: bool = True) -> str:
        """
        Add an ellipse.

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param rx: Horizontal radius of the ellipse
        :param ry: Vertical radius of the ellipse
        :param color: Color of the polygon
        :param filled: If ``True`` fills the polygon with the given color
        :param prev: If ``True`` draw previous the object, else draws post
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        assert_color(color)
        assert isinstance(rx, (int, float)) and rx > 0
        assert isinstance(ry, (int, float)) and ry > 0
        assert isinstance(filled, bool)
        return self._add_decor(DECORATION_ELLIPSE, prev,
                               (tuple(coords), rx, ry, color, filled))
Example #2
0
    def add_pie(self,
                x: NumberType,
                y: NumberType,
                radius: NumberType,
                init_angle: NumberType,
                final_angle: NumberType,
                color: ColorType,
                prev: bool = True) -> str:
        """
        Add a unfilled pie.

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param radius: Circle radius (px)
        :param init_angle: Initial angle in degrees ``(0-360)``
        :param final_angle: Final angle in degrees ``(0-360)``
        :param color: Color of the polygon
        :param prev: If ``True`` draw previous the object, else draws post
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        assert_color(color)
        assert isinstance(radius, (int, float)) and radius > 0
        assert isinstance(init_angle, (int, float))
        assert isinstance(final_angle, (int, float))
        assert init_angle != final_angle
        return self._add_decor(
            DECORATION_PIE, prev,
            (tuple(coords), int(radius), init_angle, final_angle, color))
Example #3
0
    def add_polygon(self, coords: Union[List[Tuple2NumberType], Tuple[Tuple2NumberType, ...]], color: ColorType,
                    filled: bool, width: int = 0, prev: bool = True, gfx: bool = True) -> str:
        """
        Add polygon.

        :param coords: Coordinate list, being ``(0, 0)`` the center of the object
        :param color: Color of the polygon
        :param filled: If ``True`` fills the polygon with the given color
        :param width: Line border width. Only valid if ``filled=False``
        :param prev: If ``True`` draw previous the object, else draws post
        :param gfx: If ``True`` uses pygame gfxdraw instead of draw
        :return: ID of the decoration
        """
        assert_list_vector(coords, 2)
        assert_color(color)
        assert len(coords) >= 3
        assert isinstance(filled, bool)
        assert isinstance(width, int) and width >= 0
        if filled:
            assert width == 0, 'width must be 0 if the polygon is filled'
            assert gfx, 'only gfxdraw support filled polygon, then gfx should be True'
        else:
            if width != 0 and gfx:
                gfx = False  # gfx don't support width
        return self._add_decor(DECORATION_POLYGON, prev, (tuple(coords), color, filled, width, gfx))
Example #4
0
    def add_line(self,
                 pos1: Tuple2NumberType,
                 pos2: Tuple2NumberType,
                 color: ColorType,
                 width: int = 1,
                 prev: bool = True,
                 **kwargs) -> str:
        """
        Adds a line.

        .. note::

            Consider ``(0, 0)`` coordinates as the center of the object.

        kwargs (Optional)
            - ``use_center_positioning``            Uses object center position as *(0, 0)*. ``True`` by default

        :param pos1: Position 1 *(x1, y1)*
        :param pos2: Position 2 *(x2, y2)*
        :param color: Line color
        :param width: Line width in px
        :param prev: If ``True`` draw previous the object, else draws post
        :param kwargs: Optional keyword arguments
        :return: ID of the decoration
        """
        assert_vector(pos1, 2)
        assert_vector(pos2, 2)
        assert_color(color)
        assert isinstance(width, int) and width >= 1
        length = math.sqrt(
            math.pow(pos1[0] - pos2[0], 2) + math.pow(pos1[1] - pos2[1], 2))
        assert length > 0, 'line cannot be zero-length'
        return self._add_decor(
            DECORATION_LINE, prev,
            ((tuple(pos1), tuple(pos2)), color, width, kwargs))
Example #5
0
    def set_shadow(self, enabled=True, color=None, position=None, offset=None):
        """
        Show text shadow.

        :param enabled: Shadow is enabled or not
        :type enabled: bool
        :param color: Shadow color
        :type color: list, None
        :param position: Shadow position
        :type position: str, None
        :param offset: Shadow offset
        :type offset: int, float, None
        :return: None
        """
        self._shadow = enabled
        if color is not None:
            assert_color(color)
            self._shadow_color = color
        if position is not None:
            assert_position(position)
            self._shadow_position = position
        if offset is not None:
            assert isinstance(offset, (int, float))
            if offset <= 0:
                raise ValueError('shadow offset must be greater than zero')
            self._shadow_offset = offset

        # Create shadow tuple position
        self._create_shadow_tuple()
Example #6
0
    def add_bezier(self,
                   coords: Union[List[Tuple2NumberType],
                                 Tuple[Tuple2NumberType, ...]],
                   color: ColorType,
                   steps: int = 5,
                   prev: bool = True,
                   **kwargs) -> str:
        """
        Add bezier curve.

        .. note::

            Consider ``(0, 0)`` coordinates as the center of the object.

        kwargs (Optional)
            - ``use_center_positioning``            Uses object center position as *(0, 0)*. ``True`` by default

        :param coords: Coordinate list, being ``(0, 0)`` the center of the object
        :param color: Color of the polygon
        :param steps: Interpolation steps
        :param prev: If ``True`` draw previous the object, else draws post
        :param kwargs: Optional keyword arguments
        :return: ID of the decoration
        """
        assert_list_vector(coords, 2)
        assert_color(color)
        assert len(coords) >= 3
        assert isinstance(steps, int) and steps >= 1
        return self._add_decor(DECORATION_BEZIER, prev,
                               (tuple(coords), color, steps, kwargs))
Example #7
0
    def add_pixel(self,
                  x: NumberType,
                  y: NumberType,
                  color: ColorType,
                  prev: bool = True,
                  **kwargs) -> str:
        """
        Add a pixel.

        .. note::

            Consider ``(0, 0)`` coordinates as the center of the object.

        kwargs (Optional)
            - ``use_center_positioning``            Uses object center position as *(0, 0)*. ``True`` by default

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param color: Color of the pixel
        :param prev: If ``True`` draw previous the object, else draws post
        :param kwargs: Optional keyword arguments
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        assert_color(color)
        return self._add_decor(DECORATION_PIXEL, prev,
                               (tuple(coords), color, kwargs))
Example #8
0
    def add_circle(self, x: NumberType, y: NumberType, radius: NumberType, color: ColorType, filled: bool,
                   width: int = 0, prev: bool = True, gfx: bool = True) -> str:
        """
        Add circle.

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param radius: Circle radius (px)
        :param color: Color of the polygon
        :param filled: If ``True`` fills the polygon with the given color
        :param width: Line border width. Only valid if ``filled=False``
        :param prev: If ``True`` draw previous the object, else draws post
        :param gfx: If ``True`` uses pygame gfxdraw instead of draw
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        assert_color(color)
        assert isinstance(radius, (int, float)) and radius > 0
        assert isinstance(filled, bool)
        assert isinstance(width, int) and width >= 0
        if filled:
            assert width == 0, 'width must be 0 if the circle is filled'
        else:
            if width != 0 and gfx:
                gfx = False  # gfx don't support width
        return self._add_decor(DECORATION_CIRCLE, prev, (tuple(coords), int(radius), color, filled, width, gfx))
Example #9
0
    def __init__(self,
                 title,
                 width,
                 background_color,
                 back_box=False,
                 mode=MENUBAR_STYLE_ADAPTIVE,
                 offsetx=0.0,
                 offsety=0.0,
                 onreturn=None,
                 *args,
                 **kwargs):
        assert isinstance(width, (int, float))
        assert isinstance(back_box, bool)

        assert_color(background_color)

        # MenuBar has no ID
        super(MenuBar, self).__init__(title=title,
                                      onreturn=onreturn,
                                      args=args,
                                      kwargs=kwargs)

        self._backbox = back_box
        self._backbox_pos = None  # type: (tuple,None)
        self._backbox_rect = None  # type: (pygame.rect.Rect,None)
        self._background_color = background_color
        self._box_mode = 0
        self._offsetx = 0.0
        self._offsety = 0.0
        self._polygon_pos = None  # type: (tuple,None)
        self._style = mode
        self._title = ''
        self._width = width

        self.set_title(title, offsetx, offsety)
Example #10
0
    def add_arc(self, x: NumberType, y: NumberType, radius: NumberType,
                init_angle: NumberType, final_angle: NumberType, color: ColorType,
                width: int = 0, prev: bool = True, gfx: bool = True) -> str:
        """
        Add arc.

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param radius: Circle radius (px)
        :param init_angle: Initial angle in degrees ``(0-360)``
        :param final_angle: Final angle in degrees ``(0-360)``
        :param color: Color of the polygon
        :param width: Line border width. Only valid if ``filled=False``
        :param prev: If ``True`` draw previous the object, else draws post
        :param gfx: If ``True`` uses pygame gfxdraw instead of draw
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        assert_color(color)
        assert isinstance(radius, (int, float)) and radius > 0
        assert isinstance(init_angle, (int, float))
        assert isinstance(final_angle, (int, float))
        assert isinstance(width, int) and width >= 0
        assert init_angle != final_angle
        return self._add_decor(DECORATION_ARC, prev, (tuple(coords), int(radius), init_angle, final_angle,
                                                      color, width, gfx))
Example #11
0
    def _format_opacity(color: Optional[Union[VectorType, 'BaseImage']]
                        ) -> Optional[Union[ColorType, 'BaseImage']]:
        """
        Adds opacity to a 3 channel color. (R,G,B) -> (R,G,B,A) if the color
        has not an alpha channel. Also updates the opacity to a number between
        0 and 255.

        Color may be an Image, so if this is the case return the same object.

        - If the color is a list, return a tuple.
        - If the color is ``None``, return ``None``.

        :param color: Color object
        :return: Color in the same format
        """
        if isinstance(color, BaseImage):
            return color
        if color is None:
            return color
        if isinstance(color, (tuple, list)):
            _utils.assert_color(color)
            if len(color) == 4:
                if isinstance(color, tuple):
                    return color
                return tuple(color)
            elif len(color) == 3:
                color = color[0], color[1], color[2], 255
        else:
            raise ValueError('invalid color type {0}, only tuple or list are valid'.format(color))
        return color
Example #12
0
    def _format_color_opacity(
            color: Optional[Union[ColorInputType, 'BaseImage']],
            none: bool = False) -> Optional[Union[ColorType, 'BaseImage']]:
        """
        Adds opacity to a 3 channel color. (R,G,B) -> (R,G,B,A) if the color
        has not an alpha channel. Also updates the opacity to a number between
        ``0`` (transparent) and ``255`` (opaque).

        Color may be an Image, so if this is the case return the same object.

        - If the color is a list, return a tuple.
        - If the color is ``None``, return ``None`` if ``None`` is True.

        :param color: Color object
        :param none: If ``True`` Color can be ``None``
        :return: Color in the same format
        """
        if isinstance(color, BaseImage):
            return color
        if color is None and none:
            return color
        color = format_color(color)
        if isinstance(color, VectorInstance):
            assert_color(color)
            if len(color) == 4:
                if isinstance(color, tuple):
                    return color
                return tuple(color)
            elif len(color) == 3:
                color = color[0], color[1], color[2], 255
        else:
            raise ValueError(
                'invalid color type {0}, only tuple or list are valid'.format(
                    color))
        return color
Example #13
0
    def _format_opacity(color):
        """
        Adds opacity to a 3 channel color. (R,G,B) -> (R,G,B,A) if the color
        has not an alpha channel. Also updates the opacity to a number between
        0 and 255.

        Color may be an Image, so if this is the case return the same object.
        If the color is a list, return a tuple.

        :param color: Color tuple
        :type color: tuple, list
        :return: Color in the same format
        :rtype: tuple, None
        """
        if isinstance(color, BaseImage):
            return color
        if color is None:
            return color
        if isinstance(color, (tuple, list)):
            _utils.assert_color(color)
            if len(color) == 4:
                if isinstance(color, tuple):
                    return color
                else:
                    return color[0], color[1], color[2], color[3]
            elif len(color) == 3:
                color = color[0], color[1], color[2], 255
        else:
            raise ValueError(
                'invalid color type {0}, only tuple or list are valid'.format(
                    color))
        return color
Example #14
0
    def __init__(
            self,
            title: Any,
            width: NumberType,
            background_color: ColorInputType,
            menubar_id: str = '',
            back_box: bool = False,
            back_box_background_color: ColorInputType = (0, 0, 0),
            mode: MenuBarStyleModeType = MENUBAR_STYLE_ADAPTIVE,
            modify_scrollarea: bool = True,
            offsetx: NumberType = 0,
            offsety: NumberType = 0,
            onreturn: CallbackType = None,
            *args,
            **kwargs
    ) -> None:
        assert isinstance(width, NumberInstance)
        assert isinstance(back_box, bool)

        assert width > 0, 'width must be greater or equal than zero'

        background_color = assert_color(background_color)
        back_box_background_color = assert_color(back_box_background_color)

        # MenuBar has no ID
        super(MenuBar, self).__init__(
            args=args,
            kwargs=kwargs,
            onreturn=onreturn,
            title=title,
            widget_id=menubar_id
        )

        self._backbox = back_box
        self._backbox_background_color = back_box_background_color
        self._backbox_border_width = 1  # px
        self._backbox_pos = None
        self._backbox_rect = None
        self._background_color = background_color
        self._box_mode = 0
        self._modify_scrollarea = modify_scrollarea
        self._mouseover_check_rect = lambda: self._backbox_rect
        self._offsetx = 0
        self._offsety = 0
        self._polygon_pos = None
        # north, east, south, west
        self._scrollbar_deltas = [(0, (0, 0)), (0, (0, 0)), (0, (0, 0)), (0, (0, 0))]
        self._style = mode
        self._title = ''
        self._width = int(width)

        self.set_title(title, offsetx, offsety)

        # Public's
        self.is_selectable = False
        self.fixed = True
Example #15
0
    def set_color(self, color: ColorType) -> 'Selection':
        """
        Set the selection effect color.

        :param color: Selection color
        :return: Self reference
        """
        assert_color(color)
        self.color = color
        return self
Example #16
0
    def set_color(self, color):
        """
        Set the selection color.

        :param color: Selection color
        :type color: tuple, list
        :return: None
        """
        assert_color(color)
        self.color = color
Example #17
0
    def __init__(self,
                 length: NumberType,
                 values_range: VectorIntType,
                 scrollbar_id: str = '',
                 orientation: ScrollBarOrientationType = _locals.
                 ORIENTATION_HORIZONTAL,
                 slider_pad: NumberType = 0,
                 slider_color: ColorType = (200, 200, 200),
                 page_ctrl_thick: int = 20,
                 page_ctrl_color: ColorType = (235, 235, 235),
                 onchange: CallbackType = None,
                 *args,
                 **kwargs) -> None:
        assert isinstance(length, (int, float))
        assert isinstance(values_range, (tuple, list))
        assert values_range[1] > values_range[
            0], 'minimum value first is expected'
        assert isinstance(slider_pad, (int, float))
        assert isinstance(page_ctrl_thick, int)
        assert page_ctrl_thick - 2 * slider_pad >= 2, 'slider shall be visible'

        assert_color(slider_color)
        assert_color(page_ctrl_color)

        super(ScrollBar, self).__init__(widget_id=scrollbar_id,
                                        onchange=onchange,
                                        args=args,
                                        kwargs=kwargs)

        self._values_range = list(values_range)
        self.scrolling = False
        self._mouseover = False

        self._orientation = 0
        self._opp_orientation = int(not self._orientation)

        self._page_ctrl_length = length
        self._page_ctrl_thick = page_ctrl_thick
        self._page_ctrl_color = page_ctrl_color

        self._slider_rect = None
        self._slider_pad = slider_pad
        self._slider_color = slider_color
        self._slider_position = 0

        self._single_step = 20
        self._page_step = 0

        if values_range[1] - values_range[0] > length:
            self.set_page_step(length)
        else:
            self.set_page_step(
                (values_range[1] - values_range[0]) / 5.0)  # Arbitrary
        self.set_orientation(orientation)
        self.is_selectable = False
Example #18
0
    def __init__(self,
                 length,
                 values_range,
                 scrollbar_id='',
                 orientation=_locals.ORIENTATION_HORIZONTAL,
                 slider_pad=0,
                 slider_color=(200, 200, 200),
                 page_ctrl_thick=20,
                 page_ctrl_color=(235, 235, 235),
                 onchange=None,
                 onreturn=None,
                 *args,
                 **kwargs):
        assert isinstance(length, (int, float))
        assert isinstance(values_range, (tuple, list))
        assert values_range[1] > values_range[
            0], 'minimum value first is expected'
        assert isinstance(slider_pad, (int, float))
        assert isinstance(page_ctrl_thick, (int, float))
        assert page_ctrl_thick - 2 * slider_pad >= 2, 'slider shall be visible'

        assert_color(slider_color)
        assert_color(page_ctrl_color)

        super(ScrollBar, self).__init__(widget_id=scrollbar_id,
                                        onchange=onchange,
                                        onreturn=onreturn,
                                        args=args,
                                        kwargs=kwargs)

        self._values_range = list(values_range)
        self.scrolling = False  # type: bool
        self._orientation = 0  # type: int
        self._opp_orientation = int(not self._orientation)  # type: int

        self._page_ctrl_length = length
        self._page_ctrl_thick = page_ctrl_thick
        self._page_ctrl_color = page_ctrl_color

        self._slider_rect = None  # type: (pygame.Rect,None)
        self._slider_pad = slider_pad
        self._slider_color = slider_color
        self._slider_position = 0  # type: int

        self._single_step = 20  # type: int
        self._page_step = None  # type: (int,None)

        if values_range[1] - values_range[0] > length:
            self.set_page_step(length)
        else:
            self.set_page_step(
                (values_range[1] - values_range[0]) / 5.0)  # Arbitrary
        self.set_orientation(orientation)
Example #19
0
    def set_background_color_opacity(self, opacity: float) -> 'Theme':
        """
        Modify the Menu background color with given opacity.

        :param opacity: Opacity value, from ``0`` (transparent) to ``1`` (opaque)
        :return: Self reference
        """
        _utils.assert_color(self.background_color)
        assert isinstance(opacity, float)
        assert 0 <= opacity <= 1, 'opacity must be a number between 0 (transparent) and 1 (opaque)'
        self.background_color = (self.background_color[0], self.background_color[1],
                                 self.background_color[2], int(opacity * 255))
        return self
Example #20
0
    def add_pixel(self, x: NumberType, y: NumberType, color: ColorType, prev: bool = True) -> str:
        """
        Add a pixel.

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param color: Color of the pixel
        :param prev: If ``True`` draw previous the object, else draws post
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        assert_color(color)
        return self._add_decor(DECORATION_PIXEL, prev, (tuple(coords), color))
Example #21
0
    def add_rect(
            self,
            x: NumberType,
            y: NumberType,
            rect: 'pygame.Rect',
            color: ColorInputType,
            width: int = 0,
            prev: bool = True,
            **kwargs
    ) -> str:
        """
        Adds a BaseImage object.

        .. note::

            Consider ``(0, 0)`` coordinates as the center of the object.

        kwargs (Optional)
            - ``use_center_positioning``            Uses object center position as *(0, 0)*. ``True`` by default

        :param x: X position (px), being ``0`` the center of the object
        :param y: Y position (px), being ``0`` the center of the object
        :param rect: Rect to draw
        :param color: Color of the rect
        :param width: Border width of the rect. If ``0`` draw a filled rectangle
        :param prev: If ``True`` draw previous the object, else draws post
        :param kwargs: Optional keyword arguments
        :return: ID of the decoration
        """
        assert isinstance(width, int) and width >= 0
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        color = assert_color(color)
        assert isinstance(rect, pygame.Rect)
        return self._add_decor(DECORATION_RECT, prev, (tuple(coords), rect, color, width, kwargs))
Example #22
0
    def add_ellipse(self,
                    x: NumberType,
                    y: NumberType,
                    rx: NumberType,
                    ry: NumberType,
                    color: ColorInputType,
                    filled: bool,
                    prev: bool = True,
                    **kwargs) -> str:
        """
        Adds an ellipse.

        kwargs (Optional)
            - ``use_center_positioning``    (bool) – Uses object center position as *(0, 0)*. ``True`` by default

        :param x: X position in px, being ``0`` the center of the object
        :param y: Y position in px, being ``0`` the center of the object
        :param rx: Horizontal radius of the ellipse
        :param ry: Vertical radius of the ellipse
        :param color: Color of the polygon
        :param filled: If ``True`` fills the polygon with the given color
        :param prev: If ``True`` draw previous the object, else draws post
        :param kwargs: Optional keyword arguments
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        color = assert_color(color)
        assert isinstance(rx, NumberInstance) and rx > 0
        assert isinstance(ry, NumberInstance) and ry > 0
        assert isinstance(filled, bool)
        return self._add_decor(DECORATION_ELLIPSE, prev,
                               (tuple(coords), rx, ry, color, filled, kwargs))
Example #23
0
    def add_pie(self,
                x: NumberType,
                y: NumberType,
                radius: NumberType,
                init_angle: NumberType,
                final_angle: NumberType,
                color: ColorInputType,
                prev: bool = True,
                **kwargs) -> str:
        """
        Adds a unfilled pie.

        kwargs (Optional)
            - ``use_center_positioning``    (bool) – Uses object center position as *(0, 0)*. ``True`` by default

        :param x: X position in px, being ``0`` the center of the object
        :param y: Y position in px, being ``0`` the center of the object
        :param radius: Circle radius in px
        :param init_angle: Initial angle in degrees, from ``0`` to ``360``
        :param final_angle: Final angle in degrees, from ``0`` to ``360``
        :param color: Color of the polygon
        :param prev: If ``True`` draw previous the object, else draws post
        :param kwargs: Optional keyword arguments
        :return: ID of the decoration
        """
        coords = [(x, y)]
        assert_list_vector(coords, 2)
        color = assert_color(color)
        assert isinstance(radius, NumberInstance) and radius > 0
        assert isinstance(init_angle, NumberInstance)
        assert isinstance(final_angle, NumberInstance)
        assert init_angle != final_angle
        return self._add_decor(DECORATION_PIE, prev,
                               (tuple(coords), int(radius), init_angle,
                                final_angle, color, kwargs))
Example #24
0
    def add_bezier(self, coords: Union[List[Tuple2NumberType], Tuple[Tuple2NumberType, ...]],
                   color: ColorType, steps: int = 5, prev: bool = True) -> str:
        """
        Add bezier curve.

        :param coords: Coordinate list, being ``(0, 0)`` the center of the object
        :param color: Color of the polygon
        :param steps: Interpolation steps
        :param prev: If ``True`` draw previous the object, else draws post
        :return: ID of the decoration
        """
        assert_list_vector(coords, 2)
        assert_color(color)
        assert len(coords) >= 3
        assert isinstance(steps, int) and steps >= 1
        return self._add_decor(DECORATION_BEZIER, prev, (tuple(coords), color, steps))
Example #25
0
    def _check_cell_style(align: str, background_color: ColorInputType,
                          border_color: ColorInputType,
                          border_position: WidgetBorderPositionType,
                          border_width: int, padding: PaddingType,
                          vertical_position: str) -> None:
        """
        Assert cell style.

        :param align: Horizontal align of each cell. See :py:mod:`pygame_menu.locals`
        :param background_color: Background color
        :param border_color: Border color of each cell
        :param border_position: Border position of each cell. Valid only: north, south, east, and west. See :py:mod:`pygame_menu.locals`
        :param border_width: Border width in px of each cell
        :param padding: Cell padding according to CSS rules. General shape: (top, right, bottom, left)
        :param vertical_position: Vertical position of each cell. Only valid: north, center, and south. See :py:mod:`pygame_menu.locals`
        :return: None
        """
        # Alignment
        assert_alignment(align)

        # Background color
        if background_color is not None:
            assert_color(background_color)

        # Padding
        parse_padding(padding)

        # Vertical position
        assert_position(vertical_position)
        assert vertical_position in (POSITION_NORTH, POSITION_CENTER, POSITION_SOUTH), \
            'cell vertical position must be NORTH, CENTER, or SOUTH'

        # Border color
        assert isinstance(border_width, int) and border_width >= 0
        if border_color is not None:
            assert_color(border_color)

        # Border position
        assert isinstance(border_position, (str, VectorInstance))
        if isinstance(border_position, str):
            border_position = [border_position]

        # Border positioning
        for pos in border_position:
            assert pos in (POSITION_NORTH, POSITION_SOUTH, POSITION_EAST, POSITION_WEST), \
                'only north, south, east, and west border positions are valid, ' \
                'but received "{0}"'.format(pos)
Example #26
0
    def add_line(self, pos1: Tuple2NumberType, pos2: Tuple2NumberType, color: ColorType, width: int = 1,
                 prev: bool = True) -> str:
        """
        Adds a line.

        :param pos1: Position 1 *(x1, y1)*
        :param pos2: Position 2 *(x2, y2)*
        :param color: Line color
        :param width: Line width in px
        :param prev: If ``True`` draw previous the object, else draws post
        :return: ID of the decoration
        """
        assert_vector(pos1, 2)
        assert_vector(pos2, 2)
        assert_color(color)
        assert isinstance(width, int) and width >= 1
        return self._add_decor(DECORATION_LINE, prev, ((tuple(pos1), tuple(pos2)), color, width))
Example #27
0
    def add_underline(self, color: ColorType, offset: int, width: int, force_render: bool = False) -> 'Widget':
        """
        Adds a underline to text. This is added if widget is rendered

        :param color: Underline color
        :param offset: Underline offset
        :param width: Underline width
        :param force_render: If ``True`` force widget render after addition
        :return: Self reference
        """
        assert_color(color)
        assert isinstance(offset, int)
        assert isinstance(width, int) and width > 0
        self._last_underline[1] = (color, offset, width)
        if force_render:
            self._force_render()
        return self
Example #28
0
    def _get(params, key, allowed_types=None, default=None):
        """
        Return a value from a dictionary.

        :param params: parameters dictionary
        :type params: dict
        :param key: key to look for
        :type key: str
        :param allowed_types: list of allowed types
        :type allowed_types: any
        :param default: default value to return
        :type default: any
        :return: The value associated to the key
        :rtype: any
        """
        if key not in params:
            return default

        value = params.pop(key)
        if allowed_types:
            if not isinstance(allowed_types, (tuple, list)):
                allowed_types = (allowed_types, )
            for valtype in allowed_types:
                if valtype == 'color':
                    _utils.assert_color(value)
                elif valtype == 'color_none':
                    if value is None:
                        return value
                    _utils.assert_color(value)
                elif valtype == 'color_image':
                    if isinstance(value, BaseImage):
                        return value
                    _utils.assert_color(value)
                elif valtype == 'color_image_none':
                    if value is None:
                        return value
                    elif isinstance(value, BaseImage):
                        return value
                    _utils.assert_color(value)
                elif valtype == 'position':
                    _utils.assert_position(value)
                elif valtype == 'alignment':
                    _utils.assert_alignment(value)
                elif valtype == 'tuple2':
                    _utils.assert_vector2(value)

            all_types = ('color', 'color_none', 'color_image',
                         'color_image_none', 'position', 'alignment', 'tuple2')
            others = tuple(t for t in allowed_types if t not in all_types)
            if others:
                msg = 'Theme.{} type shall be in {} types (got {})'.format(
                    key, others, type(value))
                assert isinstance(value, others), msg
        return value
Example #29
0
    def set_at(self, pos: Tuple2NumberType, color: ColorInputType) -> 'BaseImage':
        """
        Set the color of pixel on x-axis and y-axis (x, y).

        :param pos: Position on x-axis and y-axis (x, y) in px
        :param color: Color
        :return: Self reference
        """
        assert_vector(pos, 2)
        self._surface.set_at(pos, assert_color(color))
        return self
Example #30
0
    def set_background_color(self, color, inflate=(0, 0)):
        """
        Set widget background color.

        :param color: Widget background color
        :type color: tuple, list, :py:class:`pygame_menu.baseimage.BaseImage`, None
        :param inflate: Inflate background in x,y
        :type inflate: tuple, list
        :return: None
        """
        if color is not None:
            if isinstance(color, _baseimage.BaseImage):
                assert color.get_drawing_mode() == _baseimage.IMAGE_MODE_FILL, \
                    'currently widget only support IMAGE_MODE_FILL drawing mode'
            else:
                assert_color(color)
        assert_vector2(inflate)
        assert inflate[0] >= 0 and inflate[1] >= 0, \
            'widget background inflate must be equal or greater than zero in both axis'
        self._background_color = color
        self._background_inflate = inflate