Accessing calendars with EventKit on pyobjc (trouble passing entityType) - eventkit

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.

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.

Related

pyobjc & EventKit: trouble saving event (EKErrorDomain Code=11)

I'm trying to save an event using pyobjc, but I get an EKErrorDomain Code 11 ("That event does not belong to that event store").
Here's what I have so far:
ek_store = EKEventStore.alloc().initWithAccessToEntityTypes_(0)
print(f'{ek_store=}')
my_cal_identifier = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
my_calendar = ek_store.calendarWithIdentifier_(my_cal_identifier)
print(f'{my_calendar.eventStore()=}') # obviously ek_store
event = EKEvent.alloc().init()
event.setEventStore_(ek_store)
print(f'{event.eventStore()=}') # ek_store, of course
event.setStartDate_(my_startDate) # NSDate, declared earlier
event.setEndDate_(my_endDate) # NSDate, declared earlier
event.setCalendar_(my_calendar)
event.setTitle_('My new event')
ek_store.saveEvent_span_error_(
event, 0, None
) # this throws the EKErrorDomain error
I'm utterly confused by the error message: the calendar as well as the event have the right event store set (I have only one defined anyway). What does this error mean in this context?
What am I missing?
In the documentation, it says "Create a new event with the init(eventStore:) method of the EKEvent class."
So maybe my problem stems from not understanding how to correctly create a new event with pyobjc (init does not allow arguments, so how can I pass on the event store?).

How do I get UUID FIELD value in Django ModelFORM?

I am doing something fairly straightforward...I am creating a record with a unique identifier using the UUID field in my POSTRGRESQL database. It's working fine. I'm trying to use that value and do a compare when the user is updating records. However, even though the value is in the database, when I try to get it via a ModelFORM in my CLEAN it is showing up as NONE. I'm guessing there's a special way to get this value but I can't figure out what it is. I tried to use this as a reference....https://stackoverflow.com/questions/54914961/django-form-with-a-modelchoicefield-on-a-uuid-do-not-show-its-content-in-cleaned but I can't work it out.
My Model...
class Model(models.Model):
unique_identifier = models.UUIDField(primary_key=False, default=uuid.uuid4, editable=False)
My FORM...
class FORM(forms.ModelForm):
class Meta:
model = Model
def clean(self):
cleaned_data = super(UpdateSavedNewProcedureForm, self).clean()
unique_identifier = cleaned_data.get('unique_identifier')
print(unique_identifier)
When I print the unique_identifier it comes back as NONE even though I can see the value in the database. If I store the value as a CHARFIELD I can get the value...but I'm trying to avoid duplicating this field just for readability. I'm certain there's a special way to get this value but I'm stumped at the moment.
Thanks in advance for any thoughts.
My final answer thanks to #Willem Van Onsem
My Model...
class Model(models.Model):
unique_identifier = models.UUIDField(primary_key=False,
default=uuid.uuid4, editable=False)
My Form...
class FORM(forms.ModelForm):
class Meta:
model = Model
def clean(self):
cleaned_data = super(UpdateSavedNewProcedureForm, self).clean()
unique_identifier = self.instance.unique_identifier
If unique_identifier:
Do Something Cool.....

Realm how to write subquery

I am study about Realm db, this db is nice as compare with core data but I am stuck on one place as follows:
I have two RLMObject in that I created relationship and I want to run join query (sub query) on that, but I can't do that.
first object (table) in Ralm
class Dog : RLMObject
{
dynamic var name = ""
dynamic var age = 0
// create variable of Owner object
dynamic var owner = RLMArray(objectClassName: "Owner")
override class func primaryKey() -> String!{
return "name"
}
}
second object (table) in Ralm
class Owner : RLMObject{
dynamic var myName = ""
}
so I want to fetch only those Dog names which belong with owner name 'ram'
I tried following sub query
var dog = Dog.allObjects().objectsWithPredicate(NSPredicate(format:"SUBQUERY(Owner, $owner, $owner.myName = 'ram')", argumentArray: nil))
but app is crashing with following error
RealTest[1701:17960] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "SUBQUERY(owner, $owner, $owner.myName = 'ram')"'
also I search it on net I found that realm.objects but it gave me error about not found.
Thanks in advance!
Your predicate should look like this:
let predicate = NSPredicate(format:"SUBQUERY(Owner, $owner, $owner.myName = 'ram') .#count > 0", argumentArray: nil)
The idea here is to make sure you add .# count > 0 at the end, as the predicate needs to return true or false for it to work.
This can be achieved using a query like:
Dog.allObjects().objectsWhere("ANY owner.myName = 'ram'")
SUBQUERY is only necessary if you have multiple constraints on the target of the relationship that must all be fulfilled by a single row, or if you wish to express a constraint other than ANY / ALL / NONE on the number of rows that match.
That said, as of Realm Objective-C and Swift 0.98.0 SUBQUERY is now supported.
While Realm supports filtering objects via NSPredicate, at this time of writing, Realm's implementation of NSPredicate yet support every single type of keyword that the native Apple frameworks do, including SUBQUERY. Realm provides an NSPredicate cheat sheet on its website, outlining which types of queries it presently supports.
That being said, if you already have an Owner object at this point, you can actually use another Realm method on the Owner object ([RLMObject linkingObjectsOfClass:forProperty:]) to find out which Dog objects are referencing it.
Finally, that realm.objects error is because that syntax is from the native Swift version of Realm, and the code you're using here is the Objective-C version of Realm, bridged over to Swift.
Let me know if you need any more clarification!

