55import threading
66import sys
77import os
8+ import importlib .resources
9+
810import re
911import time
1012import argparse
2123from rpi_backlight import Backlight
2224from adafruit_led_animation .animation .pulse import Pulse
2325
24- from listener import Listener
26+ from . listener import Listener
2527
2628# Base Path is the folder the script resides in
27- BASE_PATH = os .path .dirname (sys .argv [0 ])
28- if BASE_PATH != "" :
29- BASE_PATH += "/"
29+ BASE_PATH = importlib .resources .files (__package__ )
3030
3131# General Settings
3232STORY_WORD_LENGTH = 800
5959BUTTON_NEW_IMAGE = "button_new.png"
6060
6161# Asset Paths
62- IMAGES_PATH = BASE_PATH + "images/"
63- FONTS_PATH = BASE_PATH + "fonts/"
62+ IMAGES_PATH = BASE_PATH . joinpath ( "images/" )
63+ FONTS_PATH = BASE_PATH . joinpath ( "fonts/" )
6464
6565# Font Path & Size
66- TITLE_FONT = (FONTS_PATH + "Desdemona Black Regular.otf" , 48 )
66+ TITLE_FONT = (FONTS_PATH . joinpath ( "Desdemona Black Regular.otf" ) , 48 )
6767TITLE_COLOR = (0 , 0 , 0 )
68- TEXT_FONT = (FONTS_PATH + "times new roman.ttf" , 24 )
68+ TEXT_FONT = (FONTS_PATH . joinpath ( "times new roman.ttf" ) , 24 )
6969TEXT_COLOR = (0 , 0 , 0 )
7070
7171# Delays Settings
@@ -262,9 +262,9 @@ def start(self):
262262 self ._load_font ("text" , TEXT_FONT )
263263
264264 # Add buttons
265- back_button_image = pygame .image .load (IMAGES_PATH + BUTTON_BACK_IMAGE )
266- next_button_image = pygame .image .load (IMAGES_PATH + BUTTON_NEXT_IMAGE )
267- new_button_image = pygame .image .load (IMAGES_PATH + BUTTON_NEW_IMAGE )
265+ back_button_image = pygame .image .load (IMAGES_PATH . joinpath ( BUTTON_BACK_IMAGE ) )
266+ next_button_image = pygame .image .load (IMAGES_PATH . joinpath ( BUTTON_NEXT_IMAGE ) )
267+ new_button_image = pygame .image .load (IMAGES_PATH . joinpath ( BUTTON_NEW_IMAGE ) )
268268 button_spacing = (
269269 self .width
270270 - (
@@ -407,7 +407,7 @@ def _rotate_mouse_pos(self, point):
407407
408408 def _load_image (self , name , filename ):
409409 try :
410- image = pygame .image .load (IMAGES_PATH + filename )
410+ image = pygame .image .load (IMAGES_PATH . joinpath ( filename ) )
411411 self .images [name ] = image
412412 except pygame .error :
413413 pass
@@ -771,7 +771,8 @@ def parse_args():
771771 return parser .parse_args ()
772772
773773
774- def main (args ):
774+ def main ():
775+ args = parse_args ()
775776 book = Book (args .rotation )
776777 try :
777778 book .start ()
@@ -790,4 +791,4 @@ def main(args):
790791
791792
792793if __name__ == "__main__" :
793- main (parse_args () )
794+ main ()
0 commit comments