Module albow.widgets.CheckWidget

Source code
from pygame import Rect
from pygame import Surface
from pygame import draw

from albow.core.ui.Widget import Widget

from albow.themes.ThemeProperty import ThemeProperty

CHECK_MARK_TWEAK = 2


class CheckWidget(Widget):

    default_size     = (16, 16)
    """
    The default size of the checkbox;  Default is 16x16
    """
    margin           = 4
    """
    The margin around the check mark;  Default is 4
    """
    border_width     = 1
    """
        This border width of the rectangle around the checkmark;  Default is 1
    """

    smooth = ThemeProperty('smooth')
    """
        Set to True if you want the checkmark anti-aliased;  Default is True
    """

    def __init__(self, **kwds):
        super().__init__(Rect((0, 0), self.default_size), **kwds)

    def draw(self, theSurface: Surface):
        """

        Args:
            theSurface:  The surface to draw on


        """
        if self.highlighted:
            r = self.get_margin_rect()
            fg = self.fg_color
            d = CHECK_MARK_TWEAK
            p1 = (r.left, r.centery - d)
            p2 = (r.centerx - d, r.bottom)
            p3 = (r.right, r.top - d)
            if self.smooth:
                draw.aalines(theSurface, fg, False, [p1, p2, p3])
            else:
                draw.lines(theSurface, fg, False, [p1, p2, p3])

Classes

class CheckWidget (**kwds)

The Widget class is the base class for all widgets. A widget occupies a rectangular area of the PyGame screen to which all drawing in it is clipped, and it may receive mouse and keyboard events. A widget may also contain subwidgets.

Note

Due to a limitation of PyGame subsurfaces, a widget's rectangle must be entirely contained within that of its parent widget. An exception will occur if this is violated.

  • Reading the following attributes retrieves the corresponding values from the widget's rect.
  • Assigning to them changes the size and position of the widget.
  • Additionally, if the size of the widget is changed via these attributes, the size and position of its subwidgets is updated according to each subwidget's anchor attribute.

    left, right, top, bottom, width, height, size,
    topleft, topright, bottomleft, bottomright,
    midleft, midright, midtop, midbottom,
    center, centerx, centery
    

This does not happen if the rect is modified directly.

Creates a new widget, initially without any parent. If a rect is given, it specifies the new widget's initial s ize and position relative to its parent.

Args

rect
A PyGame rectangle defining the portion of the parent widget's coordinate system occupied by the

widget. Modifying this rectangle changes the widget's size and position.

**kwds
Additional attributes specified as key-value pairs
Source code
class CheckWidget(Widget):

    default_size     = (16, 16)
    """
    The default size of the checkbox;  Default is 16x16
    """
    margin           = 4
    """
    The margin around the check mark;  Default is 4
    """
    border_width     = 1
    """
        This border width of the rectangle around the checkmark;  Default is 1
    """

    smooth = ThemeProperty('smooth')
    """
        Set to True if you want the checkmark anti-aliased;  Default is True
    """

    def __init__(self, **kwds):
        super().__init__(Rect((0, 0), self.default_size), **kwds)

    def draw(self, theSurface: Surface):
        """

        Args:
            theSurface:  The surface to draw on


        """
        if self.highlighted:
            r = self.get_margin_rect()
            fg = self.fg_color
            d = CHECK_MARK_TWEAK
            p1 = (r.left, r.centery - d)
            p2 = (r.centerx - d, r.bottom)
            p3 = (r.right, r.top - d)
            if self.smooth:
                draw.aalines(theSurface, fg, False, [p1, p2, p3])
            else:
                draw.lines(theSurface, fg, False, [p1, p2, p3])

Ancestors

Subclasses

Class variables

var default_size

The default size of the checkbox; Default is 16x16

var smooth

Set to True if you want the checkmark anti-aliased; Default is True

Methods

def draw(self, theSurface)

Args

theSurface
The surface to draw on
Source code
def draw(self, theSurface: Surface):
    """

    Args:
        theSurface:  The surface to draw on


    """
    if self.highlighted:
        r = self.get_margin_rect()
        fg = self.fg_color
        d = CHECK_MARK_TWEAK
        p1 = (r.left, r.centery - d)
        p2 = (r.centerx - d, r.bottom)
        p3 = (r.right, r.top - d)
        if self.smooth:
            draw.aalines(theSurface, fg, False, [p1, p2, p3])
        else:
            draw.lines(theSurface, fg, False, [p1, p2, p3])

Inherited members