Skip to content

Commit

Permalink
Run black on rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-porter committed Mar 10, 2024
1 parent ce8a6a8 commit 15d060b
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 63 deletions.
2 changes: 1 addition & 1 deletion rewrite/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from utils.font import FontCache

class Config:

class Config:
def __init__(self):
self.font_cache = FontCache()

Expand Down
2 changes: 1 addition & 1 deletion rewrite/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from data.schedule import Schedule

class Data:

class Data:
def __init__(self, screen_manager):
self.screen_manager = screen_manager

Expand Down
2 changes: 1 addition & 1 deletion rewrite/data/game.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from data.status import Status

class Game:

class Game:
@staticmethod
def from_schedule(game_data):
game = Game(game_data)
Expand Down
8 changes: 4 additions & 4 deletions rewrite/data/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from screens import Screen

class Schedule:

REFRESH_RATE = 5 * 60 # minutes
class Schedule:
REFRESH_RATE = 5 * 60 # minutes

def __init__(self, data):
self.data = data
Expand All @@ -25,7 +25,7 @@ def update(self):
self.last_update = time.time()

ScoreboardLogger.log(f"Updating schedule for {datetime.datetime.today()}")

try:
self.__fetch_updated_schedule(datetime.datetime.today())
except Exception as exception:
Expand All @@ -36,7 +36,7 @@ def update(self):

self.data.request_next_screen(Screen.GAME)

return Status.SUCCESS
return Status.SUCCESS

def __fetch_updated_schedule(self, date):
self._games = statsapi.schedule(date.strftime("%Y-%m-%d"))
Expand Down
6 changes: 3 additions & 3 deletions rewrite/data/screen_request.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from screens import Screen

class ScreenRequest:

class ScreenRequest:
class InvalidRequest(Exception):
pass

def __init__(self, type, manager, *args):
# Required arguments
self.type = type
self.type = type
self.manager = manager

# Screen-specific arguments
self.args = args
self.args = args

if self.type not in Screen:
raise ScreenRequest.InvalidRequest(f"Screen type {self.type} is not valid")
1 change: 1 addition & 0 deletions rewrite/data/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class Status(Enum):
def ok(status):
return status in [Status.SUCCESS, Status.DEFERRED]


def fail(status):
return status in [Status.FAIL]
6 changes: 3 additions & 3 deletions rewrite/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from utils import args
from driver.mode import DriverMode


class DriverWrapper:
def __init__(self):
self.hardware_load_failed = False
Expand All @@ -13,10 +14,9 @@ def __init__(self):
else:
self.set_mode(DriverMode.HARDWARE)


@property
def __name__(self):
return 'driver'
return "driver"

def is_hardware(self):
return self.mode == DriverMode.HARDWARE
Expand Down Expand Up @@ -47,4 +47,4 @@ def __getattr__(self, name):
return getattr(self.driver, name)


sys.modules['driver'] = DriverWrapper()
sys.modules["driver"] = DriverWrapper()
2 changes: 1 addition & 1 deletion rewrite/driver/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class DriverMode(Enum):
HARDWARE = 0
HARDWARE = 0
SOFTWARE_EMULATION = 1
8 changes: 2 additions & 6 deletions rewrite/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def main(matrix):
#TODO: Configure matrix dimensions
# TODO: Configure matrix dimensions
ScoreboardLogger.info(f"{SCRIPT_NAME} - v#{SCRIPT_VERSION} (32x32)")

canvas = matrix.CreateFrameCanvas()
Expand All @@ -35,11 +35,7 @@ def main(matrix):
config = Config()
screen_manager = ScreenManager(matrix, canvas, config, screen_queue)

render_thread = threading.Thread(
target=screen_manager.start,
name="render_thread",
daemon=True
)
render_thread = threading.Thread(target=screen_manager.start, name="render_thread", daemon=True)

render_thread.start()

Expand Down
9 changes: 4 additions & 5 deletions rewrite/screens/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from enum import Enum


class Screen(Enum):
STATIC = 0
CLOCK = 1
STATIC = 0
CLOCK = 1
WEATHER = 2
GAME = 3

from screens.screen_manager import ScreenManager
GAME = 3
20 changes: 10 additions & 10 deletions rewrite/screens/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from datetime import datetime as dt

class ScreenBase():

class ScreenBase:
def __init__(self, manager):
self.manager = manager

self.start_time = None
self.duration = 0

def track_duration(fn):
def wrapper(self, *args, **kwargs):
if self.start_time is None:
Expand All @@ -21,21 +21,21 @@ def wrapper(self, *args, **kwargs):

def render(self):
raise NotImplementedError("Subclasses must implement render()")

