-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautomationGui.py
108 lines (86 loc) · 3.6 KB
/
automationGui.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import stitcher
import numpy as np
import os
import subprocess
from os.path import isfile, join
import tkinter
from tkinter import filedialog
from stitcher import Stitcher
import _thread
from subprocess import DEVNULL, STDOUT, check_call
class StitcherGUI:
fileList = None;
progress = 0;
# maskImages = 0;
def shorten_filename(self,filename):
f = os.path.split(filename)[1]
return "%s~%s" % (f[:3], f[-16:]) if len(f) > 19 else f
def __init__(self, master):
self.master = master
master.title("Stitcher")
self.outputFile = None
self.browse_button = tkinter.Button(master, text="Select Folders", command=self.browseFiles)
self.browse_button.grid(row=0)
self.maskImages = tkinter.BooleanVar()
self.maskImages.set(0);
self.mask_button = tkinter.Checkbutton(master, text="Mask Images", onvalue=1, offvalue=0,variable=self.maskImages)
self.mask_button.grid(row=5)
self.stitch = tkinter.Button(master, text="Stack and Stitch", command=self.start)
self.stitch.grid(row=3, column=1)
self.progressText = tkinter.IntVar()
self.progressText.set(self.progress)
tkinter.Label(master, text="Progress :").grid(row=4,column=0)
self.progress_label = tkinter.Label(master, textvariable=self.progressText)
self.progress_label.grid(row=4, column=1)
def browseFiles(self):
# Tk().withdraw()
dirs = []
title = 'Choose Directory'
while True:
dir = filedialog.askdirectory(title=title)
if not dir:
break
dirs.append(dir)
title = 'got %s. Next dir' % dirs[-1]
# parentName = os.path.split(os.path.dirname(files[0]))[1]
# self.outputFile = os.path.join(os.path.dirname(files[0]),parentName + ".tiff")
# self.file_label_text.set(parentName + ".tiff")
self.fileList = root.tk.splitlist(dirs)
def start(self):
for folder in self.fileList:
onlyFiles = [f for f in os.listdir(folder) if isfile(join(folder, f))]
print(onlyFiles)
print(folder)
for files in onlyFiles:
if(files.endswith(".xml")):
# self.stack(folder + "/" + files)
self.stitchFolder(folder)
# stitcherHandler = Stitcher()
# print(self.fileList)
# print(self.outputFile);
# if(self.outputFile is None):
# exit()
# _thread.start_new_thread(stitcherHandler.stitchFileList, (self.fileList, self.outputFile, self.progressCallback))
def stack(self, xmlFile):
commandLine = r'"C:/Program Files/ZereneStacker/jre/bin/java.exe" -Xmx8000m -DjavaBits=64bitJava -Dlaunchcmddir="C:/Documents and Settings/AISOS Lab PC/Application Data/ZereneStacker" -classpath "C:/Program Files/ZereneStacker/ZereneStacker.jar;C:/Program Files/ZereneStacker/JREextensions/*" com.zerenesystems.stacker.gui.MainFrame -noSplashScreen -exitOnBatchScriptCompletion -runMinimized -batchScript "' + xmlFile + '"'
subprocess.call( commandLine, stdout=DEVNULL, stderr=subprocess.STDOUT)
def stitchFolder(self, targetFolder):
stitcherHandler = Stitcher()
filesToStitch = []
onlyFiles = [f for f in os.listdir(targetFolder) if isfile(join(targetFolder, f))]
for files in onlyFiles:
if(files.endswith(".jpg")):
filesToStitch.append(targetFolder + "/" + files)
parentName = os.path.split(os.path.dirname(filesToStitch[0]))[1]
outputFile = os.path.join(os.path.dirname(filesToStitch[0]),parentName + ".tiff")
print(filesToStitch)
print(outputFile);
if(outputFile is None):
exit()
_thread.start_new_thread(stitcherHandler.stitchFileList, (filesToStitch, outputFile,"test.txt", self.progressCallback, self.maskImages.get(), None))
def progressCallback(self, status, progress):
self.progressText.set(progress);
root = tkinter.Tk()
root.geometry('{}x{}'.format(400, 200))
my_gui = StitcherGUI(root)
root.mainloop()