@Jonb, @ccc, @omz or anyone else that may know. Using the code below the Custom View Controls don't work as they do when not using bindings and WrapInstance.
In this post, all works normally.
I wondered if there is something I am missing to make this work. I think I sort of get why it's not. I am thinking to do with the global a and locals, in this case the scope gets limited to the class the pyui is being loaded into.
I get the following warning:
Warning: Could not resolve custom view class: name 'OwnerDrawn' is not defined
Anyway, it would be great to get a fix for this. Up until now, loading a pyui file into a class seemed to be flawless. However this seems to be a flaw.
Hopefully, I have overlook something stupid here
import ui
def WrapInstance(obj):
class Wrapper(obj.__class__):
def __new__(cls):
return obj
return Wrapper
class OwnerDrawn(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print('in here')
def draw(self):
s = ui.Path.oval(*self.bounds)
ui.set_color('red')
s.fill()
class PYUIViewer(ui.View):
# this acts as a normal Custom ui.View class
# the root view of the class is the pyui file read in
def __init__(self, pyui_fn, *args, **kwargs):
ui.load_view(pyui_fn,
bindings={'MyClass': WrapInstance(self), 'self': self})
# call after so our kwargs modify attrs
super().__init__(*args, **kwargs)
if __name__ == '__main__':
w, h = 600, 800
f = (0, 0, w, h)
fn = 'Search_bar.pyui'
style = 'sheet'
v = PYUIViewer(fn, frame=f)
v.present('sheet')
