Skip to content

Commit

Permalink
Merge pull request #167 from MLB-LED-Scoreboard/dev
Browse files Browse the repository at this point in the history
Release 1.6.0
  • Loading branch information
ajbowler authored May 17, 2018
2 parents e1f01cf + 238db9f commit 8ffe735
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 36 deletions.
25 changes: 24 additions & 1 deletion data/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,27 @@ def __init__(self, overview):
self.outs = Outs(overview)
self.game_status = overview.status

try:
self.note = overview.note
except:
self.note = None

try:
self.reason = overview.reason
except:
self.reason = None

def get_text_for_reason(self):
if self.note:
return self.note

if self.reason:
return self.reason

return None

def __str__(self):
s = "<{} {}> {} ({}) @ {} ({}); Status: {}; Inning: (Number: {}; State: {}); B:{} S:{} O:{}; Bases: {}".format(
s = "<{} {}> {} ({}) @ {} ({}); Status: {}; Inning: (Number: {}; State: {}); B:{} S:{} O:{}; Bases: {};".format(
self.__class__.__name__, hex(id(self)),
self.away_team.abbrev, str(self.away_team.runs),
self.home_team.abbrev, str(self.home_team.runs),
Expand All @@ -33,4 +52,8 @@ def __str__(self):
str(self.pitches.strikes),
str(self.outs.number),
str(self.bases))
if self.reason:
s += " Reason: '{}';".format(self.reason)
if self.note:
s += " Notes: '{}';".format(self.note)
return s
7 changes: 4 additions & 3 deletions data/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ class Status:
FINAL = 'Final'
GAME_OVER = 'Game Over'
IN_PROGRESS = 'In Progress'
MANAGER_CHALLENGE = "Manager Challenge"
MANAGER_CHALLENGE = 'Manager Challenge'
REVIEW = 'Review'
PRE_GAME = 'Pre-Game'
POSTPONED = 'Postponed'
SCHEDULED = 'Scheduled'
SUSPENDED = 'Suspended'
WARMUP = 'Warmup'

@staticmethod
def is_static(status):
"""Returns whether the game being currently displayed has no text to scroll"""
return status in [Status.IN_PROGRESS, Status.CANCELLED, Status.DELAYED, Status.DELAYED_START, Status.POSTPONED, Status.MANAGER_CHALLENGE, Status.REVIEW]
return status in [Status.IN_PROGRESS, Status.CANCELLED, Status.DELAYED, Status.DELAYED_START, Status.POSTPONED, Status.SUSPENDED, Status.MANAGER_CHALLENGE, Status.REVIEW]

@staticmethod
def is_pregame(status):
Expand All @@ -37,7 +38,7 @@ def is_live(status):
def is_irregular(status):
"""Returns whether game is in an irregular state, such as delayed, postponed, cancelled,
or in a challenge."""
return status in [Status.POSTPONED, Status.DELAYED, Status.DELAYED_START, Status.CANCELLED, Status.MANAGER_CHALLENGE]
return status in [Status.POSTPONED, Status.SUSPENDED, Status.DELAYED, Status.DELAYED_START, Status.CANCELLED, Status.MANAGER_CHALLENGE]

@staticmethod
def is_fresh(status):
Expand Down
15 changes: 11 additions & 4 deletions ledcolors/scoreboard.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,17 @@
"b": 59
}
},
"status_text": {
"r": 255,
"g": 235,
"b": 59
"status": {
"text": {
"r": 255,
"g": 235,
"b": 59
},
"scrolling_text": {
"r": 255,
"g": 235,
"b": 59
}
},
"standings": {
"background": {
Expand Down
15 changes: 11 additions & 4 deletions ledcoords/w128h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,17 @@
}
}
},
"status_text": {
"x": 32,
"y": 20,
"short_text": false
"status": {
"text": {
"x": 96,
"y": 14,
"short_text": false
},
"scrolling_text": {
"x": 0,
"y": 30,
"width": 128
}
},
"teams": {
"background": {
Expand Down
15 changes: 11 additions & 4 deletions ledcoords/w32h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,17 @@
}
}
},
"status_text": {
"x": 16,
"y": 20,
"short_text": true
"status": {
"text": {
"x": 16,
"y": 20,
"short_text": true
},
"scrolling_text": {
"x": 0,
"y": 31,
"width": 32
}
},
"teams": {
"background": {
Expand Down
15 changes: 11 additions & 4 deletions ledcoords/w64h32.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,17 @@
}
}
},
"status_text": {
"x": 32,
"y": 20,
"short_text": false
"status": {
"text": {
"x": 32,
"y": 20,
"short_text": false
},
"scrolling_text": {
"x": 0,
"y": 31,
"width": 64
}
},
"teams": {
"background": {
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import debug

SCRIPT_NAME = "MLB LED Scoreboard"
SCRIPT_VERSION = "1.5.1"
SCRIPT_VERSION = "1.6.0"

# Get supplied command line arguments
args = args()
Expand Down
9 changes: 7 additions & 2 deletions renderers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def render(self):
refresh_rate = SCROLL_TEXT_SLOW_RATE

# If we're not scrolling anything, scroll is always finished.
if Status.is_static(self.data.overview.status):
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)
Expand Down Expand Up @@ -122,7 +122,12 @@ def __draw_game(self, game, overview):
# Draw the scoreboar renderer
elif Status.is_irregular(overview.status):
scoreboard = Scoreboard(overview)
StatusRenderer(self.canvas, scoreboard, self.data).render()
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()
Expand Down
29 changes: 21 additions & 8 deletions renderers/scrollingtext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rgbmatrix import graphics
from utils import center_text_position

class ScrollingText:
def __init__(self, canvas, x, y, width, font, text_color, background_color, text):
Expand All @@ -12,11 +13,23 @@ def __init__(self, canvas, x, y, width, font, text_color, background_color, text
self.width = width

def render(self, scroll_pos):
x = scroll_pos
pos = graphics.DrawText(self.canvas, self.font["font"], x, self.y, self.text_color, self.text)
h = self.font["size"]["height"]
for x in range(self.x):
graphics.DrawLine(self.canvas, x, self.y, x, self.y - h, self.bg_color)
for x in range(self.x + self.width, self.canvas.width):
graphics.DrawLine(self.canvas, x, self.y, x, self.y - h, self.bg_color)
return pos
if self.__text_should_scroll():
x = scroll_pos
pos = graphics.DrawText(self.canvas, self.font["font"], x, self.y, self.text_color, self.text)
h = self.font["size"]["height"]
for x in range(self.x):
graphics.DrawLine(self.canvas, x, self.y, x, self.y - h, self.bg_color)
for x in range(self.x + self.width, self.canvas.width):
graphics.DrawLine(self.canvas, x, self.y, x, self.y - h, self.bg_color)
return pos

else:
graphics.DrawText(self.canvas, self.font["font"], self.__center_position(), self.y, self.text_color, self.text)
return 0

# Maybe the text is too short and we should just center it instead?
def __text_should_scroll(self):
return len(self.text) * self.font["size"]["width"] > self.width

def __center_position(self):
return center_text_position(self.text, abs(self.width/2) + self.x, self.font["size"]["width"])
29 changes: 24 additions & 5 deletions renderers/status.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from data.status import Status
from renderers.teams import TeamsRenderer
from renderers.scrollingtext import ScrollingText
from rgbmatrix import graphics
from utils import get_font, center_text_position

Expand All @@ -9,30 +10,46 @@
# Handle statuses that are too long for 32-wide boards.
POSTPONED_SHORTHAND = 'Postpd'
CANCELLED_SHORTHAND = "Cancl'd"
SUSPENDED_SHORTHAND = "Suspnd"
CHALLENGE_SHORTHAND_32 = "Chalnge"

class StatusRenderer:
def __init__(self, canvas, scoreboard, data):
def __init__(self, canvas, scoreboard, data, scroll_pos = 0):
self.canvas = canvas
self.scoreboard = scoreboard
self.data = data
self.colors = data.config.scoreboard_colors
self.bgcolor = self.colors.graphics_color("default.background")
self.scroll_pos = scroll_pos

def render(self):
if self.scoreboard.get_text_for_reason():
text_len = self.__render_scroll_text()

TeamsRenderer(self.canvas, self.scoreboard.home_team, self.scoreboard.away_team, self.data).render()
self.__render_game_status()

if self.scoreboard.get_text_for_reason():
return text_len

def __render_game_status(self):
color = self.colors.graphics_color("status_text")
color = self.colors.graphics_color("status.text")
text = self.__get_text_for_status()
coords = self.data.config.layout.coords("status_text")
font = self.data.config.layout.font("status_text")
coords = self.data.config.layout.coords("status.text")
font = self.data.config.layout.font("status.text")
text_x = center_text_position(text, coords["x"], font["size"]["width"])
graphics.DrawText(self.canvas, font["font"], text_x, coords["y"], color, text)

def __render_scroll_text(self):
coords = self.data.config.layout.coords("status.scrolling_text")
font = self.data.config.layout.font("status.scrolling_text")
color = self.colors.graphics_color("status.scrolling_text")
scroll_text = "{}".format(self.scoreboard.get_text_for_reason())
return ScrollingText(self.canvas, coords["x"], coords["y"], coords["width"], font, color, self.bgcolor, scroll_text).render(self.scroll_pos)

def __get_text_for_status(self):
text = self.scoreboard.game_status
short_text = self.data.config.layout.coords("status_text")["short_text"]
short_text = self.data.config.layout.coords("status.text")["short_text"]
if short_text:
return self.__get_short_text(text)
if text == Status.MANAGER_CHALLENGE:
Expand All @@ -48,4 +65,6 @@ def __get_short_text(self, text):
return CANCELLED_SHORTHAND
if text == Status.MANAGER_CHALLENGE:
return CHALLENGE_SHORTHAND_32
if text == Status.SUSPENDED:
return SUSPENDED_SHORTHAND
return text

0 comments on commit 8ffe735

Please sign in to comment.