Beispiel #1
0
    def createNewEventWithCalendar_title_startDate_endDate_(
            self, calendar, title, startDate, endDate):

        # Create a new CalEvent object
        newEvent = CalEvent.event()

        # Set the calendar, title, start date and end date on the new event
        # using the parameters passed to this method
        newEvent._.calendar = calendar
        newEvent._.title = title
        newEvent._.startDate = startDate
        newEvent._.endDate = endDate

        # Save the new event to the calendar store (CalCalendarStore) and
        # return it
        res, err = CalCalendarStore.defaultCalendarStore(
        ).saveEvent_span_error_(newEvent, 0, None)
        if res:
            return newEvent

        NSLog("error:%@", err.localizedDescription())
        return None
Beispiel #2
0
    def createNewEventWithCalendar_title_startDate_endDate_(
                self, calendar, title, startDate, endDate):

        # Create a new CalEvent object
        newEvent = CalEvent.event()

        # Set the calendar, title, start date and end date on the new event
        # using the parameters passed to this method
        newEvent._.calendar = calendar;
        newEvent._.title = title;
        newEvent._.startDate = startDate;
        newEvent._.endDate = endDate;

        # Save the new event to the calendar store (CalCalendarStore) and
        # return it
        res, err = CalCalendarStore.defaultCalendarStore().saveEvent_span_error_(
                newEvent, 0, None)
        if res:
            return newEvent

        NSLog("error:%@", err.localizedDescription())
        return None
Beispiel #3
0
def createEvent(title,
                start_time,
                stop_time,
                calendar_name=u"项目",
                note='',
                url='',
                location=''):
    """
    createEvent("Python事件", "2018-10-28 10:00:00 +0800", "2018-10-28 12:00:00 +0800")
    """
    store = CalCalendarStore.defaultCalendarStore()
    for cal in store.calendars():
        if cal._.title == calendar_name:
            event = CalEvent.event()
            event._.calendar = cal
            event._.title = title
            event._.notes = textwrap.dedent(note)
            if url:
                event._.url = NSURL.URLWithString_(url)
            if location:
                event._.location = location
            event._.isAllDay = False
            start = NSDate.dateWithString_(start_time)
            stop = NSDate.dateWithString_(stop_time)
            event._.startDate = start
            event._.endDate = stop
            res, err = store.saveEvent_span_error_(event, 0, None)
            if not res:
                print("添加日历事件失败", err.localizedDescription())
                break
            else:
                print("添加日历事件成功: %s" % res)
                break
    else:
        print("没有找到合适的日历")
        for cal in store.calendars():
            print(cal._.title)
"""
Adds WWDC 2007 to the 'Work' calendar
"""
from __future__ import print_function
from CalendarStore import CalCalendarStore, CalEvent
from Foundation import NSURL, NSDate
import textwrap

store = CalCalendarStore.defaultCalendarStore()
for cal in store.calendars():
    if cal._.title == "Work":
        event = CalEvent.event()
        event._.calendar = cal
        event._.title = "WWDC 2009"
        event._.notes = textwrap.dedent(
            """\
                This June, the center of the Mac universe will be at Moscone
                West in downtown San Francisco, as developers and IT
                professionals from around the globe come together for the
                Apple Worldwide Developers Conference.

                Don't miss this opportunity to connect with Apple engineers,
                get a firsthand look at the latest technology, and spend a
                week getting the kind of inspiration you won't find anywhere
                else.
                """
        )
        event._.url = NSURL.URLWithString_("http://www.apple.com/wwdc/")
        event._.location = "Moscone West, San Francisco, CA, USA"
        event._.isAllDay = True
        start = NSDate.dateWithString_("2009-06-8 00:00:00 +0600")
"""
Adds WWDC 2007 to the 'Work' calendar
"""
from __future__ import print_function
from CalendarStore import CalCalendarStore, CalEvent
from Foundation import NSURL, NSDate
import textwrap

store = CalCalendarStore.defaultCalendarStore()
for cal in store.calendars():
    if cal._.title == "Work":
        event = CalEvent.event()
        event._.calendar = cal
        event._.title = "WWDC 2009"
        event._.notes = textwrap.dedent('''\
                This June, the center of the Mac universe will be at Moscone
                West in downtown San Francisco, as developers and IT
                professionals from around the globe come together for the
                Apple Worldwide Developers Conference.

                Don't miss this opportunity to connect with Apple engineers,
                get a firsthand look at the latest technology, and spend a
                week getting the kind of inspiration you won't find anywhere
                else.
                ''')
        event._.url = NSURL.URLWithString_('http://www.apple.com/wwdc/')
        event._.location = "Moscone West, San Francisco, CA, USA"
        event._.isAllDay = True
        start = NSDate.dateWithString_("2009-06-8 00:00:00 +0600")
        stop = NSDate.dateWithString_("2009-06-12 23:59:59 +0600")
        event._.startDate = start