omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    beta objcutil
    3
    7
    4495
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ywangd
      ywangd last edited by ywangd

      I have a subclass of the builtin ui.TextView and it is created via the awesome objc_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 a ObjCInstance object. Is it somehow possible that I can wrap it so it can be called like a regular ui.TextView? (this would allow me just to write code like v.autocorrection_type = False.

      EDIT: there is setSpellCheckingType_ method but seems to have no effect. There are certainly no setAutocorrectionType_ or setAutocapitalization_ methods.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        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.

        then see https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/occ/intf/UITextInputTraits

        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.

        1 Reply Last reply Reply Quote 0
        • ywangd
          ywangd last edited by ywangd

          There is no method called setAutocorrectionType_ or setSpellCheckingType_. 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.

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by omz

            autocorrectionType and spellCheckingType 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 like setPropertyName_, even though it doesn't show up explicitly in Apple's documentation.

            1 Reply Last reply Reply Quote 0
            • ywangd
              ywangd last edited by

              @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?

              1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by

                I see... This actually does look like a bug. As a temporary workaround, you could try the following:

                vo.performSelector_withObject_('setAutocorrectionType:', 1)
                
                1 Reply Last reply Reply Quote 1
                • ywangd
                  ywangd last edited by

                  Thanks @omz The workaround works.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors