class EventColumn(urwid.WidgetWrap): """contains the eventlist as well as the event viewer/editor""" def __init__(self, conf, collection, deleted): self.conf = conf self.collection = collection self.deleted = deleted self.divider = urwid.Divider('-') self.editor = False self.date = None self.eventcount = 0 def update(self, date): """create an EventList populated with Events for `date` and display it """ self.date = date # TODO make this switch from pile to columns depending on terminal size events = EventList( conf=self.conf, collection=self.collection, eventcolumn=self) self.eventcount = events.update(date) self.container = CPile([events]) self._w = self.container def view(self, event): """ show an event's details :param event: event to view :type event: khal.event.Event """ self.destroy() self.container.contents.append((self.divider, ('pack', None))) # self.container.options())) self.container.contents.append( (EventDisplay(self.conf, event, collection=self.collection), self.container.options())) def edit(self, event): """create an EventEditor and display it :param event: event to edit :type event: khal.event.Event """ self.destroy() self.editor = True # self.container.contents.append((self.divider, # self.container.options())) self.container.contents.append((self.divider, ('pack', None))) self.container.contents.append( (EventEditor(self.conf, event, collection=self.collection, cancel=self.destroy), self.container.options())) self.container.set_focus(2) def destroy(self, _=None, refresh=False): """ if an EventViewer or EventEditor is displayed, remove it """ if refresh and not self.date is None: self.update(self.date) self.editor = False if (len(self.container.contents) > 2 and isinstance(self.container.contents[2][0], EventViewer)): self.container.contents.pop() self.container.contents.pop() def new(self, date): """create a new event on date :param date: default date for new event :type date: datetime.date """ event = aux.new_event(dtstart=date, timezone=self.conf.locale.default_timezone) # TODO proper default cal event = self.collection.new_event(event.to_ical(), self.collection.default_calendar_name) self.edit(event) self.eventcount += 1 def selectable(self): return bool(self.eventcount)
class EventColumn(urwid.WidgetWrap): """contains the eventlist as well as the event viewer/editor""" def __init__(self, conf=None, dbtool=None): self.conf = conf self.dbtool = dbtool self.divider = urwid.Divider('-') self.editor = False self.date = None self.eventcount = 0 def update(self, date): """create an EventList populated with Events for `date` and display it """ self.date = date # TODO make this switch from pile to columns depending on terminal size events = EventList(conf=self.conf, dbtool=self.dbtool, eventcolumn=self) self.eventcount = events.update(date) self.container = CPile([events]) self._w = self.container def view(self, event): """ show an event's details :param event: event to view :type event: khal.model.Event """ self.destroy() self.container.contents.append((self.divider, ('pack', None))) #self.container.options())) self.container.contents.append( (EventDisplay(self.conf, self.dbtool, event), self.container.options())) def edit(self, event): """create an EventEditor and display it :param event: event to edit :type event: khal.model.Event """ self.destroy() self.editor = True #self.container.contents.append((self.divider, #self.container.options())) self.container.contents.append((self.divider, ('pack', None))) self.container.contents.append( (EventEditor(self.conf, self.dbtool, event, cancel=self.destroy), self.container.options())) self.container.set_focus(2) def destroy(self, _=None, refresh=False): """ if an EventViewer or EventEditor is displayed, remove it """ if refresh and not self.date is None: self.update(self.date) self.editor = False if (len(self.container.contents) > 2 and isinstance(self.container.contents[2][0], EventViewer)): self.container.contents.pop() self.container.contents.pop() def new(self, date): """create a new event on date :param date: default date for new event :type date: datetime.date """ event = aux.new_event(dtstart=date, timezone=self.conf.default.default_timezone) event = model.Event(ical=event.to_ical(), status=NEW, account=list(self.conf.sync.accounts)[-1]) self.edit(event) self.eventcount += 1 def selectable(self): return bool(self.eventcount)