def __draw_game(self, game, overview): color = self.data.config.scoreboard_colors.color("default.background") self.canvas.Fill(color["r"], color["g"], color["b"]) # Draw the pregame renderer if Status.is_pregame(overview.status): scoreboard = Scoreboard(overview) scroll_max_x = self.__max_scroll_x(self.data.config.layout.coords("pregame.scrolling_text")) pregame = Pregame(overview) renderer = PregameRenderer(self.canvas, pregame, scoreboard, self.data, self.scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) # Draw the final game renderer elif Status.is_complete(overview.status): scroll_max_x = self.__max_scroll_x(self.data.config.layout.coords("final.scrolling_text")) final = Final(game) scoreboard = Scoreboard(overview) renderer = FinalRenderer(self.canvas, final, scoreboard, self.data, self.scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) # Draw the scoreboar renderer elif Status.is_irregular(overview.status): scoreboard = Scoreboard(overview) if scoreboard.get_text_for_reason(): scroll_max_x = self.__max_scroll_x(self.data.config.layout.coords("status.scrolling_text")) renderer = StatusRenderer(self.canvas, scoreboard, self.data, self.scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) else: StatusRenderer(self.canvas, scoreboard, self.data).render() else: scoreboard = Scoreboard(overview) ScoreboardRenderer(self.canvas, scoreboard, self.data).render() self.canvas = self.matrix.SwapOnVSync(self.canvas)
def __draw_game(self, game, overview): self.canvas.Fill(*ledcolors.scoreboard.fill) # Draw the pregame renderer if Status.is_pregame(overview.status): pregame = Pregame(overview) renderer = PregameRenderer(self.canvas, pregame, self.data.config.coords["pregame"], self.scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) # Draw the final game renderer elif Status.is_complete(overview.status): final = Final(game) scoreboard = Scoreboard(overview) renderer = FinalRenderer(self.canvas, final, scoreboard, self.data.config, self.scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) # Draw the scoreboar renderer elif Status.is_irregular(overview.status): scoreboard = Scoreboard(overview) StatusRenderer(self.canvas, scoreboard, self.data.config).render() else: scoreboard = Scoreboard(overview) ScoreboardRenderer(self.canvas, scoreboard, self.data.config).render() self.canvas = self.matrix.SwapOnVSync(self.canvas)
def render(self): color = self.data.config.scoreboard_colors.color("default.background") self.canvas.Fill(color["r"], color["g"], color["b"]) starttime = time.time() # Main and only loop while True: # If we need to refresh the overview data, do that if self.data.needs_refresh: self.data.refresh_overview() # Draw the current game self.__draw_game(self.data.current_game(), self.data.overview) # Check if we need to scroll until it's finished if self.data.config.rotation_scroll_until_finished == False: self.scrolling_finished = True # Set the refresh rate refresh_rate = self.data.config.scrolling_speed # If we're not scrolling anything, scroll is always finished. if Status.is_static(self.data.overview.status) and not Scoreboard( self.data.overview).get_text_for_reason(): self.scrolling_finished = True time.sleep(refresh_rate) endtime = time.time() time_delta = endtime - starttime rotate_rate = self.__rotate_rate_for_status( self.data.overview.status) # If we're ready to rotate, let's do it if time_delta >= rotate_rate and self.scrolling_finished: starttime = time.time() self.scrolling_finished = False self.data.needs_refresh = True if Status.is_fresh(self.data.overview.status): self.scrolling_text_pos = self.canvas.width if self.__should_rotate_to_next_game(self.data.overview): self.scrolling_text_pos = self.canvas.width game = self.data.advance_to_next_game() if endtime - self.data.games_refresh_time >= GAMES_REFRESH_RATE: self.data.refresh_games() if self.data.needs_refresh: self.data.refresh_overview() if Status.is_complete(self.data.overview.status): if Final(self.data.current_game() ).winning_pitcher == 'Unknown': self.data.refresh_games()
def __render_game(self): while True: # If we need to refresh the overview data, do that if self.data.needs_refresh: self.data.refresh_overview() # Draw the current game self.__draw_game(self.data.current_game(), self.data.overview) # Check if we need to scroll until it's finished if self.data.config.rotation_scroll_until_finished == False: self.scrolling_finished = True # Set the refresh rate refresh_rate = self.data.config.scrolling_speed # Currently the only thing that's always static is the live scoreboard if Status.is_static(self.data.overview.status): self.scrolling_finished = True # If the status is irregular and there's no 'reason' text, finish scrolling if Status.is_irregular(self.data.overview.status) and Scoreboard( self.data.overview).get_text_for_reason() is None: self.scrolling_finished = True time.sleep(refresh_rate) endtime = time.time() time_delta = endtime - self.starttime rotate_rate = self.__rotate_rate_for_status( self.data.overview.status) # If we're ready to rotate, let's do it if time_delta >= rotate_rate and self.scrolling_finished: self.starttime = time.time() self.scrolling_finished = False self.scrolling_period = 0.0 self.data.needs_refresh = True if Status.is_fresh(self.data.overview.status): self.scrolling_text_pos = self.canvas.width if self.__should_rotate_to_next_game(self.data.overview): self.scrolling_text_pos = self.canvas.width game = self.data.advance_to_next_game() if endtime - self.data.games_refresh_time >= GAMES_REFRESH_RATE: self.data.refresh_games() if self.data.needs_refresh: self.data.refresh_overview() if Status.is_complete(self.data.overview.status): if Final(self.data.current_game() ).winning_pitcher == 'Unknown': self.data.refresh_games()
def __refresh_game(self, game, overview): """Draws the provided game on the canvas.""" if overview.status == PRE_GAME or overview.status == SCHEDULED: pregame = Pregame(overview) renderer = PregameRenderer(self.canvas, pregame, self.current_scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) elif overview.status == GAME_OVER or overview.status == FINAL: final = Final(game) scoreboard = Scoreboard(overview) renderer = FinalRenderer(self.canvas, final, scoreboard, self.current_scrolling_text_pos) self.__update_scrolling_text_pos(renderer.render()) else: scoreboard = Scoreboard(overview) ScoreboardRenderer(self.canvas, scoreboard).render() self.canvas = self.matrix.SwapOnVSync(self.canvas)