Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
    def create_collection_menu_button(self, s, constr, action, scale, font_size):
        """ Create Collection menu button

        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param scale: True - scale images, False - don't scale images

        :return: wifi menu button
        """
        s.bounding_box = constr
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.show_bgr = True
        s.show_img = False
        s.show_label = 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
        s.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        s.label_text_height = 40
        s.v_align = V_ALIGN_CENTER
        s.h_align = H_ALIGN_LEFT
        s.h_offset = (constr.w / 100) * 15
        s.padding = 3
        s.wrap_labels = self.config[WRAP_LABELS]
        s.fixed_height = font_size

        button = Button(self.util, s)
        
        button.add_release_listener(action)
        return button
Ejemplo n.º 3
0
    def create_track_menu_button(self, s, constr, action, show_img=True, show_label=True):
        """ Create Menu button
        
        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param scale: True - scale images, False - don't scale images
        
        :return: menu button
        """       
        
        s.bounding_box = constr
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.show_bgr = True
        s.show_img = show_img
        s.show_label = show_label
        s.source = TRACK_MENU
        if s.name in ABC_RU:
            s.text_color_normal = self.config[COLORS][COLOR_BRIGHT]
        else:
            s.text_color_normal = (255, 255, 255)
        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
        
        button = Button(self.util, s)
        button.bgr = self.config[COLORS][COLOR_DARK]
        button.add_release_listener(action)

        return button
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
 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        
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def create_book_author_menu_button(self,
                                    s,
                                    constr,
                                    action,
                                    show_img=True,
                                    show_label=True):
     """ Create Author Menu button
     
     :param s: button state
     :param constr: bounding box
     :param action: button event listener
     :param show_img: True - show image, False - don't show image
     :param show_label: True - show label, False - don't show label
     
     :return: genre menu button
     """
     s.bounding_box = constr
     s.img_x = None
     s.img_y = None
     s.auto_update = True
     s.show_bgr = True
     s.show_img = show_img
     s.show_label = show_label
     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
     s.label_text_height = 35
     button = Button(self.util, s)
     button.bgr = self.config[COLORS][COLOR_DARK]
     button.add_release_listener(action)
     return button
Ejemplo n.º 8
0
 def create_menu_button(self, s, constr, action, scale, label_area_percent, label_text_height, show_img=True):
     """ Create Menu button
     
     :param s: button state
     :param constr: scaling constraints
     :param action: button event listener
     :param scale: True - scale images, False - don't scale images
     
     :return: menu button
     """          
     if scale:
         self.set_state_scaled_icons(s, constr)
     s.bounding_box = constr
     s.img_x = None
     s.img_y = None
     s.auto_update = True
     s.show_bgr = True
     s.show_img = show_img
     s.show_label = True
     s.image_location = CENTER
     s.label_location = BOTTOM
     s.label_area_percent = label_area_percent
     s.label_text_height = label_text_height
     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
     button = Button(self.util, s)
     button.bgr = self.config[COLORS][COLOR_DARK]
     button.add_release_listener(action)         
     if getattr(s, "icon_base", False):
         button.components[1].content = s.icon_base
     button.scaled = scale        
     return button
Ejemplo n.º 9
0
 def __init__(self, util, state):
     """ Initializer
     
     :param util: utility object
     :param state: button state
     """
     Button.__init__(self, util, state)
Ejemplo n.º 10
0
    def create_collection_track_menu_button(self,
                                            s,
                                            constr,
                                            action,
                                            show_img=True,
                                            show_label=True):
        """ Create Collection Track Menu button

        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param show_img: True - show button image, False - not
        :param show_label: True - show button label, False - not

        :return: menu button
        """
        s.bounding_box = constr
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.show_bgr = True
        s.show_img = show_img
        s.show_label = show_label
        s.source = TRACK_MENU
        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
        s.wrap_labels = self.config[WRAP_LABELS]

        button = Button(self.util, s)
        button.bgr = self.config[COLORS][COLOR_DARK]
        button.add_release_listener(action)

        return button
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
    def create_latin_abc_menu_button(self, s, constr, action, scale,
                                     font_size):
        """ Create Latin ABC Menu button

        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param show_img: True - show image, False - don't show image
        :param show_label: True - show label, False - don't show label

        :return: menu button
        """
        s.bounding_box = constr
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.show_bgr = True
        s.show_img = False
        s.show_label = 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
        s.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        s.fixed_height = font_size

        button = Button(self.util, s)
        button.add_release_listener(action)

        return button
Ejemplo n.º 13
0
 def __init__(self, util, state):
     """ Initializer
     
     :param util: utility object
     :param states: button states 
     """
     Button.__init__(self, util, state)
     self.pressed = False
     self.cancel_listeners = list()
