def build_calendar_ui(self):
        '''
        Builds the actual Calendar UI after making the RESTful request.
        '''
        if not self.device_auth.authorized:
            self._error('Need to authorize first.')

        if not self.calendar:
            self.calendar = Calendar(self.device_auth)

        events = self.calendar.events()
        date_today = DateTime.today()
        sync_at = date_today.formatted()
        sync_at_message = 'Last updated at %s' % (sync_at)
        if len(events) <= 0:
            messages = [sync_at_message]
            self._notify('No events.', messages=messages)
        else:
            root = Column(layout_width=self.width,
                          layout_height=self.height,
                          padding=10)
            header = Row(parent=root, layout_height=40, wrap_content=False)
            f_date_today = date_today.formatted(include_day=True,
                                                include_time=False)
            header.add_text_content('Today - %s' % (f_date_today), text_size=4)
            header.add_image(CALENDAR_40_40, 40, 40, align=ALIGN_RIGHT)
            content_root = Row(parent=root,
                               layout_height=480,
                               wrap_content=False,
                               outline=True)
            content = Column(parent=content_root, wrap_content=False)
            content.add_spacer(10, outline=True)
            content.add_spacer(20)
            for event in events:
                summary = event.summary
                duration_info = None
                if event.start_at:
                    include_day = not event.start_at.is_today()
                    duration_info = 'At %s' % (event.start_at.formatted(
                        include_day=include_day))
                elif event.end_at:
                    duration_info = 'Ends at %s' % (event.end_at.formatted(
                        include_day=True, include_time=False))

                content.add_text_content(summary)
                if duration_info:
                    content.add_text_content(duration_info)
                content.add_spacer(height=15)
            content_root.add_node(content)
            status = Row(parent=root,
                         layout_height=40,
                         wrap_content=False,
                         outline=True)
            status.add_text_content(sync_at_message, align=ALIGN_RIGHT)
            root.add_node(header)
            root.add_node(content_root)
            root.add_node(status)
            self._draw(root)
Beispiel #2
0
def _get_all_days_to_today(date_from: datetime) -> Iterator[datetime]:
    date_to = DateTime.today()
    day_delta = timedelta(days=1)
    while date_from < date_to:
        yield date_from
        date_from += day_delta