1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-15 10:46:40 +00:00

Initial draft for a working GUI.

This commit is contained in:
Ciro Mattia Gonano
2013-01-25 12:32:21 +01:00
parent e36ee6ce4a
commit 21ac19e912
3 changed files with 86 additions and 30 deletions

View File

@@ -239,7 +239,7 @@ def Usage():
parser.print_help() parser.print_help()
def main(argv=None): def main(argv=None):
global parser, options global parser, options, epub_path
usage = "Usage: %prog [options] comic_file|comic_folder" usage = "Usage: %prog [options] comic_file|comic_folder"
parser = OptionParser(usage=usage, version=__version__) parser = OptionParser(usage=usage, version=__version__)
parser.add_option("-p", "--profile", action="store", dest="profile", default="KHD", parser.add_option("-p", "--profile", action="store", dest="profile", default="KHD",
@@ -250,14 +250,14 @@ def main(argv=None):
help="Split pages 'manga style' (right-to-left reading) [default=False]") help="Split pages 'manga style' (right-to-left reading) [default=False]")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
help="Verbose output [default=False]") help="Verbose output [default=False]")
parser.add_option("-i", "--image-processing", action="store_false", dest="imgproc", default=True, parser.add_option("--no-image-processing", action="store_false", dest="imgproc", default=True,
help="Apply image preprocessing (page splitting and optimizations) [default=True]") help="Do not apply image preprocessing (page splitting and optimizations) [default=True]")
parser.add_option("--upscale-images", action="store_true", dest="upscale", default=False, parser.add_option("--upscale-images", action="store_true", dest="upscale", default=False,
help="Resize images smaller than device's resolution [default=False]") help="Resize images smaller than device's resolution [default=False]")
parser.add_option("--stretch-images", action="store_true", dest="stretch", default=False, parser.add_option("--stretch-images", action="store_true", dest="stretch", default=False,
help="Stretch images to device's resolution [default=False]") help="Stretch images to device's resolution [default=False]")
parser.add_option("--cut-page-numbers", action="store_false", dest="cutpagenumbers", default=True, parser.add_option("--no-cut-page-numbers", action="store_false", dest="cutpagenumbers", default=True,
help="Try to cut page numbering on images [default=True]") help="Do not try to cut page numbering on images [default=True]")
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
if len(args) != 1: if len(args) != 1:
parser.print_help() parser.print_help()
@@ -269,7 +269,11 @@ def main(argv=None):
dirImgProcess(path) dirImgProcess(path)
print "Creating ePub structure..." print "Creating ePub structure..."
genEpubStruct(path) genEpubStruct(path)
epub_path = path
def getEpubPath():
global epub_path
return epub_path
if __name__ == "__main__": if __name__ == "__main__":
Copyright() Copyright()

View File