Ejemplo n.º 14
0
 def __init__(self, util, state):
     """ Initializer
     
     :param util: utility object
     :param states: button states 
     """
     Button.__init__(self, util, state)
     self.pressed = False
     self.cancel_listeners = list()
Ejemplo n.º 15
0
 def __init__(self, util, state, padding=2):
     """ Initializer
     
     :param util: utility object
     :param state: button state 
     """
     self.state = state
     self.config = util.config
     self.padding = padding
     Button.__init__(self, util, self.state)
Ejemplo n.º 16
0
 def __init__(self, util, states):
     """ Initializer
     
     :param util: utility object
     :param states: button states 
     """
     self.states = states
     self.index = 0
     self.state = states[self.index]
     self.name = self.state.name
     self.start_listeners = dict()
     Button.__init__(self, util, self.state)
Ejemplo n.º 17
0
 def __init__(self, util, states):
     """ Initializer
     
     :param util: utility object
     :param states: button states 
     """
     self.states = states
     self.index = 0
     self.state = states[self.index]
     for s in states:
         s.event_origin = self
     self.name = self.state.name
     self.start_listeners = dict()
     Button.__init__(self, util, self.state)
Ejemplo n.º 18
0
 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
Ejemplo n.º 19
0
 def create_arrow_button(self, bb, name, key, location, label_text,
                         image_area, image_size):
     """ 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_LIGHT]
     s.show_bgr = True
     s.show_img = True
     s.show_label = True
     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.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)
     if image_size != 100:
         self.resize_image(s, image_size)
     b = Button(self.util, s)
     return b
Ejemplo n.º 20
0
    def create_menu_button(self, s, constr, action, scale, label_area_percent=30, label_text_height=44, show_img=True, show_label=True, bgr=None, source=None, font_size=None, ignore_bgr_opacity=False):
        """ Create Menu button
        
        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param scale: True - scale image and label, False - don't scale image and label
        
        :return: menu button
        """          
        s.bounding_box = constr
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.show_bgr = True
        s.show_img = show_img and getattr(s, "show_img", True)
        s.show_label = show_label

        if getattr(s, "file_type", None) == FILE_AUDIO and getattr(s, "has_embedded_image", None):
            s.show_label = not self.config[HIDE_FOLDER_NAME]

        if getattr(s, "file_type", None) != None and self.config[HIDE_FOLDER_NAME]:
            s.show_selection = True

        s.image_location = getattr(s, "image_location", TOP)
        s.label_location = getattr(s, "label_location", BOTTOM)
        s.label_area_percent = label_area_percent

        if s.show_img and s.label_area_percent:
            s.image_area_percent = 100 - s.label_area_percent

        s.label_text_height = label_text_height
        s.v_align = getattr(s, "v_align", V_ALIGN_CENTER)
        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
        s.fixed_height = font_size
        s.scale = scale
        s.source = source 

        if bgr:
            s.bgr = bgr
        else:
            if ignore_bgr_opacity:
                s.bgr = self.config[COLORS][COLOR_DARK]
            else:
                s.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]

        button = Button(self.util, s)
        button.add_release_listener(action)
        if not getattr(s, "enabled", True):
            button.set_enabled(False)
        elif getattr(s, "icon_base", False) and not getattr(s, "scaled", False):
            button.components[1].content = s.icon_base
        button.scaled = scale        
        return button
Ejemplo n.º 21
0
    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
Ejemplo n.º 22
0
 def create_menu_button(self,
                        s,
                        constr,
                        action,
                        scale,
                        label_area_percent=30,
                        label_text_height=44,
                        show_img=True,
                        show_label=True,
                        bgr=None,
                        source=None,
                        font_size=None):
     """ Create Menu button
     
     :param s: button state
     :param constr: scaling constraints
     :param action: button event listener
     :param scale: True - scale image and label, False - don't scale image and label
     
     :return: menu button
     """
     s.bounding_box = constr
     s.img_x = None
     s.img_y = None
     s.auto_update = True
     s.show_bgr = True
     s.show_img = show_img and getattr(s, "show_img", True)
     s.show_label = show_label
     s.image_location = CENTER
     s.label_location = BOTTOM
     s.label_area_percent = label_area_percent
     s.label_text_height = label_text_height
     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 font_size:
         s.fixed_height = int(font_size * 0.8)
     s.scale = scale
     s.source = source
     if bgr:
         s.bgr = bgr
     else:
         s.bgr = self.config[COLORS][COLOR_DARK]
     button = Button(self.util, s)
     button.add_release_listener(action)
     if not getattr(s, "enabled", True):
         button.set_enabled(False)
     elif getattr(s, "icon_base",
                  False) and not getattr(s, "scaled", False):
         button.components[1].content = s.icon_base
     button.scaled = scale
     return button
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
    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
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
    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)