def __init__(self, util): """ Initializer :param util: utility object """ self.util = util self.config = util.config self.image_util = util.image_util self.podcasts_links = None self.summary_cache = {} self.loading = [] self.available_icon = None self.loading_icon = None self.loaded_icon = None self.podcast_image_cache = {} self.podcasts_json = [] layout = BorderLayout(util.screen_rect) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_TOP_HEIGHT_MENU_SCREEN, 0, 0) self.episode_button_font_size = int((layout.TOP.h * PERCENT_TITLE_FONT)/100.0) tmp = Menu(util, (0, 0, 0), layout.CENTER, MENU_ROWS_EPISODES, MENU_COLUMNS_EPISODES) layout = tmp.get_layout([1]*PAGE_SIZE_EPISODES) self.episode_button_bb = layout.get_next_constraints() layout = BorderLayout(util.screen_rect) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_TOP_HEIGHT_MENU_SCREEN, 0, 0) self.podcast_button_font_size = int((layout.TOP.h * PERCENT_TITLE_FONT)/100.0) tmp = Menu(util, (0, 0, 0), layout.CENTER, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS) layout = tmp.get_layout([1]*PAGE_SIZE_PODCASTS) self.podcast_button_bb = layout.get_next_constraints() layout = tmp = None
def __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listener: screen menu event listener """ self.util = util config = util.config screen_layout = BorderLayout(util.screen_rect) top = int((util.screen_rect.h * PERCENT_SAVERS) / 100) bottom = util.screen_rect.h - top screen_layout.set_pixel_constraints(top, bottom, 0, 0) layout = BorderLayout(screen_layout.TOP) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, 0, 0, 0) Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant, "saver_title", title_layout=layout.TOP) factory = Factory(util) self.bounding_box = util.screen_rect self.saver_menu = SaverMenu(util, None, layout.CENTER) self.add_component(self.saver_menu) b = config[BACKGROUND][HEADER_BGR_COLOR] c = config[COLORS][COLOR_CONTRAST] font_size = (layout.TOP.h * PERCENT_TITLE_FONT) / 100.0 label = config[LABELS][SCREENSAVER] self.screen_title.set_text(label) layout = BorderLayout(screen_layout.BOTTOM) layout.set_percent_constraints(PERCENT_DELAY_TITLE, PERCENT_DELAY_TITLE, 0, 0) self.delay_menu = SaverDelayMenu(util, None, layout.CENTER) self.add_component(self.delay_menu) layout.TOP.y += 2 layout.TOP.h -= 2 self.saver_delay_title = factory.create_output_text( "saver_delay_title", layout.TOP, b, c, int(font_size)) label = config[LABELS][DELAY] self.saver_delay_title.set_text(label) self.add_component(self.saver_delay_title) b = self.config[BACKGROUND][FOOTER_BGR_COLOR] self.navigator = SaverNavigator(util, listeners, b, layout.BOTTOM) self.add_component(self.navigator) self.top_menu_enabled = True
def __init__(self, title, util, listeners, voice_assistant, show_visibility=True): """ Initializer :param util: utility object :param listeners: listeners :param voice_assistant: voice assistant """ self.util = util self.listeners = listeners layout = BorderLayout(util.screen_rect) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) MenuScreen.__init__(self, util, listeners, 1, 1, voice_assistant) self.screen_title.set_text(title) k_layout = BorderLayout(self.layout.CENTER) k_layout.set_percent_constraints(20, 0, 0, 0) font_size = int((k_layout.TOP.h * 50) / 100) fgr = util.config[COLORS][COLOR_BRIGHT] bgr = (0, 0, 0) bb = k_layout.TOP s = int(font_size / 2) self.input_text = self.factory.create_output_text("kbd.text", bb, bgr, fgr, font_size, H_ALIGN_LEFT, shift_x=s) self.input_text.obfuscate_flag = show_visibility self.add_component(self.input_text) keyboard_layout = k_layout.CENTER self.keyboard = Keyboard(util, keyboard_layout, listeners[KEY_CALLBACK], self) self.set_menu(self.keyboard) self.keyboard.add_text_listener(self.input_text.set_text) listeners[KEY_DELETE] = self.keyboard.delete listeners[KEY_VIEW] = self.input_text.obfuscate self.navigator = KeyboardNavigator(self.util, self.layout.BOTTOM, listeners, show_visibility) self.add_navigator(self.navigator) self.link_borders()
def __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listener: screen menu event listener """ self.util = util config = util.config screen_layout = BorderLayout(config[SCREEN_RECT]) top = int((config[SCREEN_RECT].h * PERCENT_SAVERS) / 100) bottom = config[SCREEN_RECT].h - top screen_layout.set_pixel_constraints(top, bottom, 0, 0) layout = BorderLayout(screen_layout.TOP) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, 0, 0, 0) Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant, "saver_title", title_layout=layout.TOP) factory = Factory(util) self.bounding_box = config[SCREEN_RECT] self.bgr = (0, 0, 0) self.saver_menu = SaverMenu(util, (0, 0, 0), layout.CENTER) self.add_component(self.saver_menu) d = config[COLORS][COLOR_DARK_LIGHT] c = config[COLORS][COLOR_CONTRAST] font_size = (layout.TOP.h * PERCENT_TITLE_FONT)/100.0 label = config[LABELS][SCREENSAVER] self.screen_title.set_text(label) layout = BorderLayout(screen_layout.BOTTOM) layout.set_percent_constraints(PERCENT_DELAY_TITLE, PERCENT_DELAY_TITLE, 0, 0) self.delay_menu = SaverDelayMenu(util, (0, 0, 0), layout.CENTER) self.add_component(self.delay_menu) layout.TOP.y += 1 layout.TOP.h -= 1 self.saver_delay_title = factory.create_output_text("saver_delay_title", layout.TOP, d, c, int(font_size)) label = config[LABELS][DELAY] self.saver_delay_title.set_text(label) self.add_component(self.saver_delay_title) buttons = factory.create_home_player_buttons(self, layout.BOTTOM, listeners) self.home_button = buttons[0] self.player_button = buttons[1] self.top_menu_enabled = True
def __init__(self, util, bounding_box, listeners): """ Initializer :param util: utility object :param bounding_box: bounding box :param listeners: buttons listeners """ Container.__init__(self, util) self.factory = Factory(util) self.name = "collection.navigator" self.content = None self.content_x = bounding_box.x self.content_y = bounding_box.y self.listeners = listeners self.menu_buttons = [] self.config = util.config self.use_web = self.config[USAGE][USE_WEB] self.go_abc = listeners[KEY_ABC] self.go_keyboard = listeners[KEY_KEYBOARD_KEY] self.keyboard_callback = listeners[KEY_CALLBACK] self.bgr = util.config[BACKGROUND][FOOTER_BGR_COLOR] self.arrow_layout = BorderLayout(bounding_box) self.arrow_layout.set_percent_constraints(0, 0, PERCENT_ARROW_WIDTH, PERCENT_ARROW_WIDTH) self.collection_topic = None self.update_observer = None self.redraw_observer = None self.menu_button = None
def create_left_panel(self, layout, listeners): """ Create Station Screen left panel. Include Shutdown button, Left button and Home button. :param layout: left panel layout :param listeners: event listeners """ panel_layout = BorderLayout(layout.LEFT) panel_layout.set_percent_constraints(PERCENT_SIDE_BOTTOM_HEIGHT, PERCENT_SIDE_BOTTOM_HEIGHT, 0, 0) left = 0 if self.station_menu.is_button_defined(): left = self.station_menu.button.state.index self.left_button = self.factory.create_left_button( panel_layout.CENTER, str(left), 40, 100) self.page_down_button = self.factory.create_page_down_button( panel_layout.CENTER, str(left), 40, 100) self.page_down_button.set_visible(False) self.shutdown_button = self.factory.create_shutdown_button( panel_layout.TOP) self.home_button = self.factory.create_button(KEY_HOME, KEY_HOME, panel_layout.BOTTOM, image_size_percent=36) panel = Container(self.util, layout.LEFT) panel.add_component(self.shutdown_button) panel.add_component(self.left_button) panel.add_component(self.page_down_button) panel.add_component(self.home_button) Container.add_component(self, panel)
def create_right_panel(self, layout, listeners): """ Create Station Screen right panel. Include Genre button, right button and Play/Pause button :param layout: right panel layout :param listeners: event listeners """ panel_layout = BorderLayout(layout.RIGHT) panel_layout.set_percent_constraints(PERCENT_SIDE_BOTTOM_HEIGHT, PERCENT_SIDE_BOTTOM_HEIGHT, 0, 0) if self.screen_mode == STATION: self.genres_button = self.factory.create_genre_button( panel_layout.BOTTOM, self.current_genre, PERCENT_GENRE_IMAGE_AREA) elif self.screen_mode == STREAM: self.genres_button = self.factory.create_stream_button( panel_layout.BOTTOM) right = 0 if self.station_menu.is_button_defined(): right = self.playlist.length - self.station_menu.button.state.index - 1 self.right_button = self.factory.create_right_button( panel_layout.CENTER, str(right), 40, 100) self.page_up_button = self.factory.create_page_up_button( panel_layout.CENTER, str(right), 40, 100) self.page_up_button.set_visible(False) self.play_button = self.factory.create_play_pause_button( panel_layout.TOP, listeners[KEY_PLAY_PAUSE]) panel = Container(self.util, layout.RIGHT) panel.add_component(self.genres_button) panel.add_component(self.right_button) panel.add_component(self.page_up_button) panel.add_component(self.play_button) Container.add_component(self, panel)
def get_order_popup(self, bb): """ Create playback order popup menu :param bb: bounding box :return: popup menu """ items = [] items.append(PLAYBACK_CYCLIC) items.append(PLAYBACK_REGULAR) items.append(PLAYBACK_SINGLE_TRACK) items.append(PLAYBACK_SHUFFLE) items.append(PLAYBACK_SINGLE_CYCLIC) layout = BorderLayout(bb) layout.set_percent_constraints(self.top_height, 0, self.popup_width, 0) popup = Popup(items, self.util, layout.LEFT, self.clean_draw_update, self.handle_order_popup_selection, default_selection=self.playback_order) self.left_button.add_label_listener(popup.update_popup) return popup
def add_popups(self): """ Add popup menus: playback order & info """ self.bottom_layout = BorderLayout(self.layout.BOTTOM) if self.show_order and not self.show_info: self.bottom_layout.set_percent_constraints(0, 0, self.popup_width, 0) self.order_button = self.factory.create_order_button( self.bottom_layout.LEFT, self.handle_order_button, self.playback_order) self.order_popup = self.get_order_popup(self.bounding_box) self.add_component(self.order_button) elif self.show_order and self.show_info: self.bottom_layout.set_percent_constraints(0, 0, self.popup_width, self.popup_width) self.order_button = self.factory.create_order_button( self.bottom_layout.LEFT, self.handle_order_button, self.playback_order) self.info_button = self.factory.create_info_button( self.bottom_layout.RIGHT, self.handle_info_button) self.order_popup = self.get_order_popup(self.bounding_box) self.info_popup = self.get_info_popup(self.bounding_box) self.add_component(self.order_button) self.add_component(self.info_button) elif not self.show_order and self.show_info: self.bottom_layout.set_percent_constraints(0, 0, 0, self.popup_width) self.info_button = self.factory.create_info_button( self.bottom_layout.RIGHT, self.handle_info_button) self.info_popup = self.get_info_popup(self.bounding_box) self.add_component(self.info_button) self.bottom_layout.CENTER.w -= 2 self.bottom_layout.CENTER.x += 1 self.bottom_center_layout = self.bottom_layout.CENTER
def __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listeners: listeners :param voice_assistant: voice assistant """ self.util = util self.config = util.config self.listeners = listeners self.factory = Factory(util) self.go_home = listeners[KEY_HOME] self.go_file_playback = listeners[KEY_PLAY_COLLECTION] dbutil = util.get_db_util() self.selector = Selector(dbutil) self.bounding_box = util.screen_rect layout = BorderLayout(self.bounding_box) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) MenuScreen.__init__(self, util, listeners, ROWS, COLUMNS, voice_assistant, [ROWS, COLUMNS], self.turn_page, page_in_title=False, show_loading=False) m = self.factory.create_collection_menu_button font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT) self.collection_list_menu = MultiPageMenu(util, self.next_page, self.previous_page, self.set_title, self.reset_title, self.go_to_page, m, ROWS, COLUMNS, None, (0, 0, 0, 0), self.menu_layout, align=ALIGN_LEFT, font_size=font_size) self.set_menu(self.collection_list_menu) self.navigator = TopicDetailNavigator(self.util, self.layout.BOTTOM, listeners) self.add_component(self.navigator) self.current_item = None self.current_page_items = None self.first_item = None self.last_item = None self.collection_topic = None self.selection = None self.prev_page = 1 self.animated_title = True
def get_info_popup(self, bb): """ Create info popup menu :param bb: bounding box :return: popup menu """ items = [] mode = self.config[CURRENT][MODE] items.append(CLOCK) items.append(WEATHER) items.append(LYRICS) if mode == AUDIO_FILES or mode == COLLECTION: items.append(FILE_INFO) layout = BorderLayout(bb) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, 0, 0, POPUP_WIDTH_PERCENT) popup = Popup(items, self.util, layout.RIGHT, self.clean_draw_update, self.handle_info_popup_selection) self.right_button.add_label_listener(popup.update_popup) return popup
def __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listeners: listeners :param voice_assistant: voice assistant """ self.util = util self.config = util.config self.listeners = listeners self.listeners[KEY_LIST] = self.set_list self.factory = Factory(util) dbutil = util.get_db_util() self.selector = Selector(dbutil) self.bounding_box = util.screen_rect layout = BorderLayout(self.bounding_box) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) MenuScreen.__init__(self, util, listeners, ROWS, COLUMNS, voice_assistant, [ROWS, COLUMNS], self.turn_page, page_in_title=False, show_loading=False) m = self.factory.create_collection_menu_button self.topic_menu = MultiPageMenu(util, self.next_page, self.previous_page, self.set_title, self.reset_title, self.go_to_page, m, ROWS, COLUMNS, None, (0, 0, 0), self.menu_layout, align=ALIGN_LEFT) self.set_menu(self.topic_menu) self.navigator = TopicNavigator(self.util, self.layout.BOTTOM, listeners) self.components.append(self.navigator) self.current_topic = None self.current_item = None self.current_page_items = None self.first_item = None self.last_item = None self.collection_topic = None self.previous_page = 1 self.search_string = None self.source = None self.mode = KEY_LIST self.animated_title = True
def __init__(self, util, bounding_box, listeners, bgr, pages): """ Initializer :param util: utility object :param bounding_box: bounding box :param listeners: buttons listeners :param bgr: menu background :param pages: number of episodes menu pages """ Container.__init__(self, util) self.factory = Factory(util) self.name = "podcasts.navigator" self.content = bounding_box self.content_x = bounding_box.x self.content_y = bounding_box.y self.menu_buttons = [] arrow_layout = BorderLayout(bounding_box) arrow_layout.set_percent_constraints(0, 0, PERCENT_ARROW_WIDTH, PERCENT_ARROW_WIDTH) if pages > 1: constr = arrow_layout.LEFT self.left_button = self.factory.create_page_down_button(constr, "0", 40, 100) self.left_button.add_release_listener(listeners[GO_LEFT_PAGE]) self.add_component(self.left_button) self.menu_buttons.append(self.left_button) constr = arrow_layout.RIGHT self.right_button = self.factory.create_page_up_button(constr, "0", 40, 100) self.right_button.add_release_listener(listeners[GO_RIGHT_PAGE]) self.add_component(self.right_button) self.menu_buttons.append(self.right_button) layout = GridLayout(arrow_layout.CENTER) else: layout = GridLayout(bounding_box) layout.set_pixel_constraints(1, 4, 1, 0) layout.current_constraints = 0 image_size = 64 constr = layout.get_next_constraints() self.home_button = self.factory.create_button(KEY_HOME, KEY_HOME, constr, listeners[KEY_HOME], bgr, image_size_percent=image_size) self.add_component(self.home_button) self.menu_buttons.append(self.home_button) constr = layout.get_next_constraints() self.back_button = self.factory.create_button(KEY_PODCASTS_MENU, KEY_PARENT, constr, listeners[PODCASTS], bgr, image_size_percent=image_size) self.add_component(self.back_button) self.menu_buttons.append(self.back_button) constr = layout.get_next_constraints() self.back_button = self.factory.create_button(KEY_BACK, KEY_BACK, constr, listeners[GO_BACK], bgr, image_size_percent=image_size) self.add_component(self.back_button) self.menu_buttons.append(self.back_button) constr = layout.get_next_constraints() self.player_button = self.factory.create_button(KEY_PLAYER, KEY_PLAY_PAUSE, constr, listeners[KEY_PLAYER], bgr, image_size_percent=image_size) self.add_component(self.player_button) self.menu_buttons.append(self.player_button)
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, listeners, voice_assistant, state): """ Initializer :param util: utility object :param listeners: file browser listeners :param voice_assistant: voice assistant :param state: button state """ self.util = util self.config = util.config self.podcasts_util = util.get_podcasts_util() self.listeners = listeners self.factory = Factory(util) self.bounding_box = util.screen_rect self.layout = BorderLayout(self.bounding_box) self.layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) d = [MENU_ROWS_EPISODES, MENU_COLUMNS_EPISODES] MenuScreen.__init__(self, util, listeners, MENU_ROWS_EPISODES, MENU_COLUMNS_EPISODES, voice_assistant, d, self.turn_page, page_in_title=False) if hasattr(state, "podcast_url"): podcast_url = state.podcast_url self.title = self.podcasts_util.summary_cache[podcast_url].name else: self.title = state.name m = self.factory.create_episode_menu_button self.episodes_menu = MultiPageMenu(util, self.next_page, self.previous_page, self.set_title, self.reset_title, self.go_to_page, m, MENU_ROWS_EPISODES, MENU_COLUMNS_EPISODES, None, (0, 0, 0), self.menu_layout, align=ALIGN_MIDDLE) self.set_menu(self.episodes_menu) self.total_pages = PAGE_SIZE_EPISODES * 2 self.episodes = [] self.navigator = EpisodeNavigator( self.util, self.layout.BOTTOM, listeners, self.config[COLORS][COLOR_DARK_LIGHT], self.total_pages) self.components.append(self.navigator) self.current_page = 1 self.save_episode_listeners = []
def __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listeners: listeners :param voice_assistant: voice assistant """ self.util = util self.config = util.config self.listeners = listeners self.factory = Factory(util) self.podcasts_util = util.get_podcasts_util() self.bounding_box = util.screen_rect layout = BorderLayout(self.bounding_box) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) d = [MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS] MenuScreen.__init__(self, util, listeners, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS, voice_assistant, d, self.turn_page, page_in_title=False, show_loading=True) self.title = self.config[LABELS][PODCASTS] m = self.factory.create_podcast_menu_button self.podcasts_menu = MultiPageMenu(util, self.next_page, self.previous_page, self.set_title, self.reset_title, self.go_to_page, m, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS, None, (0, 0, 0), self.menu_layout, align=ALIGN_CENTER) self.set_menu(self.podcasts_menu) self.navigator = PodcastNavigator( self.util, self.layout.BOTTOM, listeners, self.config[COLORS][COLOR_DARK_LIGHT], PAGE_SIZE_PODCASTS + 1) self.components.append(self.navigator) url = self.config[PODCASTS][PODCAST_URL] if url and len(url) > 0: self.current_page = self.podcasts_util.get_podcast_page( url, PAGE_SIZE_PODCASTS) else: self.current_page = 1 self.animated_title = True
def __init__(self, util, name, bgr, slider_color, img_knob, img_knob_on, key_incr, key_decr, key_knob, bb, f, key_incr_alt=None, key_decr_alt=None): """ 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 :param key_incr_alt: alternative keyboard key associated with slider increment action :param key_decr_alt: alternative keyboard key associated with slider decrement action """ Container.__init__(self, util, background=bgr, bounding_box=bb) self.content = None self.util = util self.config = util.config self.bgr = bgr self.lock = RLock() # don't increase the following number too much as it affects VU Meter screen-saver performance self.LOOP_CYCLES_PER_SECOND = 5 self.CYCLE_TIME = 1 / self.LOOP_CYCLES_PER_SECOND self.active = True layout = BorderLayout(bb) layout.set_percent_constraints(0.0, 0.0, 20.0, 20.0) current_time_name = name + "current" total_time_name = name + "total" current_time_layout = layout.LEFT 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, key_incr_alt=key_incr_alt, key_decr_alt=key_decr_alt) self.slider.add_slide_listener(self.slider_action_handler) self.total_track_time = 0 self.seek_time = 0 self.add_component(self.slider) height = 36 font_size = int((current_time_layout.h * height)/100.0) c = self.config[COLORS][COLOR_BRIGHT] self.current = f.create_output_text(current_time_name, current_time_layout, bgr, c, font_size) self.total = f.create_output_text(total_time_name, total_time_layout, bgr, c, font_size) self.add_component(self.current) self.add_component(self.total) 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.timer_started = False
def __init__(self, util, listeners, rows, columns, voice_assistant, d=None, turn_page=None, page_in_title=True, show_loading=False): """ Initializer :param util: utility object :param listeners: file browser listeners :param rows: menu rows :param d: dictionary with menu button flags :param turn_page: turn page callback :param util: utility object """ self.util = util self.config = util.config self.factory = Factory(util) self.bounding_box = util.screen_rect self.player = None self.turn_page = turn_page self.page_in_title = page_in_title self.show_loading = show_loading self.cache = Cache(self.util) self.layout = BorderLayout(self.bounding_box) self.layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant, "menu_screen_screen_title", True, self.layout.TOP) color_dark_light = self.config[COLORS][COLOR_DARK_LIGHT] self.menu_layout = self.layout.CENTER if d: self.menu_button_layout = self.get_menu_button_layout(d) self.img_rect = self.menu_button_layout.image_rectangle listeners[GO_LEFT_PAGE] = self.previous_page listeners[GO_RIGHT_PAGE] = self.next_page try: self.navigator = BookNavigator(util, self.layout.BOTTOM, listeners, color_dark_light, d[4]) Container.add_component(self, None) Container.add_component(self, self.navigator) except: Container.add_component(self, None) self.total_pages = 0 self.current_page = 1 self.menu = None
def __init__(self, util, bounding_box, listeners): """ Initializer :param util: utility object :param bounding_box: bounding box :param listeners: buttons listeners """ Container.__init__(self, util) self.factory = Factory(util) self.name = "collection.navigator" self.content = bounding_box self.content_x = bounding_box.x self.content_y = bounding_box.y self.listeners = listeners self.menu_buttons = [] self.config = util.config self.use_web = self.config[USAGE][USE_WEB] self.arrow_layout = BorderLayout(bounding_box) self.arrow_layout.set_percent_constraints(0, 0, PERCENT_ARROW_WIDTH, PERCENT_ARROW_WIDTH) self.update_observer = None self.redraw_observer = None self.menu_buttons = [] constr = self.arrow_layout.LEFT self.left_button = self.factory.create_page_down_button( constr, "0", 40, 100) self.left_button.add_release_listener(self.listeners[GO_LEFT_PAGE]) self.add_component(self.left_button) self.menu_buttons.append(self.left_button) constr = self.arrow_layout.RIGHT self.right_button = self.factory.create_page_up_button( constr, "0", 40, 100) self.right_button.add_release_listener(self.listeners[GO_RIGHT_PAGE]) self.add_component(self.right_button) self.menu_buttons.append(self.right_button) layout = GridLayout(self.arrow_layout.CENTER) layout.set_pixel_constraints(1, 5, 1, 0) layout.current_constraints = 0 bgr = util.config[BACKGROUND][FOOTER_BGR_COLOR] self.add_button(KEY_HOME, KEY_HOME, layout, self.listeners[KEY_HOME], bgr) self.add_button(COLLECTION, KEY_PARENT, layout, self.listeners[COLLECTION], bgr) self.add_button(KEY_LIST, KEY_MENU, layout, self.listeners[COLLECTION_TOPIC], bgr) self.add_button(KEY_DETAIL, KEY_SETUP, layout, self.listeners[TOPIC_DETAIL], bgr) self.add_button(KEY_PLAYER, KEY_PLAY_PAUSE, layout, self.listeners[KEY_PLAYER], bgr) if self.use_web and self.update_observer != None: self.add_observers(self.update_observer, self.redraw_observer)
def __init__(self, state): """ Initializer. Define bounding boxes for button label (if any) and icon (if any) :param state: button state """ s = state self.padding = getattr(s, "padding", 0) gap = int((s.bounding_box.h / 100) * self.padding) x = s.bounding_box.x + gap y = s.bounding_box.y + gap w = s.bounding_box.w - (gap * 2) h = s.bounding_box.h - (gap * 2) bb = Rect(x, y, w, h) self.show_image = getattr(s, "show_img", None) self.show_label = getattr(s, "show_label", False) self.image_location = getattr(s, "image_location", CENTER) self.image_area_percent = getattr(s, "image_area_percent", 0) self.layout = BorderLayout(bb) top = bottom = left = right = 0 self.image_rectangle = self.label_rectangle = None if self.show_image and self.show_label: if self.image_location == TOP: top = self.image_area_percent bottom = 100 - top self.layout.set_percent_constraints(top, bottom, left, right) self.image_rectangle = self.layout.TOP self.label_rectangle = self.layout.BOTTOM elif self.image_location == BOTTOM: bottom = self.image_area_percent top = 100 - bottom self.layout.set_percent_constraints(top, bottom, left, right) self.image_rectangle = self.layout.BOTTOM self.label_rectangle = self.layout.TOP elif self.image_location == LEFT: left = self.image_area_percent right = 100 - left self.layout.set_percent_constraints(top, bottom, left, right) self.image_rectangle = self.layout.LEFT self.label_rectangle = self.layout.RIGHT elif self.image_location == RIGHT: right = self.image_area_percent left = 100 - right self.layout.set_percent_constraints(top, bottom, left, right) self.image_rectangle = self.layout.RIGHT self.label_rectangle = self.layout.LEFT elif self.show_image and not self.show_label: self.layout.set_percent_constraints(top, bottom, left, right) self.image_rectangle = self.layout.CENTER elif not self.show_image and self.show_label: self.layout.set_percent_constraints(0, 0, gap, gap) self.label_rectangle = self.layout.CENTER
def get_panel_layout(self, layout, panel_location): """ Get the layout of the panel for buttons :param layout: layout of the whole central area :param panel_location: panel location - left or right :return: panel layout rectangle """ if self.image_location == LOCATION_CENTER: if panel_location == LOCATION_LEFT: return BorderLayout(layout.LEFT) else: return BorderLayout(layout.RIGHT) elif self.image_location == LOCATION_LEFT: r = layout.RIGHT if panel_location == LOCATION_LEFT: return BorderLayout(Rect(r.x, r.y, r.w / 2, r.h)) else: return BorderLayout( Rect(r.x + r.w / 2 + 1, r.y, r.w / 2 - 1, r.h)) elif self.image_location == LOCATION_RIGHT: r = layout.LEFT if panel_location == LOCATION_LEFT: return BorderLayout(Rect(r.x, r.y, r.w / 2, r.h)) else: return BorderLayout( Rect(r.x + r.w / 2 + 1, r.y, r.w / 2 - 1, r.h))
def __init__(self, f, id, util, name, bgr, slider_color, img_knob, img_knob_on, key_incr, key_decr, key_knob, bb, listener, label): """ Initializer :param id: band ID :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, content=None) self.util = util self.config = util.config self.bgr = bgr self.VALUE_LAYER = 2 self.LABEL_LAYER = 1 layout = BorderLayout(bb) layout.set_percent_constraints(10.0, 10.0, 0.0, 0.0) self.id = id self.value_name = name + ".value." + str(id) self.label_name = name + ".label." + str(id) self.value_layout = layout.TOP self.label_layout = layout.BOTTOM self.label_layout.y -= 1 self.label_layout.h += 2 self.slider = Slider(util, "slider." + str(id), bgr, slider_color, img_knob, img_knob_on, None, key_incr, key_decr, key_knob, layout.CENTER) self.slider.add_slide_listener(listener) self.add_component(self.slider) height = 60 font_size = int((self.value_layout.h * height)/100.0) c = self.config[COLORS][COLOR_BRIGHT] self.top = f.create_output_text("top.label." + str(id), self.value_layout, bgr, c, font_size) self.bottom = f.create_output_text("bottom.label." + str(id), self.label_layout, bgr, c, font_size) self.bottom.set_text(label) self.add_component(self.top) self.add_component(self.bottom) self.seek_listeners = [] self.update_seek_listeners = True self.use_web = self.config[USAGE][USE_WEB]
def __init__(self, util, listeners, voice_assistant, state): """ Initializer :param util: utility object :param listeners: file browser listeners """ self.util = util self.config = util.config self.cdutil = CdUtil(util) self.factory = Factory(util) self.bounding_box = util.screen_rect self.layout = BorderLayout(self.bounding_box) self.layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant, "cd_tracks_screen_title", True, self.layout.TOP) color_dark_light = self.config[COLORS][COLOR_DARK_LIGHT] self.current_cd_drive_name = self.config[CD_PLAYBACK][CD_DRIVE_NAME] self.current_cd_drive_id = self.config[CD_PLAYBACK][CD_DRIVE_ID] self.filelist = self.get_filelist() self.file_menu = FileMenu(self.filelist, util, None, (0, 0, 0), self.layout.CENTER, align=ALIGN_LEFT) self.go_cd_player = listeners[KEY_PLAYER] self.file_menu.add_play_file_listener(self.play_track) Container.add_component(self, self.file_menu) listeners[GO_LEFT_PAGE] = self.file_menu.page_down listeners[GO_RIGHT_PAGE] = self.file_menu.page_up listeners[KEY_EJECT] = self.eject_cd listeners[KEY_REFRESH] = self.refresh_tracks connected_cd_drives = self.cdutil.get_cd_drives_number() self.navigator = CdTracksNavigator(util, connected_cd_drives, self.layout.BOTTOM, listeners, color_dark_light) Container.add_component(self, self.navigator) self.file_menu.add_left_number_listener( self.navigator.left_button.change_label) self.file_menu.add_right_number_listener( self.navigator.right_button.change_label) self.file_menu.update_buttons() self.page_turned = False self.animated_title = True
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 __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listeners: listeners :param voice_assistant: voice assistant """ self.util = util self.config = util.config self.listeners = listeners self.listeners[KEY_LIST] = self.set_list self.factory = Factory(util) dbutil = util.get_db_util() self.selector = Selector(dbutil) self.bounding_box = util.screen_rect layout = BorderLayout(self.bounding_box) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) MenuScreen.__init__(self, util, listeners, ROWS, COLUMNS, voice_assistant, [ROWS, COLUMNS], self.turn_page, page_in_title=False, show_loading=False) m = self.factory.create_collection_menu_button font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT) h = self.config[HORIZONTAL_LAYOUT] bgr = self.config[BACKGROUND][MENU_BGR_COLOR] self.topic_menu = Menu(util, bgr, self.menu_layout, ROWS, COLUMNS, create_item_method=m, align=ALIGN_LEFT, horizontal_layout=h, font_size=font_size) self.set_menu(self.topic_menu) self.navigator = TopicNavigator(self.util, self.layout.BOTTOM, listeners) self.add_navigator(self.navigator) self.current_topic = None self.current_item = None self.current_page_items = None self.first_item = None self.last_item = None self.collection_topic = None self.previous_page = 1 self.search_string = None self.source = None self.mode = KEY_LIST self.animated_title = True
def get_info_popup(self, bb): """ Create info popup menu :param bb: bounding box :return: popup menu """ items = [] items.append(CLOCK) items.append(WEATHER) items.append(LYRICS) layout = BorderLayout(bb) layout.set_percent_constraints(self.top_height, 0, 0, self.popup_width) popup = Popup(items, self.util, layout.RIGHT, self.clean_draw_update, self.handle_info_popup_selection) self.right_button.add_label_listener(popup.update_popup) return popup
def __init__(self, util, listeners, voice_assistant): """ Initializer :param util: utility object :param listeners: listeners :param voice_assistant: voice assistant """ self.util = util self.config = util.config self.listeners = listeners self.factory = Factory(util) self.go_home = listeners[KEY_HOME] self.go_keyboard = listeners[KEY_KEYBOARD_KEY] self.keyboard_callback = listeners[KEY_CALLBACK] self.wifi_selection_listeners = [] self.wifi_util = WiFiUtil(util) self.bounding_box = util.screen_rect layout = BorderLayout(self.bounding_box) layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0) d = [MENU_ROWS_WIFI, MENU_COLUMNS_WIFI] MenuScreen.__init__(self, util, listeners, MENU_ROWS_WIFI, MENU_COLUMNS_WIFI, voice_assistant, d, self.turn_page, page_in_title=False, show_loading=False) self.title = self.config[LABELS]["select.wifi"] self.set_title(1) m = self.factory.create_wifi_menu_button self.wifi_menu = MultiPageMenu(util, self.next_page, self.previous_page, self.set_title, self.reset_title, self.go_to_page, m, MENU_ROWS_WIFI, MENU_COLUMNS_WIFI, None, (0, 0, 0), self.menu_layout, align=ALIGN_MIDDLE) self.set_menu(self.wifi_menu) listeners[KEY_REFRESH] = self.set_current listeners[KEY_SORT] = self.sort_abc self.navigator = WiFiNavigator(self.util, self.layout.BOTTOM, listeners, PAGE_SIZE_WIFI + 1) self.components.append(self.navigator) self.original_networks = None self.networks = None self.sort_direction = False self.current_network = None
def create_right_panel(self, layout, listeners): """ Create right side buttons panel :param layout: panel layout :param listeners: button listeners """ panel_layout = BorderLayout(layout.RIGHT) panel_layout.set_percent_constraints(PERCENT_SIDE_BOTTOM_HEIGHT, PERCENT_SIDE_BOTTOM_HEIGHT, 0, 0) self.play_button = self.factory.create_play_pause_button( panel_layout.TOP, listeners[KEY_PLAY_PAUSE]) self.right_button = self.factory.create_right_button( panel_layout.CENTER, '', 40, 100) self.time_volume_button = self.factory.create_time_volume_button( panel_layout.BOTTOM, self.toggle_time_volume) panel = Container(self.util, layout.RIGHT) panel.add_component(self.play_button) panel.add_component(self.right_button) panel.add_component(self.time_volume_button) Container.add_component(self, panel)
def __init__(self, util): """ Initializer :param util: utility object """ self.util = util self.config = util.config self.color_web_bgr = self.config[COLORS][COLOR_WEB_BGR] Container.__init__(self, util, background=self.color_web_bgr) self.bounding_box = util.screen_rect self.start_listeners = [] factory = Factory(util) edition = "Holbein Edition" layout = BorderLayout(self.bounding_box) layout.set_percent_constraints(0, PERCENT_FOOTER_HEIGHT, 0, 0) release_font_size = (layout.BOTTOM.h * PERCENT_FOOTER_FONT) / 100.0 color_logo = self.config[COLORS][COLOR_LOGO] button = factory.create_image_button("peppy", bounding_box=layout.CENTER, bgr=self.color_web_bgr, image_size_percent=68, selected=False) x = layout.CENTER.w / 2 - button.components[1].content.get_size()[0] / 2 y = layout.CENTER.h / 2 - button.components[1].content.get_size()[1] / 2 button.components[1].content_x = x button.components[1].content_y = y self.add_component(button) layout.BOTTOM.y -= 1 layout.BOTTOM.h += 1 release = factory.create_output_text("about-name", layout.BOTTOM, self.color_web_bgr, color_logo, int(release_font_size), full_width=True, valign=V_ALIGN_TOP) release.set_text_no_draw(edition) self.add_component(release)
def get_layout(self): """ Get the layout of the center area of the screen for image and buttons :return: layout rectangle """ layout = BorderLayout(self.bounding_box) k = self.bounding_box.w / self.bounding_box.h percent_menu_width = (100.0 - self.top_height - self.bottom_height) / k panel_width = (100.0 - percent_menu_width) / 2.0 if self.image_location == LOCATION_CENTER: layout.set_percent_constraints(self.top_height, self.bottom_height, panel_width, panel_width) elif self.image_location == LOCATION_LEFT: layout.set_percent_constraints(self.top_height, self.bottom_height, 0, panel_width * 2) elif self.image_location == LOCATION_RIGHT: layout.set_percent_constraints(self.top_height, self.bottom_height, panel_width * 2, 0) return layout