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.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.content_x = x + (w - c.content.get_size()[0]) / 2 c.content_y = y + font_size / 8 self.add_component(c)
def add_image(self, image, x, y, rect=None): """ Creates new UI component from provided image and adds 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 = rect.x c.content_y = rect.y if rect: c.bounding_box = rect self.add_component(c) return c
def add_image(self, image, x, y, rect=None): """ Creates new UI component from provided image and adds 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
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.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)
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) 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)
def draw_image(self, image, x, y, container, rect=None): """ 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 """ c = Component(self) c.content = image c.content_x = x c.content_y = y if rect: c.bounding_box = rect container.add_component(c) return c
def draw_weather(self): """ Draw weather forecast """ c = self.util.weather_config[COLOR_DARK] Container.__init__(self, self.util, self.rect, BLACK) c = Component(self.util) 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)
def draw_weather(self): """ Draw Today's weather """ Container.__init__(self, self.util, self.rect, BLACK) c = Component(self.util) 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()
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.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)