コード例 #1
0
ファイル: multilinebutton.py プロジェクト: whenthelight/Peppy
    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)
コード例 #2
0
ファイル: podcastbutton.py プロジェクト: whenthelight/Peppy
    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)
コード例 #3
0
ファイル: outputtext.py プロジェクト: GregoryWest501/Peppy
    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
コード例 #4
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()
コード例 #5
0
ファイル: podcastbutton.py プロジェクト: whenthelight/Peppy
    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)
コード例 #6
0
ファイル: button.py プロジェクト: GregoryWest501/Peppy
    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
コード例 #7
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)
コード例 #8
0
ファイル: button.py プロジェクト: project-owner/Peppy
 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
コード例 #9
0
ファイル: button.py プロジェクト: GregoryWest501/Peppy
    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)
コード例 #10
0
 def get_text_component(self, text, fgr, font_height):
     """ Create text component using supplied parameters
     
     :param text: text
     :param fgr: text color
     :param font_height: font height
     
     :return: text component
     """
     self.font = self.get_font(font_height)
     label = self.font.render(text, 1, fgr)
     comp = Component(self, label)
     comp.text = text
     comp.text_size = font_height
     comp.fgr = fgr
     return comp
コード例 #11
0
ファイル: outputtext.py プロジェクト: project-owner/Peppy
 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
コード例 #12
0
ファイル: dynamictext.py プロジェクト: project-owner/Peppy
 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)
コード例 #13
0
ファイル: episodebutton.py プロジェクト: thekismet/Peppy
    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)
コード例 #14
0
ファイル: equalizerslider.py プロジェクト: whenthelight/Peppy
    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)