Skip to content

Commit f7ad9a2

Browse files
committed
Improve PyInstaller compatibility
1 parent 30661da commit f7ad9a2

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ share/python-wheels/
2929
.installed.cfg
3030
*.egg
3131
MANIFEST
32+
version.txt
3233

3334
# PyInstaller
3435
# Usually these files are written by a python script from a template

build.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
create-version-file version.yaml --outfile version.txt
2+
pyinstaller --onefile --noconsole --add-data "icons/*.png;icons" -n "HomeTray" -i icon.ico --version-file version.txt home_tray.py

home_tray.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
import wx.adv
2-
import wx
3-
4-
import requests
5-
import json
61
import sched
72
import time
3+
import configparser
4+
import wx
5+
import wx.adv
86
from _thread import start_new_thread
97
from homeassistant_api import Client
10-
import configparser
118

12-
icon_base = "icons/"
9+
def resource_path(relative_path):
10+
try:
11+
base_path = sys._MEIPASS
12+
except Exception:
13+
base_path = os.path.abspath(".")
14+
15+
return os.path.join(base_path, relative_path)
16+
17+
icon_base = resource_path('icons/')
1318
icons = {
1419
"default": {
1520
"on": "on.png",
@@ -72,7 +77,6 @@ def update_task(scheduler):
7277
start_new_thread(self.scheduler.run, ())
7378

7479
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
75-
# self.Bind(wx.adv.EVT_TASKBAR_RIGHT_DOWN, self.on_right_down)
7680

7781
self.update_state()
7882

@@ -88,7 +92,7 @@ def update_state(self):
8892
else:
8993
rgb_color = [253, 213, 27]
9094
else:
91-
rgb_color = [0, 0, 0] # or [225, 225, 225]
95+
rgb_color = [225, 225, 225]
9296

9397
icon = get_icon_path(entity_icon, entity_state)
9498
self.set_icon(icon, entity_name)
@@ -184,7 +188,7 @@ def OnInit(self):
184188
def OnExit(self):
185189
for tray_icon in self.tray_icons:
186190
tray_icon.cleanup()
187-
191+
188192
return 0
189193

190194
def main():

icon.ico

3.64 KB
Binary file not shown.

requirements.dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyinstaller-versionfile==2.1.1
2+
pyinstaller==3.5

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wxPython==4.2.0
2+
requests==2.28.2
3+
homeassistant-api==4.0.1

version.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Version: 0.0.2.0
2+
CompanyName: Vincent Schmandt
3+
FileDescription: Allows you to controll Home Assistant from the system tray.
4+
InternalName: HomeTray
5+
OriginalFilename: HomeTray.exe
6+
ProductName: HomeTray

0 commit comments

Comments
 (0)