Skip to content

Commit

Permalink
Improve PyInstaller compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentscode committed Jan 21, 2023
1 parent 30661da commit f7ad9a2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
version.txt

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
2 changes: 2 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create-version-file version.yaml --outfile version.txt
pyinstaller --onefile --noconsole --add-data "icons/*.png;icons" -n "HomeTray" -i icon.ico --version-file version.txt home_tray.py
24 changes: 14 additions & 10 deletions home_tray.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import wx.adv
import wx

import requests
import json
import sched
import time
import configparser
import wx
import wx.adv
from _thread import start_new_thread
from homeassistant_api import Client
import configparser

icon_base = "icons/"
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")

return os.path.join(base_path, relative_path)

icon_base = resource_path('icons/')
icons = {
"default": {
"on": "on.png",
Expand Down Expand Up @@ -72,7 +77,6 @@ def update_task(scheduler):
start_new_thread(self.scheduler.run, ())

self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
# self.Bind(wx.adv.EVT_TASKBAR_RIGHT_DOWN, self.on_right_down)

self.update_state()

Expand All @@ -88,7 +92,7 @@ def update_state(self):
else:
rgb_color = [253, 213, 27]
else:
rgb_color = [0, 0, 0] # or [225, 225, 225]
rgb_color = [225, 225, 225]

icon = get_icon_path(entity_icon, entity_state)
self.set_icon(icon, entity_name)
Expand Down Expand Up @@ -184,7 +188,7 @@ def OnInit(self):
def OnExit(self):
for tray_icon in self.tray_icons:
tray_icon.cleanup()

return 0

def main():
Expand Down
Binary file added icon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyinstaller-versionfile==2.1.1
pyinstaller==3.5
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wxPython==4.2.0
requests==2.28.2
homeassistant-api==4.0.1
6 changes: 6 additions & 0 deletions version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Version: 0.0.2.0
CompanyName: Vincent Schmandt
FileDescription: Allows you to controll Home Assistant from the system tray.
InternalName: HomeTray
OriginalFilename: HomeTray.exe
ProductName: HomeTray

0 comments on commit f7ad9a2

Please sign in to comment.