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_arrow_button(self, bb, name, key, location, label_text, image_area=40): """ Create Arrow button (e.g. Left, Next Page etc.) :param bb: bounding box :param name: button name :param key: keyboard key associated with button :param location: image location inside of bounding box :param label_text: button label text :param image_area: percentage of height occupied by button image :return: arrow button """ s = State() s.name = name s.bounding_box = bb s.keyboard_key = key s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.show_img = True s.show_label = True s.image_location = location s.label_location = CENTER s.image_area_percent = image_area s.label_text_height = 44 s.l_name = label_text s.auto_update = True s.text_color_normal = self.config[COLORS][COLOR_BRIGHT] s.text_color_selected = self.config[COLORS][COLOR_CONTRAST] s.text_color_disabled = self.config[COLORS][COLOR_MEDIUM] s.text_color_current = s.text_color_normal self.set_state_icons(s) b = Button(self.util, s) return b
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 = 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 = ToggleButton(self.util, state) return button
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 set_genre_button_image(self, genre): """ Set genre button image :param genre: genre button """ s = State() s.__dict__ = genre.__dict__ s.bounding_box = self.genres_button.state.bounding_box s.bgr = self.genres_button.bgr s.show_label = False s.keyboard_key = kbd_keys[KEY_MENU] self.genres_button.set_state(s)
def create_arrow_button(self, bb, name, key, location, label_text, image_area, image_size, arrow_labels=True, rest_command=None): """ Create Arrow button (e.g. Left, Next Page etc.) :param bb: bounding box :param name: button name :param key: keyboard key associated with button :param location: image location inside of bounding box :param label_text: button label text :param image_area: percentage of height occupied by button image :param arrow_labels: show arrow label or not :param rest_command: REST API command assigned to the button :return: arrow button """ s = State() s.name = name s.bounding_box = bb s.keyboard_key = key s.bgr = self.config[BACKGROUND][FOOTER_BGR_COLOR] s.show_bgr = True s.show_img = True if arrow_labels: s.show_label = True else: s.show_label = False s.image_location = location s.label_location = CENTER s.label_text_height = 40 s.l_name = label_text s.auto_update = True s.image_size_percent = image_area / 100 s.image_area_percent = image_area s.text_color_normal = self.config[COLORS][COLOR_BRIGHT] s.text_color_selected = self.config[COLORS][COLOR_CONTRAST] s.text_color_disabled = self.config[COLORS][COLOR_MEDIUM] s.text_color_current = s.text_color_normal if rest_command: s.rest_commands = [rest_command] self.set_state_icons(s) if image_size != 100: self.resize_image(s, image_size) b = Button(self.util, s) return b
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 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 set_genre_button_image(self, genre): """ Set genre button image :param genre: genre button """ if self.favorites_mode: favorites_button_state = self.favorites_util.get_favorites_button_state( self.genres_button.state.bounding_box) self.genres_button.selected = False self.genres_button.set_state(favorites_button_state) else: s = State() s.__dict__ = genre.__dict__ s.bounding_box = self.genres_button.state.bounding_box s.bgr = self.genres_button.bgr s.show_label = False s.keyboard_key = kbd_keys[KEY_MENU] self.factory.scale_genre_button_image(s, PERCENT_GENRE_IMAGE_AREA) self.genres_button.set_state(s)
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 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_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 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.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 button = Button(self.util, state) button.add_release_listener(action) return button