Accessing calendars with EventKit on pyobjc (trouble passing entityType)

99 Views Asked by At

I'm aware this might be a dumb question, but I can't figure out how to translate this simple Swift statement (didn't find an Objective-C example) into pyobjc:

let calendars = EventStore.calendars(for entityType:.Events)

What I got so far (trying out different options):

from EventKit import EKEventStore

ek_event_store = EKEventStore.alloc().init()
default_cal = ek_event_store.defaultCalendarForNewReminders()  # works, but not the calendar I wish to access

my_cal_identifier = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
my_cal = ek_event_store.calendar(my_cal_identifier))  # Error: 'EKEventStore' object has no attribute 'calendar'

calendars = ek_event_store.calendars()  # value is None. I don't know how to pass it the entityType

So I guess my problem is not knowing

  • what the entityType is supposed to be (type? value?)
  • how to pass the entityType to the calendars function.
1

There are 1 best solutions below

0
Georg Pfolz On

I figured it out (using the dir function on the event store object and on a calendar object)

from EventKit import EKEventStore

ek_event_store = EKEventStore.alloc().init()

my_cal_identifier = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
my_cal = ek_store.calendarWithIdentifier_(cal_tcv_intern_id)

all_my_calendars = ek_store.calendarsForEntityType_(0)

I didn't find the Event types in the documentation, but with trial and error, I figured it out:

  • 0: calendar
  • 1: reminder

So I also gained some better insight how pyobjc is working:

EventStore.calendars(for entityType:.Events) becomes EventStore.calendardsForEntityType(event_type).

I was also wondering why the "calendar" function could not be found, now I understand that it bacame calendarWithIdentifier in pyobjc.