tray icon

This commit is contained in:
Dobromir Popov 2024-09-10 02:58:18 +03:00
parent adb595feb8
commit 7b8e864f5d
2 changed files with 49 additions and 2 deletions

View File

@ -1,14 +1,21 @@
import os import os
from groq import Groq import sys
import pyaudio import pyaudio
import wave import wave
import pyautogui import pyautogui
import keyboard import keyboard
import mouse import mouse
import threading
from groq import Groq
import pystray
from pystray import MenuItem as item
from PIL import Image
import ctypes
# Constants # Constants
API_KEY = "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" # Make sure to use your actual API key API_KEY = "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" # Make sure to use your actual API key
BUTTON = 'ctrl' # The keyboard button to listen for BUTTON = 'ctrl' # The keyboard button to listen for
AUTO_START_PATH = os.path.expanduser(r"~\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup") # For autostart
# Initialize the Groq client # Initialize the Groq client
client = Groq(api_key=API_KEY) client = Groq(api_key=API_KEY)
@ -50,6 +57,8 @@ def transcribe_audio(filename):
response_format="json", # Optional response_format="json", # Optional
temperature=0.0 # Optional temperature=0.0 # Optional
) )
# Access the transcription text using dot notation
return transcription.text return transcription.text
def simulate_keypress(text): def simulate_keypress(text):
@ -73,5 +82,43 @@ def main():
print("Entering text...") print("Entering text...")
simulate_keypress(transcribed_text) simulate_keypress(transcribed_text)
def add_to_autostart():
"""Registers the app to autostart on login."""
script_path = os.path.abspath(__file__)
shortcut_path = os.path.join(AUTO_START_PATH, "MyApp.lnk")
# Use ctypes to create the shortcut (this is Windows specific)
shell = ctypes.windll.shell32
shell.ShellExecuteW(None, "runas", "cmd.exe", f'/C mklink "{shortcut_path}" "{script_path}"', None, 1)
print("App added to autostart.")
def quit_app(icon):
"""Quit the tray application."""
icon.stop()
sys.exit()
def setup_tray_icon():
"""Setup system tray icon and menu."""
# Create an icon image
icon_image = Image.new('RGB', (64, 64), color=(255, 0, 0)) # Red icon as an example
# Define menu items for the tray
menu = (
item('Register to Autostart', add_to_autostart),
item('Exit', lambda: quit_app(icon))
)
# Create the tray icon
icon = pystray.Icon("my_app", icon_image, menu=pystray.Menu(*menu))
# Run the tray icon
icon.run()
if __name__ == "__main__": if __name__ == "__main__":
# Start the tray icon in a separate thread so it doesn't block the main functionality
tray_thread = threading.Thread(target=setup_tray_icon)
tray_thread.daemon = True
tray_thread.start()
# Run the main function
main() main()

Binary file not shown.