Added "Split left and right pages" option
Also cleaned formatting according to Eclipse PyDev
This commit is contained in:
parent
9c065b50ef
commit
1b2c5308eb
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
|
|
||||||
from mangle.book import MainWindowBook
|
from mangle.book import MainWindowBook
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import os.path
|
|
||||||
import util
|
|
||||||
from PyQt4 import QtGui, uic
|
from PyQt4 import QtGui, uic
|
||||||
|
|
||||||
|
import util
|
||||||
|
|
||||||
|
|
||||||
class DialogAbout(QtGui.QDialog):
|
class DialogAbout(QtGui.QDialog):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
@ -14,19 +14,20 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import os.path
|
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
import util
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
from PyQt4 import QtGui, QtCore, QtXml, uic
|
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from image import ImageFlags
|
|
||||||
from about import DialogAbout
|
from PyQt4 import QtGui, QtCore, QtXml, uic
|
||||||
from options import DialogOptions
|
|
||||||
from convert import DialogConvert
|
|
||||||
from natsort import natsorted
|
from natsort import natsorted
|
||||||
|
|
||||||
|
from about import DialogAbout
|
||||||
|
from convert import DialogConvert
|
||||||
|
from image import ImageFlags
|
||||||
|
from options import DialogOptions
|
||||||
|
import util
|
||||||
|
|
||||||
|
|
||||||
class Book(object):
|
class Book(object):
|
||||||
DefaultDevice = 'Kindle Paperwhite'
|
DefaultDevice = 'Kindle Paperwhite'
|
||||||
@ -378,7 +379,7 @@ class MainWindowBook(QtGui.QMainWindow):
|
|||||||
filenames = []
|
filenames = []
|
||||||
|
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
for root, subdirs, subfiles in os.walk(unicode(directory)):
|
for root, _, subfiles in os.walk(unicode(directory)):
|
||||||
for filename in subfiles:
|
for filename in subfiles:
|
||||||
path = os.path.join(root, filename)
|
path = os.path.join(root, filename)
|
||||||
if self.isImageFile(path):
|
if self.isImageFile(path):
|
||||||
@ -407,11 +408,10 @@ class MainWindowBook(QtGui.QMainWindow):
|
|||||||
pass # the dir exists so we are going to extract the images only.
|
pass # the dir exists so we are going to extract the images only.
|
||||||
else:
|
else:
|
||||||
cbzFile.extract(f, path)
|
cbzFile.extract(f, path)
|
||||||
#Add the directories
|
if os.path.isdir(unicode(path)): # Add the directories
|
||||||
if os.path.isdir(unicode(path)):
|
|
||||||
directories.append(path)
|
directories.append(path)
|
||||||
#Add the files
|
|
||||||
self.addImageDirs(directories)
|
self.addImageDirs(directories) # Add the files
|
||||||
|
|
||||||
|
|
||||||
def isImageFile(self, filename):
|
def isImageFile(self, filename):
|
||||||
|
@ -14,10 +14,13 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import os, shutil
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
import image
|
|
||||||
import cbz
|
import cbz
|
||||||
|
import image
|
||||||
import pdfimage
|
import pdfimage
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +25,8 @@ class ImageFlags:
|
|||||||
Frame = 1 << 2
|
Frame = 1 << 2
|
||||||
Quantize = 1 << 3
|
Quantize = 1 << 3
|
||||||
Stretch = 1 << 4
|
Stretch = 1 << 4
|
||||||
|
Split = 1 << 5
|
||||||
|
SplitRight = 1 << 6
|
||||||
|
|
||||||
|
|
||||||
class KindleData:
|
class KindleData:
|
||||||
@ -81,6 +85,18 @@ class KindleData:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def splitLeft(image):
|
||||||
|
widthImg, heightImg = image.size
|
||||||
|
|
||||||
|
return image.crop((0, 0, widthImg / 2, heightImg))
|
||||||
|
|
||||||
|
|
||||||
|
def splitRight(image):
|
||||||
|
widthImg, heightImg = image.size
|
||||||
|
|
||||||
|
return image.crop((widthImg / 2, 0, widthImg, heightImg))
|
||||||
|
|
||||||
|
|
||||||
def quantizeImage(image, palette):
|
def quantizeImage(image, palette):
|
||||||
colors = len(palette) / 3
|
colors = len(palette) / 3
|
||||||
if colors < 256:
|
if colors < 256:
|
||||||
@ -176,6 +192,15 @@ def convertImage(source, target, device, flags):
|
|||||||
image = formatImage(image)
|
image = formatImage(image)
|
||||||
if flags & ImageFlags.Orient:
|
if flags & ImageFlags.Orient:
|
||||||
image = orientImage(image, size)
|
image = orientImage(image, size)
|
||||||
|
if flags & ImageFlags.SplitRight:
|
||||||
|
image = splitRight(image)
|
||||||
|
elif flags & ImageFlags.Split:
|
||||||
|
image = splitLeft(image)
|
||||||
|
# Recurse for right page
|
||||||
|
fileName, fileExtension = os.path.splitext(target)
|
||||||
|
newTarget = fileName + "r" + fileExtension
|
||||||
|
print(newTarget)
|
||||||
|
convertImage(source, newTarget, device, flags | ImageFlags.SplitRight)
|
||||||
if flags & ImageFlags.Resize:
|
if flags & ImageFlags.Resize:
|
||||||
image = resizeImage(image, size)
|
image = resizeImage(image, size)
|
||||||
if flags & ImageFlags.Stretch:
|
if flags & ImageFlags.Stretch:
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import os.path
|
from PyQt4 import QtGui, uic
|
||||||
import util
|
|
||||||
from PyQt4 import QtGui, QtCore, uic
|
|
||||||
from image import ImageFlags
|
from image import ImageFlags
|
||||||
|
import util
|
||||||
|
|
||||||
|
|
||||||
class DialogOptions(QtGui.QDialog):
|
class DialogOptions(QtGui.QDialog):
|
||||||
@ -64,6 +64,8 @@ class DialogOptions(QtGui.QDialog):
|
|||||||
imageFlags |= ImageFlags.Quantize
|
imageFlags |= ImageFlags.Quantize
|
||||||
if self.checkboxFrame.isChecked():
|
if self.checkboxFrame.isChecked():
|
||||||
imageFlags |= ImageFlags.Frame
|
imageFlags |= ImageFlags.Frame
|
||||||
|
if self.checkboxSplit.isChecked():
|
||||||
|
imageFlags |= ImageFlags.Split
|
||||||
|
|
||||||
modified = (
|
modified = (
|
||||||
self.book.title != title or
|
self.book.title != title or
|
||||||
|
@ -17,9 +17,10 @@
|
|||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
from reportlab.lib.pagesizes import letter
|
|
||||||
from image import KindleData
|
from image import KindleData
|
||||||
|
|
||||||
|
|
||||||
class PDFImage(object):
|
class PDFImage(object):
|
||||||
def __init__(self, path, title, device):
|
def __init__(self, path, title, device):
|
||||||
outputDirectory = os.path.dirname(path)
|
outputDirectory = os.path.dirname(path)
|
||||||
|
@ -158,6 +158,13 @@
|
|||||||
<string>Draw frame around images</string>
|
<string>Draw frame around images</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkboxSplit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Split left and right pages</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
3
setup.py
3
setup.py
@ -16,9 +16,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
import py2exe
|
import sys
|
||||||
|
|
||||||
|
|
||||||
sys.argv.append('py2exe')
|
sys.argv.append('py2exe')
|
||||||
|
Loading…
Reference in New Issue
Block a user