def FindDuplicatesFilesInFolder(path): shatab = [] total = 0 small_count, dup_count, error_count = 0, 0, 0 pngdir = path if not os.path.exists(path): sg.Popup('Duplicate Finder', '** Folder doesn\'t exist***', path) return pngfiles = os.listdir(pngdir) total_files = len(pngfiles) for idx, f in enumerate(pngfiles): if not sg.OneLineProgressMeter('Counting Duplicates', idx + 1, total_files, 'Counting Duplicate Files'): break total += 1 fname = os.path.join(pngdir, f) if os.path.isdir(fname): continue x = open(fname, "rb").read() m = hashlib.sha256() m.update(x) f_sha = m.digest() if f_sha in shatab: # uncomment next line to remove duplicate files # os.remove(fname) dup_count += 1 # sg.Print(f'Duplicate file - {f}') # cannot current use sg.Print with Progress Meter continue shatab.append(f_sha) msg = '{} Files processed\n {} Duplicates found'.format( total_files, dup_count) sg.Popup('Duplicate Finder Ended', msg)
Shows how 2 progress meters can be running at the same time. Note -- If the user wants to cancel a meter, it's important to use the "Cancel" button, not the X If the software determined that a meter should be cancelled early, calling OneLineProgresMeterCancel(key) will cancel the meter with the matching key """ # sg.ChangeLookAndFeel('Dark') """ The simple case is that you want to add a single meter to your code. The one-line solution """ # Display a progress meter in work loop. User is not allowed to break out of the loop for i in range(10000): if i % 5 == 0: sg.OneLineProgressMeter('My 1-line progress meter', i + 1, 10000, 'single') # Display a progress meter. Allow user to break out of loop using cancel button for i in range(10000): if not sg.OneLineProgressMeter('My 1-line progress meter', i + 1, 10000, 'single'): break layout = [[sg.T('One-Line Progress Meter Demo', font=('Any 18'))], [ sg.T('Outer Loop Count', size=(15, 1), justification='r'), sg.In(default_text='100', size=(5, 1), key='CountOuter', do_not_clear=True), sg.T('Delay'),