1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00

And one more bucket...

This commit is contained in:
Paweł Jastrzębski
2014-01-15 11:32:29 +01:00
parent 19b438844d
commit cccbd36463
8 changed files with 61 additions and 59 deletions

View File

@@ -27,7 +27,8 @@ import sys
from multiprocessing import freeze_support
from kcc.comic2ebook import main, Copyright
freeze_support()
Copyright()
main(sys.argv[1:])
sys.exit(0)
if __name__ == "__main__":
freeze_support()
Copyright()
main(sys.argv[1:])
sys.exit(0)

View File

@@ -27,7 +27,8 @@ import sys
from multiprocessing import freeze_support
from kcc.comic2panel import main, Copyright
freeze_support()
Copyright()
main(sys.argv[1:])
sys.exit(0)
if __name__ == "__main__":
freeze_support()
Copyright()
main(sys.argv[1:])
sys.exit(0)

35
kcc.py
View File

@@ -94,21 +94,22 @@ class QApplicationMessaging(QtGui.QApplication):
return True
return False
freeze_support()
KCCAplication = QApplicationMessaging(sys.argv)
if KCCAplication.isRunning():
if __name__ == "__main__":
freeze_support()
KCCAplication = QApplicationMessaging(sys.argv)
if KCCAplication.isRunning():
if len(sys.argv) > 1:
KCCAplication.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(0)
else:
messageBox = QtGui.QMessageBox()
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(':/Icon/icons/comic2ebook.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
messageBox.setWindowIcon(icon)
QtGui.QMessageBox.critical(messageBox, 'KCC - Error', 'KCC is already running!', QtGui.QMessageBox.Ok)
sys.exit(1)
KCCWindow = QtGui.QMainWindow()
KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow)
if len(sys.argv) > 1:
KCCAplication.sendMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(0)
else:
messageBox = QtGui.QMessageBox()
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(':/Icon/icons/comic2ebook.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
messageBox.setWindowIcon(icon)
QtGui.QMessageBox.critical(messageBox, 'KCC - Error', 'KCC is already running!', QtGui.QMessageBox.Ok)
sys.exit(1)
KCCWindow = QtGui.QMainWindow()
KCCUI = KCC_gui.KCCGUI(KCCAplication, KCCWindow)
if len(sys.argv) > 1:
KCCUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(KCCAplication.exec_())
KCCUI.handleMessage(sys.argv[1].decode(sys.getfilesystemencoding()))
sys.exit(KCCAplication.exec_())

View File

@@ -31,11 +31,11 @@ try:
except ImportError:
print("ERROR: Psutil is not installed!")
if platform.startswith('linux'):
import Tkinter
import tkMessageBox
importRoot = Tkinter.Tk()
import tkinter
import tkinter.messagebox
importRoot = tkinter.Tk()
importRoot.withdraw()
tkMessageBox.showerror("KCC - Error", "Psutil is not installed!")
tkinter.messagebox.showerror("KCC - Error", "Psutil is not installed!")
exit(1)
from shutil import move

View File

@@ -26,7 +26,6 @@ import os
import sys
import re
import stat
import string
import zipfile
from tempfile import mkdtemp
from shutil import move, copyfile, copytree, rmtree
@@ -153,10 +152,10 @@ def buildHTML(path, imgfile):
"'{\"targetId\":\"" + boxes[i] + "-Panel-Parent\", \"ordinal\":" + str(order[i]),
"}'></a></div>\n"])
if options.quality == 2:
imgfilepv = string.split(imgfile, ".")
imgfilepv = str.split(imgfile, ".")
imgfilepv[0] = imgfilepv[0].split("_kccxl")[0].replace("_kccnh", "").replace("_kccnv", "")
imgfilepv[0] += "_kcchq"
imgfilepv = string.join(imgfilepv, ".")
imgfilepv = ".".join(imgfilepv)
else:
imgfilepv = imgfile
if "_kccxl" in filename[0]:
@@ -210,7 +209,7 @@ def buildHTML(path, imgfile):
def buildNCX(dstdir, title, chapters):
options.uuid = str(uuid4())
options.uuid = options.uuid.encode('utf-8')
#options.uuid = options.uuid.encode('utf-8')
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
f = open(ncxfile, "w")
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
@@ -258,7 +257,7 @@ def buildOPF(dstdir, title, filelist, cover=None):
"<dc:language>en-US</dc:language>\n",
"<dc:identifier id=\"BookID\" opf:scheme=\"UUID\">", options.uuid, "</dc:identifier>\n"])
for author in options.authors:
f.writelines(["<dc:creator>", author.encode('utf-8'), "</dc:creator>\n"])
f.writelines(["<dc:creator>", author, "</dc:creator>\n"])
f.writelines(["<meta name=\"generator\" content=\"KindleComicConverter-" + __version__ + "\"/>\n",
"<meta name=\"RegionMagnification\" content=\"true\"/>\n",
"<meta name=\"region-mag\" content=\"true\"/>\n",
@@ -289,14 +288,14 @@ def buildOPF(dstdir, title, filelist, cover=None):
filename = getImageFileName(path[1])
uniqueid = os.path.join(folder, filename[0]).replace('/', '_').replace('\\', '_')
reflist.append(uniqueid)
f.write("<item id=\"page_" + uniqueid + "\" href=\""
f.write("<item id=\"page_" + str(uniqueid) + "\" href=\""
+ folder.replace('Images', 'Text') + "/" + filename[0]
+ ".html\" media-type=\"application/xhtml+xml\"/>\n")
if '.png' == filename[1]:
mt = 'image/png'
else:
mt = 'image/jpeg'
f.write("<item id=\"img_" + uniqueid + "\" href=\"" + folder + "/" + path[1] + "\" media-type=\""
f.write("<item id=\"img_" + str(uniqueid) + "\" href=\"" + folder + "/" + path[1] + "\" media-type=\""
+ mt + "\"/>\n")
f.write("<item id=\"css\" href=\"Text/style.css\" media-type=\"text/css\"/>\n")
f.write("</manifest>\n<spine toc=\"ncx\">\n")
@@ -648,19 +647,19 @@ def checkComicInfo(path, originalPath):
titleSuffix += ' #' + xml.getElementsByTagName('Number')[0].firstChild.nodeValue
options.title += titleSuffix
if len(xml.getElementsByTagName('Writer')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Writer')[0].firstChild.nodeValue, ', ')
authorsTemp = str.split(xml.getElementsByTagName('Writer')[0].firstChild.nodeValue, ', ')
for author in authorsTemp:
options.authors.append(author)
if len(xml.getElementsByTagName('Penciller')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Penciller')[0].firstChild.nodeValue, ', ')
authorsTemp = str.split(xml.getElementsByTagName('Penciller')[0].firstChild.nodeValue, ', ')
for author in authorsTemp:
options.authors.append(author)
if len(xml.getElementsByTagName('Inker')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Inker')[0].firstChild.nodeValue, ', ')
authorsTemp = str.split(xml.getElementsByTagName('Inker')[0].firstChild.nodeValue, ', ')
for author in authorsTemp:
options.authors.append(author)
if len(xml.getElementsByTagName('Colorist')) != 0:
authorsTemp = string.split(xml.getElementsByTagName('Colorist')[0].firstChild.nodeValue, ', ')
authorsTemp = str.split(xml.getElementsByTagName('Colorist')[0].firstChild.nodeValue, ', ')
for author in authorsTemp:
options.authors.append(author)
if len(options.authors) > 0:
@@ -671,7 +670,7 @@ def checkComicInfo(path, originalPath):
os.remove(xmlPath)
# TODO: Check if replacement work correctly
# TODO: Check if replacement work correctly. No zero padding!!!
#def slugify(value):
# # Normalizes string, converts to lowercase, removes non-alpha characters and converts spaces to hyphens.
# value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
@@ -898,8 +897,7 @@ def makeZIP(zipFilename, baseDir, isEPUB=False):
def Copyright():
print(('comic2ebook v%(__version__)s. '
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
print(('comic2ebook v%(__version__)s. Written by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
def Usage():

View File

@@ -117,14 +117,14 @@ def mergeDirectory(work):
os.remove(i[1])
savePath = os.path.split(imagesClear[0][1])
result.save(os.path.join(savePath[0], os.path.splitext(savePath[1])[0] + '.png'), 'PNG')
except StandardError:
except Exception:
return str(sys.exc_info()[1])
def sanitizePanelSize(panel, opt):
newPanels = []
if panel[2] > 8 * opt.height:
diff = (panel[2] / 8)
diff = int(panel[2] / 8)
newPanels.append([panel[0], panel[1] - diff*7, diff])
newPanels.append([panel[1] - diff*7, panel[1] - diff*6, diff])
newPanels.append([panel[1] - diff*6, panel[1] - diff*5, diff])
@@ -134,14 +134,14 @@ def sanitizePanelSize(panel, opt):
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
newPanels.append([panel[1] - diff, panel[1], diff])
elif panel[2] > 4 * opt.height:
diff = (panel[2] / 4)
diff = int(panel[2] / 4)
newPanels.append([panel[0], panel[1] - diff*3, diff])
newPanels.append([panel[1] - diff*3, panel[1] - diff*2, diff])
newPanels.append([panel[1] - diff*2, panel[1] - diff, diff])
newPanels.append([panel[1] - diff, panel[1], diff])
elif panel[2] > 2 * opt.height:
newPanels.append([panel[0], panel[1] - (panel[2] / 2), (panel[2] / 2)])
newPanels.append([panel[1] - (panel[2] / 2), panel[1], (panel[2] / 2)])
newPanels.append([panel[0], panel[1] - int(panel[2] / 2), int(panel[2] / 2)])
newPanels.append([panel[1] - int(panel[2] / 2), panel[1], int(panel[2] / 2)])
else:
newPanels = [panel]
return newPanels
@@ -248,8 +248,7 @@ def splitImage(work):
def Copyright():
print(('comic2panel v%(__version__)s. '
'Written 2013 by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
print(('comic2panel v%(__version__)s. Written by Ciro Mattia Gonano and Pawel Jastrzebski.' % globals()))
def main(argv=None, qtGUI=None):

View File

@@ -22,6 +22,7 @@ __docformat__ = 'restructuredtext en'
import os
from sys import platform
from functools import reduce
try:
# noinspection PyUnresolvedReferences
from PIL import Image, ImageOps, ImageStat, ImageChops
@@ -248,8 +249,8 @@ class ComicPage:
return self.image
# If image is smaller than target resolution and upscale is off - Just expand it by adding margins
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1] and not upscale:
borderw = (size[0] - self.image.size[0]) / 2
borderh = (size[1] - self.image.size[1]) / 2
borderw = int((size[0] - self.image.size[0]) / 2)
borderh = int((size[1] - self.image.size[1]) / 2)
# PV is disabled when source image is smaller than device screen and upscale is off - So we drop HQ image
if qualityMode == 2 and self.image.size[0] <= self.size[0] and self.image.size[1] <= self.size[1]:
self.purge = True
@@ -265,7 +266,7 @@ class ComicPage:
self.image = ImageOps.expand(self.image, border=(int(diff / 2), 0), fill=fill)
elif (float(self.image.size[0]) / float(self.image.size[1])) > ratioDev:
diff = int(self.image.size[0] / ratioDev) - self.image.size[1]
self.image = ImageOps.expand(self.image, border=(0, diff / 2), fill=fill)
self.image = ImageOps.expand(self.image, border=(0, int(diff / 2)), fill=fill)
if self.image.size[0] <= size[0] and self.image.size[1] <= size[1]:
method = Image.BICUBIC
else:
@@ -286,12 +287,12 @@ class ComicPage:
self.rotated = False
if width > height:
# Source is landscape, so split by the width
leftbox = (0, 0, width / 2, height)
rightbox = (width / 2, 0, width, height)
leftbox = (0, 0, int(width / 2), height)
rightbox = (int(width / 2), 0, width, height)
else:
# Source is portrait and target is landscape, so split by the height
leftbox = (0, 0, width, height / 2)
rightbox = (0, height / 2, width, height)
leftbox = (0, 0, width, int(height / 2))
rightbox = (0, int(height / 2), width, height)
filename = os.path.splitext(self.filename)
fileone = targetdir + '/' + filename[0] + '_kcca' + filename[1]
filetwo = targetdir + '/' + filename[0] + '_kccb' + filename[1]

View File

@@ -28,6 +28,7 @@ from random import choice
from string import ascii_uppercase, digits
#TODO: Check entire code. Replacing file() with open() is not enought.
class PdfJpgExtract:
def __init__(self, origFileName):
self.origFileName = origFileName
@@ -39,7 +40,7 @@ class PdfJpgExtract:
return self.path
def extract(self):
pdf = file(self.origFileName, "rb").read()
pdf = open(self.origFileName, "rb").read()
startmark = "\xff\xd8"
startfix = 0
@@ -67,7 +68,7 @@ class PdfJpgExtract:
istart += startfix
iend += endfix
jpg = pdf[istart:iend]
jpgfile = file(self.path + "/jpg%d.jpg" % njpg, "wb")
jpgfile = open(self.path + "/jpg%d.jpg" % njpg, "wb")
jpgfile.write(jpg)
jpgfile.close()