@wenchoheelio , hello me again :). Hey, i am guessing you are using UIFiles to create your interface. Thats perfectly fine and very good when your view gets complicated. But for simple views, doing a CustomView can be very easy and helpful. Esp when you are learning the ui module, you dont feel as disconnected from your view. Anyway, I did an example below. Its not perfect by any means. Many hard coded numbers in there. I am not sure where you are at. But just wanted you too see that ui CustomViews are not scary. Its just a class that subclasses ui.View.
Anyway, my example is below. Below the example, I have put the code I use each time I start a new file. Again, I am not saying its great. But for me its a standard way of starting to do something. I also do have other templates if I am going to be using a UIFile (.pyui) file also.
The only reason I am sharing this is because I had problems in the begining. Knowing how to both use the UIFile(Designer) and Custom ui.View classes for interfaces will make life easier in my opinion. Working with both sort of helps you get a better understanding of what's going on. And more importantly, I think you can start to see how easy it actually it is.
import ui
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.txtfld1 = None
self.txtfld2 = None
self.txtfld3 = None
self.tbl = None
self.make_view()
def make_view(self):
self.txtfld1 = ui.TextField(frame=(0, 0, self.width, 32),
text='(1) TextField_text')
self.txtfld2 = ui.TextField(frame=(0, 32, self.width, 32),
text='(2) TextField_text')
self.txtfld3 = ui.TextField(frame=(0, 64, self.width, 32),
text='(3) TextField_text')
self.add_subview(self.txtfld1)
self.add_subview(self.txtfld2)
self.add_subview(self.txtfld3)
self.tbl = ui.TableView(frame=(0, 128, self.width, 200))
self.tbl.data_source = ui.ListDataSource(items=[])
self.add_subview(self.tbl)
btn = ui.Button(title='Update Table',
border_width=.5,
bg_color='white',
action=self.do_update_list
)
btn.width = 150
btn.height = 40
btn.center = self.center
btn.y = self.height - btn.height - 20
self.add_subview(btn)
def do_update_list(self, sender):
self.tbl.data_source.items = [self.txtfld1.text,
self.txtfld2.text,
self.txtfld3.text
]
if __name__ == '__main__':
f = (0, 0, 300, 400)
v = MyClass(frame=f, bg_color='teal', )
v.present(style='sheet', animated=False)
This is the template, I start out with most times I want to do something. Its simple, normally I am doing simple things, so its fine for me. It's Just good to have a consistent starting point and way of doing things. You make decide on a completely different template or None at all. Its just an idea.
import ui
class MyClass(ui.View):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.make_view()
def make_view(self):
pass
if __name__ == '__main__':
f = (0, 0, 300, 400)
v = MyClass(frame=f)
v.present(style='sheet')