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.


    Override ui.View "attributes" in subclass?

    Pythonista
    attributes view ui.view
    2
    4
    2242
    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.
    • shinyformica
      shinyformica last edited by

      Long time, no post. Everything's been going swimmingly in my adventures in Pythonista-land. But I just encountered something I haven't hit before:

      I trying to figure out a way to have a ui.View subclass which can intercept the setting of properties like "background_color" so I can do something with the value separate from the normal setting of the ui.View attribute.

      If these were normal python properties, I'd know how to do it. However, things like ui.View.background_color are not normal python properties, they're some special "getset_descriptor" object on the underlying _ui.View object.

      So I can't do something like this:

      @property
      def background_color(self):
          return super(MyView, self.__class__).background_color.fget(self)
          
      @background_color.setter
      def background_color(self, color):
          super(MyView,  self.__class__).background_color.fset(self, color)
      

      And I can't find out much of anything about what a "getset_descriptor" is. If I look at ui._ui.View.background_color, it says it's an: <attribute 'background_color' of '_ui.View' objects>, which isn't very helpful...and help()/dir() aren't giving me much info either.

      Anyone have a way they've done this?

      mikael 1 Reply Last reply Reply Quote 0
      • shinyformica
        shinyformica last edited by

        Ah, was tired last night...this just required some googling.
        The getset_descriptor is the CPython property object, and I can directly get and set the value from it with:

        @property
        def background_color(self):
            return ui.View.background_color.__get__(self) 
            
        @background_color.setter
        def background_color(self, color):
            ui.View.background_color.__set__(self, color)
        
        1 Reply Last reply Reply Quote 2
        • mikael
          mikael @shinyformica last edited by

          @shinyformica, just curious: in your original post, what is the difference between super(MyView, self.__class__) and just super()?

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

            Python2 vs Python3 :)

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