def add_image(self, state, bb): """ Add image :param state: button state :param bb: bounding box """ if not state.show_img or getattr(state, "icon_base", None) == None: self.add_component(None) return c = Component(self.util) c.name = state.name + ".image" scaled = getattr(state, "scaled", False) enabled = getattr(state, "enabled", True) if not enabled: c.content = state.icon_disabled[1] c.image_filename = state.icon_disabled[0] else: if scaled: c.content = state.icon_base_scaled else: c.content = state.icon_base[1] c.image_filename = state.icon_base[0] w = c.content.get_size()[0] h = c.content.get_size()[1] c.content_x = bb.x + (bb.width - w) / 2 c.content_y = bb.y + (bb.height - h) / 2 self.add_component(c)
def __init__(self, util, digits, digit, bb, increment_listener, decrement_listener, name): """ Initializer :param util: utility object :param digits: clock digits 0-9 :param digit: the digit :param bb: digit bounding box :param increment_listener: increment listener :param decrement_listener: decrement listener :param name: component name """ self.util = util self.config = self.util.config EventContainer.__init__(self, util, bb) self.digits = digits self.digit = digit image = self.digits[self.digit][1] c = Component(self.util) c.name = name c.image_filename = self.digits[self.digit][0] c.content = image c.content_x = bb.x c.content_y = bb.y self.add_component(c) top = Rect(bb.x, bb.y, bb.w, bb.h / 2) self.add_area_listener((top, increment_listener)) bottom = Rect(bb.x, bb.y + (bb.h / 2) + 1, bb.w, bb.h / 2) self.add_area_listener((bottom, decrement_listener))
def add_page(self, page_num, page): """ Add lyrics page to the container :param page_num: lyrics page number :param page: lyrics page """ cont = Container(self.util, self.bounding_box, (0, 0, 0)) max_line_length = self.get_max_line_length(page) s = self.f.size("W") page_height = self.lines * s[1] offset_y = (self.screen_h - page_height) / 2 offset_x = (self.screen_w - max_line_length) / 2 for n, line in enumerate(page): c = Component(self.util, bgr=(0, 0, 0)) str_size = self.f.size(line) if page_num == 0 and n == 0: color = self.config[COLORS][COLOR_BRIGHT] else: color = self.config[COLORS][COLOR_CONTRAST] img = self.f.render(line, 1, color) name = GENERATED_IMAGE + str(n) c.content = (name, img) c.name = name c.image_filename = name c.content_y = offset_y + (str_size[1] * n) c.content_x = offset_x cont.add_component(c) self.add_component(cont)
def add_key(self, x, y, name, key): """ Add the key indicating current focus position :param x: x coordinate :param y: y coordinate :param name: component name :param key: key image """ size = key[1].get_size() w = size[0] h = size[1] cont = Container(self.util) cont.bgr = cont.fgr = (0, 0, 0, 0) cont.name = name + ".cont" c = Component(self.util) c.name = name c.content = key[1] c.bgr = c.fgr = (0, 0, 0, 0) c.content_x = x - w / 2 c.content_y = y c.image_filename = key[0] c.bounding_box = pygame.Rect(0, 0, w, h) cont.bounding_box = pygame.Rect(c.content_x, c.content_y, w, h) cont.add_component(c) self.add_component(cont) return cont
def add_image(self, state, bb): """ Add image :param state: button state :param bb: bounding box """ if not state.show_img: self.add_component(None) return c = Component(self.util) c.name = state.name + ".image" scaled = getattr(state, "scaled", False) if scaled: c.content = state.icon_base_scaled else: c.content = state.icon_base[1] c.image_filename = state.icon_base[0] w = c.content.get_size()[0] h = c.content.get_size()[1] c.content_x = bb.x + (bb.width - w)/2 c.content_y = bb.y + (bb.height - h)/2 self.add_component(c)
def get_shadow(self): """ Return the button shadow component :return: shadow component """ c = Component(self.util, self.shadow[1]) c.name = "station_menu.shadow" c.image_filename = self.shadow[0] c.content_x = self.bounding_box.x c.content_y = self.bounding_box.y return c
def get_shadow(self): """ Return the button shadow component :return: shadow component """ c = Component(self.util, self.shadow[1]) c.name = "station_menu.shadow" c.image_filename = self.shadow[0] w = self.shadow[1].get_size()[0] h = self.shadow[1].get_size()[1] c.content_x = self.bounding_box.x + self.bounding_box.w/2 - w/2 c.content_y = self.bounding_box.y + self.bounding_box.h/2 - h/2 return c
def draw_image(self, image, x, y, container, rect, name): """ Draw background defined by input parameters :param image: image to draw :param x: x coordinate :param y: y coordinate :param container: container to which image will be added :param rect: bounding box :param name: component name """ c = Component(self) c.name = name c.content = image c.content_x = rect.x c.content_y = rect.y c.image_filename = c.name c.bounding_box = rect container.add_component(c) return c
def get_selection_frame(self, button): """ Create the selection frame used in Page mode :param button: button for which the selection frame should be created :return: selection frame component """ x = button.components[0].content.x y = button.components[0].content.y w = button.components[0].content.w h = button.components[0].content.h i = self.image_util.scale_image(self.selection[1], (w, h)) c = Component(self.util, i) c.content_x = x c.content_y = y c.name = "station_menu.selection" c.image_filename = self.selection[0] c.visible = False c.selection_index = button.state.index_in_page return c
def get_not_found_screen(self, util): """ Set 'Lyrics not found' message in the current language :param util: utility object :return: component for lyrics not found screen """ c = Component(util, bgr=self.bgr) c.name = "base" self.lyrics_not_found_label = self.config[LABELS][LYRICS_NOT_FOUND] str_size = self.f.size(self.lyrics_not_found_label) self.label_rect = pygame.Rect(0, 0, str_size[0], str_size[1]) img = self.f.render(self.lyrics_not_found_label, 1, self.config[COLORS][COLOR_CONTRAST]) name = GENERATED_IMAGE + "not.found" c.content = (name, img) c.name = name c.image_filename = name return c
def get_selection_frame(self, button): """ Create the selection frame used in Page mode :param button: button for which the selection frame should be created :return: selection frame component """ x = button.components[0].content.x y = button.components[0].content.y w = button.components[0].content.w h = button.components[0].content.h i = self.util.scale_image(self.selection[1], (w, h)) c = Component(self.util, i) c.content_x = x c.content_y = y c.name = "station_menu.selection" c.image_filename = self.selection[0] c.visible = False c.selection_index = button.state.index_in_page return c
def __init__(self, util, name, bgr, slider_color, img_knob, img_knob_on, img_selected, key_incr, key_decr, key_knob, bb): """ Initializer :param util: utility object :param name: slider name :param bgr: slider background color :param slider_color: slider center line color :param img_knob: knob image :param img_knob_on: knob image in on state :param img_selected: knob image in selected state :param key_incr: keyboard key associated with slider increment action :param key_decr: keyboard key associated with slider decrement action :param key_knob: keyboard key associated with single click on knob :param bb: slider bounding box """ Container.__init__(self, util, background=bgr, bounding_box=bb) self.util = util self.name = name self.img_knob = img_knob[1] self.img_knob_on = img_knob_on[1] self.img_selected = img_selected self.knob_width = self.img_knob.get_size()[0] self.knob_height = self.img_knob.get_size()[1] self.knob_filename = img_knob[0] self.knob_on_filename = img_knob_on[0] self.selected = False self.dragging = False self.initial_level = 0 self.current_img = self.img_knob self.current_filename = self.knob_filename self.clicked = False self.press_listeners = list() self.slide_listeners = list() self.knob_listeners = list() self.motion_listeners = list() pygame.key.set_repeat(50, 10) self.step = 10 self.key_incr = key_incr self.key_decr = key_decr self.key_knob = key_knob slider_x = self.knob_width/2 self.bounding_box.h += 1 slider_y = self.bounding_box.y + self.bounding_box.height - self.bounding_box.height/2 slider_width = self.bounding_box.width - self.knob_width slider_height = 2 self.slider = pygame.Rect(slider_x, slider_y, slider_width, slider_height) self.slider_max_x = self.bounding_box.width - self.knob_width/2 self.slider_min_x = self.knob_width/2 self.slide_increment = (self.slider_max_x - self.slider_min_x)/100.0 self.last_knob_position = (int)(self.initial_level * self.slide_increment) self.knob_y = self.bounding_box.y + self.bounding_box.height/2 - self.knob_height/2 self.event_source_local = True comp = Component(self.util, self.bounding_box) comp.name = self.name + ".bgr" comp.bgr = bgr self.add_component(comp) comp = Component(self.util, self.slider) comp.name = self.name + ".slider" comp.thickness = 1 comp.content_x = slider_x comp.content_y = slider_y comp.bgr = slider_color self.add_component(comp) comp = Component(self.util, self.current_img) comp.name = self.name + ".knob" h = self.current_img.get_size()[1] comp.content_y = bb.y + (bb.h - h)/2 comp.image_filename = self.knob_filename self.add_component(comp)
def __init__(self, util, name, bgr, slider_color, img_knob, img_knob_on, img_selected, key_incr, key_decr, key_knob, bb, knob_selected=False, rest_commands=[]): """ Initializer :param util: utility object :param name: slider name :param bgr: slider background color :param slider_color: slider center line color :param img_knob: knob image :param img_knob_on: knob image in on state :param img_selected: knob image in selected state :param key_incr: keyboard key associated with slider increment action :param key_decr: keyboard key associated with slider decrement action :param key_knob: keyboard key associated with single click on knob :param bb: slider bounding box """ Container.__init__(self, util, background=bgr, bounding_box=bb) self.content = None if bb.h > bb.w: self.orientation = VERTICAL else: self.orientation = HORIZONTAL self.util = util self.name = name self.img_knob = img_knob[1] self.img_knob_on = img_knob_on[1] self.img_selected = img_selected self.rest_commands = rest_commands self.knob_width = self.img_knob.get_size()[0] self.knob_height = self.img_knob.get_size()[1] self.knob_filename = img_knob[0] self.knob_on_filename = img_knob_on[0] self.dragging = False self.initial_level = 0 self.check_pause = True self.handle_knob_events = True self.selected = False if knob_selected: self.selected = knob_selected self.current_img = self.img_selected[1] else: self.current_img = self.img_knob self.current_filename = self.knob_filename self.clicked = False self.press_listeners = list() self.slide_listeners = list() self.knob_listeners = list() self.motion_listeners = list() pygame.key.set_repeat(50, 10) self.step = 10 self.key_incr = key_incr self.key_decr = key_decr self.key_knob = key_knob h = self.current_img.get_size()[1] if self.orientation == HORIZONTAL: slider_x = self.bounding_box.x + self.knob_width / 2 slider_y = self.bounding_box.y + self.bounding_box.height / 2 slider_width = self.bounding_box.width - self.knob_width slider_height = 1 self.slider = pygame.Rect(slider_x, slider_y, slider_width, slider_height) self.slider_max_x = self.bounding_box.x + self.bounding_box.width - self.knob_width / 2 self.slider_min_x = self.bounding_box.x + self.knob_width / 2 self.slide_increment = (self.slider_max_x - self.slider_min_x) / 100.0 self.last_knob_position = bb.x self.knob_y = self.bounding_box.y + self.bounding_box.height / 2 - self.knob_height / 2 else: slider_x = self.bounding_box.x + self.bounding_box.width / 2 - 1 slider_y = self.bounding_box.y + self.knob_height / 2 slider_width = 1 slider_height = self.bounding_box.height - self.knob_height self.slider = pygame.Rect(slider_x, slider_y, slider_width, slider_height) self.slider_max_y = self.bounding_box.y + self.bounding_box.height - self.knob_height / 2 self.slider_min_y = self.bounding_box.y + self.knob_height / 2 self.slide_increment = (self.slider_max_y - self.slider_min_y) / 100.0 self.last_knob_position = bb.y + bb.h - self.knob_height self.knob_x = self.bounding_box.x + self.bounding_box.width / 2 - self.knob_width / 2 comp = Component(self.util, self.bounding_box) comp.name = self.name + ".bgr" comp.bgr = bgr self.add_component(comp) comp = Component(self.util, self.slider) comp.name = self.name + ".slider" comp.thickness = 1 comp.content_x = slider_x comp.content_y = slider_y comp.bgr = slider_color self.add_component(comp) comp = Component(self.util, self.current_img) comp.name = self.name + ".knob" if self.orientation == HORIZONTAL: comp.content_x = bb.x comp.content_y = bb.y + (bb.h - h) / 2 + 1 else: comp.content_x = self.knob_x comp.content_y = self.last_knob_position comp.image_filename = self.knob_filename self.add_component(comp)