Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Progressbar in PYQT5 with Python

Progressbar in PYQT5 with Python

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • monamourM Offline
    monamourM Offline
    monamour
    wrote on last edited by monamour
    #1

    Dear All,

    I have created a desktop application by PYQT5 and python 3.7, to download  a video by clicking the download button and save it locally in the PC. 
    
     The code will fetch the video link from **(lineEdit.text())** which is labeled "URL" and save it in the local directory in **(lineEdit_2.text)** which is labeled "SAVE AS". If the download stops for any reason, it will be resumed again by press the start  download button.
    
    The  question is, I want to connect the start button with a Progressbar and displaying the loading in percentage, from start downloading 1% to finish 100%. Please see the code below and the picture.
    

    The code

     def curl_progress(self,total, existing,upload_t,upload_d):
    
            try:
                frac = float(existing)/float(total)
    
    
            except ZeroDivisionError:
                frac =0
    
            print("Downloaded %d/%d (%0.2f%%)" % (existing, total, frac))
    
            if frac ==1.0:
                self.textBrowser.append("Done")
                exit()
            else:
                self.textBrowser.append(("Downloaded %d/%d (%0.2f%%)" % (existing, total, frac)))
    
    
    
    
    
        def curl_limit_rate(self,rate_limit):
            url= self.lineEdit.text()
            save_location = self.lineEdit_2.text()
    
            c = pycurl.Curl()
            #For SSL certification
            c.setopt(pycurl.CAINFO, certifi.where())
            c.setopt(c.URL, url)
            c.setopt(c.MAX_RECV_SPEED_LARGE, rate_limit)
            if os.path.exists(save_location):
                file_id = open(save_location, "ab")
                c.setopt(c.RESUME_FROM, os.path.getsize(save_location))
            else:
                file_id = open(save_location, "wb")
    
            c.setopt(c.WRITEDATA, file_id)
            c.setopt(c.NOPROGRESS, 0)
            c.setopt(c.PROGRESSFUNCTION, self.curl_progress)
            c.perform()
    

    The picture

    123.JPG

    Many thanks in advance,

    JonBJ 1 Reply Last reply
    0
    • monamourM monamour

      Dear All,

      I have created a desktop application by PYQT5 and python 3.7, to download  a video by clicking the download button and save it locally in the PC. 
      
       The code will fetch the video link from **(lineEdit.text())** which is labeled "URL" and save it in the local directory in **(lineEdit_2.text)** which is labeled "SAVE AS". If the download stops for any reason, it will be resumed again by press the start  download button.
      
      The  question is, I want to connect the start button with a Progressbar and displaying the loading in percentage, from start downloading 1% to finish 100%. Please see the code below and the picture.
      

      The code

       def curl_progress(self,total, existing,upload_t,upload_d):
      
              try:
                  frac = float(existing)/float(total)
      
      
              except ZeroDivisionError:
                  frac =0
      
              print("Downloaded %d/%d (%0.2f%%)" % (existing, total, frac))
      
              if frac ==1.0:
                  self.textBrowser.append("Done")
                  exit()
              else:
                  self.textBrowser.append(("Downloaded %d/%d (%0.2f%%)" % (existing, total, frac)))
      
      
      
      
      
          def curl_limit_rate(self,rate_limit):
              url= self.lineEdit.text()
              save_location = self.lineEdit_2.text()
      
              c = pycurl.Curl()
              #For SSL certification
              c.setopt(pycurl.CAINFO, certifi.where())
              c.setopt(c.URL, url)
              c.setopt(c.MAX_RECV_SPEED_LARGE, rate_limit)
              if os.path.exists(save_location):
                  file_id = open(save_location, "ab")
                  c.setopt(c.RESUME_FROM, os.path.getsize(save_location))
              else:
                  file_id = open(save_location, "wb")
      
              c.setopt(c.WRITEDATA, file_id)
              c.setopt(c.NOPROGRESS, 0)
              c.setopt(c.PROGRESSFUNCTION, self.curl_progress)
              c.perform()
      

      The picture

      123.JPG

      Many thanks in advance,

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @monamour
      So in outline:

      self.pb = QProgressBar(self)
      self.pb.setRange(0, 100)
      # self.pb.show()
      ....
      frac = float(existing)/float(total)
      self.pb.setValue(frac * 100)
      

      That's the principle. I cannot recall whether QProgressBar is one which updates itself without needing to go into an event loop, if not then you'll need a QCoreApplication.processEvents() somewhere, but I suspect your "video download curl progress update" already has that so you won't need your own?

      monamourM 1 Reply Last reply
      2
      • JonBJ JonB

        @monamour
        So in outline:

        self.pb = QProgressBar(self)
        self.pb.setRange(0, 100)
        # self.pb.show()
        ....
        frac = float(existing)/float(total)
        self.pb.setValue(frac * 100)
        

        That's the principle. I cannot recall whether QProgressBar is one which updates itself without needing to go into an event loop, if not then you'll need a QCoreApplication.processEvents() somewhere, but I suspect your "video download curl progress update" already has that so you won't need your own?

        monamourM Offline
        monamourM Offline
        monamour
        wrote on last edited by
        #3

        @JonB Thanks so much, it solved.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved