示例#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 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
示例#3
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
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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
示例#8
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()
示例#9
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)
示例#10
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