How to use the khal.ui.widgets.Choice function in khal

To help you get started, we’ve selected a few khal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / khal / khal / ui / editor.py View on Github external
self._rrule = rrule
        self.repeat = bool(rrule)
        self._allow_edit = not self.repeat or self.check_understood_rrule(rrule)
        self.repeat_box = urwid.CheckBox(
            'Repeat: ', state=self.repeat, on_state_change=self.check_repeat,
        )

        if "UNTIL" in self._rrule:
            self._until = "Until"
        elif "COUNT" in self._rrule:
            self._until = "Repetitions"
        else:
            self._until = "Forever"

        recurrence = self._rrule['freq'][0].lower() if self._rrule else "weekly"
        self.recurrence_choice = Choice(
            ["daily", "weekly", "monthly", "yearly"],
            recurrence,
            callback=self.rebuild,
        )
        self.interval_edit = PositiveIntEdit(
            caption='every:',
            edit_text=str(self._rrule.get('INTERVAL', [1])[0]),
        )
        self.until_choice = Choice(
            ["Forever", "Until", "Repetitions"], self._until, callback=self.rebuild,
        )

        count = str(self._rrule.get('COUNT', [1])[0])
        self.repetitions_edit = PositiveIntEdit(edit_text=count)

        until = self._rrule.get('UNTIL', [None])[0]
github pimutils / khal / khal / ui / widgets.py View on Github external
def __init__(self, alarm, delete_handler):
            duration, description = alarm
            if duration.total_seconds() > 0:
                direction = 'after'
            else:
                direction = 'before'
                duration = -1 * duration

            self.duration = DurationWidget(duration)
            self.description = ExtendedEdit(edit_text=description)
            self.direction = Choice(
                ['before', 'after'], active=direction, overlay_width=10)
            self.columns = NColumns([
                (2, urwid.Text('  ')),
                (21, self.duration),
                (14, urwid.Padding(self.direction, right=1)),
                self.description,
                (10, urwid.Button('Delete', on_press=delete_handler, user_data=self)),
            ])

            urwid.WidgetWrap.__init__(self, self.columns)
github pimutils / khal / khal / ui / widgets.py View on Github external
return self._active != self._original

    @property
    def active(self):
        return self._active

    @active.setter
    def active(self, val):
        self._active = val
        self.button = urwid.Button(self._decorate(self._active))
        urwid.PopUpLauncher.__init__(self, self.button)
        urwid.connect_signal(self.button, 'click',
                             lambda button: self.open_pop_up())


class EditSelect(Choice):
    def create_pop_up(self):
        pop_up = ChoiceListEdit(self)
        urwid.connect_signal(pop_up, 'close', lambda button: self.close_pop_up())
        return pop_up

    @property
    def active(self):
        return self._active

    @active.setter
    def active(self, val):
        self._active = val
        self.button = EnterEdit('', self._decorate(self._active))
        urwid.PopUpLauncher.__init__(self, self.button)
        urwid.connect_signal(self.button, 'enter', lambda button: self.open_pop_up())
github pimutils / khal / khal / ui / editor.py View on Github external
)
        # TODO make sure recurrence rules cannot be edited if we only
        # edit one instance (or this and future) (once we support that)
        self.recurrenceeditor = RecurrenceEditor(
            self.event.recurobject, self._conf, event.start_local,
        )
        self.summary = urwid.AttrMap(ExtendedEdit(
            caption=('', 'Title:       '), edit_text=event.summary), 'edit'
        )

        divider = urwid.Divider(' ')

        def decorate_choice(c):
            return ('calendar ' + c['name'], c['name'])

        self.calendar_chooser = Choice(
            [self.collection._calendars[c] for c in self.collection.writable_names],
            self.collection._calendars[self.event.calendar],
            decorate_choice
        )
        self.description = urwid.AttrMap(
            ExtendedEdit(
                caption=('', 'Description: '),
                edit_text=self.description,
                multiline=True
            ),
            'edit'
        )
        self.location = urwid.AttrMap(ExtendedEdit(
            caption=('', 'Location:    '), edit_text=self.location), 'edit'
        )
        self.categories = urwid.AttrMap(ExtendedEdit(
github pimutils / khal / khal / ui / editor.py View on Github external
elif "COUNT" in self._rrule:
            self._until = "Repetitions"
        else:
            self._until = "Forever"

        recurrence = self._rrule['freq'][0].lower() if self._rrule else "weekly"
        self.recurrence_choice = Choice(
            ["daily", "weekly", "monthly", "yearly"],
            recurrence,
            callback=self.rebuild,
        )
        self.interval_edit = PositiveIntEdit(
            caption='every:',
            edit_text=str(self._rrule.get('INTERVAL', [1])[0]),
        )
        self.until_choice = Choice(
            ["Forever", "Until", "Repetitions"], self._until, callback=self.rebuild,
        )

        count = str(self._rrule.get('COUNT', [1])[0])
        self.repetitions_edit = PositiveIntEdit(edit_text=count)

        until = self._rrule.get('UNTIL', [None])[0]
        if until is None and isinstance(self._startdt, dt.datetime):
            until = self._startdt.date()
        elif until is None:
            until = self._startdt

        if isinstance(until, dt.datetime):
            until = until.date()
        self.until_edit = DateEdit(
            until, self._conf['locale']['longdateformat'],
github pimutils / khal / khal / ui / editor.py View on Github external
def _rebuild_monthly_choice(self):
        weekday, xth = get_weekday_occurrence(self._startdt)
        ords = {1: 'st', 2: 'nd', 3: 'rd', 21: 'st', 22: 'nd', 23: 'rd', 31: 'st'}
        self._xth_weekday = 'on every {}{} {}'.format(
            xth, ords.get(xth, 'th'), WEEKDAYS[weekday],
        )
        self._xth_monthday = 'on every {}{} of the month'.format(
            self._startdt.day, ords.get(self._startdt.day, 'th'),
        )
        self.monthly_choice = Choice(
            [self._xth_monthday, self._xth_weekday], self._xth_monthday, callback=self.rebuild,
        )