basic working state

This commit is contained in:
nihilazo 2020-09-22 13:07:13 +01:00
parent 3a4a042cec
commit 0e5264e917
1 changed files with 39 additions and 9 deletions

48
main.py
View File

@ -1,5 +1,6 @@
import subprocess as sp
import datetime
import time
import gi
gi.require_version("Gtk","3.0")
from gi.repository import Gtk
@ -52,30 +53,59 @@ class CalendarWindow(Gtk.ApplicationWindow):
self.header_bar = Gtk.HeaderBar()
self.header_bar.set_title("Calendar")
self.header_bar.props.show_close_button = True
self.set_titlebar(self.header_bar)
self.event_list = Gtk.ListBox()
self.event_list.fill = True
self.calendar_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.calendar_box = Gtk.Paned(orientation=Gtk.Orientation.VERTICAL)
self.calendar = Gtk.Calendar()
self.calendar.fill = True
self.set_titlebar(self.header_bar)
self.calendar.expand = True
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.main_box = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL) # Box containing the list view and cal/buttons
self.main_box.add(self.calendar_box)
self.main_box.add(self.event_list)
self.add(self.main_box)
self.connect("destroy",Gtk.main_quit)
self.calendar.connect("day_selected",self._on_day_selected)
def _on_day_selected(self,calendar):
print("day selected")
calendar_date = calendar.get_date()
date = datetime.date(calendar_date.year,calendar_date.month+1,calendar_date.day)
self.header_bar.set_subtitle(date.isoformat())
self.populate_day(date)
def populate_day(self,date):
print(date)
for c in self.event_list.get_children():
self.event_list.remove_child(c)
print(c)
c.destroy()
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)
row = EventRow(event)
self.event_list.add(row)
self.event_list.show_all()
class EventRow(Gtk.ListBoxRow):
def __init__(self,event):
super().__init__()
self.description_label = Gtk.Label(label=event['description'])
self.box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
if event['type'] != 'event':
timespan = f"{event['start'].strftime('%H:%M')} - {event['end'].strftime('%H:%M')}"
self.timespan_label = Gtk.Label(label=timespan)
self.box.pack_start(self.timespan_label,0,0,0)
self.box.pack_end(self.description_label,0,0,0)
else:
self.box.pack_start(self.description_label,0,0,0)
self.add(self.box)
today = datetime.date.today()
c = CalendarWindow()
c.populate_day(datetime.date(2020,9,21))
c.populate_day(today)
c.header_bar.set_subtitle(today.isoformat())
c.show_all()
Gtk.main()