Exemple #1
0
    def __init__(self,
                 size=None,
                 color=None,
                 pressed=False,
                 dark=None,
                 hovered=False,
                 light=None,
                 thick=1,
                 clip="auto"):
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        BasicFrame.__init__(self,
                            size=size,
                            color=color,
                            clip=clip,
                            pressed=pressed,
                            hovered=hovered)
        self.dark = dark
        self.light = light
        self.thick = thick
        self.light = style.LIGHT_FACTOR if light is None else light
        self.dark = style.DARK_FACTOR if dark is None else dark
        ##        if self.light is None:
        ##            white = make_compatible(constants.WHITE, self.color)
        ##            self.light = mid_color(self.color, white)
        if isinstance(self.light, float):
            self.light = normalize_color(grow_color(self.light, self.color))
##        if self.dark is None:
##            black = make_compatible(constants.BLACK, self.color)
##            self.dark = mid_color(self.color, black)
        if isinstance(self.dark, float):
            self.dark = normalize_color(grow_color(self.dark, self.color))
Exemple #2
0
 def __init__(self,
              size=style.SIZE,
              color=style.DEF_COLOR,
              pressed=False,
              hovered=False,
              clip="auto",
              dark=None,
              light=None,
              thick=2):
     if clip is "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     BasicFrame.__init__(self,
                         size=size,
                         color=color,
                         clip=clip,
                         pressed=pressed,
                         hovered=hovered)
     self.light = style.LIGHT_FACTOR if light is None else light
     self.dark = style.DARK_FACTOR if dark is None else dark
     if isinstance(self.light, float):
         self.light = normalize_color(grow_color(self.light, self.color))
     if isinstance(self.dark, float):
         self.dark = normalize_color(grow_color(self.dark, self.color))
     self.thick = thick
    def __init__(self, size=None, color=None, pressed=False, dark=None,
                 hovered=False, light=None, thick=1, clip="auto"):
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        BasicFrame.__init__(self,
                            size=size,
                            color=color,
                            clip=clip,
                            pressed=pressed,
                            hovered=hovered)
        self.dark = dark
        self.light = light
        self.thick = thick
        self.light = style.LIGHT_FACTOR if light is None else light
        self.dark = style.DARK_FACTOR if dark is None else dark
##        if self.light is None:
##            white = make_compatible(constants.WHITE, self.color)
##            self.light = mid_color(self.color, white)
        if isinstance(self.light, float):
            self.light = normalize_color(grow_color(self.light, self.color))
##        if self.dark is None:
##            black = make_compatible(constants.BLACK, self.color)
##            self.dark = mid_color(self.color, black)
        if isinstance(self.dark, float):
            self.dark = normalize_color(grow_color(self.dark, self.color))
Exemple #4
0
def illuminate_color_except(surface, color_except, color_target, color_bulk=None,
                            subrect=None, factor=1., fadout=2):
    """
    mode : "except" means all the pixels that are not color_source.
           "exact" means all the pixels that are exacly color_source.
    """
    if not HAS_NUMPY:
        raise Exception("Could not use surfarray module from PyGame.\
                     NumPy is probably missing.")
    rect = surface.get_rect()
    newsurf = pygame.Surface(rect.size, depth=surface.get_bitsize()).convert()
    newsurf.blit(surface, (0, 0))
    if subrect:
        rect = subrect
    arrayrgb = surfarray.pixels3d(newsurf)
    points = []
    max_d = hypot(rect.w, rect.h)
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if tuple(arrayrgb[x][y]) != color_except:
                points.append((x, y))
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if not (x, y) in points:
                d = 1. - illuminate_dist(points, rect, x, y) / max_d
                d = d**fadout
                color = grow_color(factor * d, color_target)
                color = normalize_color(color)
                arrayrgb[x][y] = color
            elif color_bulk:
                arrayrgb[x][y] = color_bulk
    return newsurf
Exemple #5
0
    def __init__(self, size=None, color=None, clip="auto", radius_ext=None,
                 radius_int=None, pressed=False, dark=None, light=None, thick=1,
                 hovered=False, border_color=None): #changer border
        """If radius is in the range [0, 1], self.radius_value is the fraction
        of radius * min(size), else it is interpreted as a raw pixel value.
        """
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        ClassicFrame.__init__(self,
                              size=size,
                              color=color,
                              pressed=pressed,
                              hovered=hovered,
                              dark=dark,
                              light=light,
                              thick=thick,
                              clip=clip)
        radius_value = style.DEF_RADIUS if radius_ext is None else radius_ext
        if 0. <= radius_value <= 1.:
            radius_value = min(self.size) * radius_value
        self.radius_ext = radius_value
        self.radius_int = radius_int
        if radius_int == None:
            self.radius_int = self.radius_ext - self.thick

        self.border_color = style.BORDER_FACT if border_color is None else border_color
        if isinstance(self.border_color, float):
            self.border_color = normalize_color(grow_color(self.border_color,
                                                           self.color))
