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
Forum Updated to NodeBB v4.3 + New Features

Progressbar in PYQT5 with Python

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 861 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.
  • M Offline
    M Offline
    monamour
    wrote on 3 Jan 2020, 12:40 last edited by monamour 1 Mar 2020, 12:44
    #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,

    J 1 Reply Last reply 3 Jan 2020, 13:21
    0
    • M monamour
      3 Jan 2020, 12:40

      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,

      J Offline
      J Offline
      JonB
      wrote on 3 Jan 2020, 13:21 last edited by JonB 1 Mar 2020, 13:23
      #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?

      M 1 Reply Last reply 3 Jan 2020, 13:26
      2
      • J JonB
        3 Jan 2020, 13:21

        @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?

        M Offline
        M Offline
        monamour
        wrote on 3 Jan 2020, 13:26 last edited by
        #3

        @JonB Thanks so much, it solved.

        1 Reply Last reply
        0

        1/3

        3 Jan 2020, 12:40

        • Login

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