From 02a7bca07c688e4dae94338a654d20608172e02f Mon Sep 17 00:00:00 2001 From: Ciro Mattia Gonano Date: Mon, 28 Jan 2013 09:47:46 +0100 Subject: [PATCH] Added basic error reporting --- README.md | 27 ++++++++++++++++----------- kcc.py | 1 + kcc/gui.py | 44 ++++++++++++++++++++++++++++---------------- kcc/image.py | 10 ++++++++++ setup.py | 3 +-- 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 4079311..86c0f2c 100644 --- a/README.md +++ b/README.md @@ -84,24 +84,29 @@ and installed in `/usr/local/bin/` ## CHANGELOG - - 1.00 - Initial version - - 1.10 - Added support for CBZ/CBR files in comic2ebook.py - - 1.11 - Added support for CBZ/CBR files in KindleComicConverter - - 1.20 - Comic optimizations! Split pages not target-oriented (landscape with portrait target or portrait + - 1.00: Initial version + - 1.10: Added support for CBZ/CBR files in comic2ebook.py + - 1.11: Added support for CBZ/CBR files in KindleComicConverter + - 1.20: Comic optimizations! Split pages not target-oriented (landscape with portrait target or portrait with landscape target), add palette and other image optimizations from Mangle. WARNING: PIL is required for all image mangling! - - 1.30 - Fixed an issue in OPF generation for device resolution + - 1.30: Fixed an issue in OPF generation for device resolution Reworked options system (call with -h option to get the inline help) - - 1.40 - Added some options for controlling image optimization + - 1.40: Added some options for controlling image optimization Further optimization (ImageOps, page numbering cut, autocontrast) - - 1.41 - Fixed a serious bug on resizing when img ratio was bigger than device one - - 1.50 - Added subfolder support for multiple chapters. - - 2.00 - GUI! AppleScript is gone and Tk is used to provide cross-platform GUI support. + - 1.41: Fixed a serious bug on resizing when img ratio was bigger than device one + - 1.50: Added subfolder support for multiple chapters. + - 2.0: GUI! AppleScript is gone and Tk is used to provide cross-platform GUI support. + - 2.1: Added basic error reporting ## TODO - Add gracefully exit for CBR if no rarfile.py and no unrar executable are found - - Improve error reporting - - Recurse into dirtree for multiple comics + - Try to get filetype from magic number (found some CBR that was actually CBZ) + - Improve GUI displaying what file we're processing and giving an explicit progress status + - Better GUI design + - Add option to gen .mobi or .epub + - Validate ePub + - Make window take focus on app launch ## COPYRIGHT diff --git a/kcc.py b/kcc.py index ce81663..8594a43 100644 --- a/kcc.py +++ b/kcc.py @@ -41,4 +41,5 @@ from kcc import gui root = Tk() app = gui.MainWindow(master=root,title="Kindle Comic Converter v" + __version__) +root.tkraise() root.mainloop() diff --git a/kcc/gui.py b/kcc/gui.py index 2c4f977..b25501e 100644 --- a/kcc/gui.py +++ b/kcc/gui.py @@ -74,8 +74,9 @@ class MainWindow: self.open_folder.pack(side=LEFT) self.profile = StringVar() - self.profile.set("KHD") - w = apply(OptionMenu, (self.master, self.profile) + tuple(sorted(ProfileData.Profiles.iterkeys()))) + options = sorted(ProfileData.ProfileLabels.iterkeys()) + self.profile.set(options[-1]) + w = apply(OptionMenu, (self.master, self.profile) + tuple(options)) w.pack(anchor=W,fill=BOTH) self.image_preprocess = IntVar() @@ -117,7 +118,8 @@ class MainWindow: self.progressbar.stop() def convert(self): - argv = ["-p",self.profile.get()] + profilekey = ProfileData.ProfileLabels[self.profile.get()] + argv = ["-p",profilekey] if self.image_preprocess == 0: argv.append("--no-image-processing") if self.cut_page_numbers == 0: @@ -128,20 +130,30 @@ class MainWindow: argv.append("--upscale-images") if self.image_stretch == 1: argv.append("--stretch-images") + errors = False for entry in self.filelist: - subargv = list(argv) - subargv.append(entry) - comic2ebook.main(subargv) - path = comic2ebook.getEpubPath() - call(['kindlegen',path + "/content.opf"]) - kindlestrip.main((path + "/content.mobi", path + '.mobi')) - # try to clean up temp files... may be destructive!!! - shutil.rmtree(path, onerror=self.remove_readonly) - tkMessageBox.showinfo( - "Success!!", - "Conversion successfully done!" - ) - + try: + subargv = list(argv) + subargv.append(entry) + comic2ebook.main(subargv) + path = comic2ebook.getEpubPath() + call(['kindlegen',path + "/content.opf"]) + kindlestrip.main((path + "/content.mobi", path + '.mobi')) + # try to clean up temp files... may be destructive!!! + shutil.rmtree(path, onerror=self.remove_readonly) + except Exception, err: + tkMessageBox.showerror('Error', "Error on file %s:\n%s" % (subargv[-1], str(err))) + errors = True + if errors: + tkMessageBox.showinfo( + "Done", + "Conversion finished (some errors have been reported)" + ) + else: + tkMessageBox.showinfo( + "Done", + "Conversion successfully done!" + ) def remove_readonly(self, fn, path, excinfo): if fn is os.rmdir: diff --git a/kcc/image.py b/kcc/image.py index b914df9..a55db41 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -84,6 +84,16 @@ class ProfileData: 'KDX': ("Kindle DX", (824, 1200), Palette15), 'KDXG': ("Kindle DXG", (824, 1200), Palette16) } + + ProfileLabels = { + "Kindle" : 'K1', + "Kindle 2" : 'K2', + "Kindle 3/Keyboard" : 'K3', + "Kindle 4/NT/Touch" : 'K4', + "Kindle Paperwhite" : 'KHD', + "Kindle DX" : 'KDX', + "Kindle DXG" : 'KDXG' + } class ComicPage: def __init__(self,source,device): diff --git a/setup.py b/setup.py index b8bc812..736a3fa 100644 --- a/setup.py +++ b/setup.py @@ -25,8 +25,7 @@ APP = ['kcc.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': True, 'iconfile': 'resources/comic2ebook.icns', - 'includes': 'kcc/*.py', - 'packages': 'PIL'} + 'includes': 'kcc/*.py'} if sys.platform == 'darwin': extra_options = dict(