def illuminate_color_except(surface, color_except, color_target, color_bulk=None,
                            subrect=None, factor=1., fadout=2):
    """
    mode : "except" means all the pixels that are not color_source.
           "exact" means all the pixels that are exacly color_source.
    """
    if not HAS_NUMPY:
        raise Exception("Could not use surfarray module from PyGame.\
                     NumPy is probably missing.")
    rect = surface.get_rect()
    newsurf = pygame.Surface(rect.size, depth=surface.get_bitsize()).convert()
    newsurf.blit(surface, (0, 0))
    if subrect:
        rect = subrect
    arrayrgb = surfarray.pixels3d(newsurf)
    points = []
    max_d = hypot(rect.w, rect.h)
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if tuple(arrayrgb[x][y]) != color_except:
                points.append((x, y))
    for x in range(rect.left, rect.right):
        for y in range(rect.top, rect.bottom):
            if not (x, y) in points:
                d = 1. - illuminate_dist(points, rect, x, y) / max_d
                d = d**fadout
                color = grow_color(factor * d, color_target)
                color = normalize_color(color)
                arrayrgb[x][y] = color
            elif color_bulk:
                arrayrgb[x][y] = color_bulk
    return newsurf
 def __init__(self, size=style.SIZE, color=style.DEF_COLOR, clip="auto",
              dark=None, light=None, thick=2, pressed=False, hover=False):
     if clip is "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     BasicFrame.__init__(self,
                         size=size,
                         color=color,
                         clip=clip,
                         pressed=pressed,
                         hovered=hovered)
     self.light = style.LIGHT_FACTOR if light is None else light
     self.dark = style.DARK_FACTOR if dark is None else dark
     if isinstance(self.light, float):
         self.light = normalize_color(grow_color(self.light, self.color))
     if isinstance(self.dark, float):
         self.dark = normalize_color(grow_color(self.dark, self.color))
     self.thick = thick
 def __init__(self, size=None, color=None, clip="auto", radius_ext=12,
              radius_int=10, pressed=False, dark=None, light=None, thick=1,
              border_color=None): #changer border
     """Radius = [0, 1]"""
     if clip == "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     ClassicFrame.__init__(self, size, color, pressed, dark, light, thick,
                           clip)
     self.radius_int = radius_int
     self.radius_ext = radius_ext
     self.border_color = style.BORDER_FACT if border_color is None else border_color
     if isinstance(self.border_color, float):
         self.border_color = normalize_color(grow_color(self.border_color,
                                                        self.color))
Exemple #9
0
    def __init__(self,
                 size=None,
                 color=None,
                 clip="auto",
                 radius_ext=None,
                 radius_int=None,
                 pressed=False,
                 dark=None,
                 light=None,
                 thick=1,
                 hovered=False,
                 border_color=None):  #changer border
        """If radius is in the range [0, 1], self.radius_value is the fraction
        of radius * min(size), else it is interpreted as a raw pixel value.
        """
        if clip == "auto":
            inflation = -2 * thick
            clip = (inflation, inflation)
        ClassicFrame.__init__(self,
                              size=size,
                              color=color,
                              pressed=pressed,
                              hovered=hovered,
                              dark=dark,
                              light=light,
                              thick=thick,
                              clip=clip)
        radius_value = style.DEF_RADIUS if radius_ext is None else radius_ext
        if 0. <= radius_value <= 1.:
            radius_value = min(self.size) * radius_value
        self.radius_ext = radius_value
        self.radius_int = radius_int
        if radius_int == None:
            self.radius_int = self.radius_ext - self.thick

        self.border_color = style.BORDER_FACT if border_color is None else border_color
        if isinstance(self.border_color, float):
            self.border_color = normalize_color(
                grow_color(self.border_color, self.color))
 def __init__(self,
              size=None,
              color=None,
              clip="auto",
              radius_ext=12,
              radius_int=10,
              pressed=False,
              dark=None,
              light=None,
              thick=1,
              border_color=None):  #changer border
     """Radius = [0, 1]"""
     if clip == "auto":
         inflation = -2 * thick
         clip = (inflation, inflation)
     ClassicFrame.__init__(self, size, color, pressed, dark, light, thick,
                           clip)
     self.radius_int = radius_int
     self.radius_ext = radius_ext
     self.border_color = style.BORDER_FACT if border_color is None else border_color
     if isinstance(self.border_color, float):
         self.border_color = normalize_color(
             grow_color(self.border_color, self.color))