I have two functions within my PyQt code, one for the user to pick a file path and put the file path into a text editor box. This works fine. The second function looks in that directory, finds all the files I want and sorts them for me.
However, within this function i find the number of files and the file index its iterating over to calculate a percentage. I want to use this changing percentage variable to increment a progress bar in my UI while the function is iterating over the files.
My problem is that I cannot get this value out of the function while its iterating as it only returns the value while its finished. resulting in my progress bar not functioning correctly. Currently im just trying to get the text editor to display the value of percent to see if Its updating at all.
Defining the "percent" variable as global doesn't work. Am I approaching this wrong?
The function within my UI code called by button 2:
def file_search(self):
get = self.textEdit.toPlainText()
T.sleep(2)
search(str(get))
self.textEdit_2.setText(percent)
The function within called "search" the UI calls when I press button 2:
global percent
def search(file_path):
print "File Path: " + str(file_path)
#find all dicom files
files = glob.glob(str(file_path) + "\*.dcm")
value = 0
total = len(files)
for filename in files:
print filename
value = value + 1
percent = (value/float(total))*100
print percent
I have taken out the GUI code as it was far too long for clarity sake. If it's needed I can amend this asap.