Esempio n. 1
0
    def add_label(self, state, bb):
        """ Add button label
        
        :param state: button state
        :param bb: bounding box
        """
        if not self.show_label:
            self.add_component(None)
            return

        fixed_height = getattr(state, "fixed_height", None)
        if fixed_height:
            font_size = fixed_height
        else:
            font_size = int((bb.h * state.label_text_height) / 100.0)

        if font_size > self.config[MAXIMUM_FONT_SIZE]:
            font_size = self.config[MAXIMUM_FONT_SIZE]

        font = self.util.get_font(font_size)
        text = self.truncate_long_labels(state.l_name, bb, font)
        state.l_name = text
        size = font.size(text)
        label = font.render(text, 1, state.text_color_normal)
        c = Component(self.util, label)
        c.name = state.name + ".label"
        c.text = text
        c.text_size = font_size
        c.text_color_normal = state.text_color_normal
        c.text_color_selected = state.text_color_selected
        c.text_color_disabled = state.text_color_disabled
        c.text_color_current = c.text_color_normal

        h_align = getattr(state, H_ALIGN, None)
        if h_align != None:
            if h_align == H_ALIGN_LEFT:
                c.content_x = bb.x
        else:
            c.content_x = bb.x + (bb.width - size[0]) / 2

        v_align = getattr(state, V_ALIGN, None)
        if v_align and v_align == V_ALIGN_TOP:
            v_offset = getattr(state, V_OFFSET, 0)
            if v_offset != 0:
                v_offset = int((bb.height / 100) * v_offset)
                c.content_y = bb.y + v_offset
            else:
                c.content_y = bb.y
        else:
            c.content_y = bb.y + (bb.height - size[1]) / 2 + 1

        if len(self.components) == 2:
            self.components.append(c)
        else:
            self.components[2] = c

        desc = getattr(state, "description", None)
        if desc != None:
            self.add_description(state, desc, c.content_y, size[1], bb,
                                 font_size)
Esempio n. 2
0
    def get_star_component(self, button):
        """ Prepare star icon component for marking
        
        :param button: button to mark
        
        :return: star component
        """
        button_image_comp = button.components[1]
        button_image_x = button_image_comp.content_x
        button_image_y = button_image_comp.content_y
        button_image_size = button_image_comp.content.get_size()
        button_image_w = button_image_size[0]

        c = Component(self.util)
        bb = Rect(0, 0, self.config[SCREEN_INFO][WIDTH],
                  self.config[SCREEN_INFO][HEIGHT])
        r = 1 / 25
        c.content = self.image_util.load_multi_color_svg_icon(
            IMAGE_STAR, bb, r)
        c.bgr = c.fgr = (0, 0, 255)
        c.name = button.state.l_name + ".fav"
        img_w = c.content[1].get_size()[0]
        c.content_x = button_image_x + button_image_w - img_w - 2
        c.content_y = button_image_y + 2

        return c
Esempio n. 3
0
    def create_one_line_label(self, state, bb, font, font_size, text, padding):
        state.l_name = text
        size = font.size(text)

        if getattr(self, "selected", False):
            color = state.text_color_selected
        else:
            color = state.text_color_normal

        label = font.render(text, 1, color)
        c = Component(self.util, label)
        c.name = state.name + ".label"
        c.text = text
        c.text_size = font_size
        c.text_color_normal = state.text_color_normal
        c.text_color_selected = state.text_color_selected
        c.text_color_disabled = state.text_color_disabled
        c.text_color_current = color
        c.content_x = self.get_label_x(state, bb, size, padding)
        c.content_y = self.get_label_y(state, bb, size)

        if len(self.components) == 2:
            self.components.append(c)
        else:
            self.components[2] = c
Esempio n. 4
0
 def add_label(self,
               index,
               label,
               x,
               y,
               text,
               text_size,
               label_type,
               text_width=None):
     """ Add text label to the component list
     
     :param index: label index
     :param label: rendered text
     :param x: X coordinate for new label
     :param y: Y coordinate for new label
     :param text: the text
     :param text_size: text size
     :param label_type: label type (STATIC or ANIMATED)
     :param text_width: the width of the rendered text
     """
     comp = Component(self.util, label)
     comp.label_type = label_type
     comp.name = self.name + ".text." + str(index)
     comp.content_x = x
     comp.content_y = y
     comp.text = text
     comp.text_size = text_size
     comp.fgr = self.fgr
     if text_width:
         comp.text_width = text_width
     self.components.append(comp)
Esempio n. 5
0
 def set_track_time(self, name, time, bb, layer_num):
     """ Set track time
     
     :param name: button state
     :param time: track time
     :param bb: bounding box
     :param layer_num: layer number
     """
     font_size = int((bb.h * 45)/100.0)
     font = self.util.get_font(font_size)
     size = font.size(time)
     label = font.render(time, 1, self.config[COLORS][COLOR_BRIGHT])
     c = Component(self.util, label)
     c.bgr = (255, 0, 0)
     c.name = name
     c.text = time
     c.text_size = font_size
     c.text_color_current = self.config[COLORS][COLOR_BRIGHT]
     c.content_x = bb.x + (bb.width - size[0])/2
     c.content_y = bb.y + (bb.height - size[1])/2 
     self.components[layer_num] = c
     
     if self.visible:    
         self.draw()
         self.update()
