Skip to content

Commit

Permalink
adapt to package resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherthomas committed Aug 18, 2023
1 parent 2f30e5b commit 56292b0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Magic_AI_Storybook/magic_ai_storybook/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
2 changes: 1 addition & 1 deletion Magic_AI_Storybook/magic_ai_storybook/make_shortcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():
Comment=Run {APP_TITLE}
Terminal={"true" if RUN_IN_TERMINAL else "false"}
Name={APP_TITLE}
Exec=sudo python {APP_PATH}
Exec=sudo /root/.local/bin/magicbook-story
Type=Application
Icon={APP_ICON}
"""
Expand Down
29 changes: 15 additions & 14 deletions Magic_AI_Storybook/magic_ai_storybook/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import threading
import sys
import os
import importlib.resource

import re
import time
import argparse
Expand All @@ -21,12 +23,10 @@
from rpi_backlight import Backlight
from adafruit_led_animation.animation.pulse import Pulse

from listener import Listener
from .listener import Listener

# Base Path is the folder the script resides in
BASE_PATH = os.path.dirname(sys.argv[0])
if BASE_PATH != "":
BASE_PATH += "/"
BASE_PATH = importlib.resource.files(__package__)

# General Settings
STORY_WORD_LENGTH = 800
Expand Down Expand Up @@ -59,13 +59,13 @@
BUTTON_NEW_IMAGE = "button_new.png"

# Asset Paths
IMAGES_PATH = BASE_PATH + "images/"
FONTS_PATH = BASE_PATH + "fonts/"
IMAGES_PATH = BASE_PATH.joinpath("images/")
FONTS_PATH = BASE_PATH.joinpath("fonts/")

# Font Path & Size
TITLE_FONT = (FONTS_PATH + "Desdemona Black Regular.otf", 48)
TITLE_FONT = (FONTS_PATH.joinpath("Desdemona Black Regular.otf"), 48)
TITLE_COLOR = (0, 0, 0)
TEXT_FONT = (FONTS_PATH + "times new roman.ttf", 24)
TEXT_FONT = (FONTS_PATH.joinpath("times new roman.ttf"), 24)
TEXT_COLOR = (0, 0, 0)

# Delays Settings
Expand Down Expand Up @@ -262,9 +262,9 @@ def start(self):
self._load_font("text", TEXT_FONT)

# Add buttons
back_button_image = pygame.image.load(IMAGES_PATH + BUTTON_BACK_IMAGE)
next_button_image = pygame.image.load(IMAGES_PATH + BUTTON_NEXT_IMAGE)
new_button_image = pygame.image.load(IMAGES_PATH + BUTTON_NEW_IMAGE)
back_button_image = pygame.image.load(IMAGES_PATH.joinpath(BUTTON_BACK_IMAGE))
next_button_image = pygame.image.load(IMAGES_PATH.joinpath(BUTTON_NEXT_IMAGE))
new_button_image = pygame.image.load(IMAGES_PATH.joinpath(BUTTON_NEW_IMAGE))
button_spacing = (
self.width
- (
Expand Down Expand Up @@ -407,7 +407,7 @@ def _rotate_mouse_pos(self, point):

def _load_image(self, name, filename):
try:
image = pygame.image.load(IMAGES_PATH + filename)
image = pygame.image.load(IMAGES_PATH.joinpath(filename))
self.images[name] = image
except pygame.error:
pass
Expand Down Expand Up @@ -771,7 +771,8 @@ def parse_args():
return parser.parse_args()


def main(args):
def main():
args = parse_args()
book = Book(args.rotation)
try:
book.start()
Expand All @@ -790,4 +791,4 @@ def main(args):


if __name__ == "__main__":
main(parse_args())
main()
4 changes: 4 additions & 0 deletions Magic_AI_Storybook/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ dependencies = [
"adafruit-circuitpython-neopixel>=6.3.9",
"rpi-backlight>=2.6.0",
]

[project.scripts]
"magicbook-story" = "magic_ai_storybook:story.run"

[build-system]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"
Expand Down

0 comments on commit 56292b0

Please sign in to comment.