Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic AI Storybook python packaging #2594

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
162 changes: 162 additions & 0 deletions Magic_AI_Storybook/.gitignore
@@ -0,0 +1,162 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
3 changes: 3 additions & 0 deletions Magic_AI_Storybook/README.md
@@ -0,0 +1,3 @@
# Magic_AI_Storybook

Creates stories based on voice-input, see https://learn.adafruit.com/magic-storybook-with-chatgpt
3 changes: 3 additions & 0 deletions Magic_AI_Storybook/magic_ai_storybook/__init__.py
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
Expand Up @@ -28,7 +28,6 @@ def main():
APP_PATH = "~/Magic_AI_Storybook/story.py"
APP_ICON = "~/Magic_AI_Storybook/images/magic_book_icon.png"
FILENAME = "storybook.desktop"
ENV_PATH = "~/story"
AUTO_START = True

if os.geteuid() == 0:
Expand All @@ -42,16 +41,12 @@ def main():

APP_PATH = APP_PATH.replace("~", user_homedir)
APP_ICON = APP_ICON.replace("~", user_homedir)
PYTHON_PATH = "python"
if ENV_PATH is not None:
ENV_PATH = ENV_PATH.replace("~", user_homedir)
PYTHON_PATH = ENV_PATH + "/bin/" + PYTHON_PATH

shortcut_template = f"""[Desktop Entry]
Comment=Run {APP_TITLE}
Terminal={"true" if RUN_IN_TERMINAL else "false"}
Name={APP_TITLE}
Exec=sudo -E env PATH=$PATH {PYTHON_PATH} {APP_PATH}
Exec=sudo /root/.local/bin/magicbook-story
Type=Application
Icon={APP_ICON}
"""
Expand Down
Expand Up @@ -5,6 +5,8 @@
import threading
import sys
import os
import importlib.resources

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.resources.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 @@ -264,9 +264,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 @@ -409,7 +409,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 @@ -767,7 +767,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 @@ -786,4 +787,4 @@ def main(args):


if __name__ == "__main__":
main(parse_args())
main()