Esempio n. 6
0
    def add_description(self, state, desc, title_y, title_h, bb, font_size):
        """ Add podcast description
        
        :param state: button state
        :param desc: description text
        :param title_y: y coordinate
        :param title_h: text height
        :param bb: bounding box
        :param font_size:
        """
        desc_font_size = int(font_size * 0.7)
        font = self.util.get_font(desc_font_size)
        if self.config[SCREEN_INFO][WIDTH] <= 320:
            line_length = 56
        elif self.config[SCREEN_INFO][WIDTH] > 320 and self.config[
                SCREEN_INFO][WIDTH] <= 480:
            line_length = 58
        else:
            line_length = 64
        lines = textwrap.wrap(desc, line_length)

        for n, line in enumerate(lines[0:5]):
            label = font.render(line, 1, state.text_color_normal)
            c = Component(self.util, label)
            c.name = "desc." + str(title_y) + str(n)
            c.text = line
            c.text_size = desc_font_size
            c.text_color_normal = state.text_color_normal
            c.text_color_selected = state.text_color_selected
            c.text_color_disabled = state.text_color_disabled
            c.text_color_current = c.text_color_normal
            c.content_x = bb.x
            c.content_y = title_y + title_h + (n * desc_font_size)
            self.components.append(c)
Esempio n. 7
0
    def draw_tile_header(self, x, y, w, h, fcast):
        """ Draw tile header
        
        :param x: tile x coordinate
        :param y: tile y coordinate
        :param w: tile width
        :param h: tile height
        :param fcast: one day forecast
        """
        height = (h / 100) * TILE_HEADER_HEIGHT
        comp = Component(self.util)
        comp.name = "tile.header." + str(x) + "." + str(y)
        comp.content_x = x
        comp.content_y = y
        rect = pygame.Rect(x, y, w, height)
        comp.content = rect
        comp.fgr = self.semi_transparent_color
        comp.bgr = self.semi_transparent_color
        comp.bounding_box = rect
        self.add_component(comp)

        text_color = self.util.weather_config[COLOR_BRIGHT]
        font_size = int((height / 100) * DAY_HEIGHT)

        if fcast[DAY] == UNKNOWN:
            d = UNKNOWN
        else:
            d = self.weather_config[fcast[DAY].lower()]

        c = self.util.get_text_component(d, text_color, font_size)
        c.name = "th." + str(x) + "." + str(y)
        c.content_x = x + (w - c.content.get_size()[0]) / 2
        c.content_y = y + font_size / 8
        self.add_component(c)
Esempio n. 8
0
 def add_image(self, state, bb):
     """ Add image
     
     :param state: button state
     :param bb: bounding box
     """
     if not state.show_img:
         self.add_component(None)
         return        
     c = Component(self.util)
     c.name = state.name + ".image"
     scaled = getattr(state, "scaled", False)
     
     if scaled:    
         c.content = state.icon_base_scaled                 
     else:
         c.content = state.icon_base[1]
         
     c.image_filename = state.icon_base[0]
     w = c.content.get_size()[0]
     h = c.content.get_size()[1]
     c.content_x = bb.x + (bb.width - w)/2
     c.content_y = bb.y + (bb.height - h)/2
         
     self.add_component(c)
Esempio n. 9
0
    def add_image(self, state, bb):
        """ Add image
        
        :param state: button state
        :param bb: bounding box
        """
        if not state.show_img or getattr(state, "icon_base", None) == None:
            self.add_component(None)
            return
        c = Component(self.util)
        c.name = state.name + ".image"
        scaled = getattr(state, "scaled", False)
        enabled = getattr(state, "enabled", True)

        if not enabled:
            c.content = state.icon_disabled[1]
            c.image_filename = state.icon_disabled[0]
        else:
            if scaled:
                c.content = state.icon_base_scaled
            else:
                c.content = state.icon_base[1]
            c.image_filename = state.icon_base[0]

        w = c.content.get_size()[0]
        h = c.content.get_size()[1]
        c.content_x = bb.x + (bb.width - w) / 2
        c.content_y = bb.y + (bb.height - h) / 2

        self.add_component(c)
Esempio n. 10
0
 def add_label(self, state, bb):
     """ Add button label
     
     :param state: button state
     :param bb: bounding box
     """
     if not self.show_label:
         self.add_component(None)
         return
     font_size = int((bb.h * state.label_text_height)/100.0)
     font = self.util.get_font(font_size)
     text = state.l_name
     size = font.size(text)
     label = font.render(text, 1, state.text_color_normal)
     c = Component(self.util, label)
     c.name = state.name + ".label"
     c.text = text
     c.text_size = font_size
     c.text_color_normal = state.text_color_normal
     c.text_color_selected = state.text_color_selected
     c.text_color_disabled = state.text_color_disabled
     c.text_color_current = c.text_color_normal
     c.content_x = bb.x + (bb.width - size[0])/2
     c.content_y = bb.y + (bb.height - size[1])/2
             
     if len(self.components) == 2:
         self.components.append(c)
     else:
         self.components[2] = c
