def get_favorites_button_state(self, button_bounding_box): """ Get Favorites button state :param button_bounding_box: bounding box :return: favorites button state """ state = State() state.bounding_box = button_bounding_box scale_factor = 0.45 state.icon_base = self.image_util.load_icon_main( KEY_FAVORITES, button_bounding_box, scale_factor) state.icon_selected = self.image_util.load_icon_on( KEY_FAVORITES, button_bounding_box, scale_factor) state.name = state.l_name = state.genre = KEY_FAVORITES state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = False state.show_img = True state.show_label = False state.comparator_item = state.name state.index = 0 state.v_align = V_ALIGN_TOP state.v_offset = 0 state.voice_commands = state.name return state
def load_menu(self): """ Load menu items :return: dictionary of the items """ items = {} i = 0 for a in ABC: state = State() state.name = a state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name if a == "foo": state.index = 20.5 elif a == "bar": state.index = 40 else: state.index = i i += 1 items[state.name] = state return items
def create_book_author_items(self, authors): """ Create dictionary with author books :param authors: list of author books :return: dictionary with author books """ items = {} for i, g in enumerate(authors): state = State() state.name = g[AUTHOR_NAME] state.url = g[AUTHOR_URL] + "/" try: state.l_name = state.name + " (" + g[AUTHOR_BOOKS] + ")" except: state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state return items
def create_toggle_button(self, name, keyboard_key=None, lirc_code=None, bounding_box=None, image_size_percent=100): """ Create toggle button (e.g. Shutdown button) :param name: button name :param keyboard_key: keyboard key assigned to the button :param lirc_code: LIRC code assigned to the button :param bounding_box: button bounding box """ state = State() state.name = name state.keyboard_key = keyboard_key state.lirc_code = lirc_code state.bgr = (0, 0, 0) state.bounding_box = bounding_box state.img_x = None state.img_y = None state.auto_update = True state.image_align_v = V_ALIGN_CENTER state.show_bgr = True state.show_img = True state.image_size_percent = image_size_percent self.set_state_icons(state) button = ToggleButton(self.util, state) return button
def create_image_button(self, name, action=None, keyboard_key=None, lirc_code=None, bounding_box=None, bgr=(0, 0, 0), x_margin_percent=None, resizable=True, image_size_percent=100, source=None, selected=True): """ Create image button :param name: button name :param action: action listener :param keyboard_key: keyboard key assigned to the button :param lirc_code: LIRC code assigned to the button :param bounding_box: button bounding box :param bgr: button background color :param x_margin_percent: X margin for the button :param resizable: flag defining if button can be resized, True - resizable, False - non-resizable """ state = State() state.name = name state.bounding_box = bounding_box state.bgr = bgr state.keyboard_key = keyboard_key state.lirc_code = lirc_code state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.image_align_v = V_ALIGN_CENTER state.x_margin_percent = x_margin_percent state.resizable = resizable state.source = source state.image_size_percent = image_size_percent / 100.0 self.set_state_icons(state, selected) button = Button(self.util, state) if action: button.add_release_listener(action) return button
def create_timer_button(self, name, keyboard_key=None, lirc_code=None, bounding_box=None, image_size_percent=100, label=None): """ Create timer button :param name: button name :param keyboard_key: keyboard key assigned to the button :param lirc_code: LIRC code assigned to the button :param bounding_box: button bounding box :param image_size_percent: button icon size in percent :param label: button label """ state = State() state.name = name state.keyboard_key = keyboard_key state.lirc_code = lirc_code state.bgr = self.config[BACKGROUND][MENU_BGR_COLOR] state.bounding_box = bounding_box state.img_x = None state.img_y = None state.auto_update = True state.image_align_v = V_ALIGN_CENTER state.show_bgr = True state.show_img = True state.image_size_percent = image_size_percent self.set_state_icons(state) button = Button(self.util, state) return button
def create_image_button(self, name, action=None, keyboard_key=None, lirc_code=None, bounding_box=None, bgr=(0, 0, 0), x_margin_percent=None, resizable=True): """ Create image button :param name: button name :param action: action listener :param keyboard_key: keyboard key assigned to the button :param lirc_code: LIRC code assigned to the button :param bounding_box: button bounding box :param bgr: button background color :param x_margin_percent: X margin for the button :param resizable: flag defining if button can be resized, True - resizable, False - non-resizable """ state = State() state.name = name state.bounding_box = bounding_box state.bgr = bgr state.keyboard_key = keyboard_key state.lirc_code = lirc_code state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.image_align_v = V_ALIGN_CENTER state.x_margin_percent = x_margin_percent state.resizable = resizable self.set_state_icons(state) button = Button(self.util, state) if action: button.add_release_listener(action) return button
def create_station_button(self, s, bb, action=None): """ Create station button :param s: button state :param bb: bounding box :param action: event listener :return: station logo button """ state = State() state.icon_base = s.icon_base state.index_in_page = s.index_in_page state.index = s.index state.scaled = getattr(s, "scaled", False) state.icon_base_scaled = s.icon_base_scaled state.name = "station_menu." + s.name state.l_name = s.l_name state.url = s.url state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = True state.show_img = True state.image_align_v = V_ALIGN_BOTTOM button = Button(self.util, state) button.add_release_listener(action) return button
def create_book_genre_items(self, genres, base_url): """ Create dictionary with genres :param genres: list of genres :param base_url: base url :return: dictionary with genres """ items = {} for i, g in enumerate(genres): state = State() state.name = g[0] state.genre = base_url + g[1] state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state return items
def change_submenu(self, ch): """ Change bottom submenu :param ch: selected character """ sub = [] try: sub = FILTERS_RU[ch] except: pass items = {} cp = self.buttons.copy() backup = {} for ch in ABC_RU: backup[ch] = cp[ch].state i = len(ABC_RU) for a in sub: state = State() state.name = a state.l_name = state.name state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = False state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state i += 1 items.update(backup) self.set_items(items, 0, self.abc_action, False) self.clean_draw_update()
def create_station_button(self, s, bb, action=None): """ Create station button :param s: button state :param bb: bounding box :param action: event listener :return: station logo button """ state = State() state.icon_base = s.icon_base state.index_in_page = s.index_in_page state.index = s.index state.genre = s.genre state.scaled = getattr(s, "scaled", False) state.icon_base_scaled = s.icon_base_scaled state.name = "station_menu." + s.name state.l_name = s.l_name state.url = s.url state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = True state.show_img = True state.image_align_v = V_ALIGN_BOTTOM button = Button(self.util, state) button.add_release_listener(action) return button
def create_file_button(self, bb, action=None): """ Create default audio file button :param bb: bounding box :param action: button event listener :return: default audio file button """ state = State() state.icon_base = self.image_util.get_audio_file_icon("", bb) state.scaled = False state.name = "cd" state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = False state.show_img = True state.image_align_v = V_ALIGN_CENTER state.source = FILE_BUTTON button = Button(self.util, state) button.add_release_listener(action) return button
def set_tracks(self, tracks, page): """ Set tracks in menu :param tracks: list of tracks :param page: page number """ if tracks == None: return self.tracks = tracks items = {} start_index = TRACKS_PER_PAGE * (page - 1) end_index = start_index + TRACKS_PER_PAGE layout = GridLayout(self.bb) layout.set_pixel_constraints(TRACK_ROWS, TRACK_COLUMNS, 1, 1) constr = layout.get_next_constraints() fixed_height = int((constr.h * LABEL_HEIGHT_PERCENT) / 100.0) for i, a in enumerate(self.tracks[start_index:end_index]): state = State() state.name = a["title"] state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i state.fixed_height = fixed_height state.file_name = a["file_name"] items[state.name] = state self.set_items(items, 0, self.play_track, False)
def create_play_pause_button(self, bb, action): """ Create Play/Pause button :param bb: bounding box :param action: event listener :return: play/pause button """ states = [] pause_state = State() pause_state.name = "pause" pause_state.bounding_box = bb pause_state.bgr = (0, 0, 0) pause_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE] pause_state.action = action pause_state.img_x = None pause_state.img_y = None pause_state.auto_update = True pause_state.image_align_v = V_ALIGN_CENTER pause_state.show_bgr = True pause_state.show_img = True pause_state.image_size_percent = 0.36 play_state = State() play_state.name = "play" play_state.bounding_box = bb play_state.bgr = (0, 0, 0) play_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE] play_state.action = action play_state.img_x = None play_state.img_y = None play_state.auto_update = True play_state.image_align_v = V_ALIGN_CENTER play_state.show_bgr = True play_state.show_img = True play_state.image_size_percent = 0.36 if self.config[PLAYER_SETTINGS][PAUSE]: states.append(play_state) states.append(pause_state) else: states.append(pause_state) states.append(play_state) return self.create_multi_state_button(states)
def create_play_pause_button(self, bb, action): """ Create Play/Pause button :param bb: bounding box :param action: event listener :return: play/pause button """ states = [] bgr = self.config[BACKGROUND][MENU_BGR_COLOR] pause_state = State() pause_state.name = "pause" pause_state.bounding_box = bb pause_state.bgr = bgr pause_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE] pause_state.action = action pause_state.img_x = None pause_state.img_y = None pause_state.auto_update = True pause_state.image_align_v = V_ALIGN_CENTER pause_state.show_bgr = True pause_state.show_img = True pause_state.image_size_percent = 0.36 pause_state.rest_commands = ["playpause"] play_state = State() play_state.name = "play" play_state.bounding_box = bb play_state.bgr = bgr play_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE] play_state.action = action play_state.img_x = None play_state.img_y = None play_state.auto_update = True play_state.image_align_v = V_ALIGN_CENTER play_state.show_bgr = True play_state.show_img = True play_state.image_size_percent = 0.36 play_state.rest_commands = ["playpause"] states.append(pause_state) states.append(play_state) return self.create_multi_state_button(states)
def create_time_volume_button(self, bb, action): """ Create Time/Volume two states button :param bb: bounding box :param action: event listener :return: Time/Volume button """ states = [] bgr = self.config[BACKGROUND][MENU_BGR_COLOR] volume_state = State() volume_state.name = "speaker" volume_state.bounding_box = bb volume_state.bgr = bgr volume_state.keyboard_key = kbd_keys[KEY_SETUP] volume_state.action = action volume_state.img_x = None volume_state.img_y = None volume_state.auto_update = True volume_state.image_align_v = V_ALIGN_CENTER volume_state.show_bgr = True volume_state.show_img = True volume_state.image_size_percent = 0.36 states.append(volume_state) time_state = State() time_state.name = "time" time_state.bounding_box = bb time_state.bgr = bgr time_state.keyboard_key = kbd_keys[KEY_SETUP] time_state.action = action time_state.img_x = None time_state.img_y = None time_state.auto_update = True time_state.image_align_v = V_ALIGN_CENTER time_state.show_bgr = True time_state.show_img = True time_state.image_size_percent = 0.36 states.append(time_state) return self.create_multi_state_button(states)
def load_stations_folders(self, button_bounding_box): """ Load languages menu items :param button_bounding_box: bounding box :return: dictionary with menu items """ items = collections.OrderedDict() i = 0 current_language = self.config[CURRENT][LANGUAGE] folders = self.get_stations_folders() top_folder = self.get_stations_top_folder() for folder in folders: name = folder path = os.path.join(os.getcwd(), FOLDER_LANGUAGES, current_language, FOLDER_RADIO_STATIONS, top_folder, folder, FILE_FOLDER) folder_image = self.image_util.load_image(path) path_on = os.path.join(os.getcwd(), FOLDER_LANGUAGES, current_language, FOLDER_RADIO_STATIONS, top_folder, folder, FILE_FOLDER_ON) folder_image_on = self.image_util.load_image(path_on) state = State() state.name = state.l_name = state.genre = name if folder_image: scale_ratio = self.image_util.get_scale_ratio( (button_bounding_box.w, button_bounding_box.h), folder_image[1]) scaled_image = self.image_util.scale_image( folder_image, scale_ratio) state.icon_base = (path, scaled_image) if folder_image_on: scaled_image_on = self.image_util.scale_image( folder_image_on, scale_ratio) state.icon_selected = (path_on, scaled_image_on) state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.show_label = True state.comparator_item = state.name state.index = i state.v_align = V_ALIGN_TOP state.v_offset = 35 state.voice_commands = name items[state.name] = state i += 1 return items
def load_menu(self, names, comparator, disabled_items=None): """ Load menu items :param names: list of menu item names (should have corresponding filename) :param comparator: string used to sort items :param disabled_items: list of items which should be disabled :return: dictionary with menu items """ items = {} f = self.config[ICON_SIZE_FOLDER] for name in names: filename = name + EXT_PNG path = os.path.join(FOLDER_ICONS, f, filename) icon = self.load_image(path) filename = name + IMAGE_SELECTED_SUFFIX + EXT_PNG path_on = os.path.join(FOLDER_ICONS, f, filename) icon_on = self.load_image(path_on) filename = name + IMAGE_DISABLED_SUFFIX + EXT_PNG path_off = os.path.join(FOLDER_ICONS, f, filename) icon_off = self.load_image(path_off) state = State() state.name = name state.genre = name state.l_genre = self.config[LABELS][name] state.l_name = self.config[LABELS][name] state.icon_base = icon if icon_on: state.icon_selected = icon_on else: state.icon_selected = icon if not icon_off: state.icon_disabled = icon_on state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.show_label = True if comparator == NAME: state.comparator_item = state.name elif comparator == GENRE: state.comparator_item = state.genre if disabled_items and name in disabled_items: state.enabled = False items[state.name] = state return items
def load_menu(self): """ Load menu items """ items = {} i = 0 for a in ABC_RU: state = State() state.name = a state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state i += 1 sub = FILTERS_RU[INITIAL_CHAR] for a in sub: state = State() state.name = a state.l_name = state.name state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = False state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state i += 1 return items
def create_play_pause_button(self, bb, action): """ Create Play/Pause button :param bb: bounding box :param action: event listener :return: play/pause button """ states = [] pause_state = State() pause_state.name = "pause" pause_state.bounding_box = bb pause_state.bgr = (0, 0, 0) pause_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE] pause_state.action = action pause_state.img_x = None pause_state.img_y = None pause_state.auto_update = True pause_state.image_align_v = V_ALIGN_CENTER pause_state.show_bgr = True pause_state.show_img = True states.append(pause_state) play_state = State() play_state.name = "play" play_state.bounding_box = bb play_state.bgr = (0, 0, 0) play_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE] play_state.action = action play_state.img_x = None play_state.img_y = None play_state.auto_update = True play_state.image_align_v = V_ALIGN_CENTER play_state.show_bgr = True play_state.show_img = True states.append(play_state) return self.create_multi_state_button(states)
def get_center_button(self, s): """ Create the center button :param s: button state :return: station logo button """ bb = Rect(self.layout.CENTER.x + 1, self.layout.CENTER.y + 1, self.layout.CENTER.w - 1, self.layout.CENTER.h - 1) if not hasattr(s, "icon_base"): self.util.add_icon(s) state = State() state.icon_base = s.icon_base self.factory.set_state_scaled_icons(s, bb) state.index = s.index state.genre = s.genre state.scaled = getattr(s, "scaled", False) state.icon_base_scaled = s.icon_base_scaled state.name = "station." + s.name state.l_name = s.l_name state.url = s.url state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = True state.show_img = True state.logo_image_path = s.image_path state.image_align_v = V_ALIGN_BOTTOM state.comparator_item = self.current_state.comparator_item button = Button(self.util, state) img = button.components[1] self.logo_button_content = (img.image_filename, img.content, img.content_x, img.content_y) return button
def create_disabled_button(self, bb, name, scale): """ Create disabled button :param bb: bounding box :param name: image name :param scale: image scale :return: disabled button """ state = State() state.name = name state.icon_base = self.image_util.load_icon_off(state.name, bb, scale) state.icon_selected = state.icon_base state.bgr = self.config[BACKGROUND][MENU_BGR_COLOR] state.bounding_box = bb state.img_x = None state.img_y = None state.auto_update = True state.image_align_v = V_ALIGN_CENTER state.show_bgr = True state.show_img = True state.show_label = False return Button(self.util, state)
def create_genre_button(self, bb, state, image_area): """ Create Genre button :param bb: bounding box :param state: button state :return: genre button """ s = State() s.__dict__ = state.__dict__ s.bgr = (0, 0, 0) s.bounding_box = bb s.keyboard_key = kbd_keys[KEY_MENU] s.img_x = None s.img_y = None s.auto_update = True s.image_align_v = V_ALIGN_CENTER s.show_bgr = True s.show_img = True s.show_label = False self.scale_genre_button_image(s, image_area) return Button(self.util, s)
def create_disabled_button(self, bb, name, scale): """ Create disabled button :param bb: bounding box :param name: image name :param scale: image scale :return: disabled button """ state = State() state.name = name state.icon_base = self.util.load_mono_svg_icon(state.name, self.util.COLOR_OFF, bb, scale) state.icon_selected = state.icon_base state.bgr = (0, 0, 0) state.bounding_box = bb state.img_x = None state.img_y = None state.auto_update = True state.image_align_v = V_ALIGN_CENTER state.show_bgr = True state.show_img = True state.show_label = False return Button(self.util, state)
def load_languages_menu(self, button_bounding_box): """ Load languages menu items :param button_bounding_box: menu button bounding box :return: dictionary with menu items """ items = {} i = 0 current_language = self.get_current_language() labels = current_language[TRANSLATIONS] va_commands = self.get_va_language_commands() for language in self.config[KEY_LANGUAGES]: name = language[NAME] state = State() state.name = name state.l_name = labels[name] path = os.path.join(os.getcwd(), FOLDER_LANGUAGES, name, FILE_FLAG) img = self.prepare_flag_image(path, button_bounding_box) state.icon_base = (path, img) state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.show_label = True state.comparator_item = state.name state.index = i state.voice_commands = va_commands[name] state.v_align = V_ALIGN_TOP items[state.name] = state i += 1 return items
def create_stream_button(self, bb): """ Create Stream button :param bb: bounding box :return: genre button """ state = State() state.name = "stream" state.icon_base = self.util.load_mono_svg_icon(state.name, self.util.COLOR_OFF, bb, 0.4) state.icon_selected = state.icon_base state.bgr = (0, 0, 0) state.bounding_box = bb state.img_x = None state.img_y = None state.auto_update = True state.image_align_v = V_ALIGN_CENTER state.show_bgr = True state.show_img = True state.show_label = False return Button(self.util, state)
def load_menu(self): """ Load menu items :return: dictionary of the items """ items = {} for i, a in enumerate(ABC): state = State() state.name = a state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state return items
def create_toggle_button(self, name, keyboard_key=None, lirc_code=None, bounding_box=None): """ Create toggle button (e.g. Shutdown button) :param name: button name :param keyboard_key: keyboard key assigned to the button :param lirc_code: LIRC code assigned to the button :param bounding_box: button bounding box """ state = State() state.name = name state.keyboard_key = keyboard_key state.lirc_code = lirc_code state.bgr = (0, 0, 0) state.bounding_box = bounding_box state.img_x = None state.img_y = None state.auto_update = True state.image_align_v = V_ALIGN_CENTER state.show_bgr = True state.show_img = True self.set_state_icons(state) button = ToggleButton(self.util, state) return button
def load_menu(self, names, comparator, disabled_items=None, v_align=None, bb=None, scale=1): """ Load menu items :param names: list of menu item names (should have corresponding filename) :param comparator: string used to sort items :param disabled_items: list of items which should be disabled :param v_align: vertical alignment :param bb: bounding box :param scale: image scale factor :return: dictionary with menu items """ items = {} i = 0 for name in names: icon = self.load_mono_svg_icon(name, self.COLOR_MAIN, bb, scale) icon_on = self.load_mono_svg_icon(name, self.COLOR_ON, bb, scale) if disabled_items and name in disabled_items: icon_off = self.load_mono_svg_icon(name, self.COLOR_OFF, bb, scale) else: icon_off = None state = State() state.name = name state.genre = name try: state.l_genre = self.config[LABELS][name] state.l_name = self.config[LABELS][name] except: state.l_genre = name state.l_name = name state.icon_base = icon if icon_on: state.icon_selected = icon_on else: state.icon_selected = icon if not icon_off: state.icon_disabled = icon_on else: state.icon_disabled = icon_off state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.show_label = True state.v_align = v_align if comparator == NAME: state.comparator_item = state.name elif comparator == GENRE: state.comparator_item = state.genre if disabled_items and name in disabled_items: state.enabled = False state.index = i items[state.name] = state i += 1 return items