示例#1
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)
示例#2
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
示例#3
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)
示例#4
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
示例#5
0
 def draw_separator(self, x, y, w, h):
     """ Draw tile separator
     
     :param x: tile x coordinate
     :param y: tile y coordinate
     :param w: tile width
     :param h: tile height
     """
     height = (h / 100) * TILE_HEADER_HEIGHT
     comp = Component(self.util)
     comp.name = "sep." + str(x) + "." + str(y)
     rect = pygame.Rect(x + w, y + height, 1, h - height + 2)
     comp.content = rect
     comp.fgr = self.util.weather_config[COLOR_DARK_LIGHT]
     comp.bgr = self.util.weather_config[COLOR_DARK_LIGHT]
     comp.bounding_box = rect
     self.add_component(comp)
示例#6
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)
示例#7
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
示例#8
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)
示例#9
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)
示例#10
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)