Ejemplo n.º 1
0
 def _draw_pregame(self):
     time = self.data.get_current_date()
     gamedatetime = self.data.gametime
     if self.data.game != 0:
         if gamedatetime.day == time.day:
             date_text = 'TODAY'
         else:
             date_text = gamedatetime.strftime('%A').upper()
         overview = self.data.game
         gametime = gamedatetime.strftime("%-I:%M %p")
         # Center the game time on screen.
         date_pos = center_text(self.font_mini.getsize(date_text)[0], 32)
         gametime_pos = center_text(self.font_mini.getsize(gametime)[0], 32)
         awaysize = self.screen_config.team_logos_pos[
             overview['awayteam']]['size']
         homesize = self.screen_config.team_logos_pos[
             overview['hometeam']]['size']
         # Set the position of each logo
         away_team_logo_pos = self.screen_config.team_logos_pos[
             overview['awayteam']]['preaway']
         home_team_logo_pos = self.screen_config.team_logos_pos[
             overview['hometeam']]['prehome']
         # Open the logo image file
         away_team_logo = Image.open('logos/{}.png'.format(
             overview['awayteam'])).resize((awaysize, awaysize), 1)
         home_team_logo = Image.open('logos/{}.png'.format(
             overview['hometeam'])).resize((homesize, homesize), 1)
         # Draw the text on the Data image.
         self.draw.text((date_pos, 0), date_text, font=self.font_mini)
         self.draw.multiline_text((gametime_pos, 6),
                                  gametime,
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
         self.draw.text((25, 15), 'VS', font=self.font)
         # Put the data on the canvas
         self.canvas.SetImage(self.image, 0, 0)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"),
                              away_team_logo_pos["x"],
                              away_team_logo_pos["y"])
         self.canvas.SetImage(home_team_logo.convert("RGB"),
                              home_team_logo_pos["x"],
                              home_team_logo_pos["y"])
         # Load the canvas on screen.
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         # Refresh the Data image.
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
     else:
         #(Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
         self.draw.line((0, 0) + (self.width, 0), fill=128)
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         t.sleep(60)  # sleep for 1 min
         # Refresh canvas
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 2
0
 def _draw_pregame(self, game):
     time = self.data.get_current_date()
     gamedatetime = self.data.get_gametime()
     if gamedatetime.day == time.day:
         date_text = 'TODAY'
     else:
         date_text = gamedatetime.strftime('%A %-d %b').upper()
     gametime = gamedatetime.strftime("%-I:%M %p")
     # Center the game time on screen.
     date_pos = center_text(self.font_mini.getsize(date_text)[0], 32)
     gametime_pos = center_text(self.font_mini.getsize(gametime)[0], 32)
     # Draw the text on the Data image.
     self.draw.text((date_pos, 0), date_text, font=self.font_mini)
     self.draw.multiline_text((gametime_pos, 6),
                              gametime,
                              fill=(255, 255, 255),
                              font=self.font_mini,
                              align="center")
     self.draw.text((25, 15), 'VS', font=self.font)
     # Put the data on the canvas
     self.canvas.SetImage(self.image, 0, 0)
     if self.data.helmet_logos:
         # Open the logo image file
         away_team_logo = Image.open('logos/{}H.png'.format(
             game['awayteam'])).resize((20, 20), 1)
         home_team_logo = Image.open('logos/{}H.png'.format(
             game['hometeam'])).resize((20, 20),
                                       1).transpose(Image.FLIP_LEFT_RIGHT)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 12)
         self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 12)
     else:
         # TEMP Open the logo image file
         away_team_logo = Image.open('logos/{}.png'.format(
             game['awayteam'])).resize((20, 20), Image.BOX)
         home_team_logo = Image.open('logos/{}.png'.format(
             game['hometeam'])).resize((20, 20), Image.BOX)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 12)
         self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 12)
         # awaysize = self.screen_config.team_logos_pos[game['awayteam']]['size']
         # homesize = self.screen_config.team_logos_pos[game['hometeam']]['size']
         # # Set the position of each logo
         # away_team_logo_pos = self.screen_config.team_logos_pos[game['awayteam']]['preaway']
         # home_team_logo_pos = self.screen_config.team_logos_pos[game['hometeam']]['prehome']
         # # Open the logo image file
         # away_team_logo = Image.open('logos/{}.png'.format(game['awayteam'])).resize((awaysize, awaysize), 1)
         # home_team_logo = Image.open('logos/{}.png'.format(game['hometeam'])).resize((homesize, homesize), 1)
         # # Put the images on the canvas
         # self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
         # self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])
     # Load the canvas on screen.
     self.canvas = self.matrix.SwapOnVSync(self.canvas)
     # Refresh the Data image.
     self.image = Image.new('RGB', (self.width, self.height))
     self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 3
0
    def _draw_post_game(self):
        self.data.refresh_overview()
        if self.data.overview != 0:
            overview = self.data.overview

            # Prepare the data
            game_date = '{} {}'.format(month_abbr[self.data.month], self.data.day)
            score = '{}-{}'.format(overview['away_score'], overview['home_score'])
            period = overview['period']
            time_period = overview['time']

            # Set the position of the information on screen.
            game_date_pos = center_text(self.font_mini.getsize(game_date)[0], 32)
            time_period_pos = center_text(self.font_mini.getsize(time_period)[0], 32)
            score_position = center_text(self.font.getsize(score)[0], 32)

            # Draw the text on the Data image.
            self.draw.multiline_text((game_date_pos, -1), game_date, fill=(255, 255, 255), font=self.font_mini, align="center")
            self.draw.multiline_text((score_position, 15), score, fill=(255, 255, 255), font=self.font, align="center")
            self.draw.multiline_text((time_period_pos, 5), time_period, fill=(255, 255, 255), font=self.font_mini, align="center")

            # Only show the period if the game ended in Overtime "OT" or Shootouts "SO"
            if period == "OT" or period == "SO":
                period_position = center_text(self.font_mini.getsize(period)[0], 32)
                self.draw.multiline_text((period_position, 11), period, fill=(255, 255, 255), font=self.font_mini,align="center")

            # Open the logo image file
            away_team_logo = Image.open('logos/{}.png'.format(self.data.get_teams_info[overview['away_team_id']]['abbreviation']))
            home_team_logo = Image.open('logos/{}.png'.format(self.data.get_teams_info[overview['home_team_id']]['abbreviation']))

            # Set the position of each logo on screen.
            away_team_logo_pos = self.screen_config.team_logos_pos[str(overview['away_team_id'])]['away']
            home_team_logo_pos = self.screen_config.team_logos_pos[str(overview['home_team_id'])]['home']

            # Put the data on the canvas
            self.canvas.SetImage(self.image, 0, 0)

            # Put the images on the canvas
            self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
            self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])

            # Load the canvas on screen.
            self.canvas = self.matrix.SwapOnVSync(self.canvas)

            # Refresh the Data image.
            self.image = Image.new('RGB', (self.width, self.height))
            self.draw = ImageDraw.Draw(self.image)

        else:
            # (Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
            self.draw.line((0, 0) + (self.width, 0), fill=128)
            self.canvas = self.matrix.SwapOnVSync(self.canvas)
            time.sleep(60)  # sleep for 1 min
