-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskbar.py
75 lines (58 loc) · 2.01 KB
/
taskbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Import necessary modules
from pystray import Icon, Menu, MenuItem
from PIL import Image
import subprocess
import transliterate
import logging
# Create a logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)
fh = logging.FileHandler('taskbar.log', encoding='utf-8')
fh.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
logger.addHandler(fh)
logger.addHandler(ch)
# Initialize streamlit_process variable
streamlit_process = None
# Define on_transliterate function to handle transliteration
def on_transliterate(icon, item):
logger.info("Transliterate button clicked")
# Call transliterate function from transliterate module
transliterate.transliterate_last_accessed_file(
r"C:\Users\Bestfast\AppData\Roaming\foobar2000-v2\lyrics")
# Define on_edit function to handle editing
def on_edit(icon, item):
logger.info("Edit clicked")
# Start Streamlit server here
global streamlit_process
if streamlit_process is not None:
logger.info("Streamlit server already running, terminating")
streamlit_process.terminate()
streamlit_process = subprocess.Popen(["streamlit", "run", "streamlit.py"])
# Define on_quit function to handle quitting the application
def on_quit(icon, item):
global streamlit_process
# Terminate Streamlit process if it exists
if streamlit_process is not None:
logger.info("Terminating running Streamlit server")
streamlit_process.terminate()
# Stop the icon
icon.stop()
# Load icon image
image = Image.open("icon.ico")
# Create menu with Transliterate, Edit and Quit options
menu = Menu(
MenuItem("Transliterate", on_transliterate),
MenuItem("Edit", on_edit),
MenuItem("Quit", on_quit)
)
# Create icon with Test title, image and menu
icon = Icon("Test", image, "Test App", menu)
logger.info("Starting tray icon")
# Run the icon
icon.run()