-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtray_app.py
More file actions
198 lines (167 loc) · 6.72 KB
/
tray_app.py
File metadata and controls
198 lines (167 loc) · 6.72 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import pystray
from PIL import Image, ImageDraw
import threading
import sys
import os
import subprocess
import ctypes
# Set AppUserModelID so notifications show "GitVille" instead of "Python"
try:
myappid = 'gitville.activity.tracker.v1'
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
except Exception:
pass
from data_collector import DataCollector
def create_image():
# Create high-res image for anti-aliasing
size = 256
image = Image.new('RGBA', (size, size), (0,0,0,0))
dc = ImageDraw.Draw(image)
# 1. Background: Deep Gradient (Blue to Purple)
# Simulating gradient by drawing lines
c1 = (43, 88, 118) # #2b5876
c2 = (78, 67, 118) # #4e4376
# Rounded Mask
mask = Image.new('L', (size, size), 0)
mask_dc = ImageDraw.Draw(mask)
mask_dc.rounded_rectangle((0, 0, size, size), radius=60, fill=255)
# Draw Gradient
for y in range(size):
r = int(c1[0] + (c2[0] - c1[0]) * y / size)
g = int(c1[1] + (c2[1] - c1[1]) * y / size)
b = int(c1[2] + (c2[2] - c1[2]) * y / size)
dc.line([(0, y), (size, y)], fill=(r, g, b))
# Apply Mask (Composite)
# Instead of complex masking, we can just clear corners if we want transparent background,
# but let's just draw the gradient in a rounded rect fashion?
# PIL draw.rounded_rectangle doesn't support gradient fill.
# So we composite:
gradient = image.copy()
image = Image.new('RGBA', (size, size), (0,0,0,0))
image.paste(gradient, (0,0), mask=mask)
dc = ImageDraw.Draw(image)
# 2. Border (Glowing Cyan/Teal)
dc.rounded_rectangle((2, 2, size-2, size-2), radius=60, outline="#5ee7df", width=6)
# 3. Icon: Stylized House (White)
# Center: 128, 128
# House Base: 100 wide, 80 tall
# Roof: Triangle
house_color = "#ffffff"
# Coordinates (Centered)
cx, cy = size//2, size//2
w = 120
h = 90
# Base
base_left = cx - w//2
base_right = cx + w//2
base_top = cy - h//2 + 30 # Shift down a bit
base_bottom = cy + h//2 + 30
dc.rectangle((base_left, base_top, base_right, base_bottom), fill=house_color)
# Roof (Triangle)
roof_h = 70
roof_pts = [
(cx - w//2 - 20, base_top), # Left Overhang
(cx, base_top - roof_h), # Peak
(cx + w//2 + 20, base_top) # Right Overhang
]
dc.polygon(roof_pts, fill=house_color)
# Door (Cutout - Dark)
door_w = 40
door_h = 50
dc.rectangle((cx - door_w//2, base_bottom - door_h, cx + door_w//2, base_bottom), fill="#4e4376")
# Window (Cutout - Dark)
win_size = 30
dc.rectangle((cx - win_size//2, base_top + 20, cx + win_size//2, base_top + 20 + win_size), fill="#4e4376")
# 4. Resize to 64x64 (High Quality)
image = image.resize((64, 64), Image.Resampling.LANCZOS)
return image
class SystemTrayTracker:
def __init__(self):
self.collector = DataCollector(on_reward=self.notify_reward)
self.icon = None
def notify_reward(self, title, msg):
if self.icon:
self.icon.notify(msg, title)
def on_quit(self, icon, item):
print("Stopping collector...")
self.collector.save_data()
self.collector.stop()
icon.stop()
os._exit(0) # Force exit to kill threads
def open_map(self):
# Open visualizer_app
if getattr(sys, 'frozen', False):
subprocess.Popen([sys.executable, '--visualizer'])
else:
script_path = os.path.join(os.getcwd(), 'visualizer_app.py')
subprocess.Popen([sys.executable, script_path])
def open_stats(self):
# Open input_visualizer
if getattr(sys, 'frozen', False):
subprocess.Popen([sys.executable, '--stats'])
else:
script_path = os.path.join(os.getcwd(), 'input_visualizer.py')
subprocess.Popen([sys.executable, script_path])
def open_settings(self):
# Open settings_window
if getattr(sys, 'frozen', False):
subprocess.Popen([sys.executable, '--settings'])
else:
script_path = os.path.join(os.getcwd(), 'settings_window.py')
subprocess.Popen([sys.executable, script_path])
def open_glass(self):
# Open glass_window
if getattr(sys, 'frozen', False):
subprocess.Popen([sys.executable, '--glass'])
else:
script_path = os.path.join(os.getcwd(), 'home', 'glass_window.py')
subprocess.Popen([sys.executable, script_path])
def run(self):
# Create the icon
image = create_image()
menu = pystray.Menu(
pystray.MenuItem("Tracker Running", lambda: None, enabled=False),
pystray.MenuItem("View Map", self.open_map),
pystray.MenuItem("View Stats", self.open_stats),
pystray.MenuItem("Settings", self.open_settings),
pystray.MenuItem("Open Input", self.open_glass),
pystray.Menu.SEPARATOR,
pystray.MenuItem("Save Now", lambda: self.collector.save_data()),
pystray.MenuItem("Exit", self.on_quit)
)
self.icon = pystray.Icon("ActivityTracker", image, "My Tracker", menu)
# Auto-open glass window on startup
# We use a timer to let the tray icon settle first? Not strictly necessary but safe.
threading.Timer(1.0, self.open_glass).start()
self.icon.run()
if __name__ == "__main__":
if len(sys.argv) > 1:
if sys.argv[1] == '--visualizer':
import visualizer_app
visualizer_app.main()
elif sys.argv[1] == '--stats':
import input_visualizer
input_visualizer.main()
elif sys.argv[1] == '--settings':
import settings_window
app = settings_window.SettingsWindow()
app.mainloop()
elif sys.argv[1] == '--glass':
# We need to import glass_window.
# It is in a subdirectory 'home'.
# If we are packaged, 'home' should be importable if we add it to sys.path or if it's in the bundle.
# PyInstaller puts root next to it.
if getattr(sys, 'frozen', False):
# In frozen, 'home' is a folder in _internal (or straight up if onefile)
# But imports usually start from root.
# Let's try appending current dir to path
sys.path.append(os.path.join(sys._MEIPASS, 'home'))
from home import glass_window
else:
sys.path.append(os.path.join(os.getcwd(), 'home'))
import glass_window
app = glass_window.GlassApp()
app.mainloop()
else:
app = SystemTrayTracker()
app.run()