def ready_to_transition(self):
'''
Returns True if the screen is ready to transition away.
"""
Returns True if the screen is ready to transition away. By default, always allow the screen to transition.
Subclasses should implement this method if they desire different behavior.
Subclasses should implement this method if they desire different behavior, such as requiring screens to be visible for a certain duration.
NOTE: If this value always returns False, no screen transitions will happen!
'''
"""
return True

@track_duration
def _render(self):
self.render()

@property
def matrix(self):
return self.manager.matrix
Expand All @@ -47,7 +47,7 @@ def canvas(self):
@property
def data(self):
return self.manager.data

@property
def config(self):
return self.manager.config
1 change: 0 additions & 1 deletion rewrite/screens/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class ClockScreen(ScreenBase):

MAX_DURATION_SECONDS = 3

def render(self):
Expand Down
1 change: 0 additions & 1 deletion rewrite/screens/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class GameScreen(ScreenBase):

MAX_DURATION_SECONDS = 3

def render(self):
Expand Down
28 changes: 16 additions & 12 deletions rewrite/screens/screen_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
from screens.weather import WeatherScreen
from screens.game import GameScreen

class ScreenManager():

class ScreenManager:
SCREENS = {
Screen.STATIC: StaticScreen,
Screen.CLOCK: ClockScreen,
Screen.STATIC: StaticScreen,
Screen.CLOCK: ClockScreen,
Screen.WEATHER: WeatherScreen,
Screen.GAME: GameScreen
Screen.GAME: GameScreen,
}

def __init__(self, matrix, canvas, config, queue):
self.matrix = matrix
self.canvas = canvas
self.config = config
self.data = None
self.queue = queue
self.queue = queue
self.screen = StaticScreen(self)

def start(self):
Expand All @@ -46,35 +46,39 @@ def __handle_screen_request(self):
request = self.queue.get()

if not isinstance(request, ScreenRequest):
ScoreboardLogger.warning(f"Screen manager received transition request for instance of {type(request)}, but must be a ScreenRequest")
ScoreboardLogger.warning(
f"Screen manager received transition request for instance of {type(request)}, but must be a ScreenRequest"
)

return False

screen_class = self.SCREENS.get(request.type, None)

if not screen_class:
ScoreboardLogger.warning(f"Screen manager received transition request for screen type of {request.type}, but no such screen type exists")
ScoreboardLogger.warning(
f"Screen manager received transition request for screen type of {request.type}, but no such screen type exists"
)

return False

try:
screen = screen_class(request.manager, *request.args)
except Exception as exception:
ScoreboardLogger.exception(exception)
ScoreboardLogger.exception("Screen manager failed to process screen transition!")

return False

# If not ready to transition, re-queue the request for later.
if not self.screen.ready_to_transition():
self.queue.put(request)

return False

self.__perform_transition(screen)

return True

def __perform_transition(self, screen):
self.screen = screen

Expand Down
13 changes: 6 additions & 7 deletions rewrite/screens/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@

from screens.base import ScreenBase


class StaticScreen(ScreenBase):

'''
"""
This screen is used to display a static image on startup before real data is loaded.
'''
"""

MIN_DURATION_SECONDS = 3

# TODO: Pull this from config.
LOGO_PATH = os.path.abspath(
os.path.join(__file__, "./../../assets/logo/mlb-w32h32.png")
)
LOGO_PATH = os.path.abspath(os.path.join(__file__, "./../../assets/logo/mlb-w32h32.png"))

def __init__(self, *args):
super(self.__class__, self).__init__(*args)
Expand All @@ -27,7 +26,7 @@ def render(self):
pass

def ready_to_transition(self):
'''
"""
If the static load screen is displayed, then leave it on screen for a few seconds to avoid flashing.
'''
"""
return self.duration >= self.MIN_DURATION_SECONDS * 1000
1 change: 0 additions & 1 deletion rewrite/screens/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class WeatherScreen(ScreenBase):

MAX_DURATION_SECONDS = 3

def __init__(self, *args):
Expand Down
12 changes: 7 additions & 5 deletions rewrite/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from utils import logger as ScoreboardLogger


def args():
parser = argparse.ArgumentParser()

Expand Down Expand Up @@ -101,7 +102,11 @@ def args():
type=int,
)
parser.add_argument(
"--led-pwm-dither-bits", action="store", help="Time dithering of lower bits (Default: 0)", default=0, type=int,
"--led-pwm-dither-bits",
action="store",
help="Time dithering of lower bits (Default: 0)",
default=0,
type=int,
)
parser.add_argument(
"--config",
Expand All @@ -111,10 +116,7 @@ def args():
type=str,
)
parser.add_argument(
"--emulated",
action="store_const",
help="Force using emulator mode over default matrix display.",
const=True
"--emulated", action="store_const", help="Force using emulator mode over default matrix display.", const=True
)
return parser.parse_args()

Expand Down
2 changes: 1 addition & 1 deletion rewrite/utils/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from driver import graphics

class FontCache:

class FontCache:
FONT_PATHS = ["../assets/fonts/patched", "../submodules/matrix/fonts"]

def __init__(self):
Expand Down

0 comments on commit 15d060b

Please sign in to comment.