Add: option to split from left then right pages, add Kobo Aura h2o ereader and fix sorting bug
* Add: split option from left then right to manage some mangas * Add: the Kobo Aura H2o ereader (special resolution) * Fix: remove natsort dependency and use a custom function instead for natural sorting
This commit is contained in:
parent
f5263935ae
commit
2e8b4ac77c
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ dist
|
|||||||
*.pyo
|
*.pyo
|
||||||
*.mngl
|
*.mngl
|
||||||
*.cbz
|
*.cbz
|
||||||
|
*.bat
|
||||||
|
@ -80,7 +80,6 @@ of your choice. First you should make sure that you have the required dependenci
|
|||||||
* [Python 2.7](http://www.python.org/download/releases/2.7/)
|
* [Python 2.7](http://www.python.org/download/releases/2.7/)
|
||||||
* [Python Imaging Library (PIL)](http://www.pythonware.com/products/pil/)
|
* [Python Imaging Library (PIL)](http://www.pythonware.com/products/pil/)
|
||||||
* [ReportLab](https://pypi.python.org/pypi/reportlab)
|
* [ReportLab](https://pypi.python.org/pypi/reportlab)
|
||||||
* [natsort](https://pypi.python.org/pypi/natsort/3.0.1)
|
|
||||||
* [py2exe](http://www.py2exe.org/) (optional, for Windows distribution only)
|
* [py2exe](http://www.py2exe.org/) (optional, for Windows distribution only)
|
||||||
|
|
||||||
Now you can fetch the [latest version of the code](https://github.com/FooSoft/mangle/) and run the `mangle.pyw` script
|
Now you can fetch the [latest version of the code](https://github.com/FooSoft/mangle/) and run the `mangle.pyw` script
|
||||||
|
@ -13,14 +13,13 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# 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 re
|
||||||
from os.path import basename
|
from os.path import basename
|
||||||
import os.path
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore, QtXml, uic
|
from PyQt4 import QtGui, QtCore, QtXml, uic
|
||||||
from natsort import natsorted
|
|
||||||
|
|
||||||
from about import DialogAbout
|
from about import DialogAbout
|
||||||
from convert import DialogConvert
|
from convert import DialogConvert
|
||||||
@ -29,6 +28,13 @@ from options import DialogOptions
|
|||||||
import util
|
import util
|
||||||
|
|
||||||
|
|
||||||
|
# Sort function use to sort files in a natural order, by lowering
|
||||||
|
# characters, and manage multi levels of integers (tome 1/ page 1.jpg, etc etc)
|
||||||
|
def natural_key(string_):
|
||||||
|
"""See http://www.codinghorror.com/blog/archives/001018.html"""
|
||||||
|
return [int(s) if s.isdigit() else s.lower() for s in re.split(r'(\d+)', string_)]
|
||||||
|
|
||||||
|
|
||||||
class Book(object):
|
class Book(object):
|
||||||
DefaultDevice = 'Kindle Paperwhite'
|
DefaultDevice = 'Kindle Paperwhite'
|
||||||
DefaultOutputFormat = 'CBZ only'
|
DefaultOutputFormat = 'CBZ only'
|
||||||
@ -368,13 +374,15 @@ class MainWindowBook(QtGui.QMainWindow):
|
|||||||
for i in xrange(0, self.listWidgetFiles.count()):
|
for i in xrange(0, self.listWidgetFiles.count()):
|
||||||
filenamesListed.append(self.listWidgetFiles.item(i).text())
|
filenamesListed.append(self.listWidgetFiles.item(i).text())
|
||||||
|
|
||||||
for filename in natsorted(filenames):
|
# Get files but in a natural sorted order
|
||||||
|
for filename in sorted(filenames, key=natural_key):
|
||||||
if filename not in filenamesListed:
|
if filename not in filenamesListed:
|
||||||
filename = QtCore.QString(filename)
|
filename = QtCore.QString(filename)
|
||||||
self.listWidgetFiles.addItem(filename)
|
self.listWidgetFiles.addItem(filename)
|
||||||
self.book.images.append(filename)
|
self.book.images.append(filename)
|
||||||
self.book.modified = True
|
self.book.modified = True
|
||||||
|
|
||||||
|
|
||||||
def addImageDirs(self, directories):
|
def addImageDirs(self, directories):
|
||||||
filenames = []
|
filenames = []
|
||||||
|
|
||||||
@ -387,6 +395,7 @@ class MainWindowBook(QtGui.QMainWindow):
|
|||||||
|
|
||||||
self.addImageFiles(filenames)
|
self.addImageFiles(filenames)
|
||||||
|
|
||||||
|
|
||||||
def addCBZFiles(self, filenames):
|
def addCBZFiles(self, filenames):
|
||||||
directories = []
|
directories = []
|
||||||
tempDir = tempfile.gettempdir()
|
tempDir = tempfile.gettempdir()
|
||||||
|
@ -129,6 +129,14 @@ class DialogConvert(QtGui.QProgressDialog):
|
|||||||
# Change target once again for left page
|
# Change target once again for left page
|
||||||
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1))
|
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1))
|
||||||
|
|
||||||
|
# For right page (if requested), but in inverted mode
|
||||||
|
if(self.book.imageFlags & ImageFlags.SplitInverse):
|
||||||
|
# New path based on modified index
|
||||||
|
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0))
|
||||||
|
self.convertAndSave(source, target, device, flags ^ ImageFlags.SplitInverse | ImageFlags.SplitLeft, archive, pdf)
|
||||||
|
# Change target once again for left page
|
||||||
|
target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1))
|
||||||
|
|
||||||
# Convert page
|
# Convert page
|
||||||
self.convertAndSave(source, target, device, flags, archive, pdf)
|
self.convertAndSave(source, target, device, flags, archive, pdf)
|
||||||
|
|
||||||
|
@ -19,14 +19,17 @@ import os
|
|||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ImageFlags:
|
class ImageFlags:
|
||||||
Orient = 1 << 0
|
Orient = 1 << 0
|
||||||
Resize = 1 << 1
|
Resize = 1 << 1
|
||||||
Frame = 1 << 2
|
Frame = 1 << 2
|
||||||
Quantize = 1 << 3
|
Quantize = 1 << 3
|
||||||
Stretch = 1 << 4
|
Stretch = 1 << 4
|
||||||
Split = 1 << 5
|
Split = 1 << 5 # split right then left
|
||||||
SplitRight = 1 << 6
|
SplitRight = 1 << 6 # split only the right page
|
||||||
|
SplitLeft = 1 << 7 # split only the left page
|
||||||
|
SplitInverse = 1 << 8 # split left then right page
|
||||||
|
|
||||||
|
|
||||||
class KindleData:
|
class KindleData:
|
||||||
@ -82,7 +85,8 @@ class KindleData:
|
|||||||
'Kindle DX': ((824, 1200), Palette15a),
|
'Kindle DX': ((824, 1200), Palette15a),
|
||||||
'Kindle DXG': ((824, 1200), Palette15a),
|
'Kindle DXG': ((824, 1200), Palette15a),
|
||||||
'Kindle Touch': ((600, 800), Palette15a),
|
'Kindle Touch': ((600, 800), Palette15a),
|
||||||
'Kindle Paperwhite': ((758, 1024), Palette15b) # resolution given in manual, see http://kindle.s3.amazonaws.com/Kindle_Paperwhite_Users_Guide.pdf
|
'Kindle Paperwhite': ((758, 1024), Palette15b), # resolution given in manual, see http://kindle.s3.amazonaws.com/Kindle_Paperwhite_Users_Guide.pdf
|
||||||
|
'KoBo Aura H2o': ((1080, 1430), Palette15a), # resolution from http://www.fnac.com/Liseuse-Numerique-Kobo-by-Fnac-Kobo-Aura-H2O-Noir/a7745120/w-4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -204,10 +208,20 @@ def convertImage(source, target, device, flags):
|
|||||||
# Format according to palette
|
# Format according to palette
|
||||||
image = formatImage(image)
|
image = formatImage(image)
|
||||||
# Apply flag transforms
|
# Apply flag transforms
|
||||||
|
|
||||||
|
# Second pass of first split
|
||||||
if flags & ImageFlags.SplitRight:
|
if flags & ImageFlags.SplitRight:
|
||||||
image = splitRight(image)
|
image = splitRight(image)
|
||||||
if flags & ImageFlags.Split:
|
# First pass of first split option
|
||||||
|
if (flags & ImageFlags.Split):
|
||||||
image = splitLeft(image)
|
image = splitLeft(image)
|
||||||
|
# First pass of second splitting option
|
||||||
|
if flags & ImageFlags.SplitLeft:
|
||||||
|
image = splitLeft(image)
|
||||||
|
# second pass of second splitting option
|
||||||
|
if (flags & ImageFlags.SplitInverse):
|
||||||
|
image = splitRight(image)
|
||||||
|
|
||||||
if flags & ImageFlags.Orient:
|
if flags & ImageFlags.Orient:
|
||||||
image = orientImage(image, size)
|
image = orientImage(image, size)
|
||||||
if flags & ImageFlags.Resize:
|
if flags & ImageFlags.Resize:
|
||||||
|
@ -66,6 +66,8 @@ class DialogOptions(QtGui.QDialog):
|
|||||||
imageFlags |= ImageFlags.Frame
|
imageFlags |= ImageFlags.Frame
|
||||||
if self.checkboxSplit.isChecked():
|
if self.checkboxSplit.isChecked():
|
||||||
imageFlags |= ImageFlags.Split
|
imageFlags |= ImageFlags.Split
|
||||||
|
if self.checkboxSplitInverse.isChecked():
|
||||||
|
imageFlags |= ImageFlags.SplitInverse
|
||||||
|
|
||||||
modified = (
|
modified = (
|
||||||
self.book.title != title or
|
self.book.title != title or
|
||||||
|
@ -101,6 +101,11 @@
|
|||||||
<string>Kindle Paperwhite</string>
|
<string>Kindle Paperwhite</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>KoBo Aura H2o</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
@ -170,6 +175,13 @@
|
|||||||
<string>Split images into two pages (right, left)</string>
|
<string>Split images into two pages (right, left)</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkboxSplitInverse">
|
||||||
|
<property name="text">
|
||||||
|
<string>Split images into two pages (left, right)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
|
Loading…
Reference in New Issue
Block a user