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.


    [Share] func to get a dict of items, values from a ui.View that are not in ui.View

    Pythonista
    beginners share ui.view
    1
    1
    1437
    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.
    • Phuket2
      Phuket2 last edited by

      All I am sharing is a one line function. custom_attrs. I have shared this before, but pretty sure I was only returning the attrs not the attrs and values. But ok, its not much. I have an example below that looks pretty lame. But I wanted it for getting custom attrs from a UIFile/pyui file.
      Just std python, but as a beginner I still struggle with different types of comprehensions.
      Btw, it works. Not to say it couldn't be written better/faster.

      import ui
      
      def custom_attrs(v):
          # returns a dict with k,v found in v(iew) that are not ui.View
          return {key:getattr(v, key) for key in
                  list(set(v.__dict__) - set(vars(ui.View)))}
      
      class MyClass(ui.View):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
              self.a = None
              self.b = 1
              
      if __name__ == '__main__':
          mc = MyClass(bg_color = 'white')
          mc.present('sheet')
          print(custom_attrs(mc))
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB Forums | Contributors