mirror of
https://github.com/ciromattia/kcc
synced 2025-12-16 03:06:33 +00:00
GUI improvements
Option sorting resolved slighty lame but it work.
This commit is contained in:
4
kcc.py
4
kcc.py
@@ -29,6 +29,8 @@ import os
|
|||||||
if platform == 'darwin':
|
if platform == 'darwin':
|
||||||
os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
|
os.environ['PATH'] = '/usr/local/bin:' + os.environ['PATH']
|
||||||
root = Tk()
|
root = Tk()
|
||||||
app = gui.MainWindow(master=root,title="Kindle Comic Converter v" + __version__)
|
root.resizable(width=FALSE, height=FALSE)
|
||||||
|
root.config(padx=5, pady=5)
|
||||||
|
gui.MainWindow(master=root,title="Kindle Comic Converter v" + __version__)
|
||||||
root.tkraise()
|
root.tkraise()
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ def main(argv=None):
|
|||||||
if options.title == 'defaulttitle':
|
if options.title == 'defaulttitle':
|
||||||
options.title = os.path.splitext(os.path.basename(args[0]))[0]
|
options.title = os.path.splitext(os.path.basename(args[0]))[0]
|
||||||
if options.imgproc:
|
if options.imgproc:
|
||||||
print "\nProcessing images..."
|
print "Processing images..."
|
||||||
dirImgProcess(path + "/OEBPS/Images/")
|
dirImgProcess(path + "/OEBPS/Images/")
|
||||||
print "\nCreating ePub structure..."
|
print "\nCreating ePub structure..."
|
||||||
genEpubStruct(path)
|
genEpubStruct(path)
|
||||||
|
|||||||
104
kcc/gui.py
104
kcc/gui.py
@@ -40,6 +40,12 @@ class MainWindow:
|
|||||||
self.filelist = []
|
self.filelist = []
|
||||||
self.refresh_list()
|
self.refresh_list()
|
||||||
|
|
||||||
|
def change_gamma(self):
|
||||||
|
if self.aEntry['state'] == DISABLED:
|
||||||
|
self.aEntry['state'] = NORMAL
|
||||||
|
else:
|
||||||
|
self.aEntry['state'] = DISABLED
|
||||||
|
|
||||||
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 files", filetypes=filetypes)
|
f = tkFileDialog.askopenfilenames(title="Choose files", filetypes=filetypes)
|
||||||
@@ -70,11 +76,11 @@ class MainWindow:
|
|||||||
self.refresh_list()
|
self.refresh_list()
|
||||||
|
|
||||||
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, sticky=W + E + N + S)
|
||||||
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, sticky=W + E + N + S)
|
||||||
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, sticky=W + E + N + S)
|
||||||
|
|
||||||
self.profile = StringVar()
|
self.profile = StringVar()
|
||||||
profiles = sorted(ProfileData.ProfileLabels.iterkeys())
|
profiles = sorted(ProfileData.ProfileLabels.iterkeys())
|
||||||
@@ -83,48 +89,49 @@ class MainWindow:
|
|||||||
w.grid(row=4, column=3, sticky=W + E + N + S)
|
w.grid(row=4, column=3, sticky=W + E + N + S)
|
||||||
|
|
||||||
self.options = {
|
self.options = {
|
||||||
'epub_only': IntVar(None, 0),
|
'Aepub_only': IntVar(None, 0),
|
||||||
'image_preprocess': IntVar(None, 1),
|
'Bmangastyle': IntVar(None, 0),
|
||||||
'notquantize': IntVar(None, 0),
|
'Cimage_preprocess': IntVar(None, 0),
|
||||||
'nosplitrotate': IntVar(None, 0),
|
'Dnotquantize': IntVar(None, 0),
|
||||||
'rotate': IntVar(None, 0),
|
'Eimage_gamma': DoubleVar(None, 0.0),
|
||||||
'cut_page_numbers': IntVar(None, 1),
|
'Fimage_upscale': IntVar(None, 0),
|
||||||
'mangastyle': IntVar(None, 0),
|
'Gimage_stretch': IntVar(None, 0),
|
||||||
'image_gamma': DoubleVar(None, 0.0),
|
'Hblack_borders': IntVar(None, 0),
|
||||||
'image_upscale': IntVar(None, 0),
|
'Irotate': IntVar(None, 0),
|
||||||
'image_stretch': IntVar(None, 0),
|
'Jnosplitrotate': IntVar(None, 0),
|
||||||
'black_borders': IntVar(None, 0)
|
'Kcut_page_numbers': IntVar(None, 0)
|
||||||
}
|
}
|
||||||
self.optionlabels = {
|
self.optionlabels = {
|
||||||
'epub_only': "Generate EPUB only",
|
'Aepub_only': "Generate EPUB only",
|
||||||
'image_preprocess': "Apply image optimizations",
|
'Cimage_preprocess': "Disable image optimizations",
|
||||||
'notquantize': "Disable image quantization",
|
'Dnotquantize': "Disable image quantization",
|
||||||
'nosplitrotate': "Disable splitting and rotation",
|
'Jnosplitrotate': "Disable splitting and rotation",
|
||||||
'rotate': "Rotate landscape images instead of splitting them",
|
'Irotate': "Rotate images instead splitting them",
|
||||||
'cut_page_numbers': "Cut page numbers",
|
'Kcut_page_numbers': "Disable page numbers cutting",
|
||||||
'mangastyle': "Manga mode",
|
'Bmangastyle': "Manga mode",
|
||||||
'image_gamma': "Custom gamma\n(if 0.0 the default gamma for the profile will be used)",
|
'Eimage_gamma': "Custom gamma correction",
|
||||||
'image_upscale': "Allow image upscaling",
|
'Fimage_upscale': "Allow image upscaling",
|
||||||
'image_stretch': "Stretch images",
|
'Gimage_stretch': "Stretch images",
|
||||||
'black_borders': "Use black borders"
|
'Hblack_borders': "Use black borders"
|
||||||
}
|
}
|
||||||
for key in self.options:
|
for key in sorted(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(columnspan=4, sticky=W + N + S)
|
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], justify=RIGHT)
|
aCheckButton = Checkbutton(self.master, text=self.optionlabels[key], command=self.change_gamma)
|
||||||
aLabel.grid(column=0, columnspan=3, sticky=W + N + S)
|
aCheckButton.grid(columnspan=4, sticky=W + N + S)
|
||||||
aEntry = Entry(self.master, textvariable=self.options[key])
|
self.aEntry = Entry(self.master, textvariable=self.options[key])
|
||||||
aEntry.grid(column=3, row=(self.master.grid_size()[1] - 1), sticky=W + N + S)
|
self.aEntry['state'] = DISABLED
|
||||||
|
self.aEntry.grid(column=3, row=(self.master.grid_size()[1] - 1), sticky=W + N + S)
|
||||||
|
|
||||||
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 = Label(self.master, text="File progress:", anchor=W, justify=LEFT)
|
||||||
aLabel.grid(column=0, sticky=E)
|
aLabel.grid(column=0, sticky=E)
|
||||||
self.progress_file = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate', maximum=4)
|
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)
|
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 = Label(self.master, text="Overall progress:", anchor=W, justify=LEFT)
|
||||||
aLabel.grid(column=0, sticky=E)
|
aLabel.grid(column=0, sticky=E)
|
||||||
self.progress_overall = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
|
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)
|
self.progress_overall.grid(column=1, columnspan=3, row=(self.master.grid_size()[1] - 1), sticky=W + E + N + S)
|
||||||
@@ -142,26 +149,26 @@ class MainWindow:
|
|||||||
return
|
return
|
||||||
profilekey = ProfileData.ProfileLabels[self.profile.get()]
|
profilekey = ProfileData.ProfileLabels[self.profile.get()]
|
||||||
argv = ["-p", profilekey]
|
argv = ["-p", profilekey]
|
||||||
if self.options['image_gamma'].get() != 0.0:
|
if self.options['Eimage_gamma'].get() != 0.0:
|
||||||
argv.append("--gamma")
|
argv.append("--gamma")
|
||||||
argv.append(self.options['image_gamma'].get())
|
argv.append(self.options['Eimage_gamma'].get())
|
||||||
if self.options['image_preprocess'].get() == 0:
|
if self.options['Cimage_preprocess'].get() == 1:
|
||||||
argv.append("--noprocessing")
|
argv.append("--noprocessing")
|
||||||
if self.options['notquantize'].get() == 1:
|
if self.options['Dnotquantize'].get() == 1:
|
||||||
argv.append("--nodithering")
|
argv.append("--nodithering")
|
||||||
if self.options['nosplitrotate'].get() == 1:
|
if self.options['Jnosplitrotate'].get() == 1:
|
||||||
argv.append("--nosplitrotate")
|
argv.append("--nosplitrotate")
|
||||||
if self.options['rotate'].get() == 1:
|
if self.options['Irotate'].get() == 1:
|
||||||
argv.append("--rotate")
|
argv.append("--rotate")
|
||||||
if self.options['cut_page_numbers'].get() == 0:
|
if self.options['Kcut_page_numbers'].get() == 1:
|
||||||
argv.append("--nocutpagenumbers")
|
argv.append("--nocutpagenumbers")
|
||||||
if self.options['mangastyle'].get() == 1:
|
if self.options['Bmangastyle'].get() == 1:
|
||||||
argv.append("-m")
|
argv.append("-m")
|
||||||
if self.options['image_upscale'].get() == 1:
|
if self.options['Fimage_upscale'].get() == 1:
|
||||||
argv.append("--upscale")
|
argv.append("--upscale")
|
||||||
if self.options['image_stretch'].get() == 1:
|
if self.options['Gimage_stretch'].get() == 1:
|
||||||
argv.append("--stretch")
|
argv.append("--stretch")
|
||||||
if self.options['black_borders'].get() == 1:
|
if self.options['Hblack_borders'].get() == 1:
|
||||||
argv.append("--blackborders")
|
argv.append("--blackborders")
|
||||||
errors = False
|
errors = False
|
||||||
left_files = len(self.filelist)
|
left_files = len(self.filelist)
|
||||||
@@ -180,12 +187,10 @@ class MainWindow:
|
|||||||
self.master.update()
|
self.master.update()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
type_, value_, traceback_ = sys.exc_info()
|
type_, value_, traceback_ = sys.exc_info()
|
||||||
tkMessageBox.showerror('KCC Error', "Error on file %s:\n%s\nTraceback:\n%s" %
|
tkMessageBox.showerror('KCC Error', "Error on file %s:\n%s\nTraceback:\n%s" (subargv[-1], str(err), traceback.format_tb(traceback_)))
|
||||||
(subargv[-1], str(err), traceback.format_tb(traceback_)))
|
|
||||||
errors = True
|
errors = True
|
||||||
continue
|
continue
|
||||||
if self.options['epub_only'] == 1:
|
if self.options['Aepub_only'].get() == 0:
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
retcode = call("kindlegen \"" + epub_path + "\"", shell=True)
|
retcode = call("kindlegen \"" + epub_path + "\"", shell=True)
|
||||||
if retcode < 0:
|
if retcode < 0:
|
||||||
@@ -206,9 +211,12 @@ class MainWindow:
|
|||||||
self.progress_file['value'] = 4
|
self.progress_file['value'] = 4
|
||||||
self.master.update()
|
self.master.update()
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
tkMessageBox.showerror('Error', "Error on file %s:\n%s" % (mobifile, str(err)))
|
tkMessageBox.showerror('KindleStrip Error', "Error on file %s:\n%s" % (mobifile, str(err)))
|
||||||
errors = True
|
errors = True
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
self.progress_file['value'] = 4
|
||||||
|
self.master.update()
|
||||||
self.progress_overall['value'] = filenum
|
self.progress_overall['value'] = filenum
|
||||||
self.master.update()
|
self.master.update()
|
||||||
if errors:
|
if errors:
|
||||||
|
|||||||
Reference in New Issue
Block a user