Ejemplo n.º 4
0
 def _draw_pre_draft(self):
     draft_dt = self.data.draft_dt
     off_pos = center_text(self.font.getsize("DRAFT")[0], 32)
     szn_pos = center_text(self.font.getsize(draft_dt)[0], 32)
     self.draw.multiline_text((off_pos, 3),
                              "DRAFT",
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.draw.multiline_text((szn_pos, self.font.getsize(draft_dt)[1] + 4),
                              draft_dt,
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self._refresh_image()
Ejemplo n.º 5
0
 def _draw_off_season(self):
     off_pos = center_text(self.font.getsize("OFF")[0], 32)
     szn_pos = center_text(self.font.getsize("SEASON")[0], 32)
     self.draw.multiline_text((off_pos, 3),
                              "OFF",
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.draw.multiline_text((szn_pos, self.font.getsize("SEASON")[1] + 4),
                              "SEASON",
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.canvas.SetImage(self.image, 0, 0)
     self.canvas = self.matrix.SwapOnVSync(self.canvas)
Ejemplo n.º 6
0
 def _draw_draft_complete(self):
     off_pos = center_text(self.font.getsize('KICKOFF IN')[0], 32)
     szn_pos = center_text(self.font.getsize(self.data.start_dt)[0], 32)
     self.draw.multiline_text((off_pos, 3),
                              'KICKOFF IN',
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.draw.multiline_text(
         (szn_pos, self.font.getsize(self.data.start_dt)[1] + 4),
         self.data.start_dt,
         fill=(255, 255, 255),
         font=self.font,
         align="center")
     self._refresh_image()
Ejemplo n.º 7
0
 def _draw_draft(self):
     off_pos = center_text(self.font.getsize("WOWEE")[0], 32)
     szn_pos = center_text(self.font.getsize("IT'S NOW")[0], 32)
     self.draw.multiline_text((off_pos, 3),
                              "WOWEE",
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.draw.multiline_text(
         (szn_pos, self.font.getsize("IT'S NOW")[1] + 4),
         "IT'S NOW",
         fill=(255, 255, 255),
         font=self.font,
         align="center")
     self._refresh_image()
Ejemplo n.º 8
0
    def draw_death(self):
        """Draw the display text for the end of the game with the score."""
        display_text = ["YOU DIED"]
        display_text.append("Your score is {:04}".format(
            Asteroid.asteroid_score))
        if Asteroid.asteroid_score == self.high_score:
            display_text.append("YOU HAVE A NEW HIGH SCORE!")
        else:
            display_text.append("The high score is {:04}".format(
                self.high_score))
        display_text.append("(Q)uit or (R)estart")

        text_area_height = len(display_text) * (pyxel.FONT_HEIGHT + 2) - 2
        pyxel.rect(
            x=0,
            y=constants.DEATH_HEIGHT - 2,
            w=pyxel.width,
            h=text_area_height + 4,
            col=constants.DEATH_STRIP_COLOUR,
        )

        for i, text in enumerate(display_text):
            y_offset = (pyxel.FONT_HEIGHT + 2) * i
            text_x = center_text(text, pyxel.width, pyxel.FONT_WIDTH)
            pyxel.text(
                text_x,
                constants.DEATH_HEIGHT + y_offset,
                text,
                constants.DEATH_TEXT_COLOUR,
            )
Ejemplo n.º 9
0
    def __init__(self, data, matrix, duration=None):
        self.data = data
        self.date = datetime.datetime.today()
        self.time = datetime.datetime.now()
        self.font = data.config.layout.font
        self.font_large = data.config.layout.font_large_2
        self.matrix = matrix
        self.time_format = data.config.time_format
        self.duration = duration
        if not self.duration:
            self.duration = data.config.clock_board_duration

        # Initialize he clock
        self.clock_size = self.font_large.getsize(
            self.time.strftime(self.time_format))
        self.clock_width = self.clock_size[0]
        self.time_align = center_text(self.clock_width, 32)

        display_time = 0
        while display_time < self.duration:
            self.time = datetime.datetime.now().strftime(
                self.time_format.replace(":", " "))
            self.meridiem = datetime.datetime.now().strftime("%P")
            display_time += 1
            self.draw_clock()
            sleep(1)

            self.time = datetime.datetime.now().strftime(self.time_format)
            self.meridiem = datetime.datetime.now().strftime("%P")
            self.draw_clock()
            display_time += 1
            sleep(1)
Ejemplo n.º 10
0
    def draw_clock(self):
        self.clock_size = self.font_large.getsize(self.time)
        self.clock_width = self.clock_size[0]
        self.time_align = center_text(self.clock_width, 32)
        self.matrix.clear()
        self.matrix.draw_text((self.time_align, 4),
                              "{}".format(self.date.strftime("%b %d %Y")),
                              fill=(255, 255, 255),
                              font=self.font,
                              multiline=True)

        self.matrix.draw_text((self.time_align, 9),
                              "{}".format(self.time),
                              fill=(255, 50, 50),
                              font=self.font_large,
                              multiline=True)

        # If time format is 12h, show the meridiem
        if self.time_format == "%I:%M":
            h = 11
            for letter in self.meridiem:
                self.matrix.draw_text(
                    (self.time_align + (self.clock_width - 2), h),
                    "{}".format(letter),
                    fill=(255, 255, 255),
                    font=self.font,
                    multiline=True)
                h += 6

        self.matrix.render()
        if self.data.network_issues and not self.data.config.clock_hide_indicators:
            self.matrix.network_issue_indicator()
Ejemplo n.º 11
0
 def _draw_post_game(self):
     self.data.refresh_game()
     if self.data.game != 0:
         overview = self.data.game
         # Prepare the data
         score = '{}-{}'.format(overview['awayscore'],
                                overview['homescore'])
         # Set the position of the information on screen.
         score_position = center_text(self.font.getsize(score)[0], 32)
         # awaysize = self.screen_config.team_logos_pos[overview['hometeam']]['size']
         # homesize = self.screen_config.team_logos_pos[overview['awayteam']]['size']
         awaysize = self.screen_config.team_logos_pos[
             overview['awayteam']]['size']
         homesize = self.screen_config.team_logos_pos[
             overview['hometeam']]['size']
         # Set the position of each logo
         # away_team_logo_pos = self.screen_config.team_logos_pos[overview['hometeam']]['away']
         # home_team_logo_pos = self.screen_config.team_logos_pos[overview['awayteam']]['home']
         away_team_logo_pos = self.screen_config.team_logos_pos[
             overview['awayteam']]['away']
         home_team_logo_pos = self.screen_config.team_logos_pos[
             overview['hometeam']]['home']
         # Open the logo image file
         # away_team_logo = Image.open('logos/{}.png'.format(overview['hometeam'])).resize((awaysize, awaysize), 1)
         # home_team_logo = Image.open('logos/{}.png'.format(overview['awayteam'])).resize((homesize, homesize), 1)
         away_team_logo = Image.open('logos/{}.png'.format(
             overview['awayteam'])).resize((19, 19), 1)
         home_team_logo = Image.open('logos/{}.png'.format(
             overview['hometeam'])).resize((19, 19), 1)
         # Draw the text on the Data image.
         self.draw.multiline_text((score_position, 19),
                                  score,
                                  fill=(255, 255, 255),
                                  font=self.font,
                                  align="center")
         self.draw.multiline_text((26, 0),
                                  "END",
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
         # Put the data on the canvas
         self.canvas.SetImage(self.image, 0, 0)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"),
                              away_team_logo_pos["x"],
                              away_team_logo_pos["y"])
         self.canvas.SetImage(home_team_logo.convert("RGB"),
                              home_team_logo_pos["x"],
                              home_team_logo_pos["y"])
         # Load the canvas on screen.
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         # Refresh the Data image.
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
     else:
         # (Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
         self.draw.line((0, 0) + (self.width, 0), fill=128)
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         t.sleep(10)  # sleep for 10 sec
Ejemplo n.º 12
0
 def _draw_post_game(self, game):
     # Prepare the data
     score = '{}-{}'.format(game['awayscore'], game['homescore'])
     # Set the position of the information on screen.
     score_position = center_text(self.font.getsize(score)[0], 32)
     # Draw the text on the Data image.
     self.draw.multiline_text((score_position, 19),
                              score,
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.draw.multiline_text((26, 0),
                              "END",
                              fill=(255, 255, 255),
                              font=self.font_mini,
                              align="center")
     # Put the data on the canvas
     self.canvas.SetImage(self.image, 0, 0)
     if self.data.helmet_logos:
         # Open the logo image file
         away_team_logo = Image.open('logos/{}H.png'.format(
             game['awayteam'])).resize((20, 20), 1)
         home_team_logo = Image.open('logos/{}H.png'.format(
             game['hometeam'])).resize((20, 20),
                                       1).transpose(Image.FLIP_LEFT_RIGHT)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 0)
         self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 0)
     else:
         # TEMP Open the logo image file
         away_team_logo = Image.open('logos/{}.png'.format(
             game['awayteam'])).resize((20, 20), Image.BOX)
         home_team_logo = Image.open('logos/{}.png'.format(
             game['hometeam'])).resize((20, 20), Image.BOX)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 0)
         self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 0)
     # awaysize = self.screen_config.team_logos_pos[overview['hometeam']]['size']
     # homesize = self.screen_config.team_logos_pos[overview['awayteam']]['size']
     # awaysize = self.screen_config.team_logos_pos[game['awayteam']]['size']
     # homesize = self.screen_config.team_logos_pos[game['hometeam']]['size']
     # Set the position of each logo
     # away_team_logo_pos = self.screen_config.team_logos_pos[overview['hometeam']]['away']
     # home_team_logo_pos = self.screen_config.team_logos_pos[overview['awayteam']]['home']
     # away_team_logo_pos = self.screen_config.team_logos_pos[game['awayteam']]['away']
     # home_team_logo_pos = self.screen_config.team_logos_pos[game['hometeam']]['home']
     # Open the logo image file
     # away_team_logo = Image.open('logos/{}.png'.format(overview['hometeam'])).resize((awaysize, awaysize), 1)
     # home_team_logo = Image.open('logos/{}.png'.format(overview['awayteam'])).resize((homesize, homesize), 1)
     # away_team_logo = Image.open('logos/{}.png'.format(game['awayteam'])).resize((19, 19), 1)
     # home_team_logo = Image.open('logos/{}.png'.format(game['hometeam'])).resize((19, 19), 1)
     # Put the images on the canvas
     # self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
     # self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])
     # Load the canvas on screen.
     self.canvas = self.matrix.SwapOnVSync(self.canvas)
     # Refresh the Data image.
     self.image = Image.new('RGB', (self.width, self.height))
     self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 13
0
 def _draw_countdown(self, game):
     time = self.data.get_current_date()
     gametime = datetime.strptime(game['date'], "%Y-%m-%dT%H:%MZ")
     if time < gametime:
         gt = gametime - time
         # as beautiful as I am
         if gt > timedelta(hours=1):
             gametime = ':'.join(str(gametime - time).split(':')[:2])
         else:
             gametime = ':'.join(str(gametime -
                                     time).split(':')[1:]).split('.')[:1][0]
         # Center the game time on screen.
         gametime_pos = center_text(self.font_mini.getsize(gametime)[0], 32)
         # Draw the text on the Data image.
         self.draw.text((29, 0), 'IN', font=self.font_mini)
         self.draw.multiline_text((gametime_pos, 6),
                                  gametime,
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
         self.draw.text((25, 15), 'VS', font=self.font)
         # Put the data on the canvas
         self.canvas.SetImage(self.image, 0, 0)
         if self.data.helmet_logos:
             # Open the logo image file
             away_team_logo = Image.open('logos/{}H.png'.format(
                 game['awayteam'])).resize((20, 20), 1)
             home_team_logo = Image.open('logos/{}H.png'.format(
                 game['hometeam'])).resize(
                     (20, 20), 1).transpose(Image.FLIP_LEFT_RIGHT)
             # Put the images on the canvas
             self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 12)
             self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 12)
         else:
             # TEMP Open the logo image file
             away_team_logo = Image.open('logos/{}.png'.format(
                 game['awayteam'])).resize((20, 20), Image.BOX)
             home_team_logo = Image.open('logos/{}.png'.format(
                 game['hometeam'])).resize((20, 20), Image.BOX)
             # Put the images on the canvas
             self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 12)
             self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 12)
             # awaysize = self.screen_config.team_logos_pos[game['awayteam']]['size']
             # homesize = self.screen_config.team_logos_pos[game['hometeam']]['size']
             # # Set the position of each logo
             # away_team_logo_pos = self.screen_config.team_logos_pos[game['awayteam']]['preaway']
             # home_team_logo_pos = self.screen_config.team_logos_pos[game['hometeam']]['prehome']
             # # Open the logo image file
             # away_team_logo = Image.open('logos/{}.png'.format(game['awayteam'])).resize((awaysize, awaysize), 1)
             # home_team_logo = Image.open('logos/{}.png'.format(game['hometeam'])).resize((homesize, homesize), 1)
             # # Put the images on the canvas
             # self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
             # self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])
         # Load the canvas on screen.
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         # Refresh the Data image.
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 14
0
    def on_button_press(self, button):
        if button in (LCD.LEFT, LCD.RIGHT):
            pass

        if button == LCD.UP:
            new_idx = (self.game_idx - 1) % len(self.game_names)
            self.lcd.clear()
            self.lcd.message(utils.center_text(self.game_names[new_idx]))
            self.game_idx = new_idx

        if button == LCD.DOWN:
            new_idx = (self.game_idx + 1) % len(self.game_names)
            self.lcd.clear()
            self.lcd.message(utils.center_text(self.game_names[new_idx]))
            self.game_idx = new_idx

        if button == LCD.SELECT:
            return DIMMSelect(self.lcd, self.game_list[self.game_names[self.game_idx]])

        return self
