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.
Using 'Custom View Class' with pyui files
-
Sorry, I am lost with this one. I can see where in the ui designer were to put the name of my custom class. Which I have done. I put only the class name in. No parentheses etc...
But from there I am lost.
I thought maybe it was as magically connected that when my class is created I would have that view loaded into my class. Does not seem to be the case :) I know how to make the view a subview of my custom class, but defeats the purpose.Anyway, I think this is going to be a simple answer. I just can't get my head around it. Any help appreciated.
Thanks. -
When your script calls
ui.load_view()
, a new instance of your custom view class will be created and it's__init__()
and thendid_load()
methods will be called. -
ccc, thanks. Very easy when you know how. I think I get it now, was not evident to me at first, but can see the load_view is creating an instance of your class for you. Makes sense once thinking about it. But it is nice.
Btw, I eat my words about coding the ui is easier than using the ui designer. It reduces your code by reams of pages :) I think I just had an issue with the dependencies of pyui files. Stupid idea actually. But I found out quickly as I started trying to create a functional app. Also, the more familiar you get with the ui and python for that matter it makes more and more sense to use the ui Designer.
But thanks again. This appears to be a small thing, but a big thing in design and coding. I am sure I will use it most the time
-
ccc, I now see why the did_load method is important. Can't reference view objects in the init method. The form fails to load. Again, makes sense that you would reference the objects after the form is loaded :) but in this case , it strikes me that a setup method like Scene has would be more intuitive. Doesn't matter, it all works, which is the main thing.
-
did_load()
is that setup() method. -
Yes, I understand. But intuitively, it's more like you are responding to fired event rather than being explicitly called with certainty . Even though I am sure that's not the case under the hood. But, I agree, is the same.
Just a mindset. I was used to event driven ui's. Served up from priority queues etc. some events made it through, some didn't. Understand with python, it's a different concept. Which, I don't understand yet. But I think these are fixed callback functions that are guaranteed to be called.
It's funny, even how far the past us the past for me, still haunts me. Had to be so cautious before with c, it sort of puts the fear of God in you :)
Oh well, life goes on. It's a good day when I can work out how to imbedd a Dropbox image here :)