Sorry in advance if this is a Python question Vrs a Pythonista question. I am just not sure.
I have a cell class (a view to display information) that Inherits from both ui.View and my own class.
Anyway, this seems to work well for the most part. But when I use a pyui file as the view for the cell, I am accessing the objects with array notation. Again this works as expected.
But in threaded methods, array notation fails. Maybe it's something about early and late binding, I don't understand. Maybe it should work. I am not sure.
I put some code below, but I know it's difficult because it's only paritial , and does not run by itself.
Any ideas help appreciated. Oh, I can get object references to elements in the pyui file. But need to make an attribute in the cell class to access it before entering the thread.
```
cell we are using in the VirtualView
class TestCellVirtualViewCell2(ui.View , CellBase):
def init(self, w, h, item_index, Threaded = False, auto_start_thread =True):
CellBase.init(self, w, h , item_index, threaded = Threaded, thread_auto_start = auto_start_thread)
self.cust_view = None
self.add_item_id_label()
# This method is not threaded, is overrided method
# from Cellbase. is called automatically.
def create_cell_contents(self):
self.cust_view = ui.load_view('mycell1')
self.cust_view.frame = self.frame
self.add_subview(self.cust_view)
self.cust_view.border_width = .5
self.cust_view['lb'].text = 'hello world'
self.cust_view['img1'].image = rand_image()
# this a limitation i dont understand.
# in the thread, i can not access
# self.cust_view['img2']. i am sure its easy
# to know why, but i dont know why.
self.img2 = self.cust_view['img2']
self.start_activity()
# this method is overridden from Cellbase and
# is called on a thread. is called from Cellbase
def fetch_data(self):
# simulate loading a web resource
time.sleep(random.random())
# this is a method in Cellbase class.
# a way to exit the thread
if self.thread_check():return
time.sleep(random.random())
if self.thread_check():return
time.sleep(random.random())
if self.thread_check():return
if self.thread_check():return
self.img2.image = rand_image()
# in the non threaded code, i can access
# self.cust_view['lb'].text, in this method,
# creates an exeception. basically,
# self.cust_view['lb'] evaluates to None
#self.cust_view['lb'].text = 'Loaded'
self.stop_activity()```