Esempio n. 11
0
    def add_key(self, x, y, name, key):
        """ Add the key indicating current focus position
        
        :param x: x coordinate
        :param y: y coordinate
        :param name: component name
        :param key: key image
        """
        size = key[1].get_size()
        w = size[0]
        h = size[1]

        cont = Container(self.util)
        cont.bgr = cont.fgr = (0, 0, 0, 0)
        cont.name = name + ".cont"
        c = Component(self.util)
        c.name = name
        c.content = key[1]
        c.bgr = c.fgr = (0, 0, 0, 0)
        c.content_x = x - w / 2
        c.content_y = y
        c.image_filename = key[0]
        c.bounding_box = pygame.Rect(0, 0, w, h)
        cont.bounding_box = pygame.Rect(c.content_x, c.content_y, w, h)

        cont.add_component(c)
        self.add_component(cont)
        return cont
Esempio n. 12
0
    def prepare_label(self):
        """ Prepare label component representing this output text. Used for web. """

        text = self.text
        if text is None:
            return

        if self.obfuscate_flag:
            text = "".join(["\u2022"] * len(self.text))

        if self.font == None:
            return

        size = self.font.size(text)
        label = self.font.render(text, 1, self.fgr)
        comp = Component(self.util, label)
        comp.name = self.name + ".text"
        comp.content_x = self.bounding_box.x + self.get_x(size)
        comp.content_y = self.bounding_box.y + self.get_y(size)
        comp.text = text
        comp.text_size = self.default_font_size
        comp.fgr = self.fgr

        if len(self.components) == 1:
            self.add_component(comp)
        else:
            self.components[1] = comp
Esempio n. 13
0
    def add_page(self, page_num, page):
        """ Add lyrics page to the container
        
        :param page_num: lyrics page number
        :param page: lyrics page 
        """
        cont = Container(self.util, self.bounding_box, (0, 0, 0))
        max_line_length = self.get_max_line_length(page)
        s = self.f.size("W")
        page_height = self.lines * s[1]
        offset_y = (self.screen_h - page_height) / 2
        offset_x = (self.screen_w - max_line_length) / 2

        for n, line in enumerate(page):
            c = Component(self.util, bgr=(0, 0, 0))
            str_size = self.f.size(line)
            if page_num == 0 and n == 0:
                color = self.config[COLORS][COLOR_BRIGHT]
            else:
                color = self.config[COLORS][COLOR_CONTRAST]
            img = self.f.render(line, 1, color)
            name = GENERATED_IMAGE + str(n)
            c.content = (name, img)
            c.name = name
            c.image_filename = name
            c.content_y = offset_y + (str_size[1] * n)
            c.content_x = offset_x
            cont.add_component(c)
        self.add_component(cont)
Esempio n. 14
0
    def add_label(self, state, bb):
        """ Add button label
        
        :param state: button state
        :param bb: bounding box
        """
        if not self.show_label:
            self.add_component(None)
            return
        font_size = int(state.label_text_height)
        font = self.util.get_font(font_size)

        label = state.l_name

        text = self.truncate_long_labels(label, bb, font)
        size = font.size(text)
        rendered_label = font.render(text, 1, self.text_color_normal)
        c = Component(self.util, rendered_label)
        c.name = label + ".label"
        c.text = text
        c.text_size = font_size
        c.text_color_normal = self.text_color_normal
        c.text_color_selected = self.text_color_selected
        c.text_color_disabled = self.text_color_disabled
        c.text_color_current = c.text_color_normal
        c.content_x = bb.x + (bb.width - size[0]) / 2
        c.content_y = bb.y + (bb.height - size[1]) / 2 + self.padding * 1.5
        self.components.append(c)
Esempio n. 15
0
    def __init__(self, util, digits, digit, bb, increment_listener,
                 decrement_listener, name):
        """ Initializer
        
        :param util: utility object
        :param digits: clock digits 0-9
        :param digit: the digit
        :param bb: digit bounding box
        :param increment_listener: increment listener
        :param decrement_listener: decrement listener
        :param name: component name
        """
        self.util = util
        self.config = self.util.config
        EventContainer.__init__(self, util, bb)
        self.digits = digits
        self.digit = digit
        image = self.digits[self.digit][1]

        c = Component(self.util)
        c.name = name
        c.image_filename = self.digits[self.digit][0]
        c.content = image
        c.content_x = bb.x
        c.content_y = bb.y

        self.add_component(c)

        top = Rect(bb.x, bb.y, bb.w, bb.h / 2)
        self.add_area_listener((top, increment_listener))
        bottom = Rect(bb.x, bb.y + (bb.h / 2) + 1, bb.w, bb.h / 2)
        self.add_area_listener((bottom, decrement_listener))
