Skip to content

Commit

Permalink
fix errors exiting the program, add tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
I5UCC committed Jun 28, 2024
1 parent c81d0f4 commit 09cb3ee
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.3.0
v2.3.1
6 changes: 5 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import traceback
import glob
import shutil
from tray_icon import TrayIcon
from threading import Thread

from zeroconf._exceptions import NonUniqueNameException
Expand Down Expand Up @@ -210,14 +211,17 @@ def stop() -> None:
None
"""
xinput.running = False
tray.stop()
ovr.shutdown()
osc.shutdown()


logging.basicConfig(level=logging.DEBUG if len(sys.argv) > 1 else logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', handlers=[logging.StreamHandler(), logging.FileHandler(get_absolute_path("log.log"))])

VERSION = open(get_absolute_path("VERSION")).read().strip()

tray = TrayIcon(stop, get_absolute_path("icon.ico"))
tray.run()

# Argument Parser
parser = argparse.ArgumentParser(description='ThumbParamsOSC: Takes button data from SteamVR and sends it to an OSC-Client')
parser.add_argument('-d', '--debug', required=False, action='store_true', help='prints values for debugging')
Expand Down
3 changes: 2 additions & 1 deletion src/osc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self, conf: dict, avatar_change_function, run_server = True) -> Non
self.binary_num_bits = int(conf["Binary_bits"])
self.binary_potencies = [2**i for i in range(self.binary_num_bits)]
self.binary_potency = (2**self.binary_num_bits) - 1

self.server = None
self.oscqs = None
self.osc_client = udp_client.SimpleUDPClient(self.ip, self.port)
if run_server:
self.start_server(avatar_change_function)
Expand Down
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ argparse
requests
psutil
pyglet
pillow
4 changes: 2 additions & 2 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

VERSION = open("VERSION").read().strip()

packages = ["argparse", "certifi", "charset_normalizer", "idna", "ifaddr", "lief", "openvr", "psutil", "pyglet", "pythonosc", "requests", "urllib3", "zeroconf", "ctypes"]
packages = ["argparse", "certifi", "charset_normalizer", "idna", "ifaddr", "lief", "openvr", "psutil", "pyglet", "pythonosc", "requests", "urllib3", "zeroconf", "ctypes", "pystray", "PIL"]
exclude = ["tkinter", "lib2to3", "test", "unittest", "xmlrpc"]
file_include = ["config.json", "Run Debug Mode.bat", "bindings/", "app.vrmanifest", "VERSION"]
file_include = ["config.json", "Run Debug Mode.bat", "bindings/", "app.vrmanifest", "VERSION", "icon.ico"]
bin_excludes = ["_bz2.pyd", "_decimal.pyd", "_hashlib.pyd", "_lzma.pyd", "_queue.pyd", "_ssl.pyd", "libcrypto-1_1.dll", "libssl-1_1.dll", "ucrtbase.dll", "VCRUNTIME140.dll"]

build_exe_options = {"packages": packages, "excludes": exclude, "include_files": file_include, "bin_excludes": bin_excludes}
Expand Down
22 changes: 22 additions & 0 deletions src/tray_icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pystray
import sys

from PIL import Image, ImageDraw

class TrayIcon:
def __init__(self, stop_func, icon_path):
self.icon = Image.open(icon_path)
self.menu = pystray.Menu(
pystray.MenuItem("Exit", stop_func)
)
self.tray_icon = pystray.Icon("tray_icon", self.icon, "ThumbparamsOSC", self.menu)

def run(self):
self.tray_icon.run_detached()

def stop(self):
self.tray_icon.stop()

if __name__ == "__main__":
tray_icon = TrayIcon()
tray_icon.run()

0 comments on commit 09cb3ee

Please sign in to comment.