omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    UI Progress bar resets in tableview

    Pythonista
    2
    5
    2848
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • yas
      yas last edited by

      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 4 Replies Last reply Reply Quote 0
      • cvp
        cvp @yas last edited by

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

        1 Reply Last reply Reply Quote 1
        • cvp
          cvp @yas last edited by 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()
          
          1 Reply Last reply Reply Quote 0
          • cvp
            cvp @yas last edited by

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

                def animation():
                    a['progress'].width = 150
                ui.animate(animation, duration=1.0)
            
            1 Reply Last reply Reply Quote 0
            • cvp
              cvp @yas last edited by 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()
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Powered by NodeBB Forums | Contributors