Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Outliner with drag/drop reordering - part 2
-
I need help...
Next script works correctly, event is canceled or added but my delegate method is not called.
What is wrong? Thanks for helping me.import ui from objc_util import * load_framework('EventKitUI') EKEventEditViewController = ObjCClass('EKEventEditViewController') def eventEditViewController_didCompleteWith_(_self, _cmd, _controller, _action): controller = ObjCInstance(_controller) action = ObjCInstance(_action) print(action) controller.dismissViewControllerAnimated_completion_(True, None) try: MyEventEditViewDelegate = ObjCClass('MyEventEditViewDelegate') except: MyEventEditViewDelegate = create_objc_class( 'MyEventEditViewDelegate', methods=[eventEditViewController_didCompleteWith_,], protocols=['EKEventEditViewDelegate'] ) @on_main_thread def EventEdit(title=None): v = ui.View() if title: v.name = title v.rgb = None vc = ObjCInstance(v) store = ObjCClass('EKEventStore').alloc().init() calendar = None for cal in store.calendars(): #print(cal.title()) if str(cal.title()) == 'Outline': calendar = cal break EventEditViewController = EKEventEditViewController.new().autorelease() #print(dir(EventEditViewController)) EventEditViewController.editViewDelegate = MyEventEditViewDelegate.alloc().init() EventEditViewController.eventStore = store event = ObjCClass('EKEvent').eventWithEventStore_(store) event.title = 'Todo: text line' event.setCalendar_(calendar) EventEditViewController.event = event clview = EventEditViewController.view() w,h = ui.get_screen_size() v.frame = (0,0,w,h) vc.addSubview_(clview) v.present('fullscreen') #v.wait_modal() return EventEdit()
-
@cvp Perhaps i have not thought this through, but would the event editor be used to set the default for events or would it be used to edit any event that has been added? If the latter, then I’m not sure what the advantage is to performing the edit within Pythonista as opposed to going to the calendar and editing it.
-
@ihf As you asked to be able to add some fields (2nd alarm, repeat) to a newly added due date event, I searched the easiest way which is this standard screen. But I did not wanted to allow editing, only adding.
But if you want....In French, we say "le client est roi" (I leave you translate 😀)
If you think you only need a few fields, please tell me which ones and I will program them instead of using this standard screen. -
@cvp I think the English expression is “the customer is always right“, but it sounds better in French :-) The only fields that I was thinking of were repeat and alarm but I suppose that if I view the due date feature as a way to manage ToDo events generally, you might as well use the standard edit panel.
-
@ihf Said:
you might as well use the standard edit panel.
As you have seen in my other post, I need help to get feedback of the standard screen.
-
@cvp I'm not sure, but I think the method name needs to be
eventEditViewController_didCompleteWithAction_
Not
eventEditViewController_didCompleteWith_
Although objc_util let's you call using the shortcut
eventEditViewController_didCompleteWith(action=obj)
, it dies that by trying kwarg names as the "nouns" when trying to find matching selectors that start the same. But the actual selector has the "noun" ("Action") in the selector name, and the underlying delegate mechanism is looking for the exact selector. Actually, I think you will find, since you confirmed to the protocol, that there actually is a method so named in your object, and that's the method getting called.The apple reference docs usually default to swift, which has its own name mangling approach -- make sure you always change the drop-down to objc.
-
@JonB thanks to help
I changed the name as adviced and when I tap- add, I get a segmentation fault in fault_log
- cancel, I get
-
@JonB EKEventEditViewController has a method
editor_didCompleteWithAction_
but this did not work. -
What if you create an empty method which simply returns. Do you get seg fault?
-
@cvp action will be an nsinteger! Hence segfault when cast as ObjCInstance
See typedef for EKEventEditViewAction.
-
@JonB you're right, I was just busy to directly prinT(_action) instead of getting its objcinstance
Thanks a lot as usual
-
@JonB I've still a problem to close/dismiss the ViewController
-
Possibly try calling the dismiss with on_main_thread?
Are you getting a segfault with the dismiss, it something else?
-
Oh I see. Can you print the full traceback?
-
@JonB no error but nothing happens, perhaps I have to close the ui.View
-
@JonB if I close thé ui.View without dismissing, it is ok
-
@JonB said:
make sure you always change the drop-down to objc.
I hadn't imagined it would be any different, I'll try not to forget to check every time. again a huge thank you for your skills and your availability to help
-
@ihf I just begin to (try to) integrate the standard event editor. I have some questions:
- when we paste copied lines, if a line had already a due date, actually the program also sets the due date of the new line with the same date, I don't think that's normal. Do you want I don't set automatically this due date, so you could always set the due date manually
- you know that we have sometimes duplicate. As now, we know that the standard eventIdentifier is not unique but depends of the device, I will change that in the future but actually, I advice that you set/unset/update a due date (thus the event) always on the same device to avoid this possible generation of duplicates. Do you agree?
-
@cvp I agree that copied lines should not create a new due date for the same item. Yes, I agree that setting snd unsetting due dates from the same device is ok as a temporary measure but, of course, it’s not intuitive.
-
@ihf Sid:
setting and unsetting due dates from the same device is ok as a temporary measure
The problem that will follow is that, if I change the way to identify an event, by an unique value cross devices, What do do with old events? Support old way and new way or only new way?
And, it is probable that I'll begin with outlines events for Apple Watch, less important if bugs.
And you will need to be patient. I'm less motivated than at the begin of the development.