-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathDemo_Compare_Files.py
50 lines (38 loc) · 1.36 KB
/
Demo_Compare_Files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import FreeSimpleGUI as sg
'''
Simple "diff" in PySimpleGUI
'''
sg.theme('Dark Blue 3')
def GetFilesToCompare():
form_rows = [[sg.Text('Enter 2 files to comare')],
[sg.Text('File 1', size=(15, 1)),
sg.InputText(key='-file1-'), sg.FileBrowse()],
[sg.Text('File 2', size=(15, 1)), sg.InputText(key='-file2-'),
sg.FileBrowse(target='-file2-')],
[sg.Submit(), sg.Cancel()]]
window = sg.Window('File Compare', form_rows)
event, values = window.read()
window.close()
return event, values
def main():
button, values = GetFilesToCompare()
f1, f2 = values['-file1-'], values['-file2-']
if any((button != 'Submit', f1 == '', f2 == '')):
sg.popup_error('Operation cancelled')
return
# --- This portion of the code is not GUI related ---
with open(f1, 'rb') as file1:
with open(f2, 'rb') as file2:
a = file1.read()
b = file2.read()
for i, x in enumerate(a):
if x != b[i]:
sg.popup('Compare results for files', f1, f2,
'**** Mismatch at offset {} ****'.format(i))
break
else:
if len(a) == len(b):
sg.popup('**** The files are IDENTICAL ****')
if __name__ == '__main__':
main()