-
Notifications
You must be signed in to change notification settings - Fork 0
/
Converter.py
85 lines (60 loc) · 2.31 KB
/
Converter.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
import tkFileDialog as tf
from Tkinter import *
import os, datetime
from time import sleep
import VIPS_exe
'''
Converter : a simple file conversion dialog box to convert a bunch of files in a directory recursively to the Google Maps tiled format.
Just call
python Converter.py
Author: Thomas Pengo
License : GPL 3
'''
class ConverterDialog(Frame):
indir = ''
outdir = ''
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.pack(fill=BOTH,expand=1)
Label(self, text = "Welcome! Select an input and output directory to start.").grid(row=0,column=0,columnspan=3)
Label(self, text = "Input directory").grid(row=1,column=0,sticky=E)
Label(self, text = "Output directory").grid(row=2,column=0,sticky=E)
self.indir_e = Entry(self, text=''); self.indir_e.grid(row=1,column=1,sticky=W+E)
self.outdir_e = Entry(self, text=''); self.outdir_e.grid(row=2,column=1,sticky=W+E)
self.indir_b = Button(self, text="Browse", command=self.changeInDir); self.indir_b.grid(row=1,column=2,sticky=W)
self.outdir_b = Button(self, text="Browse", command=self.changeOutDir); self.outdir_b.grid(row=2,column=2,sticky=W)
self.logBox = Text(self, width=100, height=10);
self.logBox.insert(END, str(datetime.datetime.today()));
self.logBox.grid(row=3,column=0,columnspan=3,rowspan=4,sticky=W+E+N+S);
Button(self,text="Go!", command=self.go).grid(row=7,column=0,columnspan=3)
def changeInDir(self):
self.indir = tf.askdirectory()
self.indir_e.delete(0)
self.indir_e.insert(0,self.indir)
def changeOutDir(self):
self.outdir = tf.askdirectory()
self.outdir_e.delete(0)
self.outdir_e.insert(0,self.outdir)
def log(self,text):
for line in text.split('\n'):
self.logBox.insert(END,"\n "+line)
self.parent.update_idletasks()
print text
def doFile(self,input, output):
self.log('Starting '+input+' >> '+output)
VIPS_exe.VIPS_dzsave(input, output)
def go(self):
indir = self.indir_e.get()
outdir = self.outdir_e.get()
for root, dirs, files in os.walk(indir, topdown=True):
for infile in files:
infilepath = os.path.join(root,infile)
outfilepath = os.path.join(outdir,infile.rsplit('.')[0])
self.doFile(infilepath, outfilepath)
if __name__ == '__main__':
root = Tk()
app = ConverterDialog(root)
root.mainloop()