Custom View Class - in pyui files.... [tip]
Ok, I feel foolish, I was after this functionality for a long time in pyui files and it's just been sitting there, God knows for how long. Maybe 1.6 😱
So, if you create a pyui file in the designer. Add a Custom View Control from the add menu to it. Then in the Custom View Class (property sheet) for that view in designer, add the class name of a Custom uiView that you have defined in your code.
Presto, that class is the class used as the ui.View.
Look, I know many just know this. But there are so many things that are possible, hard to keep up with it all.
Anyway, below is sample code. Just need to create a pyui file. Very simple one.
import ui class OwnerDrawn(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def draw(self): s = ui.Path.oval(*self.bounds) ui.set_color('red') s.fill() if __name__ == '__main__': w, h = 600, 800 f = (0, 0, w, h) # load a standard pyui file as normal. In the pyui file, there is # a custom View Control. its Custom View Class property in the # pyui file is set to OwnerDrawn. v = ui.load_view('Search_bar') v.present('sheet')
This has been there since before 1.6. It was in 1.5, iirc.
@Webmaster4o , lol does not surprise me. But let's face it a lot of little treasures in Pythonista.
I wish they could all be documented, but I understand why they are not. It would take a big chunk out of the development time. I can't remember how long I have had Pythonista now, but I am astounded how much it has evolved in that short time.