Esempio n. 16
0
    def create_two_lines_label(self, state, bb, font, font_size, text,
                               text_with_ellipses, padding):
        length = len(text_with_ellipses) - 3
        first_line = text[0:length]
        if first_line:
            first_line = first_line.strip()
        second_line = self.truncate_long_labels(text[length:], bb, font)
        if second_line:
            second_line = second_line.strip()

        size = font.size(first_line)
        label = font.render(first_line, 1, state.text_color_normal)
        c = Component(self.util, label)
        c.name = first_line + ".label"
        c.text = first_line
        c.text_size = font_size
        c.text_color_normal = state.text_color_normal
        c.text_color_selected = state.text_color_selected
        c.text_color_disabled = state.text_color_disabled
        c.text_color_current = c.text_color_normal
        c.content_x = self.get_label_x(state, bb, size, padding)
        padding = (bb.h / 100) * 5
        c.content_y = bb.y + padding
        if len(self.components) == 2:
            self.components.append(c)
        else:
            self.components[2] = c
        x = c.content_x

        f_size = font_size - int((font_size / 100) * 20)
        f = self.util.get_font(f_size)
        s = font.size(second_line)
        label = f.render(second_line, 1, state.text_color_disabled)
        c = Component(self.util, label)
        c.name = second_line + ".label"
        c.text = second_line
        c.text_size = f_size
        c.text_color_normal = state.text_color_disabled
        c.text_color_selected = state.text_color_selected
        c.text_color_disabled = state.text_color_disabled
        c.text_color_current = c.text_color_disabled
        c.content_x = x
        c.content_y = padding * 2 + bb.y + s[1] - s[1] / 3
        self.components.append(c)
Esempio n. 17
0
 def get_shadow(self):
     """ Return the button shadow component
     
     :return: shadow component
     """
     c = Component(self.util, self.shadow[1])
     c.name = "station_menu.shadow"
     c.image_filename = self.shadow[0]
     c.content_x = self.bounding_box.x
     c.content_y = self.bounding_box.y
     return c
Esempio n. 18
0
 def get_shadow(self):
     """ Return the button shadow component
     
     :return: shadow component
     """
     c = Component(self.util, self.shadow[1])
     c.name = "station_menu.shadow"
     c.image_filename = self.shadow[0]
     w = self.shadow[1].get_size()[0]
     h = self.shadow[1].get_size()[1]    
     c.content_x = self.bounding_box.x + self.bounding_box.w/2 - w/2
     c.content_y = self.bounding_box.y + self.bounding_box.h/2 - h/2
     return c
Esempio n. 19
0
 def add_image(self, image, x, y, rect=None):
     """ Create new UI component from provided image and add it to the UI container.
     
     :param image: the image object
     :param x: x coordinate of the image top left corner
     :param y: y coordinate of the image top left corner
     :param rect: bounding rectangle of the image
     """               
     c = Component(self.util)
     c.content = image
     c.content_x = x
     c.content_y = y
     if rect: c.bounding_box = rect
     self.add_component(c)
     return c
Esempio n. 20
0
 def add_background(self, state):
     """ Add button background bounding box
     
     :param state: button state
     """
     if not state.show_bgr:
         self.add_component(None)
         return
     c = Component(self.util)
     c.name = state.name + ".bgr"
     c.content = state.bounding_box
     c.bgr = c.fgr = getattr(state, "bgr", (0, 0, 0))
     c.content_x = state.bounding_box.x
     c.content_y = state.bounding_box.y
     self.add_component(c)
Esempio n. 21
0
 def draw_background(self, x, y, w, h):
     """ Draw background defined by input parameters
     
     :param x: x coordinate
     :param y: y coordinate
     :param w: width
     :param h: height
     """
     c = Component(self.util)
     c.name = "today.bgr"
     c.content = pygame.Rect(x, y, w, h)
     c.content_x = x
     c.content_y = y
     c.bounding_box = c.content
     c.bgr = self.semi_transparent_color
     self.add_component(c)
Esempio n. 22
0
    def draw_weather(self):
        """ Draw weather forecast  """

        Container.__init__(self, self.util, self.rect, BLACK)

        c = Component(self.util)
        c.name = "forecast.bgr"
        c.content = self.initial_image
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = self.rect
        self.add_component(c)

        widths = self.get_widths()
        heights = self.get_heights()

        self.draw_tiles(widths, heights)
Esempio n. 23
0
    def add_selection(self, state, bb):
        if not self.selected:
            return

        border = 2
        c = Component(self.util, t=border)
        c.name = state.name + ".selection"
        x = state.bounding_box.x + border / 2
        y = state.bounding_box.y + border / 2
        w = state.bounding_box.w - border
        h = state.bounding_box.h - border
        c.content = pygame.Rect(x, y, w, h)
        c.bgr = state.text_color_selected
        c.fgr = (0, 0, 0, 0)

        c.content_x = state.bounding_box.x
        c.content_y = state.bounding_box.y
        self.add_component(c)
Esempio n. 24
0
 def prepare_label(self):
     """ Prepare label component representing this output text. Used for web. """
     
     if self.text == None:
         return            
     size = self.font.size(self.text)
     label = self.font.render(self.text, 1, self.fgr)
     comp = Component(self.util, label)
     comp.name = self.name + ".text"
     comp.content_x = self.bounding_box.x + self.get_x(size)
     comp.content_y = self.bounding_box.y + self.get_y(size)
     comp.text = self.text
     comp.text_size = self.default_font_size
     comp.fgr = self.fgr
     if len(self.components) == 1:
         self.add_component(comp)
     else:
         self.components[1] = comp
