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.
No way to end editing
no i stand corrected... i must have been thinking of something else.
Those accessoryInputViews are not "standard"... the dev always has to implement himself.
It should, in theory be possible with the beta objc module... i spent a few minutes trying, and while i was able to get an accessoryInputView attached, it did not show up. But that may be because i was not using the right types.
You could also implement this sort of thing as an overlay that is tied to the kb frame, but that seems annoying perhaps.
It appears that with objc we can also change the kb Return button to a blue Done, or Go, etc, maybe that would scratch your itch?
Here is a way to access the inputAccessoryView, in the beta.
# coding: utf-8 from objc_util import * import ui '''set up top level view and textfield''' v=ui.View() tf=ui.TextField(frame=[0,0,400,30]) v.add_subview(tf) tfobj=ObjCInstance(tf) '''set up toolbar''' keyboardToolbar=ObjCClass('UIToolbar').alloc().init() keyboardToolbar.sizeToFit() flexBarButton=ObjCClass('UIBarButtonItem').alloc().initWithBarButtonSystemItem_target_action_(5,None,None) doneBarButton=ObjCClass('UIBarButtonItem').alloc().initWithBarButtonSystemItem_target_action_(0,tfobj,sel('endEditing:')) keyboardToolbar.items = [flexBarButton, doneBarButton] tfobj.textField().inputAccessoryView= keyboardToolbar v.present()
Thanks! "New to Pythonista" question: How do I get access to objc? Is this Xcode only?
There is a beta version of the upcoming 1.6.
Search the forums, there is a link to the signup request form.
Thanks omz, I got access to the beta and am now trying to understand JonB's sample above.
Any pointers on relevant objc usage documentation and samples?
Not having an ObjectiveC background, I am really starting from basics here. E.g. I have a TextView, not a TextField, so what method should I use in the final binding call? It is not textField(), nor did an experimental textView() work.
Just remove the call to textField, tfobj directly supports inputAccessory view.
As to how to go about learning objc in python... that's tricky. maybe find some simple example objc from stackoverflow, etc, and start converting it line by line to python. The tricky thing for me is always the named constants, often have to look up the objc header files, though some are available using ctypes in_dll.
I can follow your sample and read Apple docs in order to add more buttons to the bar, but I cannot get a call through back to a Python handler function when a button is clicked. All my attempts fail with Pythonista crashing.
All ideas would be highly welcome.
i changed TextField to TextView, and tfobj.textField() to simply tfobj, and this code worked.
Yes, sorry for being unclear.
Your code works beautifully. My problem comes when I try to add another button to do something else -- to take advantage of all that screen space -- I don't know how to get the button to call a handler function in Python.
Ok, found a working solution in the MapView objc sample:
Need to use a dummy ui.Button and set the Python click handler function as its "action". Then can use the button as the target and sel("invokeAction:") as the action when defining the Objc accessory button.