-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel_helper.py
71 lines (53 loc) · 2.15 KB
/
label_helper.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
import PySimpleGUI as sg
import os
def nextBtn():
return sg.Button("Next")
def prevBtn():
return sg.Button("Previous")
def selectFilesLayout():
layout = [
[sg.Input(key=("_FILES_")), sg.FilesBrowse()],
[nextBtn()]
]
return layout
def inputFilenameLayout(displayImage):
layout = [
[displayImage],
[sg.InputText(key="Answer", do_not_clear=False)],
[prevBtn(), nextBtn()]
]
return layout
browseWindow = sg.Window("Select Files", selectFilesLayout())
event, fileDict = browseWindow.Read()
if event != "Next" or len(fileDict["Browse"]) == 0:
exit()
else:
browseWindow.Close()
fileList = fileDict["_FILES_"].split(';')
fileAbsDir = '/'.join(fileList[0].split('/')[:-1])
fileList = [filename.split('/')[-1].split('.')[0] for filename in fileList]
displayImage = sg.Image(fileAbsDir + '/' + fileList[0] + ".png", key="imageContainer")
inputWindow = sg.Window("[{}/{}] Please Input - {}".format(1, len(fileList), fileList[0]),
inputFilenameLayout(displayImage))
index = 0
while True:
newFilename = ""
response = {}
event, response = inputWindow.Read()
newFilename = response["Answer"]
if event == "Previous" and index > 0:
if newFilename != "":
os.rename(os.path.join(fileAbsDir, fileList[index] + ".png"), os.path.join(fileAbsDir, newFilename + ".png"))
fileList[index] = newFilename
index -= 1
if event == "Next":
if newFilename != "":
os.rename(os.path.join(fileAbsDir, fileList[index] + ".png"), os.path.join(fileAbsDir, newFilename + ".png"))
fileList[index] = newFilename
index += 1
if index >= len(fileList):
break
inputWindow.FindElement("imageContainer").Update(fileAbsDir + '/' + fileList[index] + ".png")
inputWindow.TKroot.title("[{}/{}] Please input - {}".format(index + 1, len(fileList), fileList[index]))
inputWindow.Close()
sg.Window("Finished!", [[sg.Text("Finished updating {} image labels.".format(len(fileList)))], [sg.OK()]]).Read()