Esempio n. 25
0
 def draw_image(self, image, x, y, container, rect, name):
     """ Draw background defined by input parameters
     
     :param image: image to draw
     :param x: x coordinate
     :param y: y coordinate
     :param container: container to which image will be added
     :param rect: bounding box
     :param name: component name
     """
     c = Component(self)
     c.name = name
     c.content = image
     c.content_x = rect.x
     c.content_y = rect.y
     c.image_filename = c.name
     c.bounding_box = rect
     container.add_component(c)
     return c
Esempio n. 26
0
    def add_background(self, state):
        """ Add button background bounding box
        
        :param state: button state
        """
        if not state.show_bgr:
            self.add_component(None)
            return
        c = Component(self.util)
        c.name = state.name + ".bgr"
        c.content = state.bounding_box
        c.bgr = c.fgr = getattr(state, "bgr", (0, 0, 0))

        c.content_x = state.bounding_box.x
        c.content_y = state.bounding_box.y
        if len(self.components) > 0:
            self.components[0] = c
        else:
            self.add_component(c)
Esempio n. 27
0
 def get_selection_frame(self, button):
     """ Create the selection frame used in Page mode
     
     :param button: button for which the selection frame should be created
     
     :return: selection frame component
     """
     x = button.components[0].content.x
     y = button.components[0].content.y
     w = button.components[0].content.w
     h = button.components[0].content.h
     i = self.image_util.scale_image(self.selection[1], (w, h))
     c = Component(self.util, i)
     c.content_x = x
     c.content_y = y
     c.name = "station_menu.selection"
     c.image_filename = self.selection[0]
     c.visible = False
     c.selection_index = button.state.index_in_page
     return c
Esempio n. 28
0
 def get_selection_frame(self, button):
     """ Create the selection frame used in Page mode
     
     :param button: button for which the selection frame should be created
     
     :return: selection frame component
     """
     x = button.components[0].content.x
     y = button.components[0].content.y
     w = button.components[0].content.w
     h = button.components[0].content.h
     i = self.util.scale_image(self.selection[1], (w, h))
     c = Component(self.util, i)
     c.content_x = x
     c.content_y = y
     c.name = "station_menu.selection"
     c.image_filename = self.selection[0]
     c.visible = False
     c.selection_index = button.state.index_in_page
     return c
Esempio n. 29
0
    def draw_weather(self):
        """ Draw Today's weather """

        Container.__init__(self, self.util, self.rect, BLACK)

        c = Component(self.util)
        c.name = "today"
        c.content = self.initial_image
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = self.rect
        self.add_component(c)

        top_height = self.draw_top_background()
        self.draw_bottom_background()
        self.draw_city(top_height)
        self.draw_time(top_height)
        self.draw_code()
        self.draw_temp()
        self.draw_high_low()
        self.draw_details()
Esempio n. 30
0
 def draw_tile_body(self, x, y, w, h, fcast):
     """ Draw center part of the tile
     
     :param x: tile x coordinate
     :param y: tile y coordinate
     :param w: tile width
     :param h: tile height
     :param fcast: one day forecast
     """
     top_height = (h / 100) * TILE_HEADER_HEIGHT
     y += top_height
     h = h - top_height + 1
     comp = Component(self.util)
     comp.name = "tile.body" + str(x) + "." + str(y)
     comp.content_x = x
     comp.content_y = y
     rect = pygame.Rect(x, y, w, h)
     comp.content = rect
     comp.fgr = self.util.weather_config[COLOR_BRIGHT]
     comp.bgr = self.util.weather_config[COLOR_BRIGHT]
     comp.bounding_box = rect
     self.add_component(comp)
Esempio n. 31
0
    def draw_high_low(self):
        """ Draw high/low today's temperatures """

        bb_x = self.temp_right_edge
        bb_y = int((self.rect.h / 100) * TOP_HEIGHT)
        bb_w = self.rect.w - bb_x
        bb_h = self.rect.h - bb_y - int((self.rect.h / 100) * BOTTOM_HEIGHT)
        text_color = self.util.weather_config[COLOR_CONTRAST]
        font_size = int((bb_w / 100) * HIGH_LOW_TEXT_SIZE)

        c = self.util.get_text_component(self.high, text_color, font_size)
        c.name = "high"
        w = c.content.get_size()[0]
        h = c.content.get_size()[1]
        c.content_x = bb_x + int((bb_w - w) / 2)
        c.content_y = bb_y + int((bb_h - h) / 2) - (font_size / 2)
        self.add_component(c)

        c = self.util.get_text_component(self.low, text_color, font_size)
        c.name = "low"
        w = c.content.get_size()[0]
        h = c.content.get_size()[1]
        c.content_x = bb_x + int((bb_w - w) / 2)
        c.content_y = bb_y + int((bb_h - h) / 2) + (font_size / 1.4)
        self.add_component(c)

        x = c.content_x
        y = bb_y + int(bb_h / 2)
        w = c.content.get_size()[0]
        h = 2
        r = pygame.Rect(x, y, w, h)
        c = Component(self.util, r)
        c.name = "sep" + ".text"
        c.content_x = 0
        c.content_y = 0
        c.fgr = text_color
        c.bgr = text_color
        self.add_component(c)
