I know I have asked this before in various ways. I hope I am in a better position to understand the answers now. Also to express what I am trying to achieve.
At the end of the post there is some simple code to create a custom ui class and then add it as a subview to a ui.View. Tried to keep it simple as possible.
What I would love to be able to do is create that class once, assign it to a var. thereafter when I want an instance of that class, I would like to be able to copy the memory object to get a new instance.
The code below shows a very simple example and probably does not warrant speeding up. But what I really want to do, is to have the 'Cell' class read multiple .pyui files to composite/render a view. So let's say 5 or 6 or more .pyui files loaded to compose my view and I need this composite view as fast as possible. It makes sense to me, that if I composite the view once, then just copy memory bytes, there would be a huge difference in speed. I can also appreciate there are some file buffering the issues I am unaware of. But still the execution of the python code in ui.py must be still hefty and slow compared to just copying some memory bytes.
In the code below, is the version that works. Just normal. Create a class inheriting from ui.View, then add it as a subview to another view. But lines above commented out try to use copy.copy and copy.deepcopy, niether result in the view being shown.
I have tried to comprehend the copy module the best I can, it seems to me it should be possible. But maybe there is something under Pythonista's hood that makes this impossible.
I would like to try and find out once and for all if am am on a fools quest or not.
Any help really appreciated. Again, sorry I have asked this before. If there was a good answer, I was not able to comprehend it. I am hoping I can now!
import ui
import copy
class Cell(ui.View):
def __init__(self):
self.width = 100
self.height = 20
lb = ui.Label(frame = self.frame)
lb.text = 'Hello World'
self.add_subview(lb)
if __name__ == '__main__':
cell_template = Cell()
f = (0,0,500,400)
v = ui.View(frame = f )
#c = copy.deepcopy(cell_template)
#c = copy.copy(cell_template)
c = cell_template
v.add_subview(c)
v.present('sheet')