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 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_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 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_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 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, 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