Esempio n. 32
0
 def add_label(self, index, label, x, y, text, text_size, label_type, text_width=None):
     """ Add text label to the component list
     
     :param index: label index
     :param label: rendered text
     :param x: X coordinate for new label
     :param y: Y coordinate for new label
     :param text: the text
     :param text_size: text size
     :param label_type: label type (STATIC or ANIMATED)
     :param text_width: the width of the rendered text
     """
     comp = Component(self.util, label)
     comp.label_type = label_type
     comp.name = self.name + ".text." + str(index)
     comp.content_x = x
     comp.content_y = y
     comp.text = text
     comp.text_size = text_size
     comp.fgr = self.fgr
     if text_width:
         comp.text_width = text_width
     self.components.append(comp)
Esempio n. 33
0
    def set_labels(self, name, v, bb, layer_num):
        font_size = int((bb.h * 45) / 100.0)
        font = self.util.get_font(font_size)
        size = font.size(v)
        label = font.render(v, 1, self.config[COLORS][COLOR_BRIGHT])
        c = Component(self.util, label)
        c.bgr = (255, 0, 0)
        c.name = name
        c.text = v
        c.text_size = font_size
        c.text_color_current = self.config[COLORS][COLOR_BRIGHT]
        c.content_x = bb.x + (bb.width - size[0]) / 2
        c.content_y = bb.y + (bb.height - size[1]) / 2
        self.components[layer_num] = c

        if self.visible:
            self.draw()
            self.update()

            if self.use_web and getattr(self, "web_seek_listener", None):
                s = State()
                s.event_origin = self
                s.seek_time_label = v
                self.web_seek_listener(s)
Esempio n. 34
0
    def add_description(self, state, desc, title_y, title_h, bb, font_size):
        """ Add episode description
        
        :param state: button state
        :param desc: description text
        :param title_y: y coordinate
        :param title_h: text height
        :param bb: bounding box
        :param font_size:
        """
        if self.config[SCREEN_INFO][WIDTH] <= 320:
            desc_font_size = int(font_size * 0.8)
            line_length = 52
        else:
            desc_font_size = int(font_size * 0.7)
            line_length = 70

        lines = textwrap.wrap(desc, line_length)
        font = self.util.get_font(desc_font_size)

        for n, line in enumerate(lines[0:3]):
            try:
                label = font.render(line, 1, state.text_color_normal)
            except:
                continue
            c = Component(self.util, label)
            c.name = "desc." + str(title_y) + str(n)
            c.text = line
            c.text_size = desc_font_size
            c.text_color_normal = state.text_color_normal
            c.text_color_selected = state.text_color_selected
            c.text_color_disabled = state.text_color_disabled
            c.text_color_current = c.text_color_normal
            c.content_x = bb.x
            c.content_y = title_y + (title_h * 0.8) + (n * desc_font_size)
            self.components.append(c)
