How to use the khal.icalendar.new_event 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 / __init__.py View on Github external
def new(self, date, end=None):
        """create a new event on `date` at the next full hour and edit it

        :param date: default date for new event
        :type date: datetime.date
        :param end: optional, date the event ends on (inclusive)
        :type end: datetime.date
        """
        if not self.pane.collection.writable_names:
            self.pane.window.alert(('alert', 'No writable calendar.'))
            return
        if end is None:
            start = dt.datetime.combine(date, dt.time(dt.datetime.now().hour))
            end = start + dt.timedelta(minutes=60)
            event = icalendar_helpers.new_event(
                dtstart=start, dtend=end, summary='',
                timezone=self._conf['locale']['default_timezone'],
                locale=self._conf['locale'],
            )
        else:
            event = icalendar_helpers.new_event(
                dtstart=date, dtend=end + dt.timedelta(days=1), summary='',
                allday=True, locale=self._conf['locale'],
            )
        event = self.pane.collection.new_event(
            event.to_ical(), self.pane.collection.default_calendar_name)
        self.edit(event)
github pimutils / khal / khal / controllers.py View on Github external
def new_from_args(collection, calendar_name, conf, dtstart=None, dtend=None,
                  summary=None, description=None, allday=None, location=None,
                  categories=None, repeat=None, until=None, alarms=None,
                  timezone=None, format=None, env=None):
    """Create a new event from arguments and add to vdirs"""
    if isinstance(categories, str):
        categories = list([category.strip() for category in categories.split(',')])
    try:
        event = new_vevent(
            locale=conf['locale'], location=location, categories=categories,
            repeat=repeat, until=until, alarms=alarms, dtstart=dtstart,
            dtend=dtend, summary=summary, description=description, timezone=timezone,
        )
    except ValueError as error:
        raise FatalError(error)
    event = Event.fromVEvents(
        [event], calendar=calendar_name, locale=conf['locale'])

    try:
        collection.new(event)
    except ReadOnlyCalendarError:
        raise FatalError(
            'ERROR: Cannot modify calendar "{}" as it is read-only'.format(calendar_name)
        )
github pimutils / khal / khal / ui / __init__.py View on Github external
:param end: optional, date the event ends on (inclusive)
        :type end: datetime.date
        """
        if not self.pane.collection.writable_names:
            self.pane.window.alert(('alert', 'No writable calendar.'))
            return
        if end is None:
            start = dt.datetime.combine(date, dt.time(dt.datetime.now().hour))
            end = start + dt.timedelta(minutes=60)
            event = icalendar_helpers.new_event(
                dtstart=start, dtend=end, summary='',
                timezone=self._conf['locale']['default_timezone'],
                locale=self._conf['locale'],
            )
        else:
            event = icalendar_helpers.new_event(
                dtstart=date, dtend=end + dt.timedelta(days=1), summary='',
                allday=True, locale=self._conf['locale'],
            )
        event = self.pane.collection.new_event(
            event.to_ical(), self.pane.collection.default_calendar_name)
        self.edit(event)
github pimutils / khal / khal / ui / __init__.py View on Github external
:param end: optional, date the event ends on (inclusive)
        :type end: datetime.date
        """
        if not self.pane.collection.writable_names:
            self.pane.window.alert(('alert', 'No writable calendar.'))
            return
        if end is None:
            start = dt.datetime.combine(date, dt.time(dt.datetime.now().hour))
            end = start + dt.timedelta(minutes=60)
            event = icalendar_helpers.new_event(
                dtstart=start, dtend=end, summary='',
                timezone=self._conf['locale']['default_timezone'],
                locale=self._conf['locale'],
            )
        else:
            event = icalendar_helpers.new_event(
                dtstart=date, dtend=end + dt.timedelta(days=1), summary='',
                allday=True, locale=self._conf['locale'],
            )
        event = self.pane.collection.new_event(
            event.to_ical(), self.pane.collection.default_calendar_name)
        self.edit(event)
github pimutils / khal / khal / ui / __init__.py View on Github external
def new(self, date, end=None):
        """create a new event on `date` at the next full hour and edit it

        :param date: default date for new event
        :type date: datetime.date
        :param end: optional, date the event ends on (inclusive)
        :type end: datetime.date
        """
        if not self.pane.collection.writable_names:
            self.pane.window.alert(('alert', 'No writable calendar.'))
            return
        if end is None:
            start = dt.datetime.combine(date, dt.time(dt.datetime.now().hour))
            end = start + dt.timedelta(minutes=60)
            event = icalendar_helpers.new_event(
                dtstart=start, dtend=end, summary='',
                timezone=self._conf['locale']['default_timezone'],
                locale=self._conf['locale'],
            )
        else:
            event = icalendar_helpers.new_event(
                dtstart=date, dtend=end + dt.timedelta(days=1), summary='',
                allday=True, locale=self._conf['locale'],
            )
        event = self.pane.collection.new_event(
            event.to_ical(), self.pane.collection.default_calendar_name)
        self.edit(event)