1
0
mirror of https://github.com/ciromattia/kcc synced 2026-05-29 18:53:07 +00:00

Updated GUI

Plus small notquantize tweaks.
This commit is contained in:
Paweł Jastrzębski
2013-03-05 23:41:48 +01:00
parent b162425e52
commit 718af10be7
3 changed files with 30 additions and 39 deletions
+3 -3
View File
@@ -301,17 +301,17 @@ def dirImgProcess(path):
facing = "left" facing = "left"
img0 = image.ComicPage(split[0], options.profile) img0 = image.ComicPage(split[0], options.profile)
applyImgOptimization(img0, True, toRight1) applyImgOptimization(img0, True, toRight1)
img0.saveToDir(dirpath) img0.saveToDir(dirpath, options.notquantize)
img1 = image.ComicPage(split[1], options.profile) img1 = image.ComicPage(split[1], options.profile)
applyImgOptimization(img1, True, toRight2) applyImgOptimization(img1, True, toRight2)
img1.saveToDir(dirpath) img1.saveToDir(dirpath, options.notquantize)
else: else:
if facing == "right": if facing == "right":
facing = "left" facing = "left"
else: else:
facing = "right" facing = "right"
applyImgOptimization(img) applyImgOptimization(img)
img.saveToDir(dirpath) img.saveToDir(dirpath, options.notquantize)
def genEpubStruct(path): def genEpubStruct(path):
+25 -34
View File
@@ -40,24 +40,19 @@ class MainWindow:
self.refresh_list() self.refresh_list()
def open_files(self): def open_files(self):
filetypes = [('all files', '.*'), ('Comic files', ('*.cbr', '*.cbz', '*.zip', '*.rar', '*.pdf'))] filetypes = [('All files', '.*'), ('Comic files', ('*.cbr', '*.cbz', '*.zip', '*.rar', '*.pdf'))]
f = tkFileDialog.askopenfilenames(title="Choose a file...", filetypes=filetypes) f = tkFileDialog.askopenfilenames(title="Choose files", filetypes=filetypes)
if not isinstance(f, tuple): if not isinstance(f, tuple):
try: try:
import re import re
f = re.findall('\{(.*?)\}', f) f = re.findall('\{(.*?)\}', f)
except: except:
import tkMessageBox
tkMessageBox.showerror(
"Open file",
"askopenfilename() returned other than a tuple and no regex module could be found"
)
sys.exit(1) sys.exit(1)
self.filelist.extend(f) self.filelist.extend(f)
self.refresh_list() self.refresh_list()
def open_folder(self): def open_folder(self):
f = tkFileDialog.askdirectory(title="Choose a folder...") f = tkFileDialog.askdirectory(title="Choose folder:")
self.filelist.extend([f]) self.filelist.extend([f])
self.refresh_list() 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 = Button(self.master, text="Clear files", command=self.clear_files)
self.clear_file.grid(row=4, column=0, rowspan=3) 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_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.open_folder.grid(row=4, column=2, rowspan=3)
self.profile = StringVar() self.profile = StringVar()
profiles = sorted(ProfileData.ProfileLabels.iterkeys()) profiles = sorted(ProfileData.ProfileLabels.iterkeys())
self.profile.set(profiles[-1]) self.profile.set(profiles[-1])
w = apply(OptionMenu, (self.master, self.profile) + tuple(profiles)) 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 = { self.options = {
'epub_only': IntVar(None, 0), 'epub_only': IntVar(None, 0),
'image_preprocess': IntVar(None, 1), 'image_preprocess': IntVar(None, 1),
'notquantize': IntVar(None, 0),
'nosplitrotate': IntVar(None, 0), 'nosplitrotate': IntVar(None, 0),
'rotate': IntVar(None, 0), 'rotate': IntVar(None, 0),
'cut_page_numbers': IntVar(None, 1), 'cut_page_numbers': IntVar(None, 1),
@@ -99,13 +95,14 @@ class MainWindow:
'black_borders': IntVar(None, 0) 'black_borders': IntVar(None, 0)
} }
self.optionlabels = { self.optionlabels = {
'epub_only': "Generate ePub only (does not call 'kindlegen')", 'epub_only': "Generate EPUB only",
'image_preprocess': "Apply image optimizations", 'image_preprocess': "Apply image optimizations",
'notquantize': "Disable image quantization",
'nosplitrotate': "Disable splitting and rotation", 'nosplitrotate': "Disable splitting and rotation",
'rotate': "Rotate landscape images instead of splitting them", 'rotate': "Rotate landscape images instead of splitting them",
'cut_page_numbers': "Cut page numbers", 'cut_page_numbers': "Cut page numbers",
'mangastyle': "Manga-style (right-to-left reading, applies to reading and splitting)", 'mangastyle': "Manga mode",
'image_gamma': "Gamma value", 'image_gamma': "Gamma",
'image_upscale': "Allow image upscaling", 'image_upscale': "Allow image upscaling",
'image_stretch': "Stretch images", 'image_stretch': "Stretch images",
'black_borders': "Use black borders" 'black_borders': "Use black borders"
@@ -113,35 +110,31 @@ class MainWindow:
for key in self.options: for key in self.options:
if isinstance( self.options[key], IntVar ) or isinstance( self.options[key], BooleanVar ): 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 = 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 ): elif isinstance( self.options[key], DoubleVar ):
aLabel = Label(self.master, text=self.optionlabels[key]) 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 = Entry(self.master, textvariable=self.options[key])
aEntry.grid(column=3, row=(self.master.grid_size()[1]-1), sticky='w') aEntry.grid(column=3, row=(self.master.grid_size()[1]-1), sticky=W + N + S)
self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
self.submit = Button(self.master, text="Execute!", command=self.start_conversion, fg="red") self.submit = Button(self.master, text="CONVERT", command=self.start_conversion, fg="red")
self.submit.grid(column=3) self.submit.grid(columnspan=4, sticky=W + E + N + S)
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)
def start_conversion(self): def start_conversion(self):
self.progressbar.start()
self.convert() self.convert()
self.progressbar.stop()
def convert(self): def convert(self):
if len(self.filelist) < 1: 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 return
profilekey = ProfileData.ProfileLabels[self.profile.get()] profilekey = ProfileData.ProfileLabels[self.profile.get()]
argv = ["-p", profilekey] argv = ["-p", profilekey]
argv.append("--gamma")
argv.append(self.options['image_gamma'].get())
if self.options['image_preprocess'].get() == 0: if self.options['image_preprocess'].get() == 0:
argv.append("--no-image-processing") argv.append("--no-image-processing")
if self.options['notquantize'].get() == 1:
argv.append("--nodithering")
if self.options['nosplitrotate'].get() == 1: if self.options['nosplitrotate'].get() == 1:
argv.append("--nosplitrotate") argv.append("--nosplitrotate")
if self.options['rotate'].get() == 1: if self.options['rotate'].get() == 1:
@@ -150,8 +143,6 @@ class MainWindow:
argv.append("--no-cut-page-numbers") argv.append("--no-cut-page-numbers")
if self.options['mangastyle'].get() == 1: if self.options['mangastyle'].get() == 1:
argv.append("-m") argv.append("-m")
argv.append("--gamma")
argv.append(self.options['image_gamma'].get())
if self.options['image_upscale'].get() == 1: if self.options['image_upscale'].get() == 1:
argv.append("--upscale-images") argv.append("--upscale-images")
if self.options['image_stretch'].get() == 1: if self.options['image_stretch'].get() == 1:
@@ -166,7 +157,7 @@ class MainWindow:
subargv.append(entry) subargv.append(entry)
epub_path = comic2ebook.main(subargv) epub_path = comic2ebook.main(subargv)
except Exception, err: 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 errors = True
continue continue
if self.options['epub_only'] == 1: if self.options['epub_only'] == 1:
@@ -178,7 +169,7 @@ class MainWindow:
else: else:
print >>sys.stderr, "Child returned", retcode print >>sys.stderr, "Child returned", retcode
except OSError as e: 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 errors = True
continue continue
mobifile = epub_path.replace('.epub', '.mobi') mobifile = epub_path.replace('.epub', '.mobi')
@@ -193,12 +184,12 @@ class MainWindow:
if errors: if errors:
tkMessageBox.showinfo( tkMessageBox.showinfo(
"Done", "Done",
"Conversion finished (some errors have been reported)" "Conversion failed. Errors have been reported."
) )
else: else:
tkMessageBox.showinfo( tkMessageBox.showinfo(
"Done", "Done",
"Conversion successfully done!" "Conversion successful!"
) )
def remove_readonly(self, fn, path): def remove_readonly(self, fn, path):
+2 -2
View File
@@ -111,12 +111,12 @@ class ComicPage:
raise RuntimeError('Cannot read image file %s' % source) raise RuntimeError('Cannot read image file %s' % source)
self.image = self.image.convert('RGB') self.image = self.image.convert('RGB')
def saveToDir(self, targetdir): def saveToDir(self, targetdir, notquantize):
filename = os.path.basename(self.origFileName) filename = os.path.basename(self.origFileName)
try: try:
self.image = self.image.convert('L') # convert to grayscale self.image = self.image.convert('L') # convert to grayscale
os.remove(os.path.join(targetdir,filename)) 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") self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".jpg"), "JPEG")
else: else:
self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".png"), "PNG") self.image.save(os.path.join(targetdir, os.path.splitext(filename)[0] + ".png"), "PNG")