5
5
import threading
6
6
import sys
7
7
import os
8
+ import importlib .resources
9
+
8
10
import re
9
11
import time
10
12
import argparse
21
23
from rpi_backlight import Backlight
22
24
from adafruit_led_animation .animation .pulse import Pulse
23
25
24
- from listener import Listener
26
+ from . listener import Listener
25
27
26
28
# 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__ )
30
30
31
31
# General Settings
32
32
STORY_WORD_LENGTH = 800
59
59
BUTTON_NEW_IMAGE = "button_new.png"
60
60
61
61
# 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/" )
64
64
65
65
# Font Path & Size
66
- TITLE_FONT = (FONTS_PATH + "Desdemona Black Regular.otf" , 48 )
66
+ TITLE_FONT = (FONTS_PATH . joinpath ( "Desdemona Black Regular.otf" ) , 48 )
67
67
TITLE_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 )
69
69
TEXT_COLOR = (0 , 0 , 0 )
70
70
71
71
# Delays Settings
@@ -262,9 +262,9 @@ def start(self):
262
262
self ._load_font ("text" , TEXT_FONT )
263
263
264
264
# 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 ) )
268
268
button_spacing = (
269
269
self .width
270
270
- (
@@ -407,7 +407,7 @@ def _rotate_mouse_pos(self, point):
407
407
408
408
def _load_image (self , name , filename ):
409
409
try :
410
- image = pygame .image .load (IMAGES_PATH + filename )
410
+ image = pygame .image .load (IMAGES_PATH . joinpath ( filename ) )
411
411
self .images [name ] = image
412
412
except pygame .error :
413
413
pass
@@ -771,7 +771,8 @@ def parse_args():
771
771
return parser .parse_args ()
772
772
773
773
774
- def main (args ):
774
+ def main ():
775
+ args = parse_args ()
775
776
book = Book (args .rotation )
776
777
try :
777
778
book .start ()
@@ -790,4 +791,4 @@ def main(args):
790
791
791
792
792
793
if __name__ == "__main__" :
793
- main (parse_args () )
794
+ main ()
0 commit comments