Beispiel #1
0
class WeatherModule(BaseModule):

    def __init__(self,evManager,viewContainer):

        super().__init__(evManager,viewContainer)

        self.name = "WeatherModule"
        self.moduleRect = pygame.Rect(280,50,190,145)
        self.color = Config.BLUE_COLOR
        self.viewContainer = viewContainer



    def drawModule(self,surface):
        self.weatherButton = Button(self.evManager,"WeatherView", self.viewContainer)
        self.weatherButton.create_button(surface,Config.BLUE_COLOR,280,50,190,145)
        self.drawWeatherInfo(surface)
        pygame.display.flip()

    def drawWeatherInfo(self,surface):
        weather = WeatherModel()
        currentWeather = weather.getCurrentWeather()

        font = pygame.font.Font("fonts/Verdana.ttf", 30)
        font.set_bold(True)

        tempText = "%sºC" % currentWeather["temp"]
        temp = font.render(tempText, True, Config.WHITE_COLOR)

        font = pygame.font.Font("fonts/Verdana.ttf", 12)
        font.set_bold(True)
        windText = "%s Km/h" % currentWeather["wind"]
        wind = font.render(windText, True, Config.WHITE_COLOR)

        tempRect = temp.get_rect()
        tempRect.x = 375
        tempRect.y = 90
        surface.blit(temp,tempRect)

        windRect = wind.get_rect()
        windRect.x = self.moduleRect.centerx - (windRect.width / 2) - 10
        windRect.y = 160
        surface.blit(wind,windRect)

        imageCompass = pygame.image.load("images/minicompass.png").convert_alpha()
        surface.blit(imageCompass,(windRect.x + windRect.width + 5,windRect.y-8))

        imageWeatherName = "images/weather%i.png" % currentWeather["sky"]
        imageWeather = pygame.image.load(imageWeatherName).convert_alpha()
        surface.blit(imageWeather,(self.moduleRect.x + 15,self.moduleRect.y + 20))
Beispiel #2
0
    def drawMenuOption(self, index):
        font = pygame.font.Font("fonts/Verdana.ttf", 18)
        font.set_bold(True)
        textOption = self.menuOptions[index][1]
        option = font.render(textOption, True, Config.WHITE_COLOR)
        optionRect = option.get_rect()
        optionRect.x = self.menuRect.x + 10
        optionRect.y = self.menuRect.y + (optionRect.height * ((3 * index / 2) + 1)) + 70

        option = Button(self.evManager, self.menuOptions[index][0], self.name, index)
        option.subView = True
        option.create_button(self.window, self.color, optionRect.x, optionRect.y, optionRect.width, optionRect.height)
        option.write_text(
            self.window,
            self.menuOptions[index][1],
            Config.WHITE_COLOR,
            Button.LEFT_MIDDLE,
            18,
            optionRect.width,
            optionRect.height,
            optionRect.x,
            optionRect.y,
        )
        self.menuOptionsButtons.append(option)
Beispiel #3
0
class GeneralView(BaseView):
    def __init__(self, evManager, name):
        super().__init__(evManager)
        self.name = name
        self.menuRect = pygame.Rect(10, 10, 145, 300)
        self.menuOptions = []
        self.menuOptionsButtons = []
        self.icon = None

    def drawRect(self):
        pass

    def drawMenu(self):
        self.drawIcon()
        for index in range(len(self.menuOptions)):
            self.drawMenuOption(index)

    def drawMenuOption(self, index):
        font = pygame.font.Font("fonts/Verdana.ttf", 18)
        font.set_bold(True)
        textOption = self.menuOptions[index][1]
        option = font.render(textOption, True, Config.WHITE_COLOR)
        optionRect = option.get_rect()
        optionRect.x = self.menuRect.x + 10
        optionRect.y = self.menuRect.y + (optionRect.height * ((3 * index / 2) + 1)) + 70

        option = Button(self.evManager, self.menuOptions[index][0], self.name, index)
        option.subView = True
        option.create_button(self.window, self.color, optionRect.x, optionRect.y, optionRect.width, optionRect.height)
        option.write_text(
            self.window,
            self.menuOptions[index][1],
            Config.WHITE_COLOR,
            Button.LEFT_MIDDLE,
            18,
            optionRect.width,
            optionRect.height,
            optionRect.x,
            optionRect.y,
        )
        self.menuOptionsButtons.append(option)

    def drawView(self):
        self.emptyScreen()
        self.drawRect()
        self.drawBackButton(self.window)
        pygame.display.flip()

    def drawIcon(self):
        imageButton = pygame.image.load("images/" + self.icon).convert_alpha()
        positionDraw = (self.menuRect.right - 80, self.menuRect.top + 5)
        self.window.blit(imageButton, positionDraw)

    def drawBackButton(self, surface):
        self.backButton = Button(self.evManager, "BackView", self.name)
        self.backButton.create_button(surface, self.color, 20, 20, 45, 60)
        self.backButton.draw_image_button("back.png", Button.LEFT_MIDDLE)

    def selectActiveInnerView(self, index):
        font = pygame.font.Font("fonts/Verdana.ttf", 18)
        mark = font.render("1", True, Config.WHITE_COLOR)
        markRect = mark.get_rect()
        markRect.x = self.menuRect.right - 10
        markRect.y = self.menuRect.y + (markRect.height * ((3 * index / 2) + 1)) + 70
        markRect.width = 10

        pygame.draw.rect(self.window, Config.WHITE_COLOR, markRect, 0)

    def drawInnerView(self, view):
        view.drawView(self.window)
        pygame.display.flip()
Beispiel #4
0
 def drawBackButton(self, surface):
     self.backButton = Button(self.evManager, "BackView", self.name)
     self.backButton.create_button(surface, self.color, 20, 20, 45, 60)
     self.backButton.draw_image_button("back.png", Button.LEFT_MIDDLE)
Beispiel #5
0
 def drawModule(self,surface):
     self.weatherButton = Button(self.evManager,"WeatherView", self.viewContainer)
     self.weatherButton.create_button(surface,Config.BLUE_COLOR,280,50,190,145)
     self.drawWeatherInfo(surface)
     pygame.display.flip()