Ejemplo n.º 15
0
 def _draw_countdown(self):
     time = self.data.get_current_date()
     gametime = datetime.strptime(self.data.game['date'], "%Y-%m-%dT%H:%MZ")
     print(time, gametime)
     if time < gametime:
         print(gametime - time)
         overview = self.data.game
         gt = gametime - time
         # as beautiful as I am
         if gt > timedelta(hours=1):
             gametime = ':'.join(str(gametime - time).split(':')[:2])
         else:
             gametime = ':'.join(str(gametime -
                                     time).split(':')[1:]).split('.')[:1][0]
         # Center the game time on screen.
         gametime_pos = center_text(self.font_mini.getsize(gametime)[0], 32)
         awaysize = self.screen_config.team_logos_pos[
             overview['awayteam']]['size']
         homesize = self.screen_config.team_logos_pos[
             overview['hometeam']]['size']
         # Set the position of each logo
         away_team_logo_pos = self.screen_config.team_logos_pos[
             overview['awayteam']]['preaway']
         home_team_logo_pos = self.screen_config.team_logos_pos[
             overview['hometeam']]['prehome']
         # Open the logo image file
         away_team_logo = Image.open('logos/{}.png'.format(
             overview['awayteam'])).resize((19, 19), 1)
         home_team_logo = Image.open('logos/{}.png'.format(
             overview['hometeam'])).resize((19, 19), 1)
         # Draw the text on the Data image.
         self.draw.text((29, 0), 'IN', font=self.font_mini)
         self.draw.multiline_text((gametime_pos, 6),
                                  gametime,
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
         self.draw.text((25, 15), 'VS', font=self.font)
         # Put the data on the canvas
         self.canvas.SetImage(self.image, 0, 0)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"),
                              away_team_logo_pos["x"],
                              away_team_logo_pos["y"])
         self.canvas.SetImage(home_team_logo.convert("RGB"),
                              home_team_logo_pos["x"],
                              home_team_logo_pos["y"])
         # Load the canvas on screen.
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         # Refresh the Data image.
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
         t.sleep(1)
