-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-calendar.py
More file actions
executable file
·136 lines (112 loc) · 4.42 KB
/
Copy pathquick-calendar.py
File metadata and controls
executable file
·136 lines (112 loc) · 4.42 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
#!/usr/bin/env python3
import gi
import datetime
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GLib
class QuickCalendar(Gtk.Window):
def __init__(self):
super().__init__(type=Gtk.WindowType.POPUP)
self.set_decorated(False)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_keep_above(True)
screen = self.get_screen()
visual = screen.get_rgba_visual()
if visual and screen.is_composited():
self.set_visual(visual)
self.setup_css()
self.main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=16)
self.main_box.set_name("cal_box")
# Header (Time and Date)
header_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=20)
self.lbl_time = Gtk.Label()
self.lbl_time.set_name("time_label")
self.lbl_time.set_halign(Gtk.Align.START)
self.lbl_date = Gtk.Label()
self.lbl_date.set_name("date_label")
self.lbl_date.set_halign(Gtk.Align.END)
header_box.pack_start(self.lbl_time, True, True, 0)
header_box.pack_start(self.lbl_date, False, False, 0)
self.main_box.pack_start(header_box, False, False, 0)
# Calendar Grid
self.calendar = Gtk.Calendar()
self.calendar.set_name("calendar_grid")
self.main_box.pack_start(self.calendar, True, True, 0)
self.add(self.main_box)
self.connect("focus-out-event", lambda *args: Gtk.main_quit())
self.connect("map-event", self.on_map)
self.connect("unmap-event", self.on_unmap)
self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self.connect("button-press-event", self.on_button_press)
self.connect("key-press-event", self.on_key_press)
GLib.timeout_add_seconds(1, self.update_time)
self.update_time()
GLib.idle_add(self.position_window)
def update_time(self):
now = datetime.datetime.now()
hour12 = now.hour % 12
if hour12 == 0: hour12 = 12
ampm = "AM" if now.hour < 12 else "PM"
self.lbl_time.set_markup(f"<span weight='bold' size='24000'>{hour12}:{now.strftime('%M')} {ampm}</span>")
self.lbl_date.set_markup(f"<span weight='bold' size='14000'>{now.strftime('%m/%d')}</span>")
return True
def on_key_press(self, widget, event):
if event.keyval == Gdk.KEY_Escape:
Gtk.main_quit()
def position_window(self):
geometry = Gdk.Display.get_default().get_primary_monitor().get_geometry()
width, height = self.get_size()
x = geometry.width - width - 100
y = geometry.height - height - 60
self.move(x, y)
self.present()
return False
def setup_css(self):
css = b'''
* { outline: none; color: #fafafa; }
window { background-color: transparent; }
#cal_box {
background-color: #18181b;
border-radius: 20px;
border: 1px solid #27272a;
box-shadow: 0 4px 12px rgba(0,0,0,0.5);
padding: 24px;
}
calendar {
background-color: #18181b;
color: #fafafa;
}
calendar:selected {
background-color: #ef4444;
color: #ffffff;
border-radius: 4px;
}
#time_label {
color: #fafafa;
}
#date_label {
color: #a1a1aa;
}
'''
provider = Gtk.CssProvider()
provider.load_from_data(css)
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
def on_map(self, widget, event):
seat = Gdk.Display.get_default().get_default_seat()
seat.grab(self.get_window(), Gdk.SeatCapabilities.ALL_POINTING, True, None, None, None)
return False
def on_unmap(self, widget, event):
seat = Gdk.Display.get_default().get_default_seat()
seat.ungrab()
return False
def on_button_press(self, widget, event):
width, height = self.get_size()
if event.x < 0 or event.x > width or event.y < 0 or event.y > height:
Gtk.main_quit()
return True
return False
if __name__ == "__main__":
app = QuickCalendar()
app.show_all()
Gtk.main()