-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtick-tray.py
More file actions
executable file
·593 lines (536 loc) · 19.3 KB
/
Copy pathtick-tray.py
File metadata and controls
executable file
·593 lines (536 loc) · 19.3 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
#!/usr/bin/env python3
"""Tick Tray Indicator — Premium dark-themed GTK popup for Tick task manager."""
import json
import os
import signal
import subprocess
import threading
import urllib.request
from datetime import datetime
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
gi.require_version("AyatanaAppIndicator3", "0.1")
from gi.repository import Gtk, Gdk, GLib, Pango, AyatanaAppIndicator3
API_BASE = "http://localhost:8080"
API_TASKS = f"{API_BASE}/api/tasks"
API_LINKS = f"{API_BASE}/api/quicklinks"
ICON_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tick-icon.png")
REFRESH_SEC = 30
C_BG = "#0c0c10"
C_PANEL = "#111116"
C_BORDER = "#1f1f2a"
C_HOVER = "#1a1a22"
C_TEXT = "#eaeafa"
C_SEC = "#83839a"
C_MUTED = "#525266"
C_ACCENT = "#4ade80"
C_ACCENT_HOVER = "#22c55e"
C_FAINT = "#2a2a35"
CSS = f"""
window.tick-popup {{
background: transparent;
}}
.tick-container {{
background: {C_PANEL};
border: 1px solid {C_BORDER};
border-radius: 14px;
padding: 6px 0px;
box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}}
.tick-header {{
padding: 12px 22px 4px 22px;
}}
.tick-header-title {{
color: {C_TEXT};
font-weight: 700;
font-size: 15px;
letter-spacing: 0.5px;
}}
.tick-header-date {{
color: {C_SEC};
font-size: 11px;
font-weight: 600;
letter-spacing: 1.5px;
}}
.tick-section {{
color: {C_MUTED};
font-size: 10px;
font-weight: 700;
letter-spacing: 2px;
padding: 16px 22px 6px 22px;
}}
.tick-task-row {{
padding: 8px 16px;
margin: 2px 6px;
border-radius: 8px;
}}
.tick-task-row:hover {{
background: {C_HOVER};
}}
.tick-task-title {{
color: {C_TEXT};
font-size: 14px;
}}
.tick-task-done {{
color: {C_MUTED};
font-size: 14px;
text-decoration: line-through;
}}
.tick-check {{
min-width: 18px; min-height: 18px;
border: 1.5px solid {C_MUTED};
border-radius: 5px;
background: transparent;
padding: 0;
}}
.tick-check:hover {{
border-color: {C_ACCENT};
}}
.tick-check.checked {{
background: {C_ACCENT};
border-color: {C_ACCENT};
color: {C_BG};
font-weight: 900;
font-size: 12px;
}}
.tick-entry-box {{
margin: 4px 22px;
background: {C_BG};
border: 1px solid {C_BORDER};
border-radius: 8px;
}}
.tick-entry {{
background: transparent;
color: {C_TEXT};
font-size: 13px;
border: none;
box-shadow: none;
padding: 10px 14px;
caret-color: {C_ACCENT};
}}
.tick-entry:focus {{
background: transparent;
border: none;
box-shadow: none;
}}
.tick-btn-add {{
background: transparent;
color: {C_ACCENT};
font-weight: 800;
font-size: 15px;
border: none;
border-left: 1px solid {C_BORDER};
border-radius: 0 8px 8px 0;
padding: 0 16px;
}}
.tick-btn-add:hover {{
background: {C_HOVER};
color: {C_ACCENT_HOVER};
}}
.tick-focus-time {{
color: {C_TEXT};
font-size: 26px;
font-weight: 400;
letter-spacing: 1px;
}}
.tick-focus-btn {{
background: {C_BG};
border: 1px solid {C_BORDER};
border-radius: 8px;
color: {C_SEC};
padding: 8px 12px;
font-size: 14px;
}}
.tick-focus-btn:hover {{
background: {C_HOVER};
color: {C_TEXT};
border-color: {C_MUTED};
}}
.tick-link-row {{
padding: 8px 16px;
margin: 2px 6px;
border-radius: 8px;
}}
.tick-link-row:hover {{
background: {C_HOVER};
}}
.tick-link-label {{
color: {C_SEC};
font-size: 13px;
}}
.tick-link-row:hover .tick-link-label {{
color: {C_TEXT};
}}
.tick-empty {{
color: {C_MUTED};
font-size: 12px;
font-style: italic;
padding: 4px 22px;
}}
.tick-footer {{
margin-top: 10px;
padding: 16px 22px;
border-top: 1px solid {C_BORDER};
}}
.tick-progress-bar {{
min-height: 4px;
border-radius: 2px;
background: {C_BORDER};
margin: 8px 0;
}}
.tick-progress-fill {{
min-height: 4px;
border-radius: 2px;
background: {C_ACCENT};
}}
.tick-btn-dash {{
background: {C_BG};
border: 1px solid {C_BORDER};
border-radius: 8px;
color: {C_TEXT};
font-size: 13px;
font-weight: 600;
padding: 10px;
margin-top: 10px;
}}
.tick-btn-dash:hover {{
background: {C_HOVER};
border-color: {C_MUTED};
}}
"""
def _api(method, url, data=None, timeout=4):
"""Make an API call. Returns (parsed_json, True) on success, (None, False) on failure."""
try:
body = json.dumps(data).encode() if data else None
req = urllib.request.Request(url, method=method, data=body)
if body:
req.add_header("Content-Type", "application/json")
with urllib.request.urlopen(req, timeout=timeout) as r:
code = r.getcode()
raw = r.read().decode()
if 200 <= code < 300:
parsed = json.loads(raw) if raw.strip() else None
return parsed, True
return None, False
except Exception as e:
print(f"[tick-tray] API error: {method} {url} → {e}")
return None, False
class TickPopup(Gtk.Window):
def __init__(self):
super().__init__(type=Gtk.WindowType.TOPLEVEL)
self.set_decorated(False)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_type_hint(Gdk.WindowTypeHint.POPUP_MENU)
self.set_keep_above(True)
self.set_default_size(360, -1)
self.set_resizable(False)
# Make window transparent to allow curved borders of container to show
screen = self.get_screen()
visual = screen.get_rgba_visual()
if visual:
self.set_visual(visual)
self.set_app_paintable(True)
self.get_style_context().add_class("tick-popup")
self.tasks = []
self.links = []
self.pom_time = 25 * 60
self.pom_running = False
self.pom_mode = "work"
self.pom_timer_id = None
self._updating = False # Guard: suppress focus-out during data refresh
self.connect("focus-out-event", self._on_focus_out)
self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.main_box.get_style_context().add_class("tick-container")
self.add(self.main_box)
self._rebuild()
self._refresh_data()
def _on_focus_out(self, widget, event):
"""Hide the popup unless we're in the middle of a data refresh."""
if not self._updating:
self.hide()
return False
def _rebuild(self):
for child in self.main_box.get_children():
child.destroy()
# HEADER
hdr = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
hdr.get_style_context().add_class("tick-header")
title = Gtk.Label(label="✓ Tick")
title.get_style_context().add_class("tick-header-title")
hdr.pack_start(title, False, False, 0)
dt = Gtk.Label(label=datetime.now().strftime("%a, %b %d").upper())
dt.get_style_context().add_class("tick-header-date")
hdr.pack_end(dt, False, False, 0)
self.main_box.pack_start(hdr, False, False, 0)
# MAIN SCROLL
scr = Gtk.ScrolledWindow()
scr.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scr.set_max_content_height(480)
scr.set_propagate_natural_height(True)
content = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
scr.add(content)
self.main_box.pack_start(scr, True, True, 0)
# TASKS
pending = [t for t in self.tasks if not t.get("completed")]
completed = [t for t in self.tasks if t.get("completed")]
ts_lbl = Gtk.Label(label="TASKS")
ts_lbl.set_xalign(0)
ts_lbl.get_style_context().add_class("tick-section")
content.pack_start(ts_lbl, False, False, 0)
if not self.tasks:
emp = Gtk.Label(label="No tasks for today")
emp.set_xalign(0)
emp.get_style_context().add_class("tick-empty")
content.pack_start(emp, False, False, 0)
else:
for task in pending:
content.pack_start(self._make_task_row(task), False, False, 0)
if completed:
cs_lbl = Gtk.Label(label=f"COMPLETED · {len(completed)}")
cs_lbl.set_xalign(0)
cs_lbl.get_style_context().add_class("tick-section")
content.pack_start(cs_lbl, False, False, 0)
for task in completed:
content.pack_start(self._make_task_row(task), False, False, 0)
# ADD TASK
entry_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
entry_box.get_style_context().add_class("tick-entry-box")
entry = Gtk.Entry()
entry.set_placeholder_text("Add a new task...")
entry.get_style_context().add_class("tick-entry")
entry.connect("activate", self._on_add_task)
entry_box.pack_start(entry, True, True, 0)
add_btn = Gtk.Button(label="+")
add_btn.get_style_context().add_class("tick-btn-add")
add_btn.connect("clicked", lambda _: self._on_add_task(entry))
entry_box.pack_start(add_btn, False, False, 0)
content.pack_start(entry_box, False, False, 0)
# FOCUS
fs_lbl = Gtk.Label(label="FOCUS" if self.pom_mode == "work" else "BREAK")
fs_lbl.set_xalign(0)
fs_lbl.get_style_context().add_class("tick-section")
if self.pom_mode == "work":
# Add subtle color to focus label
fs_lbl.modify_fg(Gtk.StateFlags.NORMAL, Gdk.color_parse(C_ACCENT))
content.pack_start(fs_lbl, False, False, 0)
fbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=14)
fbox.set_margin_start(22)
fbox.set_margin_end(22)
mins, secs = self.pom_time // 60, self.pom_time % 60
self.time_label = Gtk.Label(label=f"{mins:02d}:{secs:02d}")
self.time_label.get_style_context().add_class("tick-focus-time")
fbox.pack_start(self.time_label, False, False, 0)
play_btn = Gtk.Button(label="⏸" if self.pom_running else "▶")
play_btn.get_style_context().add_class("tick-focus-btn")
play_btn.connect("clicked", self._toggle_pom)
fbox.pack_start(play_btn, False, False, 0)
rst_btn = Gtk.Button(label="↺")
rst_btn.get_style_context().add_class("tick-focus-btn")
rst_btn.connect("clicked", self._reset_pom)
fbox.pack_start(rst_btn, False, False, 0)
content.pack_start(fbox, False, False, 0)
# LINKS
ls_lbl = Gtk.Label(label="LINKS")
ls_lbl.set_xalign(0)
ls_lbl.get_style_context().add_class("tick-section")
content.pack_start(ls_lbl, False, False, 0)
if not self.links:
emp = Gtk.Label(label="No quicklinks")
emp.set_xalign(0)
emp.get_style_context().add_class("tick-empty")
content.pack_start(emp, False, False, 0)
else:
for link in self.links:
if link.get("type") == "folder" or not link.get("url"):
continue
if link.get("type") == "folder" or not link.get("url"):
continue
row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
row.get_style_context().add_class("tick-link-row")
icon = Gtk.Label(label="↗")
icon.modify_fg(Gtk.StateFlags.NORMAL, Gdk.color_parse(C_MUTED))
row.pack_start(icon, False, False, 0)
lbl = Gtk.LinkButton.new_with_label(link.get("url", "#"), link.get("name", "—"))
lbl.get_child().get_style_context().add_class("tick-link-label")
lbl.set_halign(Gtk.Align.START)
row.pack_start(lbl, True, True, 0)
content.pack_start(row, False, False, 0)
# FOOTER
footer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
footer.get_style_context().add_class("tick-footer")
if self.tasks:
done = sum(1 for t in self.tasks if t.get("completed"))
total = len(self.tasks)
pct = done / total if total else 0
pbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
p_lbl = Gtk.Label(label="PROGRESS")
p_lbl.modify_fg(Gtk.StateFlags.NORMAL, Gdk.color_parse(C_MUTED))
p_lbl.modify_font(Pango.FontDescription('10'))
pbox.pack_start(p_lbl, False, False, 0)
p_val = Gtk.Label(label=f"{done}/{total}")
p_val.modify_fg(Gtk.StateFlags.NORMAL, Gdk.color_parse(C_ACCENT))
p_val.modify_font(Pango.FontDescription('bold 11'))
pbox.pack_end(p_val, False, False, 0)
footer.pack_start(pbox, False, False, 0)
# Bar
bar_bg = Gtk.Box()
bar_bg.get_style_context().add_class("tick-progress-bar")
bar_fill = Gtk.Box()
bar_fill.get_style_context().add_class("tick-progress-fill")
# Max width logic via size request
bar_fill.set_size_request(int(315 * pct), -1)
bar_bg.pack_start(bar_fill, False, False, 0)
footer.pack_start(bar_bg, False, False, 0)
dash_btn = Gtk.Button(label="Open Full Dashboard")
dash_btn.get_style_context().add_class("tick-btn-dash")
dash_btn.connect("clicked", lambda _: subprocess.Popen(["xdg-open", API_BASE]))
footer.pack_start(dash_btn, False, False, 0)
self.main_box.pack_end(footer, False, False, 0)
self.main_box.show_all()
def _make_task_row(self, task):
row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
row.get_style_context().add_class("tick-task-row")
is_done = task.get("completed")
chk = Gtk.Button(label="✔" if is_done else "")
chk.get_style_context().add_class("tick-check")
if is_done:
chk.get_style_context().add_class("checked")
tid = task.get("id")
chk.connect("clicked", lambda _, t=tid: self._toggle_task(t))
row.pack_start(chk, False, False, 0)
lbl = Gtk.Label(label=task.get("title", ""))
lbl.set_xalign(0)
lbl.set_ellipsize(Pango.EllipsizeMode.END)
lbl.set_max_width_chars(35)
lbl.get_style_context().add_class("tick-task-done" if is_done else "tick-task-title")
row.pack_start(lbl, True, True, 0)
return row
def _toggle_task(self, task_id):
def do():
_, ok = _api("PATCH", f"{API_TASKS}?id={task_id}")
if ok:
GLib.idle_add(self._refresh_data_async)
threading.Thread(target=do, daemon=True).start()
def _on_add_task(self, entry):
title = entry.get_text().strip()
if not title: return
entry.set_text("")
date = datetime.now().strftime("%Y-%m-%d")
def do():
_, ok = _api("POST", API_TASKS, {"title": title, "date": date})
if ok:
GLib.idle_add(self._refresh_data_async)
threading.Thread(target=do, daemon=True).start()
def _toggle_pom(self, _btn):
self.pom_running = not self.pom_running
if self.pom_running and not self.pom_timer_id:
self.pom_timer_id = GLib.timeout_add(1000, self._pom_tick)
self._rebuild()
def _reset_pom(self, _btn):
self.pom_running = False
self.pom_time = 25 * 60 if self.pom_mode == "work" else 5 * 60
if self.pom_timer_id:
GLib.source_remove(self.pom_timer_id)
self.pom_timer_id = None
self._rebuild()
def _pom_tick(self):
if not self.pom_running:
self.pom_timer_id = None
return False
self.pom_time -= 1
if self.pom_time <= 0:
self.pom_running = False
self.pom_mode = "break" if self.pom_mode == "work" else "work"
self.pom_time = 5 * 60 if self.pom_mode == "break" else 25 * 60
self.pom_timer_id = None
self._rebuild()
return False
if hasattr(self, 'time_label') and self.time_label:
m, s = self.pom_time // 60, self.pom_time % 60
self.time_label.set_text(f"{m:02d}:{s:02d}")
return True
def _refresh_data_async(self):
"""Kick off a background thread to fetch data, then rebuild on main thread."""
def do():
tasks_data, t_ok = _api("GET", API_TASKS)
links_data, l_ok = _api("GET", API_LINKS)
def apply():
self._updating = True
if t_ok:
self.tasks = tasks_data if tasks_data is not None else []
if l_ok:
self.links = links_data if links_data is not None else []
self._rebuild()
self._updating = False
return False
GLib.idle_add(apply)
threading.Thread(target=do, daemon=True).start()
def _refresh_data(self):
"""Synchronous refresh — only used for initial load."""
tasks_data, t_ok = _api("GET", API_TASKS)
links_data, l_ok = _api("GET", API_LINKS)
if t_ok:
self.tasks = tasks_data if tasks_data is not None else []
if l_ok:
self.links = links_data if links_data is not None else []
self._rebuild()
def toggle_visible(self):
if self.get_visible():
self.hide()
else:
# Position the window near the tray icon, clamped to screen bounds
display = Gdk.Display.get_default()
seat = display.get_default_seat()
pointer = seat.get_pointer()
_, x, y = pointer.get_position()
screen = display.get_default_screen()
sw = screen.get_width()
sh = screen.get_height()
wx = max(10, min(x - 180, sw - 380))
wy = max(10, min(32, sh - 600))
self.move(wx, wy)
self.show_all()
self.present()
# Fetch data in background so the window appears instantly
self._refresh_data_async()
class TickTray:
def __init__(self):
self.indicator = AyatanaAppIndicator3.Indicator.new(
"tick-tray", ICON_PATH,
AyatanaAppIndicator3.IndicatorCategory.APPLICATION_STATUS,
)
self.indicator.set_status(AyatanaAppIndicator3.IndicatorStatus.ACTIVE)
self.indicator.set_title("Tick")
menu = Gtk.Menu()
show_item = Gtk.MenuItem(label="✓ Show Tick")
show_item.connect("activate", lambda _: self.popup.toggle_visible())
menu.append(show_item)
dash = Gtk.MenuItem(label="🖥 Full Dashboard")
dash.connect("activate", lambda _: subprocess.Popen(["xdg-open", API_BASE]))
menu.append(dash)
menu.append(Gtk.SeparatorMenuItem())
quit_item = Gtk.MenuItem(label="Quit")
quit_item.connect("activate", lambda _: Gtk.main_quit())
menu.append(quit_item)
menu.show_all()
self.indicator.set_menu(menu)
self.popup = TickPopup()
GLib.timeout_add_seconds(REFRESH_SEC, self._auto_refresh)
def _auto_refresh(self):
if self.popup.get_visible():
self.popup._refresh_data_async()
return True
def main():
provider = Gtk.CssProvider()
provider.load_from_data(CSS.encode())
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(), provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION,
)
signal.signal(signal.SIGINT, signal.SIG_DFL)
TickTray()
Gtk.main()
if __name__ == "__main__":
main()