How to make basic bindings in ReactiveCocoa 3 and 4

I've been reading up on ReactiveCocoa v3 lately and I'm struggling with just setting up basic stuff. I've already read the changelog, the tests, the few SO questions and the articles by Colin Eberhardt on the subject. However, I'm still missing examples on basic bindings.
Let's say I have an app that presents the menu of the day. The app is using RAC3 and the MVVM pattern.
Model (Menu)
The model has one simple method for fetching todays menu. As for now, this don't do any network requests, it basically just creates a model object. The mainCourse property is a String.
class func fetchTodaysMenu() -> SignalProducer<Menu, NoError> {
return SignalProducer {
sink, dispoable in
let newMenu = Menu()
newMenu.mainCourse = "Some meat"
sendNext(sink, newMenu)
sendCompleted(sink)
}
}
ViewModel (MenuViewModel)
The view model exposes different String variables for letting the view controller show the menu. Let's just add one property for showing the main course.
var mainCourse = MutableProperty("")
And we add a binding for this property:
self.mainCourse <~ Menu.fetchTodaysMenu()
|> map { menu in
return menu.mainCourse!
}
ViewController (MenuViewController)
Last but not least, I want to present this main course in a view. I'll add a UILabel for this.
var headline = UILabel()
And finally I want to set the text property of that UILabel by observing my view model. Something like:
self.headline.text <~ viewModel.headline.producer
Which unfortunately does not work.
Questions
The method fetchTodaysMenu() returns a SignalProducer<Menu, NoError>, but what if I want this method to return a SignalProducer<Menu, NSError> instead? This would make my binding in my view model fail as the method now may return an error. How do I handle this?
As mentioned, the current binding in my view controller does not work. I've been playing around with creating a MutableProperty that represents the text property of the UILabel, but I never got it right. I also think it feels clumsy or verbose to have to create extra variables for each property I want to bind. This was not needed in RAC2. I intentionally also tried to avoid using DynamicProperty, but maybe I shouldn't? I basically just want to find the right way of doing RAC(self.headline, text) = RACObserve(self.viewModel, mainCourse);.
Any other feedback/guidance on how to make this basic setup is highly appreciated.
So, after writing this question Colin Eberhardt made a part 3 of his RAC3 blog post series which includes a interesting and very relevant example of using MVVM and RAC3. The post can be found here and the source code here.
Based on his work, I've managed to answer my own questions:
By taking a slightly different approach, I'm able to make the fetchTodaysMenu() return a SignalProducer<Menu, NSError> as wanted. Here's how what I then would do in my view model:
MenuService.fetchTodaysMenu()
|> observeOn(QueueScheduler.mainQueueScheduler)
|> start(next: { response in
self.mainCourse.put(response.mainCourse!)
}, error: {
println("Error \($0)")
})
It seems like there's no UIKit bindings yet as of RAC3 beta 4. Colin made some UIKit extensions himself to help him make these bindings I was looking for as well. These can be found here. Adding them to my project, made be able to do exactly what I wanted to:
self.mainCourse.rac_text <~ self.viewModel.mainCourse
Update May 25, 2015
After been working a lot more with ReactiveCocoa 3, I would like to answer 1) once again. By using catch, it's possible to do this in a more declarative manner. I ended up implementing a small helper function for this:
public func ignoreError<T: Any, E: ErrorType>(signalProducer: SignalProducer<T, E>) -> SignalProducer<T, NoError> {
return signalProducer
|> catch { _ in
SignalProducer<T, NoError>.empty
}
}
The function transforms any NSError to NoError making it possible to bind as I wanted to by doing MenuService.fetchTodaysMenu() |> ignoreError.
I open sourced my project as this might be a good starting point for others looking into ReactiveCocoa 3.0:
https://github.com/s0mmer/TodaysReactiveMenu
Update March 5, 2016
As highlighted in the comments, since Swift 2, the ignoreError function would now look like:
public func ignoreError() -> SignalProducer<Value, NoError> {
return flatMapError { _ in
SignalProducer<Value, NoError>.empty
}
}
Also, an extension library called Rex has also been made, where something similar has been added.

PowerShell: Add Reference to COM Interface ID directly

Is there by any chance a posibility to create a reference to an Interface ID Directly.
I tried something in a syntax form like but didnt work ...
$CO = new-object -ComObject "System.__ComObject#{fafa4e17-1ee2-4905-a10e-fe7c18bf5554}"
This Interface id is from Virtualbox.VirtualBox itself
I know that I can reference it with VirtualBox.VirtualBox naturally.
Can you refernce interface ids directly .... ??
As long the Interface is Public I Think you can but i cant find any example . ??
Thanks:)
I found the solution to my own problem by accessing it through:
[System.Runtime.InteropServices.Marshal]::GetTypeFromCLSID('fafa4e17-1ee2-4905-a10e-fe7c18bf5554')
OR:
$Type = [Type]::GetTypeFromCLSID('fafa4e17-1ee2-4905-a10e-fe7c18bf5554')
$Vbox = [System.Activator]::CreateInstance($Type)
$Vbox.APIVersion
This answered my question; case closed :)