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.


    objc_util / Declaired Enum / Custom Views

    Pythonista
    2
    4
    3039
    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.
    • reticulated
      reticulated last edited by

      Hello it's me again!

      I am playing around with implementing a UIStackView via objc_util

      I have two questions:

      1. How do I get access to the Enumerations?

      Such as "UILayoutConstraintAxisVertical" or "UIStackView.Distribution.fill"?

      I've used the load_framework helper to load UIKit, and QuartzCore and no luck.

      --

      1. I know I can't use ui.View.add_subview() when using a custom UIView class (such as UIStackView); but I can access ui.View().objc_instance.addSubview() and it seems to work.

      My code is too messy to post, but I will later if I can't get it going with this.

      I am setting up a subclass of ui.View(), from there I've setup UIStackView as self.stackview.

      The UIStackView uses its subviews to render the content.

      Is there anything i can do to allow me to use the ui.View().add_subview()?

      2.5:

      Also, if anyone can give me a thought on how I am planning on implementing this..

      class StackView (ui.View):
          
          def __init__(self):
              self.stackview = UIStackView.alloc().init()
              # Setup stackview options..
              # Setup properties for common used SV opt's
              
          @on_main_thread
          def add_subview(self, subview, use_stackview=True):
              # TODO: Add Error checking
              if use_stackview:
                  self.stackview.addSubview(subview)
              else:
                  self.add_subview(subview)
      

      This is a quick rough idea of how I see it working, so it "feels" like it was embedded in Pythonista.

      Any help on above items would be grand!

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

        Note: I meant super().add_subview for regular subview

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

          @reticulated
          C enumerations are essentially local constants, thus they don't appear as symbols you can lookup.

          Usually a good search for the name will lead you to its definition. For instance
          https://developer.apple.com/documentation/uikit/uilayoutconstraintaxis/uilayoutconstraintaxisvertical?language=objc
          Shows the value is 1 for that value.

          Just write your own uikit.py that defines convienece constants you need. For example, https://github.com/pybee/toga/blob/master/src/iOS/toga_iOS/libs/uikit.py

          Some constants that are actually exported (extern in header files, or objects) can be retrieved using in_dll on the appropriate ctypes type:

          c_void_p.in_dll(c, 'AVMediaTypeVideo')
          
          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            One thing you should do: add stackview as a subview of self, set it's frame to self.bounds, and define a custom layout to enforce this always whenever self changes size (you could also set up the stackview flex, but that's slightly more complex using objc). That way, the flex settings in the custom UI.View will let the view live more naturally inside pythonista views. And by having the stack as a subview of your custom view, higher level views don't need to use objc to interact with it.

            One problem you will have is that subviews of the stackview will be unable to use superview, since the superview isn't a python object. You could add custom attributes to subviews in your custom add_subview, to point back to your custom view as the"real" superview.

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