-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexchange_gui.py
90 lines (67 loc) · 2.52 KB
/
exchange_gui.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
"""
Created on Fri May 21 12:15:59 2021
@author:Naveen Kumar Vasudevan,
Doctoral Candidate,
The Xi Research Group,
Department of Chemical Engineering,
McMaster University,
Hamilton,
Canada.
naveenovan@gmail.com
https://naveenovan.wixsite.com/kuroonai
"""
import PySimpleGUI as sg
import pathlib
firstcolumn = [
[sg.Text("Input files")],
[sg.Text("From")],
[sg.Text("To ", justification='right')],
[sg.Text('Progress')],
]
secondcolumn = [
[sg.In(size=(40, 1), enable_events=True, key="IN-files"), sg.FilesBrowse(key="IN-file-browser")],
[sg.Combo(['from extension'], size=(10,4), key='fromexts')],
[sg.In(size=(10,4), key='toexts', justification='left')],
[sg.ProgressBar(1, orientation='h', size=(40, 20), key='progress'), sg.Text( size=(10,1), key='progper')],
]
thirdcolumn = [
[sg.Button('exchange', size=(10,1), key='exchange'),sg.Button('Done', size=(10,1), key='Done')]
]
layout = [
[
sg.Column(firstcolumn),
sg.Column(secondcolumn),
sg.Column(thirdcolumn),
]
]
window = sg.Window("Kuroonai's extension changer", layout, icon='Images/logo.ico')
if __name__ == "__main__":
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED or event == 'Done':
break
elif event == "IN-files":
allfiles = values["IN-files"]
files = allfiles.split(';')
extlist = []
for f in files:
extlist.append(pathlib.Path(f).suffix)
extlist = set(extlist)
extlistback = []
for ext in extlist:
extlistback.append(ext)
window.Element('fromexts').Update(values=extlistback, value=ext, size=(10,4))
elif event=='exchange':
fromext = values['fromexts']
toext = values['toexts']
if not toext.startswith('.') : toext = '.'+toext
progress_bar = window.FindElement('progress')
progper = window.FindElement('progper')
files = [f for f in files if f.endswith(fromext)]
for i, f in enumerate(files):
p = pathlib.Path(f)
p.rename(p.with_suffix(toext))
progress_bar.UpdateBar(i+1)
progper.update('{} of {} done'.format(i+1,len(files)))
window.close()