예제 #1
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
예제 #2
0
 def __init__(self, conf=None, dbtool=None, eventcolumn=None):
     self.conf = conf
     self.dbtool = dbtool
     self.eventcolumn = eventcolumn
     pile = urwid.Filler(CPile([]))
     urwid.WidgetWrap.__init__(self, pile)
     self.update()
예제 #3
0
파일: __init__.py 프로젝트: djhume/khal
 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
예제 #4
0
    def __init__(self, accounts, account_chooser):
        self.account_chooser = account_chooser
        acc_list = []
        for one in accounts:
            button = urwid.Button(one,
                                  on_press=self.set_account,
                                  user_data=one)

            acc_list.append(button)
        pile = CPile(acc_list)
        fill = urwid.Filler(pile)
        self.__super.__init__(urwid.AttrMap(fill, 'popupbg'))
예제 #5
0
    def __init__(self, conf, dbtool, event):
        super(EventDisplay, self).__init__(conf, dbtool)
        lines = []
        lines.append(urwid.Text(event.vevent['SUMMARY']))

        # start and end time/date
        if event.allday:
            startstr = event.start.strftime(self.conf.default.dateformat)
            if event.start == event.end:
                lines.append(urwid.Text('On: ' + startstr))
            else:
                endstr = event.end.strftime(self.conf.default.dateformat)
                lines.append(urwid.Text('From: ' + startstr + ' to: ' +
                                        endstr))

        else:
            startstr = event.start.strftime(self.conf.default.dateformat +
                                            ' ' + self.conf.default.timeformat)
            if event.start.date == event.end.date:
                endstr = event.end.strftime(self.conf.default.timeformat)
            else:
                endstr = event.end.strftime(self.conf.default.dateformat +
                                            ' ' + self.conf.default.timeformat)
                lines.append(urwid.Text('From: ' + startstr + ' To: ' +
                                        endstr))

        # resource
        lines.append(urwid.Text('Calendar: ' + event.account))

        # description and location
        for key, desc in [('DESCRIPTION', 'Desc'), ('LOCATION', 'Loc')]:
            try:
                lines.append(
                    urwid.Text(desc + ': ' +
                               str(event.vevent[key].encode('utf-8'))))
            except KeyError:
                pass

        pile = CPile(lines)
        self._w = urwid.Filler(pile, valign='top')
예제 #6
0
파일: __init__.py 프로젝트: nicferrier/khal
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)
예제 #7
0
 def __init__(self, conf, dbtool):
     self.conf = conf
     self.dbtool = dbtool
     pile = CPile([])
     urwid.WidgetWrap.__init__(self, pile)
예제 #8
0
    def toggle(self, checkbox, state):
        """change from allday to datetime event

        :param checkbox: the checkbox instance that is used for toggling, gets
                         automatically passed by urwid (is not used)
        :type checkbox: checkbox
        :param state: True if allday event, False if datetime
        :type state: bool
        """
        self.allday = state
        datewidth = len(self.startdate) + 7

        edit = urwid.Edit(caption=('', 'From: '),
                          edit_text=self.startdate,
                          wrap='any')
        edit = urwid.AttrMap(
            edit,
            self.startdate_bg,
            'editcp',
        )
        edit = urwid.Padding(edit,
                             align='left',
                             width=datewidth,
                             left=0,
                             right=1)
        self.startdatewidget = edit

        edit = urwid.Edit(caption=('', 'To:   '),
                          edit_text=self.enddate,
                          wrap='any')
        edit = urwid.AttrMap(
            edit,
            self.enddate_bg,
            'editcp',
        )
        edit = urwid.Padding(edit,
                             align='left',
                             width=datewidth,
                             left=0,
                             right=1)
        self.enddatewidget = edit
        if state is True:
            timewidth = 1
            self.starttimewidget = urwid.Text('')
            self.endtimewidget = urwid.Text('')
        elif state is False:
            timewidth = len(self.starttime) + 1
            edit = urwid.Edit(edit_text=self.starttime, wrap='any')
            edit = urwid.AttrMap(
                edit,
                self.starttime_bg,
                'editcp',
            )
            edit = urwid.Padding(edit,
                                 align='left',
                                 width=len(self.starttime) + 1,
                                 left=1)
            self.starttimewidget = edit

            edit = urwid.Edit(edit_text=self.endtime, wrap='any')
            edit = urwid.AttrMap(
                edit,
                self.endtime_bg,
                'editcp',
            )
            edit = urwid.Padding(edit,
                                 align='left',
                                 width=len(self.endtime) + 1,
                                 left=1)
            self.endtimewidget = edit

        columns = CPile([
            CColumns([(datewidth, self.startdatewidget),
                      (timewidth, self.starttimewidget)],
                     dividechars=1),
            CColumns([(datewidth, self.enddatewidget),
                      (timewidth, self.endtimewidget)],
                     dividechars=1), self.checkallday
        ],
                        focus_item=2)
        urwid.WidgetWrap.__init__(self, columns)
예제 #9
0
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)