Forum Archive

UI Progress bar resets in tableview

yas

I am trying to make a downloader's ui,
but the problem after it pauses, the progress get resetted when scrolled down and scrolled up.

import ui

@ui.in_background
def progress_(sender):
    a=sender.superview
    for f in range(150):

        a['progress'].width=f
    return a['progress']

def make():
    a=ui.TableViewCell()
    b=ui.Label(frame=a.content_view.frame)
    c=ui.Label(frame=a.content_view.frame)

    c.name='progress'
    c.width=0
    c.bg_color='lightblue'
    h=ui.Button(frame=b.frame)
    h.x=250
    h.width=59
    h.action=progress_
    h.image=ui.Image('iob:arrow_expand_256')

    a.add_subview(b)
    a.add_subview(h)
    a.add_subview(c)
    return a
class listdata():
    def __init__(self):
        self.tv=ui.TableViewCell()
        self.b=ui.Button()
        self.l=ui.Label()
    def tableview_number_of_rows(self,t,s):
        return 20
    def tableview_cell_for_row(self,t,s,r):
        return make()


s=ui.TableView()
s.allows_selection=False

s.data_source=listdata()
s.present()
cvp

@yas make() is called each time the row is displayed or redisplayed. And your make recreates each time the label, thus...

cvp

@yas really not nice but it does what you want.
Normally, you should use tableview_did_select...

import ui

@ui.in_background
def progress_(sender):
    a=sender.superview
    for f in range(150):

        a['progress'].width=f
    tableview,row = sender.tableview_row
    tableview.done[row] = True
    return# a['progress']

def make(tableview,row):
    a=ui.TableViewCell()
    b=ui.Label(frame=a.content_view.frame)
    c=ui.Label(frame=a.content_view.frame)

    c.name='progress'
    if row not in tableview.done:
        c.width=0
    else:
        c.width = 150
    c.bg_color='lightblue'
    h=ui.Button(frame=b.frame)
    h.tableview_row = (tableview,row)
    h.x=250
    h.width=59
    h.action=progress_
    h.image=ui.Image('iob:arrow_expand_256')

    a.add_subview(b)
    a.add_subview(h)
    a.add_subview(c)
    return a
class listdata():
    def __init__(self):
        self.tv=ui.TableViewCell()
        self.b=ui.Button()
        self.l=ui.Label()
    def tableview_number_of_rows(self,t,s):
        return 40
    def tableview_cell_for_row(self,t,s,r):
        return make(t,r)


s=ui.TableView()
s.allows_selection=False

s.data_source=listdata()
s.done = {}
s.present()
cvp

@yas for the fun, replace your loop on 150 by

    def animation():
        a['progress'].width = 150
    ui.animate(animation, duration=1.0)
cvp

@yas if you put some text in your b label, you can set your progress bar as transparent

    b.text = 'test'
    c.bg_color=(0,0,0.8,0.2)#'lightblue'
    c.bring_to_front()