@@ -21,10 +21,11 @@ __copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from Tkinter import * from Tkinter import *
import tkFileDialog import tkFileDialog, tkMessageBox, ttk
import ttk import comic2ebook, kindlestrip
import comic2ebook
from image import ProfileData from image import ProfileData
from subprocess import call
import os, shutil, stat
class MainWindow: class MainWindow:
@@ -77,30 +78,78 @@ class MainWindow:
w = apply(OptionMenu, (self.master, self.profile) + tuple(sorted(ProfileData.Profiles.iterkeys()))) w = apply(OptionMenu, (self.master, self.profile) + tuple(sorted(ProfileData.Profiles.iterkeys())))
w.pack(anchor=W,fill=BOTH) w.pack(anchor=W,fill=BOTH)
self.mangastyle = BooleanVar() self.image_preprocess = IntVar()
self.mangastyle = False self.image_preprocess = 1
self.cut_page_numbers = IntVar()
self.cut_page_numbers = 1
self.mangastyle = IntVar()
self.mangastyle = 0
self.image_upscale = IntVar()
self.image_upscale = 0
self.image_stretch = IntVar()
self.image_stretch = 0
self.c = Checkbutton(self.master, text="Apply image optimizations",
variable=self.image_preprocess)
self.c.select()
self.c.pack()
self.c = Checkbutton(self.master, text="Cut page numbers",
variable=self.cut_page_numbers)
self.c.pack()
self.c = Checkbutton(self.master, text="Split manga-style (right-to-left reading)", self.c = Checkbutton(self.master, text="Split manga-style (right-to-left reading)",
variable=self.mangastyle) variable=self.mangastyle)
self.c.pack()
self.c = Checkbutton(self.master, text="Allow image upscaling",
variable=self.image_upscale)
self.c.pack()
self.c = Checkbutton(self.master, text="Stretch images",
variable=self.image_stretch)
self.c.pack() self.c.pack()
#now for a button
self.submit = Button(self.master, text="Execute!", command=self.convert, fg="red")
self.submit.pack()
self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate') self.progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
#now for a button
self.submit = Button(self.master, text="Execute!", command=self.start_conversion, fg="red")
self.submit.pack()
self.progressbar.pack(side=BOTTOM) self.progressbar.pack(side=BOTTOM)
def start_conversion(self):
self.progressbar.start()
self.convert()
self.progressbar.stop()
def convert(self): def convert(self):
argv = ["-p",self.profile.get()] argv = ["-p",self.profile.get()]
if self.mangastyle: if self.image_preprocess == 0:
argv.append("--no-image-processing")
if self.cut_page_numbers == 0:
argv.append("--no-cut-page-numbers")
if self.mangastyle == 1:
argv.append("-m") argv.append("-m")
self.progressbar.start() if self.image_upscale == 1:
argv.append("--upscale-images")
if self.image_stretch == 1:
argv.append("--stretch-images")
for entry in self.filelist: for entry in self.filelist:
subargv = list(argv) subargv = list(argv)
subargv.append(entry) subargv.append(entry)
comic2ebook.main(subargv) 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!"
)
print "Done!"
def remove_readonly(self, fn, path, excinfo):
if fn is os.rmdir:
os.chmod(path, stat.S_IWRITE)
os.rmdir(path)
elif fn is os.remove:
os.chmod(path, stat.S_IWRITE)
os.remove(path)
def __init__(self, master, title): def __init__(self, master, title):
self.filelist = [] self.filelist = []

View File

@@ -206,6 +206,20 @@ class SectionStripper:
def getHeader(self): def getHeader(self):
return self.stripped_data_header return self.stripped_data_header
def main(argv=None):
infile = argv[0]
outfile = argv[1]
data_file = file(infile, 'rb').read()
try:
strippedFile = SectionStripper(data_file)
file(outfile, 'wb').write(strippedFile.getResult())
print "Header Bytes: " + binascii.b2a_hex(strippedFile.getHeader())
if len(argv)==3:
file(argv[2], 'wb').write(strippedFile.getStrippedData())
except StripException, e:
print "Error: %s" % e
sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
sys.stdout=Unbuffered(sys.stdout) sys.stdout=Unbuffered(sys.stdout)
print ('KindleStrip v%(__version__)s. ' print ('KindleStrip v%(__version__)s. '
@@ -218,16 +232,5 @@ if __name__ == "__main__":
print "<strippeddatafile> is optional." print "<strippeddatafile> is optional."
sys.exit(1) sys.exit(1)
else: else:
infile = sys.argv[1] main(sys.argv[1:])
outfile = sys.argv[2]
data_file = file(infile, 'rb').read()
try:
strippedFile = SectionStripper(data_file)
file(outfile, 'wb').write(strippedFile.getResult())
print "Header Bytes: " + binascii.b2a_hex(strippedFile.getHeader())
if len(sys.argv)==4:
file(sys.argv[3], 'wb').write(strippedFile.getStrippedData())
except StripException, e:
print "Error: %s" % e
sys.exit(1)
sys.exit(0) sys.exit(0)