From 718af10be78ea1c210de9bc5c52fc2f79a65a3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Tue, 5 Mar 2013 23:41:48 +0100 Subject: [PATCH] Updated GUI Plus small notquantize tweaks. --- kcc/comic2ebook.py | 6 ++--- kcc/gui.py | 59 ++++++++++++++++++++-------------------------- kcc/image.py | 4 ++-- 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index c39ffeb..4b71098 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -301,17 +301,17 @@ def dirImgProcess(path): facing = "left" img0 = image.ComicPage(split[0], options.profile) applyImgOptimization(img0, True, toRight1) - img0.saveToDir(dirpath) + img0.saveToDir(dirpath, options.notquantize) img1 = image.ComicPage(split[1], options.profile) applyImgOptimization(img1, True, toRight2) - img1.saveToDir(dirpath) + img1.saveToDir(dirpath, options.notquantize) else: if facing == "right": facing = "left" else: facing = "right" applyImgOptimization(img) - img.saveToDir(dirpath) + img.saveToDir(dirpath, options.notquantize) def genEpubStruct(path): diff --git a/kcc/gui.py b/kcc/gui.py index beb44e0..2ce2bed 100644 --- a/kcc/gui.py +++ b/kcc/gui.py @@ -40,24 +40,19 @@ class MainWindow: self.refresh_list() def open_files(self): - filetypes = [('all files', '.*'), ('Comic files', ('*.cbr', '*.cbz', '*.zip', '*.rar', '*.pdf'))] - f = tkFileDialog.askopenfilenames(title="Choose a file...", filetypes=filetypes) + filetypes = [('All files', '.*'), ('Comic files', ('*.cbr', '*.cbz', '*.zip', '*.rar', '*.pdf'))] + f = tkFileDialog.askopenfilenames(title="Choose files", filetypes=filetypes) if not isinstance(f, tuple): try: import re f = re.findall('\{(.*?)\}', f) except: - import tkMessageBox - tkMessageBox.showerror( - "Open file", - "askopenfilename() returned other than a tuple and no regex module could be found" - ) sys.exit(1) self.filelist.extend(f) self.refresh_list() def open_folder(self): - f = tkFileDialog.askdirectory(title="Choose a folder...") + f = tkFileDialog.askdirectory(title="Choose folder:") self.filelist.extend([f]) self.refresh_list() @@ -75,20 +70,21 @@ class MainWindow: self.clear_file = Button(self.master, text="Clear files", command=self.clear_files) self.clear_file.grid(row=4, column=0, rowspan=3) - self.open_file = Button(self.master, text="Add files...", command=self.open_files) + self.open_file = Button(self.master, text="Add files", command=self.open_files) self.open_file.grid(row=4, column=1, rowspan=3) - self.open_folder = Button(self.master, text="Add folder...", command=self.open_folder) + self.open_folder = Button(self.master, text="Add folder", command=self.open_folder) self.open_folder.grid(row=4, column=2, rowspan=3) self.profile = StringVar() profiles = sorted(ProfileData.ProfileLabels.iterkeys()) self.profile.set(profiles[-1]) w = apply(OptionMenu, (self.master, self.profile) + tuple(profiles)) - w.grid(row=1, column=3) + w.grid(row=4, column=3, sticky=W + E + N + S) self.options = { 'epub_only': IntVar(None, 0), 'image_preprocess': IntVar(None, 1), + 'notquantize': IntVar(None, 0), 'nosplitrotate': IntVar(None, 0), 'rotate': IntVar(None, 0), 'cut_page_numbers': IntVar(None, 1), @@ -99,13 +95,14 @@ class MainWindow: 'black_borders': IntVar(None, 0) } self.optionlabels = { - 'epub_only': "Generate ePub only (does not call 'kindlegen')", + 'epub_only': "Generate EPUB only", 'image_preprocess': "Apply image optimizations", + 'notquantize': "Disable image quantization", 'nosplitrotate': "Disable splitting and rotation", 'rotate': "Rotate landscape images instead of splitting them", 'cut_page_numbers': "Cut page numbers", - 'mangastyle': "Manga-style (right-to-left reading, applies to reading and splitting)", - 'image_gamma': "Gamma value", + 'mangastyle': "Manga mode", + 'image_gamma': "Gamma", 'image_upscale': "Allow image upscaling", 'image_stretch': "Stretch images", 'black_borders': "Use black borders" @@ -113,35 +110,31 @@ class MainWindow: for key in self.options: if isinstance( self.options[key], IntVar ) or isinstance( self.options[key], BooleanVar ): aCheckButton = Checkbutton(self.master, text=self.optionlabels[key], variable=self.options[key]) - aCheckButton.grid(column=3, sticky='w') + aCheckButton.grid(columnspan=4, sticky=W + N + S) elif isinstance( self.options[key], DoubleVar ): aLabel = Label(self.master, text=self.optionlabels[key]) - aLabel.grid(column=2, sticky='w') + aLabel.grid(column=2, sticky=W + N + S) aEntry = Entry(self.master, textvariable=self.options[key]) - aEntry.grid(column=3, row=(self.master.grid_size()[1]-1), sticky='w') - self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate') + aEntry.grid(column=3, row=(self.master.grid_size()[1]-1), sticky=W + N + S) - self.submit = Button(self.master, text="Execute!", command=self.start_conversion, fg="red") - self.submit.grid(column=3) - self.progressbar.grid(column=0, columnspan=4, sticky=W + E + N + S) - - self.notelabel = Label(self.master, - text="GUI can seem frozen while converting, kindly wait until some message appears!") - self.notelabel.grid(column=0, columnspan=4, sticky=W + E + N + S) + self.submit = Button(self.master, text="CONVERT", command=self.start_conversion, fg="red") + self.submit.grid(columnspan=4, sticky=W + E + N + S) def start_conversion(self): - self.progressbar.start() self.convert() - self.progressbar.stop() def convert(self): if len(self.filelist) < 1: - tkMessageBox.showwarning('No file selected', "You should really select some files to convert...") + tkMessageBox.showwarning('No files selected!', "Please choose files to convert.") return profilekey = ProfileData.ProfileLabels[self.profile.get()] argv = ["-p", profilekey] + argv.append("--gamma") + argv.append(self.options['image_gamma'].get()) if self.options['image_preprocess'].get() == 0: argv.append("--no-image-processing") + if self.options['notquantize'].get() == 1: + argv.append("--nodithering") if self.options['nosplitrotate'].get() == 1: argv.append("--nosplitrotate") if self.options['rotate'].get() == 1: @@ -150,8 +143,6 @@ class MainWindow: argv.append("--no-cut-page-numbers") if self.options['mangastyle'].get() == 1: argv.append("-m") - argv.append("--gamma") - argv.append(self.options['image_gamma'].get()) if self.options['image_upscale'].get() == 1: argv.append("--upscale-images") if self.options['image_stretch'].get() == 1: @@ -166,7 +157,7 @@ class MainWindow: subargv.append(entry) epub_path = comic2ebook.main(subargv) except Exception, err: - tkMessageBox.showerror('Error comic2ebook', "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 continue if self.options['epub_only'] == 1: @@ -178,7 +169,7 @@ class MainWindow: else: print >>sys.stderr, "Child returned", retcode except OSError as e: - tkMessageBox.showerror('Error kindlegen', "Error on file %s:\n%s" % (epub_path, e)) + tkMessageBox.showerror('KindleGen Error', "Error on file %s:\n%s" % (epub_path, e)) errors = True continue mobifile = epub_path.replace('.epub', '.mobi') @@ -193,12 +184,12 @@ class MainWindow: if errors: tkMessageBox.showinfo( "Done", - "Conversion finished (some errors have been reported)" + "Conversion failed. Errors have been reported." ) else: tkMessageBox.showinfo( "Done", - "Conversion successfully done!" + "Conversion successful!" ) def remove_readonly(self, fn, path): diff --git a/kcc/image.py b/kcc/image.py index e856d81..3cac5b2 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -111,12 +111,12 @@ class ComicPage: raise RuntimeError('Cannot read image file %s' % source) self.image = self.image.convert('RGB') - def saveToDir(self, targetdir): + def saveToDir(self, targetdir, notquantize): filename = os.path.basename(self.origFileName) try: self.image = self.image.convert('L') # convert to grayscale os.remove(os.path.join(targetdir,filename)) - if options.notquantize: + if notquantize: self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".jpg"), "JPEG") else: self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".png"), "PNG")