No way to end editing
When running a script with a UI, there is no button to end editing/dismiss the keyboard.
This applies at least to iOS 9 running on iPhone 6.
Only way to dismiss the keyboard is to have something else the user can click, which is not elegant nor aligned with the user experience in e.g. Safari or when running a script in iPad (where a dedicated dismiss keyboard button is available).
Does anyone know a workaround?
Webmaster4o last edited by
Both TextField and TextView have end_editing.
You can call it from the
actioncallback, or use a delegate that implements
def textfield_should_return(self, textfield): textfield.end_editing() return True
For a TextView, you could use
Thanks. I am aware of the programmatic options, but would not like to include a UI button or create a custom keyboard just for the purpose of ending editing, a function that in stock applications and on iPad is available on the keyboard.
JonB last edited by JonB
You mean the "hide keyboard" button on ipad ( which does NOT end editing, even in stock apps)? Or do you mean the circled X that appears in the textfield itself in some apps, say, for a searchbox?
Can you post a screenshot of the kb in pythonista, and the kb in another app, so we can see what you mean? Have you tried various
.keyboard_typesettings to see if any get closer to what you are after?
On the iPad, the hide keyboard button does end editing. Likewise the blue "Done" above the keyboard in e.g. Safari. Neither is available when running a Pythonista script on the iPhone.
Setting a different keyboard type was a good idea, but unfortunately none of them help with this.
Well, this is probably just one of those things that we have to live with until Apple maybe does something.
(Including screenshots seems to require uploading then somewhere else and then linking to them - I will skip that for now.)
Oh yeah, Hide Keyboard button probably does not end editing on iPad if you have a bluetooth keyboard connected.
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.