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