objc_util / Declaired Enum / Custom Views
Hello it's me again!
I am playing around with implementing a UIStackView via objc_util
I have two questions:
- 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.
- 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()?
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!
Note: I meant super().add_subview for regular subview
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
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:
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.