Update .gitignore and enhance console visibility controls in main.py

This commit is contained in:
ZareMate 2025-01-13 20:32:08 +01:00
parent 814b7c9d36
commit b3afc9f785
Signed by: zaremate
GPG Key ID: 369A0E45E03A81C3
2 changed files with 19 additions and 2 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
./*.png
/*.png

19
main.py
View File

@ -9,10 +9,19 @@ import pystray
from PIL import Image, ImageDraw
import threading
import ctypes
import os
# Set the title for the PowerShell window
ctypes.windll.kernel32.SetConsoleTitleW("ESP32 Discord Controller")
# Set the process name for Task Manager
try:
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW("ESP32 Discord Controller")
os.system("title ESP32 Discord Controller")
except:
pass
def get_serial_port():
if len(sys.argv) > 1 and sys.argv[1].startswith("-com="):
return sys.argv[1].split("=")[1]
@ -85,6 +94,14 @@ def create_image():
fill="black")
return image
def toggle_console():
whnd = ctypes.windll.kernel32.GetConsoleWindow()
if whnd != 0:
if ctypes.windll.user32.IsWindowVisible(whnd):
ctypes.windll.user32.ShowWindow(whnd, 0)
else:
ctypes.windll.user32.ShowWindow(whnd, 1)
def on_quit(icon, item):
icon.stop()
if 'ser' in globals() and ser.is_open:
@ -102,7 +119,7 @@ def hide_in_tray():
hide_console()
icon = pystray.Icon("ESP32-discord")
icon.icon = create_image()
icon.menu = pystray.Menu(pystray.MenuItem('Quit', on_quit))
icon.menu = pystray.Menu(pystray.MenuItem('Quit', on_quit), pystray.MenuItem('Toggle Console', toggle_console))
threading.Thread(target=icon.run).start()
def main():