Ejemplo n.º 16
0
    def setup(self):
        red = (255, 0, 0)
        screen = pygame.display.get_surface()
        width = screen.get_width()
        height = screen.get_height()

        win_text = UIText('YOU DID IT!', 0, 0, 'win_text', 120, red)
        center_position = center_text(win_text, 0, 0, width, height)
        win_text.set_position(center_position)
        win_text.hide()

        self.add_element(win_text)

        move_count = UIText('Moves: 0', 10, 610, 'move_count', size=35)
        self.add_element(move_count)
Ejemplo n.º 17
0
    def _draw_pregame(self):

        if self.data.get_schedule() != 0:

            overview = self.data.schedule

            # Save when the game start
            game_time = overview['game_time']

            # Center the game time on screen.
            game_time_pos = center_text(self.font_mini.getsize(game_time)[0], 32)

            # Set the position of each logo
            away_team_logo_pos = self.screen_config.team_logos_pos[str(overview['away_team_id'])]['away']
            home_team_logo_pos = self.screen_config.team_logos_pos[str(overview['home_team_id'])]['home']

            # Open the logo image file
            away_team_logo = Image.open('logos/{}.png'.format(self.data.get_teams_info[overview['away_team_id']]['abbreviation']))
            home_team_logo = Image.open('logos/{}.png'.format(self.data.get_teams_info[overview['home_team_id']]['abbreviation']))

            # Draw the text on the Data image.
            self.draw.text((22, -1), 'TODAY', font=self.font_mini)
            self.draw.multiline_text((game_time_pos, 5), game_time, fill=(255, 255, 255), font=self.font_mini, align="center")
            self.draw.text((25, 13), 'VS', font=self.font)

            # Put the data on the canvas
            self.canvas.SetImage(self.image, 0, 0)

            # Put the images on the canvas
            self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
            self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])

            # Load the canvas on screen.
            self.canvas = self.matrix.SwapOnVSync(self.canvas)

            # Refresh the Data image.
            self.image = Image.new('RGB', (self.width, self.height))
            self.draw = ImageDraw.Draw(self.image)
        else:
            #(Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
            self.draw.line((0, 0) + (self.width, 0), fill=128)
            self.canvas = self.matrix.SwapOnVSync(self.canvas)
            time.sleep(60)  # sleep for 1 min
            # Refresh canvas
            self.image = Image.new('RGB', (self.width, self.height))
            self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 18
0
    def __init__(self, data, matrix, sleepEvent):
        self.data = data
        self.font = data.config.layout.font
        #self.font_large = data.config.layout.font_large_2
        self.font_large = data.config.layout.font_pb
        self.matrix = matrix
        self.state = data.pb_state

        # Initialize
        self.pbdis_size = self.font_large.getsize(self.state)
        self.pbdis_width = self.pbdis_size[0]
        self.pbdis_align = center_text(self.pbdis_width, 28)

        self.pb_reboot_icon = Image.open(get_file('assets/images/reboot.png'))
        self.pb_halt_icon = Image.open(get_file('assets/images/halt.png'))

        display_time = 0
        while display_time < DISPLAY_DURATION:
            self.draw_pbdis()
            display_time += 1
            sleep(1)
Ejemplo n.º 19
0
 def _draw_game(self):
     # self.data.refresh_game()
     overview = self.data.game
     homescore = overview['homescore']
     awayscore = overview['awayscore']
     while True:
         # Refresh the data
         if self.data.needs_refresh:
             debug.info('Refresh game overview')
             self.data.refresh_game()
             self.data.needs_refresh = False
         if self.data.game != 0:
             overview = self.data.game
             # Use This code if you want the goal animation to run only for your fav team's goal
             # if self.data.fav_team_id == overview['hometeam']:
             #     if overview['homescore'] > homescore:
             #         self._draw_goal()
             # else:
             #     if overview['awayscore'] > awayscore:
             #         self._draw_goal()
             # Use this code if you want the goal animation to run for both team's goal.
             # Run the goal animation if there is a goal.
             if overview['homescore'] > homescore + 5 or overview['awayscore'] > awayscore + 5:
                self._draw_td()
             elif overview['homescore'] > homescore + 2 or overview['awayscore'] > awayscore + 2:
                self._draw_fg()
             # Prepare the data
             # score = '{}-{}'.format(overview['awayscore'], overview['homescore'])
             if overview['possession'] == overview['awayid']:
                 pos = overview['awayteam']
             else:
                 pos = overview['hometeam']
             quarter = str(overview['quarter'])
             time_period = overview['time']
             # this is ugly but I want to replace the possession info with down info and spot info
             down = None
             spot = None
             game_info = None
             if overview['down']:
                 down = re.sub(r"[a-z]+", "", overview['down']).replace(" ", "")
                 info_pos = center_text(self.font_mini.getsize(str(down))[0], 32)
                 self.draw.multiline_text((info_pos, 19), str(down), fill=(255, 255, 255), font=self.font_mini, align="center")
             if overview['spot']:
                 spot = overview['spot'].replace(" ", "")
                 info_pos = center_text(self.font_mini.getsize(spot)[0], 32)
                 self.draw.multiline_text((info_pos, 25), spot, fill=(255, 255, 255), font=self.font_mini, align="center")
             pos_colour = (255, 255, 255)
             if overview['redzone']:
                 pos_colour = (255, 25, 25)
             # Set the position of the information on screen.
             homescore = '{0:02d}'.format(homescore)
             awayscore = '{0:02d}'.format(awayscore)
             home_score_size = self.font.getsize(homescore)[0]
             home_score_pos = center_text(self.font.getsize(homescore)[0], 16)
             away_score_pos = center_text(self.font.getsize(awayscore)[0], 48)
             time_period_pos = center_text(self.font_mini.getsize(time_period)[0], 32)
             # score_position = center_text(self.font.getsize(score)[0], 32)
             quarter_position = center_text(self.font_mini.getsize(quarter)[0], 32)
             info_pos = center_text(self.font_mini.getsize(pos)[0], 32)
             self.draw.multiline_text((info_pos, 13), pos, fill=pos_colour, font=self.font_mini, align="center")
             # Set the position of each logo on screen.
             awaysize = self.screen_config.team_logos_pos[overview['awayteam']]['size']
             homesize = self.screen_config.team_logos_pos[overview['hometeam']]['size']
             # Set the position of each logo
             away_team_logo_pos = self.screen_config.team_logos_pos[overview['awayteam']]['away']
             home_team_logo_pos = self.screen_config.team_logos_pos[overview['hometeam']]['home']
             # Open the logo image file
             away_team_logo = Image.open('logos/{}.png'.format(overview['awayteam'])).resize((19, 19), 1)
             home_team_logo = Image.open('logos/{}.png'.format(overview['hometeam'])).resize((19, 19), 1)
             # Draw the text on the Data image.
             self.draw.multiline_text((quarter_position, 0), quarter, fill=(255, 255, 255), font=self.font_mini, align="center")
             self.draw.multiline_text((time_period_pos, 6), time_period, fill=(255, 255, 255), font=self.font_mini, align="center")
             self.draw.multiline_text((6, 19), awayscore, fill=(255, 255, 255), font=self.font, align="center")
             self.draw.multiline_text((59 - home_score_size, 19), homescore, fill=(255, 255, 255), font=self.font, align="center")
             # self.draw.multiline_text((score_position, 19), score, fill=(255, 255, 255), font=self.font, align="center")
             # Put the data on the canvas
             self.canvas.SetImage(self.image, 0, 0)
             # Put the images on the canvas
             self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
             self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])
             # Load the canvas on screen.
             self.canvas = self.matrix.SwapOnVSync(self.canvas)
             # Refresh the Data image.
             self.image = Image.new('RGB', (self.width, self.height))
             self.draw = ImageDraw.Draw(self.image)
             # Check if the game is over
             if overview['state'] == 'post':
                 debug.info('GAME OVER')
                 break
             # Save the scores.
             awayscore = overview['awayscore']
             homescore = overview['homescore']
             self.data.needs_refresh = True
             t.sleep(1)
         else:
             # (Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
             self.draw.line((0, 0) + (self.width, 0), fill=128)
             self.canvas = self.matrix.SwapOnVSync(self.canvas)
             t.sleep(60)  # sleep for 1 min
