1

I have a script which copies files from one folder to another. During the execution, i wish to rize a progress bar window and show the percentage of execution. The progress bar window code is (UI itself made in QT Designer):

class Progress(QWidget, Progress.Ui_Progress):
    def __init__(self):
        super(Progress, self).__init__()
        # SETUP UI
        self.setupUi(self)

        self.progressBar.setValue(??????)

In the main script, I run window before copy function

self.pb = Progress()
self.pb.show()

And then I copy files:

from distutils.dir_util import copy_tree    
copy_tree(path_SRC, path_NEW)

So I am confused, how to link progress bar setValue to show the coping progress.

kiryha
  • 183
  • 1
  • 2
  • 14
  • Where does the `copy_tree` come from? – deets Oct 19 '17 at 15:58
  • copy tree is from: `from distutils.dir_util import copy_tree` And it could be any other custom function, I wish to understand how to set up such things in general. – kiryha Oct 19 '17 at 16:05
  • 1
    That's a rather weird choice. May that be as it is, you can't achieve what you are after with this. Because you don't get any progress information out of the function. You need to use or write a function that allows for that. For proper percentages, you also need to first count the number of files to copy. And then you need to put this into a qthread & communicate the progress to the main-thread via a queued signal. – deets Oct 19 '17 at 16:12
  • Ok, but this is really what it is: a function that copies files from one folder to another, and content is always different. How can I get progress information of that process? – kiryha Oct 19 '17 at 16:27
  • 1
    You can e.g. build a copy_tree function yourself that works using os.walk. You need a walk to count files/gather files, and then you work through them and copy them one by one. Thus you can emit update information on each copied file. – deets Oct 19 '17 at 16:37
  • How to setup in this case? `def copy(listOfFiles): for i in listOfFiles: # copy file` – kiryha Oct 19 '17 at 16:40
  • 1
    Take a look. https://nikolak.com/pyqt-threading-tutorial/ – deets Oct 19 '17 at 18:45

0 Answers0