initial commit

This commit is contained in:
Nihilazo 2020-09-22 07:38:25 +01:00
commit 3a4a042cec
1 changed files with 81 additions and 0 deletions

81
main.py Normal file
View File

@ -0,0 +1,81 @@
import subprocess as sp
import datetime
import gi
gi.require_version("Gtk","3.0")
from gi.repository import Gtk
calcurse_event_cmd = ["calcurse", "-Q",
"--input-datefmt","4",
"--output-datefmt","4",
"--filter-type", "cal",
"--format-recur-apt", '"apt;%S;%E;%m\n"',
"--format-apt", '"apt;%S;%E;%m\n"',
"--format-event", '"event;%m\n"',
"--from"]
def get_event_list(date): # Gets the clean event list output from calcurse.
date_str = date.isoformat()
cmd = calcurse_event_cmd.copy()
cmd.append(date_str)
calcurse_out = sp.run(cmd,capture_output=True).stdout
decoded = calcurse_out.decode().replace("\"","")
out = decoded.splitlines()[1:]
return out
def parse_event_list(event_list): # parses calcurse event list into dicts for future use
split_events = [event.split(';') for event in event_list]
out = []
for event in split_events:
if event[0] == "event":
out.append({
'type':'event',
'start': datetime.time(0),
'description': event[1],
})
elif event[0] == "apt":
out.append({
'type':'apt',
'start': parse_time(event[1]),
'end': parse_time(event[2]),
'description': event[3]
})
return out
def parse_time(time): # Takes a time as returned by calcurse, returns a datetime.time object
t = time.split(':')
return datetime.time(int(t[0]),int(t[1]))
class CalendarWindow(Gtk.ApplicationWindow):
def __init__(self):
super().__init__()
self.header_bar = Gtk.HeaderBar()
self.header_bar.set_title("Calendar")
self.header_bar.props.show_close_button = True
self.event_list = Gtk.ListBox()
self.event_list.fill = True
self.calendar_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.calendar = Gtk.Calendar()
self.calendar.fill = True
self.set_titlebar(self.header_bar)
self.calendar_box.add(self.calendar)
self.calendar_box.add(Gtk.Label(label="PlaceHolder"))
self.main_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) # Box containing the list view and cal/buttons
self.main_box.pack_start(self.calendar_box,0,0,0)
self.main_box.pack_end(self.event_list,0,0,0)
self.add(self.main_box)
self.connect("destroy",Gtk.main_quit)
def populate_day(self,date):
for c in self.event_list.get_children():
self.event_list.remove_child(c)
events = parse_event_list(get_event_list(date))
sorted_events = sorted(events, key=lambda k: k['start'])
for event in sorted_events:
l = Gtk.Label(label=event)
self.event_list.add(l)
c = CalendarWindow()
c.populate_day(datetime.date(2020,9,21))
c.show_all()
Gtk.main()