diff options
author | Paweł Jastrzębski <pawelj@vulturis.eu> | 2014-01-15 11:32:29 +0100 |
---|---|---|
committer | Paweł Jastrzębski <pawelj@vulturis.eu> | 2014-01-15 11:32:29 +0100 |
commit | cccbd36463fbd3395e200eed0a20e7d7782e549d (patch) | |
tree | bf2005771ac244e187388275f420e3c1d0bd273c | |
parent | Bucket of various tweaks (diff) | |
download | kcc-cccbd36463fbd3395e200eed0a20e7d7782e549d.tar.gz kcc-cccbd36463fbd3395e200eed0a20e7d7782e549d.tar.bz2 kcc-cccbd36463fbd3395e200eed0a20e7d7782e549d.zip |
And one more bucket...
-rw-r--r-- | kcc-c2e.py | 9 | ||||
-rw-r--r-- | kcc-c2p.py | 9 | ||||
-rw-r--r-- | kcc.py | 35 | ||||
-rw-r--r-- | kcc/cbxarchive.py | 8 | ||||
-rwxr-xr-x | kcc/comic2ebook.py | 26 | ||||
-rw-r--r-- | kcc/comic2panel.py | 13 | ||||
-rwxr-xr-x | kcc/image.py | 15 | ||||
-rw-r--r-- | kcc/pdfjpgextract.py | 5 |
8 files changed, 61 insertions, 59 deletions
diff --git a/kcc-c2e.py b/kcc-c2e.py index 744555b..cfd6766 100644 --- a/kcc-c2e.py +++ b/kcc-c2e.py @@ -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) \ No newline at end of file +if __name__ == "__main__": + freeze_support() + Copyright() + main(sys.argv[1:]) + sys.exit(0) \ No newline at end of file diff --git a/kcc-c2p.py b/kcc-c2p.py index 87bcd1c..d112569 100644 --- a/kcc-c2p.py +++ b/kcc-c2p.py @@ -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) \ No newline at end of file +if __name__ == "__main__": + freeze_support() + Copyright() + main(sys.argv[1:]) + sys.exit(0) \ No newline at end of file diff --git a/kcc.py b/kcc.py index 397dc0b..c445924 100644 --- a/kcc.py +++ b/kcc.py @@ -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_()) diff --git a/kcc/cbxarchive.py b/kcc/cbxarchive.py index 459a4c1..baa3036 100644 --- a/kcc/cbxarchive.py +++ b/kcc/cbxarchive.py @@ -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 diff --git a/kcc/comic2ebook.py b/kcc/comic2ebook.py index 6e6f91f..ba9025b 100755 --- a/kcc/comic2ebook.py +++ b/kcc/comic2ebook.py @@ -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(): diff --git a/kcc/comic2panel.py b/kcc/comic2panel.py index 34d9763..5994b3e 100644 --- a/kcc/comic2panel.py +++ b/kcc/comic2panel.py @@ -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): diff --git a/kcc/image.py b/kcc/image.py index a703177..7a53a0a 100755 --- a/kcc/image.py +++ b/kcc/image.py @@ -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] diff --git a/kcc/pdfjpgextract.py b/kcc/pdfjpgextract.py index 34ea74d..cb3f084 100644 --- a/kcc/pdfjpgextract.py +++ b/kcc/pdfjpgextract.py @@ -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() |