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 1
1
# -*- mode: python ; coding: utf-8 -*-
2
2
3
+ RELATIVE_ICON_PATH = "./extra/icon.ico"
3
4
block_cipher = None
4
5
5
6
def kasa_dist_info_datas ():
@@ -20,7 +21,8 @@ def kasa_dist_info_datas():
20
21
a = Analysis (['kasatk/__main__.py' ],
21
22
pathex = ['.\\ env\\ Lib\\ site-packages\\ ' , '.' ],
22
23
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" )],
24
26
hiddenimports = [],
25
27
hookspath = [],
26
28
runtime_hooks = [],
@@ -44,5 +46,7 @@ exe = EXE(pyz,
44
46
upx = True ,
45
47
upx_exclude = [],
46
48
runtime_tmpdir = None ,
47
- icon = 'extra/icon.ico' ,
49
+ icon = RELATIVE_ICON_PATH ,
48
50
console = False )
51
+
52
+ # vi:syntax=python
Original file line number Diff line number Diff line change 18
18
logger = logging .getLogger (__name__ )
19
19
20
20
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
+
21
31
class LightState (TypedDict ):
22
32
on_off : int
23
33
mode : str
@@ -370,7 +380,11 @@ def main():
370
380
root = tkinter .Tk ()
371
381
root .title ("Kasa Devices" )
372
382
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 )
374
388
scroll_frame = ScrollableFrame (root )
375
389
device_frame = KasaDevices (scroll_frame .scrollable_frame )
376
390
device_frame .pack ()
You can’t perform that action at this time.
0 commit comments