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.
How to turn off spellchecking in a custom TextView?
-
I have a subclass of the builtin
ui.TextView
and it is created via the awesomeobjc_util
tools. It does have many great features. I am still finding my way through the new class. My question now is that I cannot find a way to turn off the spellchecking for the custom TextView. Code is as follows:from objc_util import * CustomTV = create_objc_class('CustomTV', ObjCClass('SUITextView')) def main(): main_view = ui.View(frame=(0, 0, 400, 400)) v = CustomTV.alloc().initWithFrame_(((0, 0), (400, 400))) # Now how do I turn off spell checking here? # There is no setSpellCheckingType_ method ... ObjCInstance(main_view).addSubview_(v) main_view.present('sheet') if __name__ == '__main__': main()
Similarly, how do I turn off Auto-Correction and Auto-Captialization (they seem to be off by default but what if I'd like to enable them)?
A further question (may be naive) is: The new View object is a subclass of
ui.TextView
, but it is presented as aObjCInstance
object. Is it somehow possible that I can wrap it so it can be called like a regularui.TextView
? (this would allow me just to write code likev.autocorrection_type = False
.EDIT: there is setSpellCheckingType_ method but seems to have no effect. There are certainly no setAutocorrectionType_ or setAutocapitalization_ methods.
-
you could always wrap your object in a python class, and handle specifc entries using @properties.
alternatively, you may be able to override setattr, to call the approprite set objc method.
Also, do you actually need to subclass the textview, or do you iust need a custom delegate? A vanilla textview can be customized in many ways i think.
if you look in the UITextView library reference
The appearance of the keyboard itself can be customized using the properties provided by the UITextInputTraits protocol. Text view objects implement this protocol and support the properties it defines. You can use these properties to specify the type of keyboard (ASCII, Numbers, URL, Email, and others) to display. You can also configure the basic text entry behavior of the keyboard, such as whether it supports automatic capitalization and correction of the text.
you will use setAutocorrectionType_(), etc. (prepend set, then capitalize first letter of attribute, and add an underscore). see the constants enumeration at the end of that document, it is a normal C enum.
-
There is no method called
setAutocorrectionType_
orsetSpellCheckingType_
. I did read the apple docs before asking the question. I understand they are part of the input trait protocol. But I can find no way to set them.from ui import TextView from objc_util import * vo = ObjCInstance(TextView()) # how do you turn off spell checking using just vo ??
I need to subclass TextView to provide the
keyCommand
method so it can support combo-keys from an external keyboard. -
autocorrectionType
andspellCheckingType
are Objective-C properties. That's basically just syntactic sugar for getter/setter methods. If a property isn't read-only, there's always a method likesetPropertyName_
, even though it doesn't show up explicitly in Apple's documentation. -
@omz I understand what you mean by property setter and getter. They are the first thing I tried and did not work. Following two method calls report error
No method found for selector ...
v.setAutocorrectionType_(1) v.setAutocapitalizationType_(0)
I was able to call
v.setSpellCheckingType_(1)
but it has no effect with all arguments I tried.Is this a bug?
-
I see... This actually does look like a bug. As a temporary workaround, you could try the following:
vo.performSelector_withObject_('setAutocorrectionType:', 1)
-
Thanks @omz The workaround works.