File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 11# -*- mode: python ; coding: utf-8 -*-
22
3+ RELATIVE_ICON_PATH = "./extra/icon.ico"
34block_cipher = None
45
56def kasa_dist_info_datas ():
@@ -20,7 +21,8 @@ def kasa_dist_info_datas():
2021a = Analysis (['kasatk/__main__.py' ],
2122 pathex = ['.\\ env\\ Lib\\ site-packages\\ ' , '.' ],
2223 binaries = [],
23- datas = [kasa_dist_info_datas ()],
24+ # Note: the second item in each tuple MUST be a directory.
25+ datas = [kasa_dist_info_datas (), (RELATIVE_ICON_PATH , "./extra" )],
2426 hiddenimports = [],
2527 hookspath = [],
2628 runtime_hooks = [],
@@ -44,5 +46,7 @@ exe = EXE(pyz,
4446 upx = True ,
4547 upx_exclude = [],
4648 runtime_tmpdir = None ,
47- icon = 'extra/icon.ico' ,
49+ icon = RELATIVE_ICON_PATH ,
4850 console = False )
51+
52+ # vi:syntax=python
Original file line number Diff line number Diff line change 1818logger = logging .getLogger (__name__ )
1919
2020
21+ def resource_path (relative_path ):
22+ """Find a resource in a PyInstaller executable, or in the local directory"""
23+ if hasattr (sys , "_MEIPASS" ):
24+ logger .info ("Finding resource inside PyInstaller executable" )
25+ p = os .path .join (sys ._MEIPASS , relative_path )
26+ assert os .path .exists (p )
27+ return p
28+ return os .path .join (os .path .abspath ("." ), relative_path )
29+
30+
2131class LightState (TypedDict ):
2232 on_off : int
2333 mode : str
@@ -370,7 +380,11 @@ def main():
370380 root = tkinter .Tk ()
371381 root .title ("Kasa Devices" )
372382 root .geometry ("500x400" )
373- root .iconbitmap ("extra/icon.ico" )
383+ try :
384+ root .iconbitmap (resource_path ("extra/icon.ico" ))
385+ except Exception as e :
386+ logger .warning ("Failed to load application icon." )
387+ logger .error (e )
374388 scroll_frame = ScrollableFrame (root )
375389 device_frame = KasaDevices (scroll_frame .scrollable_frame )
376390 device_frame .pack ()
You can’t perform that action at this time.
0 commit comments