Add files via upload

Added progress frame and progress bars
This commit is contained in:
Lerking
2018-02-09 07:51:48 +01:00
committed by GitHub
parent 9790d56233
commit 22ec98d04d
+27 -4
View File
@@ -1,4 +1,4 @@
from tkinter import Tk, Label, Button, LabelFrame from tkinter import Tk, ttk, Label, Button, LabelFrame
from tkinter import filedialog, Entry, Checkbutton from tkinter import filedialog, Entry, Checkbutton
from tkinter import Grid, StringVar from tkinter import Grid, StringVar
from tkinter import N, E, S, W from tkinter import N, E, S, W
@@ -17,7 +17,8 @@ class h2incGUI:
self.addinc = StringVar() self.addinc = StringVar()
self.infofolder = 'Number of folders: 0' self.infofolder = 'Number of folders: 0'
self.infofile = 'Number of headers: 0' self.infofile = 'Number of headers: 0'
self.currentfile = 'Current file: '
self.totprogress = 'Total progress: '
self.sourcedir.set('Select source directory!') self.sourcedir.set('Select source directory!')
self.destdir.set('Select destination directory!') self.destdir.set('Select destination directory!')
@@ -35,7 +36,7 @@ class h2incGUI:
self.sourceentry = Entry(self.frame, textvariable=self.sourcedir) self.sourceentry = Entry(self.frame, textvariable=self.sourcedir)
self.sourceentry.grid(row=0, column=1, sticky=E+W, pady=5) self.sourceentry.grid(row=0, column=1, sticky=E+W, pady=5)
self.sourcedir_button = Button(self.frame, text="Source directory...", command= lambda: self.select_sourcedir(self.sourcedir, self.infofiles)) self.sourcedir_button = Button(self.frame, text="Source directory...", command= lambda: self.select_sourcedir(self.sourcedir))
self.sourcedir_button.grid(row=0, column=2, sticky=W, padx=(3, 5), pady=5) self.sourcedir_button.grid(row=0, column=2, sticky=W, padx=(3, 5), pady=5)
self.destlabel = Label(self.frame, text='Destination: ') self.destlabel = Label(self.frame, text='Destination: ')
@@ -76,18 +77,38 @@ class h2incGUI:
self.translate_button.grid(row=3, column=0, sticky=W, padx=5, pady=5) self.translate_button.grid(row=3, column=0, sticky=W, padx=5, pady=5)
self.translate_button.config(state=DISABLED) self.translate_button.config(state=DISABLED)
def select_sourcedir(self, sourcedir, infofile): self.progressframe = LabelFrame(self.transframe, text='Progress')
self.progressframe.grid(row=4, rowspan=2, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
self.progressframe.grid_columnconfigure(1, weight=1)
self.cfilelabel = Label(self.progressframe, text=self.currentfile)
self.cfilelabel.grid(row=6, column=0, sticky=W, padx=5, pady=5)
self.cfilelabel.config(state=DISABLED)
self.cfileprogress = ttk.Progressbar(self.progressframe, orient='horizontal', mode='determinate')
self.cfileprogress.grid(row=7, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
self.totallabel = Label(self.progressframe, text=self.totprogress)
self.totallabel.grid(row=8, column=0, sticky=W, padx=5, pady=5)
self.totallabel.config(state=DISABLED)
self.totalprogress = ttk.Progressbar(self.progressframe, orient='horizontal', mode='determinate')
self.totalprogress.grid(row=9, column=0, columnspan=3, sticky=N+S+E+W, padx=5, pady=5)
def select_sourcedir(self, sourcedir):
root.directory = os.path.abspath(filedialog.askdirectory()) root.directory = os.path.abspath(filedialog.askdirectory())
if root.directory: if root.directory:
sourcedir.set(root.directory) sourcedir.set(root.directory)
filecnt = sourcedir_filecnt(root.directory) filecnt = sourcedir_filecnt(root.directory)
if filecnt > 0: if filecnt > 0:
tempstr = 'Number of headers: '+str(filecnt) tempstr = 'Number of headers: '+str(filecnt)
temptot = 'Total progress: 0 of '+str(filecnt)
print ('Source directory: ', sourcedir.get()) print ('Source directory: ', sourcedir.get())
self.destlabel.config(state=NORMAL) self.destlabel.config(state=NORMAL)
self.destentry.config(state=NORMAL) self.destentry.config(state=NORMAL)
self.destdir_button.config(state=NORMAL) self.destdir_button.config(state=NORMAL)
self.infofiles.config(text=tempstr) self.infofiles.config(text=tempstr)
self.totallabel.config(text=temptot)
foldercnt = sourcedir_foldercnt(root.directory) foldercnt = sourcedir_foldercnt(root.directory)
if foldercnt > 0: if foldercnt > 0:
tempstr = 'Number of folders: '+str(foldercnt) tempstr = 'Number of folders: '+str(foldercnt)
@@ -102,6 +123,8 @@ class h2incGUI:
self.infofolders.config(state=NORMAL) self.infofolders.config(state=NORMAL)
self.infofiles.config(state=NORMAL) self.infofiles.config(state=NORMAL)
self.translate_button.config(state=NORMAL) self.translate_button.config(state=NORMAL)
self.cfilelabel.config(state=NORMAL)
self.totallabel.config(state=NORMAL)
def translate(self, destdir, addinc): def translate(self, destdir, addinc):
doinc = addinc.get() doinc = addinc.get()