77from shutil import copyfile
88import configparser
99import os
10+ import sys
1011
12+ def getResourcePath (filename ):
13+ """ Get absolute path to resource, works for dev and for PyInstaller """
14+ if hasattr (sys , '_MEIPASS' ):
15+ return os .path .join (sys ._MEIPASS , filename )
16+
17+ rootPath = os .path .dirname (__file__ )
18+ return os .path .join (rootPath , filename )
1119
1220class Game :
1321 def __init__ (self ,
14- rootPath ,
1522 width ,
1623 height ,
1724 timings ,
@@ -30,7 +37,7 @@ def __init__(self,
3037 display .set_caption ("Destroy the flower!" )
3138
3239 ##########ICON##########
33- ico = os . path . join ( rootPath , "flower.png" )
40+ ico = getResourcePath ( "flower.png" )
3441 gameIcon = pygame .image .load (ico )
3542 display .set_icon (gameIcon )
3643 ##############
@@ -332,10 +339,8 @@ def split(st) -> list:
332339
333340if __name__ == "__main__" :
334341 ################ ROOT FIX ################
335- rootPath = os .path .dirname (__file__ )
336-
337- config_path = os .path .join (rootPath , config_path )
338- time_path = os .path .join (rootPath , time_path )
342+ config_path = getResourcePath (config_path )
343+ time_path = getResourcePath (time_path )
339344
340345 ################ TIMINGS ################
341346 read_timings ()
@@ -362,7 +367,7 @@ def split(st) -> list:
362367
363368 time = datetime .timedelta (minutes = st [0 ], seconds = st [1 ], milliseconds = st [2 ])
364369
365- game = Game (rootPath , wid , hei , timings , nst , (nsp [0 ], nsp [1 ]),
370+ game = Game (wid , hei , timings , nst , (nsp [0 ], nsp [1 ]),
366371 (psp [0 ], psp [1 ]), time .total_seconds ()* 1000.0 )
367372
368373 #game = Game(800, 700, 2000, (400, 100), (400, 600), time.total_seconds()*1000.0)
0 commit comments