Override ui.View "attributes" in subclass?
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?
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)
@shinyformica, just curious: in your original post, what is the difference between
super(MyView, self.__class__)and just
Python2 vs Python3 :)