Ejemplo n.º 20
0
 def _draw_live_game(self, game):
     homescore = game['homescore']
     awayscore = game['awayscore']
     print("home: ", homescore, "away: ", awayscore)
     # Refresh the data
     if self.data.needs_refresh:
         debug.info('Refresh game overview')
         self.data.refresh_games()
         self.data.needs_refresh = False
     # Use this code if you want the animations to run
     if game['homescore'] > homescore + 5 or game[
             'awayscore'] > awayscore + 5:
         debug.info('should draw TD')
         self._draw_td()
     elif game['homescore'] > homescore + 2 or game[
             'awayscore'] > awayscore + 2:
         debug.info('should draw FG')
         self._draw_fg()
     # Prepare the data
     # score = '{}-{}'.format(overview['awayscore'], overview['homescore'])
     if game['possession'] == game['awayid']:
         pos = game['awayteam']
     else:
         pos = game['hometeam']
     quarter = str(game['quarter'])
     time_period = game['time']
     # this is ugly but I want to replace the possession info with down info and spot info
     down = None
     spot = None
     game_info = None
     if game['down']:
         down = re.sub(r"[a-z]+", "", game['down']).replace(" ", "")
         info_pos = center_text(self.font_mini.getsize(str(down))[0], 32)
         self.draw.multiline_text((info_pos, 19),
                                  str(down),
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
     if game['spot']:
         spot = game['spot'].replace(" ", "")
         info_pos = center_text(self.font_mini.getsize(spot)[0], 32)
         self.draw.multiline_text((info_pos, 25),
                                  spot,
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
     pos_colour = (255, 255, 255)
     if game['redzone']:
         pos_colour = (255, 25, 25)
     # Set the position of the information on screen.
     homescore = '{0:02d}'.format(homescore)
     awayscore = '{0:02d}'.format(awayscore)
     home_score_size = self.font.getsize(homescore)[0]
     home_score_pos = center_text(self.font.getsize(homescore)[0], 16)
     away_score_pos = center_text(self.font.getsize(awayscore)[0], 48)
     time_period_pos = center_text(
         self.font_mini.getsize(time_period)[0], 32)
     # score_position = center_text(self.font.getsize(score)[0], 32)
     quarter_position = center_text(self.font_mini.getsize(quarter)[0], 32)
     info_pos = center_text(self.font_mini.getsize(pos)[0], 32)
     self.draw.multiline_text((info_pos, 13),
                              pos,
                              fill=pos_colour,
                              font=self.font_mini,
                              align="center")
     self.draw.multiline_text((quarter_position, 0),
                              quarter,
                              fill=(255, 255, 255),
                              font=self.font_mini,
                              align="center")
     self.draw.multiline_text((time_period_pos, 6),
                              time_period,
                              fill=(255, 255, 255),
                              font=self.font_mini,
                              align="center")
     self.draw.multiline_text((6, 19),
                              awayscore,
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     self.draw.multiline_text((59 - home_score_size, 19),
                              homescore,
                              fill=(255, 255, 255),
                              font=self.font,
                              align="center")
     # Put the data on the canvas
     self.canvas.SetImage(self.image, 0, 0)
     if self.data.helmet_logos:
         # Open the logo image file
         away_team_logo = Image.open('logos/{}H.png'.format(
             game['awayteam'])).resize((20, 20), 1)
         home_team_logo = Image.open('logos/{}H.png'.format(
             game['hometeam'])).resize((20, 20),
                                       1).transpose(Image.FLIP_LEFT_RIGHT)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 0)
         self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 0)
     else:
         # TEMP Open the logo image file
         away_team_logo = Image.open('logos/{}.png'.format(
             game['awayteam'])).resize((20, 20), Image.BOX)
         home_team_logo = Image.open('logos/{}.png'.format(
             game['hometeam'])).resize((20, 20), Image.BOX)
         # Put the images on the canvas
         self.canvas.SetImage(away_team_logo.convert("RGB"), 1, 0)
         self.canvas.SetImage(home_team_logo.convert("RGB"), 43, 0)
     # Set the position of each logo on screen.
     # awaysize = self.screen_config.team_logos_pos[game['awayteam']]['size']
     # homesize = self.screen_config.team_logos_pos[game['hometeam']]['size']
     # # Set the position of each logo
     # away_team_logo_pos = self.screen_config.team_logos_pos[game['awayteam']]['away']
     # home_team_logo_pos = self.screen_config.team_logos_pos[game['hometeam']]['home']
     # # Open the logo image file
     # away_team_logo = Image.open('logos/{}.png'.format(game['awayteam'])).resize((19, 19), 1)
     # home_team_logo = Image.open('logos/{}.png'.format(game['hometeam'])).resize((19, 19), 1)
     # Draw the text on the Data image.
     # self.draw.multiline_text((quarter_position, 0), quarter, fill=(255, 255, 255), font=self.font_mini, align="center")
     # self.draw.multiline_text((time_period_pos, 6), time_period, fill=(255, 255, 255), font=self.font_mini, align="center")
     # self.draw.multiline_text((6, 19), awayscore, fill=(255, 255, 255), font=self.font, align="center")
     # self.draw.multiline_text((59 - home_score_size, 19), homescore, fill=(255, 255, 255), font=self.font, align="center")
     # self.draw.multiline_text((score_position, 19), score, fill=(255, 255, 255), font=self.font, align="center")
     # Put the images on the canvas
     # self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
     # self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])
     # Load the canvas on screen.
     self.canvas = self.matrix.SwapOnVSync(self.canvas)
     # Refresh the Data image.
     self.image = Image.new('RGB', (self.width, self.height))
     self.draw = ImageDraw.Draw(self.image)
     # Check if the game is over
     if game['state'] == 'post':
         debug.info('GAME OVER')
     # Save the scores.
     # awayscore = game['awayscore']
     # homescore = game['homescore']
     self.data.needs_refresh = True
Ejemplo n.º 21
0
    def _draw_pregame(self):

        if self.data.get_schedule() != 0:

            overview = self.data.schedule

            # Save when the game start
            game_time = overview['game_time']

            # Center the game time on screen.
            game_time_pos = center_text(
                Fonts.font_mini.getsize(game_time)[0], 32)

            # Set the position of each logo
            away_team_logo_pos = self.screen_config.team_logos_pos[str(
                overview['away_team_id'])]['away']
            home_team_logo_pos = self.screen_config.team_logos_pos[str(
                overview['home_team_id'])]['home']

            url = 'https://www-league.nhlstatic.com/images/logos/teams-current-primary-light/{}.svg'
            away_image = ImageHelper.image_from_svg(
                url.format(overview['away_team_id']))
            away_image.thumbnail((64, 32))
            self.matrix.draw_image((0, 0), away_image)

            home_image = ImageHelper.image_from_svg(
                url.format(overview['home_team_id']))
            home_image.thumbnail((64, 32))
            self.matrix.draw_image((32, 0), home_image)

            # Draw the text on the Data image.
            self.matrix.draw_text((22, -1), 'TODAY', font=Fonts.font_mini)
            self.matrix.draw_text((game_time_pos, 5),
                                  game_time,
                                  multiline=True,
                                  fill=(255, 255, 255),
                                  font=Fonts.font_mini,
                                  align="center")
            self.matrix.draw_text((25, 13), 'VS', font=Fonts.font)

            # Put the data on the canvas
            self.matrix.render()
            self.matrix.clear()

            # # Put the images on the canvas
            # self.canvas.SetImage(away_team_logo.convert("RGB"), away_team_logo_pos["x"], away_team_logo_pos["y"])
            # self.canvas.SetImage(home_team_logo.convert("RGB"), home_team_logo_pos["x"], home_team_logo_pos["y"])

            # # Load the canvas on screen.
            # self.canvas = self.matrix.SwapOnVSync(self.canvas)

            # # Refresh the Data image.
            # self.image = Image.new('RGB', (self.width, self.height))
            # self.draw = ImageDraw.Draw(self.image)
        else:
            #(Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
            self.draw.line((0, 0) + (self.width, 0), fill=128)
            self.canvas = self.matrix.SwapOnVSync(self.canvas)
            self.sleepEvent.wait(60)  # sleep for 1 min
            # Refresh canvas
            self.image = Image.new('RGB', (self.width, self.height))
            self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 22
0
 def _draw_pregame(self):
     # get the matchup
     # get the matchup pics and resize them to 32x32
     # don't you love how messy this is? boy
     if self.data.matchup:
         matchup = self.data.matchup
         opp_av = matchup['opp_av']
         user_av = matchup['user_av']
         if opp_av is None:
             opp_av = 'noneLogo.png'
         if user_av is None:
             user_av = 'noneLogo.png'
         week = self.data.week
         if week == 0:
             week = 1
         game_date = 'WEEK {}'.format(week)
         avsize = self.avsize
         vs = 'VS'
         user_name = matchup['user_name']
         opp_name = matchup['opp_name']
         user_team = matchup.get('user_team')
         opp_team = matchup.get('opp_team')
         # choose team names that fit
         if user_team and len(user_team) < 13:
             user_name = user_team
         if opp_team and len(opp_team) < 13:
             opp_name = opp_team
         game_date_pos = center_text(
             self.font_mini.getsize(game_date)[0], 32)
         vs_pos = center_text(self.font_vs.getsize(vs)[0], 32)
         self.draw.multiline_text((game_date_pos, 0),
                                  game_date,
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
         self.draw.multiline_text((vs_pos + 1, 14),
                                  vs,
                                  fill=(255, 255, 255),
                                  font=self.font_vs,
                                  align="center")
         if len(user_name) > 12 or len(opp_name) > 12:
             avsize = 23
             opp_logo = Image.open('logos/{}.png'.format(opp_av)).resize(
                 (avsize, avsize), 1)
             user_logo = Image.open('logos/{}.png'.format(user_av)).resize(
                 (avsize, avsize), 1)
             # Set the position of each logo on screen.
             opp_team_logo_pos = {"x": 0, "y": 9}
             user_team_logo_pos = {"x": 41, "y": 9}
         else:
             self.draw.multiline_text((0, 6),
                                      opp_name,
                                      fill=(255, 255, 255),
                                      font=self.font_mini,
                                      align="left")
             self.draw.multiline_text(
                 (self.width - self.font_mini.getsize(user_name)[0],
                  self.height - self.font_mini.getsize(user_name)[1]),
                 user_name,
                 fill=(255, 255, 255),
                 font=self.font_mini,
                 align="left")
             # Open the logo image file
             # Draw the text on the Data image.
             opp_logo = Image.open('logos/{}.png'.format(opp_av)).resize(
                 (self.avsize, self.avsize), 1)
             user_logo = Image.open('logos/{}.png'.format(user_av)).resize(
                 (self.avsize, self.avsize), 1)
             # Set the position of each logo on screen.
             opp_team_logo_pos = {"x": 0, "y": 13}
             user_team_logo_pos = {"x": 45, "y": 7}
         # Put the data on the canvas
         self.canvas.SetImage(self.image, 0, 0)
         # Put the images on the canvas
         self.canvas.SetImage(opp_logo.convert("RGB"),
                              opp_team_logo_pos["x"],
                              opp_team_logo_pos["y"])
         self.canvas.SetImage(user_logo.convert("RGB"),
                              user_team_logo_pos["x"],
                              user_team_logo_pos["y"])
         # Load the canvas on screen.
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         # Refresh the Data image.
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
     else:
         #(Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
         self.draw.line((0, 0) + (self.width, 0), fill=128)
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         t.sleep(60)  # sleep for 1 min
         # Refresh canvas
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
Ejemplo n.º 23
0
 def _draw_post_game(self):
     self.data.refresh_matchup()
     if self.data.matchup != 0:
         matchup = self.data.matchup
         opp_av = matchup['opp_av']
         user_av = matchup['user_av']
         if opp_av is None:
             opp_av = 'noneLogo.png'
         if user_av is None:
             user_av = 'noneLogo.png'
         # testing
         # Using big and small numbers
         # this is so so so terrible, I know but idc come at me I'll fix it eventually when I'm not tired and trying random chit
         opp_big, opp_small = divmod(matchup['opp_score'], 1)
         opp_big = int(opp_big)
         opp_small = int(round(opp_small, 2) * 100)
         if opp_small < 10:
             opp_small = '0' + str(opp_small)
             opp_small_score = '{}'.format(opp_small)
         else:
             opp_small_score = '{0:02d}'.format(opp_small)
         user_big, user_small = divmod(matchup['user_score'], 1)
         user_big = int(user_big)
         user_small = int(round(user_small, 2) * 100)
         if user_small < 10:
             user_small = '0' + str(user_small)
             user_small_score = '{}'.format(user_small)
         else:
             user_small_score = '{0:02d}'.format(user_small)
         opp_big_size = self.font.getsize(str(opp_big))[0]
         opp_small_size = self.font_mini.getsize(str(opp_small))[0]
         user_big_size = self.font.getsize(str(user_big))[0]
         user_small_size = self.font_mini.getsize(str(user_small))[0]
         user_big_score = '{}'.format(user_big)
         opp_big_score = '{}'.format(opp_big)
         # trying to centre them to make it a bit more a e s t h e t i c (essentially adding padding)
         left_offset = int(math.floor(opp_big / 100))
         # end testing
         # Prepare the data
         game_date = 'WEEK {}'.format(self.data.week)
         result = ''
         opp_colour = (255, 255, 255)
         user_colour = (255, 255, 255)
         if matchup['opp_score'] > matchup['user_score']:
             result = 'LOSS'
             opp_colour = (25, 200, 25)
             user_colour = (200, 25, 25)
         else:
             result = 'WIN'
             opp_colour = (200, 25, 25)
             user_colour = (25, 200, 25)
         self.draw.multiline_text((left_offset, 19),
                                  opp_big_score,
                                  fill=opp_colour,
                                  font=self.font,
                                  align="left")
         self.draw.multiline_text((opp_big_size + left_offset, 19),
                                  opp_small_score,
                                  fill=opp_colour,
                                  font=self.font_mini,
                                  align="left")
         self.draw.multiline_text(
             (self.width - user_small_size - user_big_size, 19),
             user_big_score,
             fill=user_colour,
             font=self.font,
             align="right")
         self.draw.multiline_text((self.width - user_small_size, 19),
                                  user_small_score,
                                  fill=user_colour,
                                  font=self.font_mini,
                                  align="right")
         # Set the position of the information on screen.
         game_date_pos = center_text(
             self.font_mini.getsize(game_date)[0], 32)
         result_pos = center_text(
             self.font_res.getsize(result)[0],
             32)  # this was font_mini before, was that on purpose?
         # result_pos = center_text(self.font_mini.getsize(result)[0], 32)
         # Draw the text on the Data image.
         self.draw.multiline_text((game_date_pos, 0),
                                  game_date,
                                  fill=(255, 255, 255),
                                  font=self.font_mini,
                                  align="center")
         self.draw.multiline_text((result_pos, 9),
                                  result,
                                  fill=(255, 255, 255),
                                  font=self.font_res,
                                  align="center")
         # Open the logo image file
         opp_logo = Image.open('logos/{}.png'.format(opp_av)).resize(
             (19, 19), 1)
         user_logo = Image.open('logos/{}.png'.format(user_av)).resize(
             (19, 19), 1)
         # Set the position of each logo on screen.
         opp_team_logo_pos = {"x": 0, "y": 0}
         user_team_logo_pos = {"x": 45, "y": 0}
         # Put the data on the canvas
         self.canvas.SetImage(self.image, 0, 0)
         # Put the images on the canvas
         self.canvas.SetImage(opp_logo.convert("RGB"),
                              opp_team_logo_pos["x"],
                              opp_team_logo_pos["y"])
         self.canvas.SetImage(user_logo.convert("RGB"),
                              user_team_logo_pos["x"],
                              user_team_logo_pos["y"])
         # Load the canvas on screen.
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         # Refresh the Data image.
         self.image = Image.new('RGB', (self.width, self.height))
         self.draw = ImageDraw.Draw(self.image)
     else:
         # (Need to make the screen runs) If connection to the API fails, show bottom red line and refresh in 1 min.
         self.draw.line((0, 0) + (self.width, 0), fill=128)
         self.canvas = self.matrix.SwapOnVSync(self.canvas)
         t.sleep(60)  # sleep for 1 min
Ejemplo n.º 24
0
    def _draw_game(self):
        self.data.refresh_overview()
        overview = self.data.overview
        home_score = overview['home_score']
        away_score = overview['away_score']

        while True:

            # Refresh the data
            if self.data.needs_refresh:
                debug.info('Refresh game overview')
                self.data.refresh_overview()
                self.data.needs_refresh = False

            if self.data.overview != 0:
                overview = self.data.overview

                # Use This code if you want the goal animation to run only for your fav team's goal
                # if self.data.fav_team_id == overview['home_team_id']:
                #     if overview['home_score'] > home_score:
                #         self._draw_goal()
                # else:
                #     if overview['away_score'] > away_score:
                #         self._draw_goal()

                # Use this code if you want the goal animation to run for both team's goal.
                # Run the goal animation if there is a goal.
                if overview['home_score'] > home_score or overview[
                        'away_score'] > away_score:  # audio possible insertion point
                    self._draw_goal()

                # Prepare the data
                score = '{}-{}'.format(overview['away_score'],
                                       overview['home_score'])
                period = overview['period']
                time_period = overview['time']

                # Set the position of the information on screen.
                time_period_pos = center_text(
                    self.font_mini.getsize(time_period)[0], 32)
                score_position = center_text(self.font.getsize(score)[0], 32)
                period_position = center_text(
                    self.font_mini.getsize(period)[0], 32)

                # Set the position of each logo on screen.
                away_team_logo_pos = self.screen_config.team_logos_pos[str(
                    overview['away_team_id'])]['away']
                home_team_logo_pos = self.screen_config.team_logos_pos[str(
                    overview['home_team_id'])]['home']

                # Open the logo image file
                away_team_logo = Image.open('logos/{}.png'.format(
                    self.data.get_teams_info[
                        overview['away_team_id']]['abbreviation']))
                home_team_logo = Image.open('logos/{}.png'.format(
                    self.data.get_teams_info[
                        overview['home_team_id']]['abbreviation']))

                # Draw the text on the Data image.
                self.draw.multiline_text((score_position, 15),
                                         score,
                                         fill=(255, 255, 255),
                                         font=self.font,
                                         align="center")
                self.draw.multiline_text((period_position, -1),
                                         period,
                                         fill=(255, 255, 255),
                                         font=self.font_mini,
                                         align="center")
                self.draw.multiline_text((time_period_pos, 5),
                                         time_period,
                                         fill=(255, 255, 255),
                                         font=self.font_mini,
                                         align="center")

                # Put the data on the canvas
                self.canvas.SetImage(self.image, 0, 0)

                # Put the images on the canvas
                self.canvas.SetImage(away_team_logo.convert("RGB"),
                                     away_team_logo_pos["x"],
                                     away_team_logo_pos["y"])
                self.canvas.SetImage(home_team_logo.convert("RGB"),
                                     home_team_logo_pos["x"],
                                     home_team_logo_pos["y"])

                # Load the canvas on screen.
                self.canvas = self.matrix.SwapOnVSync(self.canvas)

                # Refresh the Data image.
                self.image = Image.new('RGB', (self.width, self.height))
                self.draw = ImageDraw.Draw(self.image)

                # Check if the period is over
                if self.data.get_end_of_period():
                    debug.info('End of Period check successful')
                    self.draw_end_of_period()

                # Check if the game is over
                if overview['game_status'] == 6 or overview['game_status'] == 7:
                    debug.info('GAME OVER')
                    break

                # Save the scores.
                away_score = overview['away_score']
                home_score = overview['home_score']

                self.data.needs_refresh = True
                time.sleep(60)
            else:
                # (Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
                self.draw.line((0, 0) + (self.width, 0), fill=128)
                self.canvas = self.matrix.SwapOnVSync(self.canvas)
                time.sleep(60)  # sleep for 1 min
Ejemplo n.º 25
0
 def _draw_game(self):
     self.data.refresh_matchup()
     matchup = self.data.matchup
     opp_av = matchup['opp_av']
     user_av = matchup['user_av']
     if opp_av is None:
         opp_av = 'noneLogo.png'
     if user_av is None:
         user_av = 'noneLogo.png'
     user_score = matchup.get('user_score')
     opp_score = matchup.get('opp_score')
     self.data.needs_refresh = True
     extra_sleep = 0
     while True:
         # Refresh the data
         if self.data.needs_refresh and self.data.check_scores:
             debug.info('Refresh game matchup')
             extra_sleep = 0
             self.data.refresh_scores()
             self.data.needs_refresh = False
         else:
             debug.info('Not refreshing, will update in 1 minute')
             extra_sleep = 40
             self.data.check_if_playing()
             self.data.needs_refresh = True
         if self.data.matchup:
             # colours
             opp_colour = (255, 255, 255)
             user_colour = (255, 255, 255)
             matchup = self.data.matchup
             game_date = 'WEEK {}'.format(self.data.week)
             # small increase in score
             if matchup['user_score'] > user_score:
                 user_colour = (165, 200, 50)
             if matchup['opp_score'] > opp_score:
                 opp_colour = (165, 200, 50)
             # decrease in score
             if matchup['user_score'] < user_score:
                 user_colour = (175, 25, 25)
             if matchup['opp_score'] < opp_score:
                 opp_colour = (175, 25, 25)
             # big play! 5+ points for someone, turn it gold
             if matchup.get('user_score',
                            0) > (user_score + 5) or matchup.get(
                                'opp_score', 0) > (opp_score + 5):
                 self._draw_big_play()
             if matchup['user_score'] > user_score + 5:
                 user_colour = (255, 215, 0)
             if matchup['opp_score'] > opp_score + 5:
                 opp_colour = (255, 215, 0)
             # Using big and small numbers
             opp_big, opp_small = divmod(matchup['opp_score'], 1)
             opp_big = int(opp_big)
             opp_small = int(round(opp_small, 2) * 100)
             if opp_small < 10:
                 opp_small = '0' + str(opp_small)
                 opp_small_score = '{}'.format(opp_small)
             else:
                 opp_small_score = '{0:02d}'.format(opp_small)
             user_big, user_small = divmod(matchup['user_score'], 1)
             user_big = int(user_big)
             user_small = int(round(user_small, 2) * 100)
             if user_small < 10:
                 user_small = '0' + str(user_small)
                 user_small_score = '{}'.format(user_small)
             else:
                 user_small_score = '{0:02d}'.format(user_small)
             opp_diff = '{:0.2f}'.format(
                 abs(opp_score - matchup['opp_score']))
             user_diff = '{:0.2f}'.format(
                 abs(user_score - matchup['user_score']))
             opp_big_size = self.font.getsize(str(opp_big))[0]
             opp_small_size = self.font_mini.getsize(str(opp_small))[0]
             user_big_size = self.font.getsize(str(user_big))[0]
             user_small_size = self.font_mini.getsize(str(user_small))[0]
             user_diff_size = self.font_mini.getsize(user_diff)[0]
             opp_diff_size = self.font_mini.getsize(opp_diff)[0]
             # this is bad form I know but idc come at me I'll fix it eventually when I'm not tired and trying random chit
             opp_big_score = '{}'.format(opp_big)
             user_big_score = '{}'.format(user_big)
             # trying to centre them to make it a bit more a e s t h e t i c (essentially adding padding)
             left_offset = int(
                 math.floor(opp_big / 100)
             )  # ((self.width / 2) - (opp_big_size + opp_small_size)) / 2 - 2
             # eventually may colour differently depending on score advantage
             self.draw.multiline_text((left_offset, 19),
                                      opp_big_score,
                                      fill=opp_colour,
                                      font=self.font,
                                      align="left")
             self.draw.multiline_text((opp_big_size + left_offset, 19),
                                      opp_small_score,
                                      fill=opp_colour,
                                      font=self.font_mini,
                                      align="left")
             self.draw.multiline_text(
                 (self.width - user_small_size - user_big_size, 19),
                 user_big_score,
                 fill=user_colour,
                 font=self.font,
                 align="right")
             self.draw.multiline_text((self.width - user_small_size, 19),
                                      user_small_score,
                                      fill=user_colour,
                                      font=self.font_mini,
                                      align="right")
             # diffs
             if abs(opp_score - matchup['opp_score']) > 0:
                 self.draw.multiline_text((21, 6),
                                          opp_diff,
                                          fill=opp_colour,
                                          font=self.font_mini,
                                          align="left")
             if abs(user_score - matchup['user_score']) > 0:
                 self.draw.multiline_text(
                     (self.width - 20 - user_diff_size, 12),
                     user_diff,
                     fill=user_colour,
                     font=self.font_mini,
                     align="right")
             # Set the projections on the screen?
             game_date_pos = center_text(
                 self.font_mini.getsize(game_date)[0], 32)
             # score_position = center_text(self.font.getsize(score)[0], 32)
             # Set the position of each logo on screen.
             self.draw.multiline_text((game_date_pos, -1),
                                      game_date,
                                      fill=(255, 255, 255),
                                      font=self.font_mini,
                                      align="center")
             # Open the logo image file
             opp_logo = Image.open('logos/{}.png'.format(opp_av)).resize(
                 (19, 19), 1)
             user_logo = Image.open('logos/{}.png'.format(user_av)).resize(
                 (19, 19), 1)
             # Set the position of each logo on screen.
             opp_team_logo_pos = {"x": 0, "y": 0}
             user_team_logo_pos = {"x": 45, "y": 0}
             # Put the data on the canvas
             self.canvas.SetImage(self.image, 0, 0)
             # Put the images on the canvas
             self.canvas.SetImage(opp_logo.convert("RGB"),
                                  opp_team_logo_pos["x"],
                                  opp_team_logo_pos["y"])
             self.canvas.SetImage(user_logo.convert("RGB"),
                                  user_team_logo_pos["x"],
                                  user_team_logo_pos["y"])
             # Load the canvas on screen.
             self.canvas = self.matrix.SwapOnVSync(self.canvas)
             # Refresh the Data image.
             self.image = Image.new('RGB', (self.width, self.height))
             self.draw = ImageDraw.Draw(self.image)
             # Save the scores.
             opp_score = matchup['opp_score']
             user_score = matchup['user_score']
             self.data.needs_refresh = True
             t.sleep(20 + extra_sleep)
         else:
             # (Need to make the screen run on it's own) If connection to the API fails, show bottom red line and refresh in 1 min.
             self.draw.line((0, 0) + (self.width, 0), fill=128)
             self.canvas = self.matrix.SwapOnVSync(self.canvas)
             t.sleep(20)