def __init__(self, util, bounding_box=None, background=None, visible=True, content=None, image_filename=None): """ Initializer :param util: utility object :param bounding_box: container bounding box :param background: container background color :param visible: visibility flag, True - visible, False - invisible """ if content: cnt = content else: cnt = bounding_box Component.__init__(self, util, c=cnt, bb=bounding_box, bgr=background, v=visible) self.components = list() if image_filename: self.image_filename = image_filename
def add_label(self, index, label, x, y, text, text_size, label_type, text_width=None): """ Add text label to the component list :param index: label index :param label: rendered text :param x: X coordinate for new label :param y: Y coordinate for new label :param text: the text :param text_size: text size :param label_type: label type (STATIC or ANIMATED) :param text_width: the width of the rendered text """ comp = Component(self.util, label) comp.label_type = label_type comp.name = self.name + ".text." + str(index) comp.content_x = x comp.content_y = y comp.text = text comp.text_size = text_size comp.fgr = self.fgr if text_width: comp.text_width = text_width self.components.append(comp)
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 draw(self): """ Draw all components in container. Doesn't draw invisible container. """ if not self.visible: return Component.draw(self) for comp in self.components: if comp: comp.draw()
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) c.content = ("img", img) c.content_y = offset_y + (str_size[1] * n) c.content_x = offset_x cont.add_component(c) self.add_component(cont)
def __init__(self, util): """ Initializer :param util: contains configuration object """ self.config = util.config Component.__init__(self, util, bgr=(0, 0, 0)) plugin_folder = type(self).__name__.lower() Screensaver.__init__(self, plugin_folder) self.bounding_box = util.screen_rect military_time_format = self.plugin_config_file.getboolean(PLUGIN_CONFIGURATION, MILITARY_TIME_FORMAT) if military_time_format: self.TIME_FORMAT = "%H:%M" else: self.TIME_FORMAT = "%I:%M" self.animated = self.plugin_config_file.getboolean(PLUGIN_CONFIGURATION, ANIMATED) if self.animated: font_vertical_percent = 20 else: font_vertical_percent = 50 font_size = int((font_vertical_percent * self.bounding_box.h)/100) self.f = util.get_font(font_size)
def __init__(self, util): """ Initializer :param util: utility object """ self.util = util self.config = util.config self.screen_w = self.config[SCREEN_INFO][WIDTH] self.screen_h = self.config[SCREEN_INFO][HEIGHT] self.lines = 12 line_length = 52 font_vertical_percent = 5 self.name = LYRICS self.lyrics_util = LyricsUtil(util.k2, self.lines, line_length) self.lyrics_not_found_label = self.config[LABELS][LYRICS_NOT_FOUND] plugin_folder = type(self).__name__.lower() Screensaver.__init__(self, plugin_folder) self.bounding_box = util.screen_rect Container.__init__(self, util, self.bounding_box, (0, 0, 0)) font_size = int((font_vertical_percent * self.bounding_box.h) / 100) self.f = util.get_font(font_size) self.lyrics_not_found = True c = Component(util, bgr=(0, 0, 0)) c.name = "base" self.set_not_found(c) self.add_component(c) self.current_page = 1 self.current_song = ""
def add_bgr(self): """ Add background rectangle """ comp = Component(self.util, self.bounding_box) comp.name = self.name + ".bgr" comp.bgr = self.bgr self.add_component(comp)
def add_label(self, state, bb): """ Add button label :param state: button state :param bb: bounding box """ if not self.show_label: self.add_component(None) return font_size = int((bb.h * state.label_text_height)/100.0) font = self.util.get_font(font_size) text = state.l_name size = font.size(text) label = font.render(text, 1, state.text_color_normal) c = Component(self.util, label) c.name = state.name + ".label" c.text = text c.text_size = font_size c.text_color_normal = state.text_color_normal c.text_color_selected = state.text_color_selected c.text_color_disabled = state.text_color_disabled c.text_color_current = c.text_color_normal c.content_x = bb.x + (bb.width - size[0])/2 c.content_y = bb.y + (bb.height - size[1])/2 if len(self.components) == 2: self.components.append(c) else: self.components[2] = c
def set_visible(self, flag): """ Set container visible/invisible. Set all components in container visible/invisible. :param flag: True - visible, False - invisible """ Component.set_visible(self, flag) for comp in self.components: if comp: comp.set_visible(flag)
def init_container(self): """ Initialize container """ c = Component(self.util) self.add_component(c) for r in range(self.size): c = Component(self.util) self.add_component(c) c = Component(self.util) self.add_component(c)
def __init__(self, util, bounding_box=None, background=None, visible=True): """ Initializer :param util: utility object :param bounding_box: container bounding box :param background: container background color :param visible: visibility flag, True - visible, False - invisible """ Component.__init__(self, util, bb=bounding_box, bgr=background, v=visible) self.components = list()
def set_track_time(self, name, time, bb, layer_num): """ Set track time :param name: button state :param time: track time :param bb: bounding box :param layer_num: layer number """ font_size = int((bb.h * 45)/100.0) font = self.util.get_font(font_size) size = font.size(time) label = font.render(time, 1, self.config[COLORS][COLOR_BRIGHT]) c = Component(self.util, label) c.bgr = (255, 0, 0) c.name = name c.text = time c.text_size = font_size c.text_color_current = self.config[COLORS][COLOR_BRIGHT] c.content_x = bb.x + (bb.width - size[0])/2 c.content_y = bb.y + (bb.height - size[1])/2 self.components[layer_num] = c if self.visible: self.draw() self.update()
def draw_tile_header(self, x, y, w, h, fcast): """ Draw tile header :param x: tile x coordinate :param y: tile y coordinate :param w: tile width :param h: tile height :param fcast: one day forecast """ height = (h / 100) * TILE_HEADER_HEIGHT comp = Component(self.util) comp.name = "tile.header." + str(x) + "." + str(y) comp.content_x = x comp.content_y = y rect = pygame.Rect(x, y, w, height) comp.content = rect comp.fgr = self.semi_transparent_color comp.bgr = self.semi_transparent_color comp.bounding_box = rect self.add_component(comp) text_color = self.util.weather_config[COLOR_BRIGHT] font_size = int((height / 100) * DAY_HEIGHT) if fcast[DAY] == UNKNOWN: d = UNKNOWN else: d = self.weather_config[fcast[DAY].lower()] c = self.util.get_text_component(d, text_color, font_size) c.name = "th." + str(x) + "." + str(y) c.content_x = x + (w - c.content.get_size()[0]) / 2 c.content_y = y + font_size / 8 self.add_component(c)
def create_keyboard(self, keyboard_type, span, transition_map): """ Create keyboard :param keyboard_type: type :param span: span :param transition_map: transition map """ layout = self.get_layout(span) buttons = [] keys = None self.current_keyboard_type = keyboard_type try: buttons = self.keyboards[keyboard_type] self.components = buttons return except: pass if keyboard_type == KEYBOARD_abc: keys = KEYBOARD_1 elif keyboard_type == KEYBOARD_ABC: keys = KEYBOARD_2 elif keyboard_type == KEYBOARD_123: keys = KEYBOARD_3 elif keyboard_type == KEYBOARD_symbol: keys = KEYBOARD_4 for i, k in enumerate(keys): if not k: c = Component(self.util, layout[i], bgr=self.config[BACKGROUND][MENU_BGR_COLOR]) c.parent_screen = self.screen c.name = "gap" + str(i) buttons.append(c) continue s = State() s.index = i s.name = k s.l_name = k s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.bounding_box = layout[i] s.key_map = transition_map[i] button = self.factory.create_menu_button(s, layout[i], self.press_key, False, 50, 100, False, True) buttons.append(button) buttons[0].set_selected(True) self.keyboards[keyboard_type] = buttons self.components = buttons if keyboard_type != KEYBOARD_abc: self.set_observers() self.buttons = {i : item for i, item in enumerate(buttons)}
def __init__(self, util): """ Initializer :param util: contains config object """ self.config = util.config Component.__init__(self, util) self.bounding_box = self.config[SCREEN_RECT] self.logo_size = int((100 * self.bounding_box.h)/320) self.r = pygame.Rect(0, 0, self.logo_size, self.logo_size) self.update_period = 4
def __init__(self, util): """ Initializer :param util: contains config object """ self.config = util.config Component.__init__(self, util, bgr=(0, 0, 0)) self.bounding_box = self.config[SCREEN_RECT] self.TIME_FORMAT = "%I:%M" font_size = int((60 * self.bounding_box.h)/320) self.f = util.get_font(font_size) self.update_period = 4
def add_bgr(self): """ Add background rectangle """ if not self.full_width: self.bounding_box.x += 1 self.bounding_box.y += 1 self.bounding_box.w -= 2 self.bounding_box.h -= 1 comp = Component(self.util, self.bounding_box) comp.name = self.name + ".bgr" comp.bgr = self.bgr self.add_component(comp)
def get_clickable_rect(self): """ Return the list of rectangles which define the clickable areas on screen. Used for web browser. :return: list of rectangles """ c = Component(self.util) c.name = "clickable_rect" c.content = self.menu.bounding_box c.bgr = c.fgr = (0, 0, 0) c.content_x = c.content_y = 0 d = [c] return d
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 set_visible(self, flag): """ Set container visible/invisible. Set all components in container visible/invisible. :param flag: True - visible, False - invisible """ Component.set_visible(self, flag) for comp in self.components: if not comp: continue if getattr(comp, "popup", None) == True: if not comp.visible: continue else: comp.set_visible(flag)
def prepare_label(self): """ Prepare label component representing this output text. Used for web. """ text = self.text if text is None: return if self.obfuscate_flag: text = "".join(["\u2022"] * len(self.text)) if self.font == None: return size = self.font.size(text) label = self.font.render(text, 1, self.fgr) comp = Component(self.util, label) comp.name = self.name + ".text" comp.content_x = self.bounding_box.x + self.get_x(size) comp.content_y = self.bounding_box.y + self.get_y(size) comp.text = text comp.text_size = self.default_font_size comp.fgr = self.fgr if len(self.components) == 1: self.add_component(comp) else: self.components[1] = comp
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, image, x, y, rect=None): """ Create new UI component from provided image and add it to the UI container. :param image: the image object :param x: x coordinate of the image top left corner :param y: y coordinate of the image top left corner :param rect: bounding rectangle of the image """ c = Component(self.util) c.content = image c.content_x = x c.content_y = y if rect: c.bounding_box = rect self.add_component(c) return c
def add_background(self, state): """ Add button background bounding box :param state: button state """ if not state.show_bgr: self.add_component(None) return c = Component(self.util) c.name = state.name + ".bgr" c.content = state.bounding_box c.bgr = c.fgr = getattr(state, "bgr", (0, 0, 0)) c.content_x = state.bounding_box.x c.content_y = state.bounding_box.y self.add_component(c)
def __init__(self, util): """ Initializer :param util: contains configuration object """ Container.__init__(self, util, util.screen_rect, (0, 0, 0)) plugin_folder = type(self).__name__.lower() Screensaver.__init__(self, plugin_folder) self.util = util self.config = util.config self.bounding_box = util.screen_rect self.default_folder = os.path.join(PACKAGE_SCREENSAVER, plugin_folder, DEFAULT_SLIDES_FOLDER) self.name = SLIDESHOW config_slides_folder = self.plugin_config_file.get( PLUGIN_CONFIGURATION, CONFIG_SLIDES_FOLDER) if config_slides_folder: self.current_folder = config_slides_folder else: self.current_folder = self.default_folder self.random = self.plugin_config_file.get(PLUGIN_CONFIGURATION, RANDOM_ORDER) self.slides = [] self.component = Component(util) self.component.name = self.name self.add_component(self.component)
def __init__(self, util): """ Initializer :param util: contains config object """ self.config = util.config Component.__init__(self, util) plugin_folder = type(self).__name__.lower() Screensaver.__init__(self, plugin_folder) self.util = util self.bounding_box = util.screen_rect vertical_size_percent = self.plugin_config_file.getint( PLUGIN_CONFIGURATION, VERTICAL_SIZE_PERCENT) self.logo_size = int( (vertical_size_percent * self.bounding_box.h) / 100) self.r = pygame.Rect(0, 0, self.logo_size, self.logo_size)
def __init__(self, util): """ Initializer :param util: contains config object """ self.name = LOGO plugin_folder = type(self).__name__.lower() Screensaver.__init__(self, self.name, util, plugin_folder) Container.__init__(self, util, bounding_box=util.screen_rect, background=self.bg[1], content=self.bg[2], image_filename=self.bg[3]) self.config = util.config self.image_util = util.image_util self.util = util vertical_size_percent = self.plugin_config_file.getint( PLUGIN_CONFIGURATION, VERTICAL_SIZE_PERCENT) self.logo_size = int( (vertical_size_percent * self.bounding_box.h) / 100) self.r = pygame.Rect(0, 0, self.logo_size, self.logo_size) self.component = Component(util) self.component.name = GENERATED_IMAGE + self.name self.component.image_filename = self.component.name self.add_component(self.component)
def get_text_component(self, text, fgr, font_height): """ Create text component using supplied parameters :param text: text :param fgr: text color :param font_height: font height :return: text component """ self.font = self.get_font(font_height) label = self.font.render(text, 1, fgr) comp = Component(self, label) comp.text = text comp.text_size = font_height comp.fgr = fgr return comp
def get_clickable_rect(self): """ Return the list of rectangles which define the clickable areas on screen. Used for web browser. :return: list of rectangles """ bb = self.screen_title.bounding_box x = 0 y = bb.h w = bb.width h = self.station_menu.bounding_box.height c = Component(self.util) c.name = "clickable_rect" c.content = pygame.Rect(x, y, w, h) c.bgr = c.fgr = (0, 0, 0) c.content_x = c.content_y = 0 d = [c] return d
def __init__(self, util, handle_slider_event, bounding_box=None): """ Initializer :param util: utility object :param handle_slider_event: slider event handler :param listeners: menu listeners :param bgr: menu background :param bounding_box: bounding box """ self.labels = [ "31", "63", "125", "250", "500", "1k", "2k", "4k", "8k", "16k" ] self.util = util Container.__init__(self, util) name = "equalizermenu" self.factory = Factory(util) self.bounding_box = bounding_box self.bounding_box.y += 1 self.bounding_box.h -= 1 self.bgr_color = util.config[BACKGROUND][MENU_BGR_COLOR] self.eq_layout = BorderLayout(self.bounding_box) self.eq_layout.set_percent_constraints(0, 0, 5, 5) self.bands = 10 self.sliders = self.add_sliders(handle_slider_event) self.current_slider = -1 self.left_filler = Component(util, self.eq_layout.LEFT) self.left_filler.name = name + ".bgr.left" self.left_filler.bgr = self.bgr_color self.add_component(self.left_filler) self.right_filler = Component(util, self.eq_layout.RIGHT) self.right_filler.name = name + ".bgr.right" self.right_filler.bgr = self.bgr_color self.add_component(self.right_filler) self.SLOW_INCREMENT = 1 self.FAST_INCREMENT = self.sliders[0].slider.knob_height / 2 self.mouse_events = [ pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN, pygame.MOUSEMOTION ]
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 __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 __init__(self, util): """ Initializer :param util: utility object which contains configuration """ self.util = util self.config = util.config Component.__init__(self, util, None, None, False) self.current_image = None self.current_volume = 0 self.start_listeners = [] self.stop_listeners = [] self.current_screensaver = self.get_screensaver() self.update_period = self.current_screensaver.get_update_period() self.current_delay = self.get_delay() self.current_screen = None self.saver_running = False self.one_cycle_period = 1000 / self.config[SCREEN_INFO][FRAME_RATE] self.counter = 0 self.delay_counter = 0
def __init__(self, util): """ Initializer :param util: utility object which contains config """ self.util = util self.config = util.config Component.__init__(self, util, None, None, False) self.current_image = None self.current_volume = 0 self.start_listeners = [] self.stop_listeners = [] self.current_screensaver = self.get_screensaver() self.update_period = self.current_screensaver.get_update_period() self.current_delay = self.get_delay() self.current_screen = None self.saver_running = False self.one_cycle_period = 1000 / self.config[SCREEN_INFO][FRAME_RATE] self.counter = 0 self.delay_counter = 0
def get_star_component(self, button): """ Prepare star icon component for marking :param button: button to mark :return: star component """ button_image_comp = button.components[1] button_image_x = button_image_comp.content_x button_image_y = button_image_comp.content_y button_image_size = button_image_comp.content.get_size() button_image_w = button_image_size[0] c = Component(self.util) bb = Rect(0, 0, self.config[SCREEN_INFO][WIDTH], self.config[SCREEN_INFO][HEIGHT]) r = 1 / 25 c.content = self.image_util.load_multi_color_svg_icon( IMAGE_STAR, bb, r) c.bgr = c.fgr = (0, 0, 255) c.name = button.state.l_name + ".fav" img_w = c.content[1].get_size()[0] c.content_x = button_image_x + button_image_w - img_w - 2 c.content_y = button_image_y + 2 return c
def __init__(self, util, name, bgr, slider_color, img_knob, img_knob_on, 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 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.config = util.config self.lock = RLock() self.CURRENT_TIME_LAYER = 3 self.TOTAL_TIME_LAYER = 2 # don't increase the following number too much as it affects UV Meter screen-saver performance self.LOOP_CYCLES_PER_SECOND = 5 self.CYCLE_TIME = 1 / self.LOOP_CYCLES_PER_SECOND self.active = True comp = Component(self.util, bb) comp.name = name + "bgr" comp.bgr = bgr self.add_component(comp) layout = BorderLayout(bb) layout.set_percent_constraints(0.0, 0.0, 20.0, 20.0) self.current_time_name = name + "current" self.total_time_name = name + "total" self.current_time_layout = layout.LEFT self.total_time_layout = layout.RIGHT self.slider = Slider(util, name + "slider", bgr, slider_color, img_knob, img_knob_on, None, key_incr, key_decr, key_knob, layout.CENTER, False) self.slider.add_slide_listener(self.slider_action_handler) self.total_track_time = 0 self.seek_time = 0 self.add_component(self.slider) c = Component(self.util, None) # init total time layer self.add_component(c) c = Component(self.util, None) # init current time layer self.add_component(c) self.seek_listeners = [] self.start_timer_listeners = [] self.stop_timer_listeners = [] self.update_seek_listeners = True self.use_web = self.config[USAGE][USE_WEB] self.stop_timer() thread = Thread(target = self.start_loop) thread.start()
def __init__(self, util): """ Initializer :param util: contains configuration object """ Component.__init__(self, util) plugin_folder = type(self).__name__.lower() Screensaver.__init__(self, plugin_folder) self.util = util self.config = util.config self.bounding_box = self.config[SCREEN_RECT] self.default_folder = os.path.join(PACKAGE_SCREENSAVER, plugin_folder, DEFAULT_SLIDES_FOLDER) config_slides_folder = self.plugin_config_file.get( PLUGIN_CONFIGURATION, CONFIG_SLIDES_FOLDER) if config_slides_folder: self.current_folder = config_slides_folder else: self.current_folder = self.default_folder self.slides = []
def __init__(self, util): """ Initializer :param util: contains config object """ Component.__init__(self, util) self.config = util.config self.bounding_box = self.config[SCREEN_RECT] self.slides = util.load_screensaver_images("slideshow", "slides") self.w = self.config[SCREEN_INFO][WIDTH] self.h = self.config[SCREEN_INFO][HEIGHT] l = [] for slide in self.slides: width = slide[1].get_size()[0] height = slide[1].get_size()[1] if width == self.w and height == self.h: l.append(slide) else: if width > self.w and height > self.h: k1 = self.w/width k2 = self.h/height width = int(width * (min(k1, k2))) height = int(height * (min(k1, k2))) elif width > self.w and height < self.h: k = self.w/width width = int(width * k) height = int(height * k) elif width < self.w and height >self.h: k = self.h/height width = int(width * k) height = int(height * k) img = util.scale_image(slide[1], (width, height)) t = (slide[0], img) l.append(t) self.slides = l self.indexes = cycle(range(len(self.slides))) self.update_period = 6
def draw_background(self, x, y, w, h): """ Draw background defined by input parameters :param x: x coordinate :param y: y coordinate :param w: width :param h: height """ c = Component(self.util) c.name = "today.bgr" c.content = pygame.Rect(x, y, w, h) c.content_x = x c.content_y = y c.bounding_box = c.content c.bgr = self.semi_transparent_color self.add_component(c)
def add_selection(self, state, bb): if not self.selected: return border = 2 c = Component(self.util, t=border) c.name = state.name + ".selection" x = state.bounding_box.x + border / 2 y = state.bounding_box.y + border / 2 w = state.bounding_box.w - border h = state.bounding_box.h - border c.content = pygame.Rect(x, y, w, h) c.bgr = state.text_color_selected c.fgr = (0, 0, 0, 0) c.content_x = state.bounding_box.x c.content_y = state.bounding_box.y self.add_component(c)
def prepare_label(self): """ Prepare label component representing this output text. Used for web. """ if self.text == None: return size = self.font.size(self.text) label = self.font.render(self.text, 1, self.fgr) comp = Component(self.util, label) comp.name = self.name + ".text" comp.content_x = self.bounding_box.x + self.get_x(size) comp.content_y = self.bounding_box.y + self.get_y(size) comp.text = self.text comp.text_size = self.default_font_size comp.fgr = self.fgr if len(self.components) == 1: self.add_component(comp) else: self.components[1] = comp
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)