def __init__(self, color=None, image=None, elements=None, normal_params=None, mode="scale to screen", finish=True): """Background element for another element or menu. <color>: if not None, define the color for the background. <image>: if not None, define the image of the background. <Mode>: None : if an image is passed, its original size is kept. Otherwise, a <color> (white by default) rect of the size of the screen is used as background image. 'scale to screen' : if an image is passed, it is scaled to fit screen. Otherwise, see behaviour for None. 'cut to screen' : if an image is passed, it is shrinked to fit the screen. Otherwise, use behaviour for None. """ super(Background, self).__init__("", elements, normal_params, finish=False) W, H = functions.get_screen_size() if image: painter = ImageFrame(image, mode=mode) else: if color: painter = BasicFrame((W, H), color) else: painter = BasicFrame((W, H), (255, 255, 255)) self.set_painter(painter) if finish: self.finish()
def __init__(self, size=None, colorkey=constants.WHITE, clip=None, color_target=None, color_bulk=None, subrect=None, pressed=False, hovered=False, factor=1., fadout=10., bulk_alpha=255): if size is None: size = style.SIZE if color_target is None: color_target = style.DEF_COLOR BasicFrame.__init__(self, size=size, color=colorkey, clip=clip, pressed=pressed, hovered=hovered) self.color_target = color_target self.color_bulk = color_bulk self.subrect = subrect self.factor = factor self.fadout = fadout self.bulk_alpha = bulk_alpha
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))
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, color=None, image=None, elements=None, normal_params=None, mode="scale to screen"): """Mode: None : if an image is passed, its original size is kept. Otherwise, a <color> (white by default) rect of the size of the screen is used as background image. 'scale to screen' : if an image is passed, it is scaled to fit screen. Otherwise, see behaviour for None. 'cut to screen' : if an image is passed, it is shrinked to fit screen. Otherwise, see behaviour for None. """ super(Background, self).__init__("", elements, normal_params) W, H = functions.get_screen_size() if image: painter = ImageFrame(image, mode=mode) else: if color: painter = BasicFrame((W, H), color) else: painter = BasicFrame((W, H), (255, 255, 255)) self.set_painter(painter)
def __init__(self, size=None, color=None, clip=None, radius=0.): """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. """ BasicFrame.__init__(self, size, color, clip) self.radius_value = style.DEF_RADIUS if radius is None else radius if 0. <= radius <= 1.: self.radius_value = min(self.size) * radius
def __init__(self, size, color1, color2, nx, ny): BasicFrame.__init__(self, size=size, color=color1) self.color2 = color2 self.color1 = color1 self.nx = nx self.ny = ny self.frame = True self.xinternal = True self.yinternal = True
def __init__(self, grid, color1, color2, frame=True, rects=True): if frame: grid.move((1,1)) size = grid.frame.inflate((2,2)).size else: size = grid.frame.size BasicFrame.__init__(self, size=size, color=color1) self.color2 = color2 self.color1 = color1 self.grid = grid self.frame = frame self.rects = rects
def __init__(self, grid, color1, color2, frame=True, rects=True): if frame: grid.move((1, 1)) size = grid.frame.inflate((2, 2)).size else: size = grid.frame.size BasicFrame.__init__(self, size=size, color=color1) self.color2 = color2 self.color1 = color1 self.grid = grid self.frame = frame self.rects = rects
def __init__(self, size=style.SIZE, colorkey=constants.WHITE, clip=None, color_target=style.DEF_COLOR, color_bulk=None, subrect=None, pressed=False, hovered=False, factor=1., fadout=10., bulk_alpha=255): BasicFrame.__init__(self, size=size, color=colorkey, clip=clip, pressed=pressed, hovered=hovered) self.color_target = color_target self.color_bulk = color_bulk self.subrect = subrect self.factor = factor self.fadout = fadout self.bulk_alpha = bulk_alpha
def draw(self): surface = BasicFrame.draw(self) if self.pressed: draw_rect(surface, self.dark, Rect((0, 0), self.size), self.thick+2) elif self.hovered: draw_rect(surface, self.dark, Rect((0, 0), self.size), self.thick) return surface
def draw(self): surface = BasicFrame.draw(self) if not self.pressed: draw_rect(surface, self.dark, Rect((0, 0), self.size), self.thick) else: draw_rect(surface, self.light, Rect((0, 0), self.size), self.thick) return surface
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 get_fusion(self, title, center_title): """Fusion the painter.img and the title.img and returns this fusion""" if self.pressed: if center_title is True: # center the title on the element rect title.center_on(self.size) title._pos = (title._pos[0], title._pos[1] + self.thick) # center_title is the topleft argument elif center_title is not False: title._pos = center_title else: title._pos = (0, 0) painter_img = self.get_surface() title.blit_on(painter_img) return painter_img else: return BasicFrame.get_fusion(self, title, center_title)
def get_example_element(color, size): painter_frame = functions.obtain_valid_painter(painterstyle.DEF_PAINTER, pressed=True, size=size) if painter_frame.clip: color_size = painter_frame.clip.size else: color_size = size painter_example = BasicFrame(size=color_size, color=color) example = Element() example.set_painter(painter_example) example.finish() frame = Element(elements=[example]) frame.set_painter(painter_frame) frame.finish() example.set_center(frame.get_fus_center()) return frame
def __init__(self, path=None, color=None, elements=None, normal_params=None): """Image element. <path>: the path to the image. <color>: if path is None, use this color instead of image. """ super(Image, self).__init__("", elements, normal_params) if path: painter = ImageFrame(path, mode=None) else: if color: painter = BasicFrame(style.SIZE, color) else: raise Exception("You must specify either a path or a color") self.set_painter(painter)
def draw(self): surface = BasicFrame.draw(self) self.blit_borders_on(surface) return surface