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.


    Installing numdifftools library

    Pythonista
    4
    18
    3722
    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.
    • JonB
      JonB @cvp last edited by

      @cvp really? I have never really used pyto, but it looked to me that the pyto_ui module was a thin wrapper around UIKit using rubicon objc. ObjCInstance might work a little differently -- you might need to find the object or pointer to pass into ObjCInstance, since the Rubicon version might not automatically look for the _objc_instance or .ptr attribute.

      It looks like there should be a py_view_ attribute of pyto Views, which might be the ObjCInstance directly?

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

        @JonB I was in the Pyto Discord discussion group and I asked help for this problem and a smart guy answered to use

        tv = pyto_ui.textView("some text...")
        tv_objc = ObjCInstance(tv.__py_view__.managed)
        print(tv_objc.objc_class.instance_methods)
        

        He said: "Right, I think because rubicon implements a wrapper of the UITextView (UIView, etc) with some kind of limitations. The limited exposed methods though, I think, they are due to Pyto'simplementation."

        but that gives some attributes but not (all?) methods like in Pythonista.
        So I was not able, for instance, to use Attributes or bring_to_front and so on.

        Unfortunately, it seems that the developer never answers herself to questions/bugs.

        Edit: it seems that setAttributedText is also a method of TextField.ObjectiveC

        Édit: and of TextView. setAllowsEditingTextAttributes: and setAttributedText: seem to be the only two existing methods

        For TextField, I've been able to display it coloured via attributes, and also for TextView

        I have also been able to use setInputView_ even if this method is not in the list of methods....nor dir

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

          I believe Rubicon objects have an ObjCClass or objc_class attribute. Are these pyto UI objects, or standards objects?

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

            @JonB yes Rubicon has Objcclass and I can create real ObjectiveC objects like in Pythonista, for example

            NSMutableAttributedString=ObjCClass('NSMutableAttributedString')
            attrtext = NSMutableAttributedString.alloc()
            
            color = ObjCClass('UIColor').colorWithRed_green_blue_alpha_(1, 0, 10, 1)
            

            But Pyto objects,like Pyto_ui.TextField are Pyto objects and it is not so easy as in Pythonista to use their methods because their list is not given by a dir. But I'm confident because I think all standard methods are available without to be sure by advance, I have to try each time. And differently of Pythonista, attributes may not be "called ", like

            tfo.inputAssistantItem.setLeadingBarButtonGroups(None)
            Instead of
            tfo.inputAssistantItem().setLeadingBarButtonGroups(None)
            In Pythonista
            
            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by JonB

              Yes:

              https://github.com/ColdGrub1384/Pyto/blob/008bf515bee4a420ac820f1904d88521fb2f14ef/Pyto/Model/Python Bridging/UI/Views/PyTextView.swift

              The attribute TextView of the PyTextView object is a standard UITextView.

              And from pyto_ui.py:

                self.__py_view__ = __PyTextView__.newView()
              

              So
              TextView.__py_view__.TextView should give you the Rubicon ObjCInstance of the UITextView.

              Or, you might need to import rubicon.objc and call ObjCInstance on the result?

              Looking at Rubicon's ObjCInstance, it doesn't expose the methods and properties via dir, I don't think. But, you can find them in

                      'instance_methods': 
                      'instance_properties': 
              

              Which are dicts that maybe live in the ObjCClass of an object. So try

              print(Your_pyto_textview.__py_view__.TextView.objc_class.instance_methods.keys())
              
              cvp 2 Replies Last reply Reply Quote 0
              • cvp
                cvp @JonB last edited by

                @JonB said:

                instance_methods

                I had tried that but it gave only two methods, not all I have used after.... But, actually, all methods I need (until now) are accepted even if not listed in instance_methods.

                Thanks for your appreciated help, as usual

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

                  @JonB said:

                  print(Your_pyto_textview.py_view.TextView.objc_class.instance_methods.keys())

                  For info

                  Traceback (most recent call last):
                    File "iCloud/Outline/TextField Attributes.py", line 71, in <module>
                      print(Your_pyto_textview.__py_view__.TextView.objc_class.instance_methods.keys())
                    File "Pyto.app/Lib/rubicon/objc/api.py", line 651, in __getattr__
                      raise AttributeError(
                  AttributeError: rubicon.objc.api.ObjCInstance Pyto.PyTextView has no attribute TextView
                  >>> ```
                  1 Reply Last reply Reply Quote 0
                  • JonB
                    JonB @cvp last edited by

                    @cvp you might need to call _load_methods on the object.

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

                      @JonB Thanks, I'll remember if I meet problems (if I continue this process of conversion to Pyto).

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

                        @cvp try this: print(Your_pyto_textview.py_view.TextView.objc_class.partial_methods.keys())

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

                          fixed underscore

                          Your_pyto_textview.__py_view__.TextView.objc_class.partial_methods.keys())
                          
                          cvp 2 Replies Last reply Reply Quote 0
                          • cvp
                            cvp @bosco last edited by

                            @bosco same error

                            1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @bosco last edited by cvp

                              @bosco @JonB

                              print(text_field.__py_view__.managed.objc_class.partial_methods.keys())
                              

                              Gives

                              dict_keys(['.cxx_destruct', 'initWithFrame', 'traitCollectionDidChange', 'initWithCoder'
                              ])
                              
                              print(text_field.__py_view__.managed.objc_class.instance_methods.keys())
                              

                              Gives

                              dict_keys(['allowsEditingTextAttributes', 'setAllowsEditingTextAttributes:', 'setAttribu
                              tedText:', 'setInputView:'])
                              
                              1 Reply Last reply Reply Quote 0
                              • JonB
                                JonB last edited by JonB

                                Sorry, looking at the Rubicon code again, the instance_methods attribute only gets filled on demand for the methods called by Rubicon.
                                But the instance_method_ptrs should be filled whenever you try to access any methods in the class. (Or after _load_methods() is called on the objc class object, once. That might not be needed, not sure). Again, you want instance_method_ptrs.keys().

                                jb

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

                                  @JonB said:

                                  instance_method_ptrs.keys().

                                  print(text_field.__py_view__.managed.objc_class.instance_method_ptrs.keys())
                                  

                                  Gives

                                  dict_keys(['.cxx_destruct', 'initWithFrame:textContainer:', 'traitCollectionDidChange:',
                                   'initWithCoder:'])
                                  

                                  But anyway, don't worry, I'll each try if the method I want to use is accepted or not.

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