Esempio n. 35
0
    def __init__(self,
                 util,
                 name,
                 bgr,
                 slider_color,
                 img_knob,
                 img_knob_on,
                 img_selected,
                 key_incr,
                 key_decr,
                 key_knob,
                 bb,
                 knob_selected=False,
                 rest_commands=[]):
        """ 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 img_selected: knob image in selected 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.content = None
        if bb.h > bb.w:
            self.orientation = VERTICAL
        else:
            self.orientation = HORIZONTAL
        self.util = util
        self.name = name
        self.img_knob = img_knob[1]
        self.img_knob_on = img_knob_on[1]
        self.img_selected = img_selected
        self.rest_commands = rest_commands

        self.knob_width = self.img_knob.get_size()[0]
        self.knob_height = self.img_knob.get_size()[1]
        self.knob_filename = img_knob[0]
        self.knob_on_filename = img_knob_on[0]
        self.dragging = False
        self.initial_level = 0
        self.check_pause = True
        self.handle_knob_events = True

        self.selected = False
        if knob_selected:
            self.selected = knob_selected
            self.current_img = self.img_selected[1]
        else:
            self.current_img = self.img_knob

        self.current_filename = self.knob_filename
        self.clicked = False
        self.press_listeners = list()
        self.slide_listeners = list()
        self.knob_listeners = list()
        self.motion_listeners = list()
        pygame.key.set_repeat(50, 10)
        self.step = 10
        self.key_incr = key_incr
        self.key_decr = key_decr
        self.key_knob = key_knob
        h = self.current_img.get_size()[1]

        if self.orientation == HORIZONTAL:
            slider_x = self.bounding_box.x + self.knob_width / 2
            slider_y = self.bounding_box.y + self.bounding_box.height / 2
            slider_width = self.bounding_box.width - self.knob_width
            slider_height = 1
            self.slider = pygame.Rect(slider_x, slider_y, slider_width,
                                      slider_height)
            self.slider_max_x = self.bounding_box.x + self.bounding_box.width - self.knob_width / 2
            self.slider_min_x = self.bounding_box.x + self.knob_width / 2
            self.slide_increment = (self.slider_max_x -
                                    self.slider_min_x) / 100.0
            self.last_knob_position = bb.x
            self.knob_y = self.bounding_box.y + self.bounding_box.height / 2 - self.knob_height / 2
        else:
            slider_x = self.bounding_box.x + self.bounding_box.width / 2 - 1
            slider_y = self.bounding_box.y + self.knob_height / 2
            slider_width = 1
            slider_height = self.bounding_box.height - self.knob_height
            self.slider = pygame.Rect(slider_x, slider_y, slider_width,
                                      slider_height)
            self.slider_max_y = self.bounding_box.y + self.bounding_box.height - self.knob_height / 2
            self.slider_min_y = self.bounding_box.y + self.knob_height / 2
            self.slide_increment = (self.slider_max_y -
                                    self.slider_min_y) / 100.0
            self.last_knob_position = bb.y + bb.h - self.knob_height
            self.knob_x = self.bounding_box.x + self.bounding_box.width / 2 - self.knob_width / 2

        comp = Component(self.util, self.bounding_box)
        comp.name = self.name + ".bgr"
        comp.bgr = bgr
        self.add_component(comp)

        comp = Component(self.util, self.slider)
        comp.name = self.name + ".slider"
        comp.thickness = 1
        comp.content_x = slider_x
        comp.content_y = slider_y
        comp.bgr = slider_color
        self.add_component(comp)

        comp = Component(self.util, self.current_img)
        comp.name = self.name + ".knob"

        if self.orientation == HORIZONTAL:
            comp.content_x = bb.x
            comp.content_y = bb.y + (bb.h - h) / 2 + 1
        else:
            comp.content_x = self.knob_x
            comp.content_y = self.last_knob_position

        comp.image_filename = self.knob_filename
        self.add_component(comp)
Esempio n. 36
0
 def __init__(self, util, name, bgr, slider_color, img_knob, img_knob_on, img_selected, 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 img_selected: knob image in selected 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.name = name
     self.img_knob = img_knob[1]
     self.img_knob_on = img_knob_on[1]
     self.img_selected = img_selected
     self.knob_width = self.img_knob.get_size()[0]
     self.knob_height = self.img_knob.get_size()[1]
     self.knob_filename = img_knob[0]
     self.knob_on_filename = img_knob_on[0]
     self.selected = False
     self.dragging = False
     self.initial_level = 0
     self.current_img = self.img_knob
     self.current_filename = self.knob_filename
     self.clicked = False
     self.press_listeners = list()
     self.slide_listeners = list()
     self.knob_listeners = list()
     self.motion_listeners = list()
     pygame.key.set_repeat(50, 10)
     self.step = 10
     self.key_incr = key_incr
     self.key_decr = key_decr
     self.key_knob = key_knob
     slider_x = self.knob_width/2
     self.bounding_box.h += 1
     slider_y = self.bounding_box.y + self.bounding_box.height - self.bounding_box.height/2
     slider_width = self.bounding_box.width - self.knob_width
     slider_height = 2
     self.slider = pygame.Rect(slider_x, slider_y, slider_width, slider_height)
     self.slider_max_x = self.bounding_box.width - self.knob_width/2
     self.slider_min_x = self.knob_width/2
     self.slide_increment = (self.slider_max_x - self.slider_min_x)/100.0
     self.last_knob_position = (int)(self.initial_level * self.slide_increment)
     self.knob_y = self.bounding_box.y + self.bounding_box.height/2 - self.knob_height/2
     self.event_source_local = True 
     
     comp = Component(self.util, self.bounding_box)
     comp.name = self.name + ".bgr"
     comp.bgr = bgr
     self.add_component(comp)
     
     comp = Component(self.util, self.slider)
     comp.name = self.name + ".slider"
     comp.thickness = 1
     comp.content_x = slider_x
     comp.content_y = slider_y
     comp.bgr = slider_color
     self.add_component(comp)
     
     comp = Component(self.util, self.current_img)
     comp.name = self.name + ".knob"
     h = self.current_img.get_size()[1]
     comp.content_y = bb.y + (bb.h - h)/2
     comp.image_filename = self.knob_filename
     self.add_component(comp)
Esempio n. 37
0
    def __init__(self,
                 items,
                 util,
                 bounding_box,
                 update_parent,
                 callback,
                 default_selection=None):
        """ Initializer

        :param items: list of item names
        :param util: utility object
        :param bounding_box: bounding box
        :param update_parent: redraw parent function
        :param callback: menu selection callback
        """
        Container.__init__(self, util, bounding_box, (0, 0, 0))
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        self.update_parent = update_parent
        self.callback = callback
        self.popup = True

        c = Component(self.util)
        w = self.config[SCREEN_INFO][WIDTH]
        h = self.config[SCREEN_INFO][HEIGHT]
        c.content = pygame.Rect(0, 0, w, h)
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = c.content
        c.bgr = (0, 0, 0, 0)
        c.name = "popup.overlay.bgr"
        c.handle_event = self.handle_outside_event
        self.add_component(c)

        c = Component(self.util)
        c.content = pygame.Rect(bounding_box.x, bounding_box.y, bounding_box.w,
                                bounding_box.h - 1)
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = c.content
        c.bgr = self.config[COLORS][COLOR_BRIGHT]
        c.name = "popup.bgr"
        self.add_component(c)

        self.cols = 1
        self.rows = len(items)

        m = self.create_popup_menu_button
        b = pygame.Rect(bounding_box.x, bounding_box.y, bounding_box.w,
                        bounding_box.h - 2)
        self.menu = Menu(util,
                         None,
                         b,
                         self.rows,
                         self.cols,
                         create_item_method=m)

        layout = GridLayout(self.menu.bb)
        layout.set_pixel_constraints(self.rows, self.cols, 1, 1)
        bounding_box = layout.get_next_constraints()
        self.modes = self.util.load_menu(items,
                                         NAME, [],
                                         V_ALIGN_TOP,
                                         bb=bounding_box,
                                         scale=IMAGE_SCALE)

        if not default_selection:
            selection = self.modes[items[0]]
        else:
            selection = self.modes[default_selection]

        self.menu.set_items(self.modes, 0, self.select_item, False)
        self.menu.visible = False
        self.menu.item_selected(selection)
        self.add_component(self.menu)

        self.redraw_observer = None
        self.clicked = False
        self.visible = False
Esempio n. 38
0
    def __init__(self, util, name, time_key, digits, bb, timer_lock,
                 clock_change_callback, change_codes):
        """ Initializer
        
        :param util: utility object
        :param name: component name
        :param time_key: key of the clock time in configuration
        :param digits: images of the clock digits 0-9
        :param bb: clock bounding box
        :param gap: gap between hours and minutes
        :param icon_size: size of the button icon size
        :param timer_lock: lock object
        :param clock_change_callback: callback function
        :param change_codes: codes for increment and decrement for hours and minutes 
        """
        self.util = util
        self.name = name
        self.timer_lock = timer_lock
        self.clock_change_callback = clock_change_callback
        self.config = self.util.config
        Container.__init__(self, util)
        self.content = None
        self.clock_bb = bb
        self.bounding_box = bb.LEFT
        size = digits[0][1].get_size()
        self.digit_w = size[0]
        self.digit_h = size[1]
        separator = util.image_util.get_flipclock_separator(self.digit_h / 3)
        self.shift_x = 2
        border_x = bb.RIGHT.x
        self.change_codes = change_codes
        self.change_listeners = []

        r = pygame.Rect(bb.x, bb.y + 1, border_x, bb.h - 1)
        c = Component(self.util, r, bb=bb)
        c.name = name + ".bgr"
        c.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.add_component(c)

        size = separator[1].get_size()
        w = size[0]
        h = size[1]
        c = Component(self.util)
        c.name = name + ".separator"
        c.content = separator
        separator_x = (border_x / 2) - (w / 2)
        separator_y = bb.y + (bb.h / 2) - (h / 2)
        c.content_x = separator_x
        c.content_y = separator_y
        self.add_component(c)

        self.time_key = time_key
        current_time = datetime.now().strftime("%H%M")
        try:
            self.time = self.config[TIMER][time_key]
        except:
            self.time = current_time

        if len(self.time.strip()) == 0:
            self.time = current_time
            with self.timer_lock:
                self.config[TIMER][self.time_key] = self.time

        h1_x = separator_x - (self.digit_w * 2) - w
        h1_n = name + ".h1"
        self.h1 = self.add_digit(digits, int(self.time[0]), h1_x,
                                 self.increment_hours, self.decrement_hours,
                                 h1_n)

        h2_x = separator_x - self.digit_w - w
        h2_n = name + ".h2"
        self.h2 = self.add_digit(digits, int(self.time[1]), h2_x,
                                 self.increment_hours, self.decrement_hours,
                                 h2_n)

        m1_x = separator_x + w * 2
        m1_n = name + ".m1"
        self.m1 = self.add_digit(digits, int(self.time[2]), m1_x,
                                 self.increment_minutes,
                                 self.decrement_minutes, m1_n)

        m2_x = separator_x + self.digit_w + w * 2
        m2_n = name + ".m2"
        self.m2 = self.add_digit(digits, int(self.time[3]), m2_x,
                                 self.increment_minutes,
                                 self.decrement_minutes, m2_n)

        key_height = self.digit_h
        self.top_image = util.image_util.get_flipclock_key(
            "key-top.png", key_height)
        self.bottom_image = util.image_util.get_flipclock_key(
            "key-bottom.png", key_height)
        self.top_image_on = util.image_util.get_flipclock_key(
            "key-top-on.png", key_height)
        self.bottom_image_on = util.image_util.get_flipclock_key(
            "key-bottom-on.png", key_height)

        y = self.clock_bb.y + (self.clock_bb.h / 2) - (self.digit_h / 2)
        self.h_top = self.add_key(h2_x, y, h2_n + ".top.key", self.top_image)
        self.m_top = self.add_key(m2_x, y, m2_n + ".top.key", self.top_image)

        y = self.clock_bb.y + (self.clock_bb.h / 2) - (
            self.digit_h /
            2) + self.digit_h - self.bottom_image[1].get_size()[1]
        self.h_bottom = self.add_key(h2_x, y, h2_n + ".bottom.key",
                                     self.bottom_image)
        self.m_bottom = self.add_key(m2_x, y, m2_n + ".bottom.key",
                                     self.bottom_image)

        self.selected_key = None