1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 17:56:30 +00:00

Display progressbars (fixes #13)

Still to change into something less eye-bleeding ;)
This commit is contained in:
Ciro Mattia Gonano
2013-03-06 15:08:42 +01:00
parent ce824f4cab
commit 4cfac52d6a

View File

@@ -23,6 +23,7 @@ __docformat__ = 'restructuredtext en'
from Tkinter import * from Tkinter import *
import tkFileDialog import tkFileDialog
import tkMessageBox import tkMessageBox
import ttk
import comic2ebook import comic2ebook
import kindlestrip import kindlestrip
from image import ProfileData from image import ProfileData
@@ -118,9 +119,21 @@ class MainWindow:
self.submit = Button(self.master, text="CONVERT", command=self.start_conversion, fg="red") self.submit = Button(self.master, text="CONVERT", command=self.start_conversion, fg="red")
self.submit.grid(columnspan=4, sticky=W + E + N + S) self.submit.grid(columnspan=4, sticky=W + E + N + S)
aLabel = Label(self.master, text="file progress", justify=RIGHT)
aLabel.grid(column=0, sticky=E)
self.progress_file = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate', maximum=4)
self.progress_file.grid(column=1, columnspan=3, row=(self.master.grid_size()[1] - 1), sticky=W + E + N + S)
aLabel = Label(self.master, text="overall progress", justify=RIGHT)
aLabel.grid(column=0, sticky=E)
self.progress_overall = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
self.progress_overall.grid(column=1, columnspan=3, row=(self.master.grid_size()[1] - 1), sticky=W + E + N + S)
def start_conversion(self): def start_conversion(self):
self.submit['state'] = DISABLED
self.master.update()
self.convert() self.convert()
self.submit['state'] = NORMAL
self.master.update()
def convert(self): def convert(self):
if len(self.filelist) < 1: if len(self.filelist) < 1:
@@ -150,12 +163,20 @@ class MainWindow:
if self.options['black_borders'].get() == 1: if self.options['black_borders'].get() == 1:
argv.append("--black-borders") argv.append("--black-borders")
errors = False errors = False
left_files = len(self.filelist)
filenum = 0
self.progress_overall['value'] = 0
self.progress_overall['maximum'] = left_files
for entry in self.filelist: for entry in self.filelist:
filenum += 1
self.progress_file['value'] = 1
self.master.update() self.master.update()
subargv = list(argv) subargv = list(argv)
try: try:
subargv.append(entry) subargv.append(entry)
epub_path = comic2ebook.main(subargv) epub_path = comic2ebook.main(subargv)
self.progress_file['value'] = 2
self.master.update()
except Exception, err: except Exception, err:
tkMessageBox.showerror('KCC Error', "Error on file %s:\n%s" % (subargv[-1], str(err))) tkMessageBox.showerror('KCC Error', "Error on file %s:\n%s" % (subargv[-1], str(err)))
errors = True errors = True
@@ -168,6 +189,8 @@ class MainWindow:
print >>sys.stderr, "Child was terminated by signal", -retcode print >>sys.stderr, "Child was terminated by signal", -retcode
else: else:
print >>sys.stderr, "Child returned", retcode print >>sys.stderr, "Child returned", retcode
self.progress_file['value'] = 3
self.master.update()
except OSError as e: except OSError as e:
tkMessageBox.showerror('KindleGen Error', "Error on file %s:\n%s" % (epub_path, e)) tkMessageBox.showerror('KindleGen Error', "Error on file %s:\n%s" % (epub_path, e))
errors = True errors = True
@@ -177,10 +200,14 @@ class MainWindow:
shutil.move(mobifile, mobifile + '_tostrip') shutil.move(mobifile, mobifile + '_tostrip')
kindlestrip.main((mobifile + '_tostrip', mobifile)) kindlestrip.main((mobifile + '_tostrip', mobifile))
os.remove(mobifile + '_tostrip') os.remove(mobifile + '_tostrip')
self.progress_file['value'] = 4
self.master.update()
except Exception, err: except Exception, err:
tkMessageBox.showerror('Error', "Error on file %s:\n%s" % (mobifile, str(err))) tkMessageBox.showerror('Error', "Error on file %s:\n%s" % (mobifile, str(err)))
errors = True errors = True
continue continue
self.progress_overall['value'] = filenum
self.master.update()
if errors: if errors:
tkMessageBox.showinfo( tkMessageBox.showinfo(
"Done", "Done",