1
0
mirror of https://github.com/ciromattia/kcc synced 2026-05-26 01:12:46 +00:00

comic2panel: GUI support and itegration with comic2ebook

This commit is contained in:
Paweł Jastrzębski
2013-08-12 12:59:58 +02:00
parent 723be29118
commit c8bb9b4f5f
2 changed files with 63 additions and 19 deletions

View File

@@ -35,6 +35,7 @@ try:
from PyQt4 import QtCore from PyQt4 import QtCore
except ImportError: except ImportError:
QtCore = None QtCore = None
import comic2panel
import image import image
import cbxarchive import cbxarchive
import pdfjpgextract import pdfjpgextract
@@ -357,7 +358,7 @@ def dirImgProcess(path):
while not splitpages.ready(): while not splitpages.ready():
# noinspection PyBroadException # noinspection PyBroadException
try: try:
queue.get(True, 1) queue.get(True, 5)
except: except:
pass pass
if not GUI.conversionAlive: if not GUI.conversionAlive:
@@ -820,6 +821,7 @@ def main(argv=None, qtGUI=None):
global parser, options, epub_path, splitCount, GUI global parser, options, epub_path, splitCount, GUI
parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False) parser = OptionParser(usage="Usage: %prog [options] comic_file|comic_folder", add_help_option=False)
mainOptions = OptionGroup(parser, "MAIN") mainOptions = OptionGroup(parser, "MAIN")
experimentalOptions = OptionGroup(parser, "EXPERIMENTAL")
processingOptions = OptionGroup(parser, "PROCESSING") processingOptions = OptionGroup(parser, "PROCESSING")
outputOptions = OptionGroup(parser, "OUTPUT SETTINGS") outputOptions = OptionGroup(parser, "OUTPUT SETTINGS")
customProfileOptions = OptionGroup(parser, "CUSTOM PROFILE") customProfileOptions = OptionGroup(parser, "CUSTOM PROFILE")
@@ -839,6 +841,8 @@ def main(argv=None, qtGUI=None):
help="Outputs a CBZ archive and does not generate EPUB") help="Outputs a CBZ archive and does not generate EPUB")
outputOptions.add_option("--batchsplit", action="store_true", dest="batchsplit", default=False, outputOptions.add_option("--batchsplit", action="store_true", dest="batchsplit", default=False,
help="Split output into multiple files"), help="Split output into multiple files"),
experimentalOptions.add_option("-w", "--webstrip", action="store_true", dest="webstrip", default=False,
help="Webstrip processing mode"),
processingOptions.add_option("--blackborders", action="store_true", dest="black_borders", default=False, processingOptions.add_option("--blackborders", action="store_true", dest="black_borders", default=False,
help="Use black borders instead of white ones") help="Use black borders instead of white ones")
processingOptions.add_option("--forcecolor", action="store_true", dest="forcecolor", default=False, processingOptions.add_option("--forcecolor", action="store_true", dest="forcecolor", default=False,
@@ -868,6 +872,7 @@ def main(argv=None, qtGUI=None):
otherOptions.add_option("-h", "--help", action="help", otherOptions.add_option("-h", "--help", action="help",
help="Show this help message and exit") help="Show this help message and exit")
parser.add_option_group(mainOptions) parser.add_option_group(mainOptions)
parser.add_option_group(experimentalOptions)
parser.add_option_group(outputOptions) parser.add_option_group(outputOptions)
parser.add_option_group(processingOptions) parser.add_option_group(processingOptions)
parser.add_option_group(customProfileOptions) parser.add_option_group(customProfileOptions)
@@ -883,9 +888,16 @@ def main(argv=None, qtGUI=None):
parser.print_help() parser.print_help()
return return
path = getWorkFolder(args[0]) path = getWorkFolder(args[0])
if options.webstrip:
if GUI:
GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Splitting images')
if options.customheight > 0:
comic2panel.main(['-y ' + str(options.customheight), '-i', path], qtGUI)
else:
comic2panel.main(['-y ' + str(image.ProfileData.Profiles[options.profile][1][1]), '-i', path], qtGUI)
splitCount = 0 splitCount = 0
if options.imgproc: if options.imgproc:
print "Processing images..." print "\nProcessing images..."
if GUI: if GUI:
GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Processing images') GUI.emit(QtCore.SIGNAL("progressBarTick"), 'status', 'Processing images')
dirImgProcess(path + "/OEBPS/Images/") dirImgProcess(path + "/OEBPS/Images/")
@@ -947,6 +959,11 @@ def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
def checkOptions(): def checkOptions():
global options global options
# Webstrip mode mandatory options
if options.webstrip:
options.rotate = True
options.black_borders = False
options.quality = 0
# Landscape mode is only supported by Kindle Touch and Paperwhite. # Landscape mode is only supported by Kindle Touch and Paperwhite.
if options.profile == 'K4T' or options.profile == 'KHD': if options.profile == 'K4T' or options.profile == 'KHD':
options.landscapemode = True options.landscapemode = True

View File

@@ -22,17 +22,21 @@ __license__ = 'ISC'
__copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@vulturis.eu>' __copyright__ = '2012-2013, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@vulturis.eu>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import sys
import os import os
from shutil import rmtree, copytree import sys
from shutil import rmtree, copytree, move
from optparse import OptionParser, OptionGroup from optparse import OptionParser, OptionGroup
from multiprocessing import Pool, freeze_support from multiprocessing import Pool, Queue, freeze_support
try: try:
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
from PIL import Image, ImageStat from PIL import Image, ImageStat
except ImportError: except ImportError:
print "ERROR: Pillow is not installed!" print "ERROR: Pillow is not installed!"
exit(1) exit(1)
try:
from PyQt4 import QtCore
except ImportError:
QtCore = None
def getImageFileName(imgfile): def getImageFileName(imgfile):
@@ -66,7 +70,8 @@ def sanitizePanelSize(panel, options):
return newPanels return newPanels
def splitImage_init(options): def splitImage_init(queue, options):
splitImage.queue = queue
splitImage.options = options splitImage.options = options
@@ -78,7 +83,8 @@ def splitImage(work):
# Harcoded options # Harcoded options
threshold = 10.0 threshold = 10.0
delta = 10 delta = 10
print ".",
splitImage.queue.put(".")
fileExpanded = os.path.splitext(name) fileExpanded = os.path.splitext(name)
image = Image.open(os.path.join(path, name)) image = Image.open(os.path.join(path, name))
image = image.convert('RGB') image = image.convert('RGB')
@@ -163,7 +169,6 @@ def splitImage(work):
targetHeight += panels[panel][2] targetHeight += panels[panel][2]
newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '-' + fill + '.png'), 'PNG') newPage.save(os.path.join(path, fileExpanded[0] + '-' + str(pageNumber) + '-' + fill + '.png'), 'PNG')
pageNumber += 1 pageNumber += 1
print ".",
os.remove(os.path.join(path, name)) os.remove(os.path.join(path, name))
@@ -173,13 +178,15 @@ def Copyright():
# noinspection PyBroadException # noinspection PyBroadException
def main(argv=None): def main(argv=None, qtGUI=None):
global options global options
parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False) parser = OptionParser(usage="Usage: %prog [options] comic_folder", add_help_option=False)
mainOptions = OptionGroup(parser, "MANDATORY") mainOptions = OptionGroup(parser, "MANDATORY")
otherOptions = OptionGroup(parser, "OTHER") otherOptions = OptionGroup(parser, "OTHER")
mainOptions.add_option("-y", "--height", type="int", dest="height", default=0, mainOptions.add_option("-y", "--height", type="int", dest="height", default=0,
help="Height of the target device screen") help="Height of the target device screen")
mainOptions.add_option("-i", "--in-place", action="store_true", dest="inPlace", default=False,
help="Overwrite source directory")
otherOptions.add_option("-d", "--debug", action="store_true", dest="debug", default=False, otherOptions.add_option("-d", "--debug", action="store_true", dest="debug", default=False,
help="Create debug file for every splitted image") help="Create debug file for every splitted image")
otherOptions.add_option("-h", "--help", action="help", otherOptions.add_option("-h", "--help", action="help",
@@ -187,44 +194,64 @@ def main(argv=None):
parser.add_option_group(mainOptions) parser.add_option_group(mainOptions)
parser.add_option_group(otherOptions) parser.add_option_group(otherOptions)
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
if qtGUI:
GUI = qtGUI
else:
GUI = None
if len(args) != 1: if len(args) != 1:
parser.print_help() parser.print_help()
return return
if options.height > 0: if options.height > 0:
options.sourceDir = args[0] options.sourceDir = args[0]
options.targetDir = args[0] + "-Splitted" options.targetDir = args[0] + "-Splitted"
print "Spliting images..." print "\nSplitting images..."
if os.path.isdir(options.sourceDir): if os.path.isdir(options.sourceDir):
rmtree(options.targetDir, True) rmtree(options.targetDir, True)
copytree(options.sourceDir, options.targetDir) copytree(options.sourceDir, options.targetDir)
work = [] work = []
pool = Pool(None, splitImage_init, [options]) pagenumber = 0
queue = Queue()
pool = Pool(None, splitImage_init, [queue, options])
for root, dirs, files in os.walk(options.targetDir, False): for root, dirs, files in os.walk(options.targetDir, False):
for name in files: for name in files:
if getImageFileName(name) is not None: if getImageFileName(name) is not None:
pagenumber += 1
work.append([root, name]) work.append([root, name])
else: else:
os.remove(os.path.join(root, name)) os.remove(os.path.join(root, name))
if GUI:
GUI.emit(QtCore.SIGNAL("progressBarTick"), pagenumber)
if len(work) > 0: if len(work) > 0:
workers = pool.map_async(func=splitImage, iterable=work) workers = pool.map_async(func=splitImage, iterable=work)
pool.close() pool.close()
if GUI:
while not workers.ready():
# noinspection PyBroadException
try:
queue.get(True, 5)
except:
pass
GUI.emit(QtCore.SIGNAL("progressBarTick"))
pool.join() pool.join()
queue.close()
try: try:
workers.get() workers.get()
except: except:
rmtree(options.targetDir) rmtree(options.targetDir)
print "ERROR: One of workers crashed. Cause: " + str(sys.exc_info()[1]) raise RuntimeError("One of workers crashed. Cause: " + str(sys.exc_info()[1]))
sys.exit(1) if GUI:
GUI.emit(QtCore.SIGNAL("progressBarTick"), 1)
if options.inPlace:
rmtree(options.sourceDir, True)
move(options.targetDir, options.sourceDir)
else: else:
rmtree(options.targetDir) rmtree(options.targetDir)
print "ERROR: Source directory is empty!" raise UserWarning("Source directory is empty.")
sys.exit(1)
else: else:
print "ERROR: Provided path is not a directory!" raise UserWarning("Provided path is not a directory.")
sys.exit(1)
else: else:
print "ERROR: Target height is not set!" raise UserWarning("Target height is not set.")
sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
freeze_support() freeze_support()