diff --git a/mangle/book.py b/mangle/book.py index 1b34560..cb6f555 100644 --- a/mangle/book.py +++ b/mangle/book.py @@ -91,7 +91,7 @@ class Book(object): self.title = root.attribute('title', 'Untitled') self.overwrite = root.attribute('overwrite', 'true' if Book.DefaultOverwrite else 'false') == 'true' self.device = root.attribute('device', Book.DefaultDevice) - self.outputFormat = root.attribute('outputFormat', 'image+cbz') + self.outputFormat = root.attribute('outputFormat', Book.DefaultOutputFormat) self.imageFlags = int(root.attribute('imageFlags', str(Book.DefaultImageFlags))) self.filename = filename self.modified = False diff --git a/mangle/cbz.py b/mangle/cbz.py index f3cd9d8..dc23583 100644 --- a/mangle/cbz.py +++ b/mangle/cbz.py @@ -25,15 +25,19 @@ class Archive(object): outputPath = os.path.join(outputDirectory, outputFileName) self.zipfile = ZipFile(outputPath, 'w', ZIP_STORED) + def addFile(self, filename): arcname = os.path.basename(filename) self.zipfile.write(filename, arcname) + def __enter__(self): return self + def __exit__(self, exc_type, exc_val, exc_tb): self.close() + def close(self): self.zipfile.close() diff --git a/mangle/convert.py b/mangle/convert.py index d51a300..506d542 100644 --- a/mangle/convert.py +++ b/mangle/convert.py @@ -13,10 +13,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . + import os, shutil - from PyQt4 import QtGui, QtCore - import image import cbz @@ -26,7 +25,7 @@ class DialogConvert(QtGui.QProgressDialog): QtGui.QProgressDialog.__init__(self) self.book = book - self.directory = directory + self.bookPath = os.path.join(unicode(directory), unicode(self.book.title)) self.timer = None self.setWindowTitle('Exporting book...') @@ -34,46 +33,45 @@ class DialogConvert(QtGui.QProgressDialog): self.setValue(0) self.archive = None - if 'cbz' in self.book.outputFormat: - # TODO: switch to API 2, to get rid of the unicode conversions - self.archive = cbz.Archive( - os.path.join(unicode(self.directory), unicode(self.book.title))) + if 'CBZ' in self.book.outputFormat: + self.archive = cbz.Archive(self.bookPath) def showEvent(self, event): if self.timer is None: self.timer = QtCore.QTimer() - self.connect(self.timer, QtCore.SIGNAL('timeout()'), self.onTimer) + self.timer.timeout.connect(self.onTimer) self.timer.start(0) def hideEvent(self, event): """Called when the dialog finishes processing.""" - # close the archive if we created a CBZ file + + # Close the archive if we created a CBZ file if self.archive is not None: self.archive.close() - # remove image directory if the user didn't wish for images - if 'image' not in self.book.outputFormat: - path = os.path.join(unicode(self.directory), unicode(self.book.title)) - shutil.rmtree(path) + + # Remove image directory if the user didn't wish for images + if 'Image' not in self.book.outputFormat: + shutil.rmtree(self.bookPath) + def onTimer(self): index = self.value() - directory = os.path.join(unicode(self.directory), unicode(self.book.title)) - target = os.path.join(directory, '%05d.png' % index) + target = os.path.join(self.bookPath, '%05d.png' % index) source = unicode(self.book.images[index]) if index == 0: try: - if not os.path.isdir(directory): - os.makedirs(directory) + if not os.path.isdir(self.bookPath): + os.makedirs(self.bookPath) except OSError: - QtGui.QMessageBox.critical(self, 'Mangle', 'Cannot create directory %s' % directory) + QtGui.QMessageBox.critical(self, 'Mangle', 'Cannot create directory %s' % self.bookPath) self.close() return try: - base = os.path.join(directory, unicode(self.book.title)) + base = os.path.join(self.bookPath, unicode(self.book.title)) mangaName = base + '.manga' if self.book.overwrite or not os.path.isfile(mangaName): @@ -89,7 +87,7 @@ class DialogConvert(QtGui.QProgressDialog): mangaSave.close() except IOError: - QtGui.QMessageBox.critical(self, 'Mangle', 'Cannot write manga file(s) to directory %s' % directory) + QtGui.QMessageBox.critical(self, 'Mangle', 'Cannot write manga file(s) to directory %s' % self.bookPath) self.close() return False diff --git a/mangle/resource/ui/about.ui b/mangle/resource/ui/about.ui index 7964539..56f8be8 100644 --- a/mangle/resource/ui/about.ui +++ b/mangle/resource/ui/about.ui @@ -47,11 +47,11 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">Mangle</span></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Version 2.2</p> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Manga processor by Alex Yatskov for the Kindle e-book reader. Please see <span style=" font-style:italic;">license.txt</span> for licensing information. Visit the homepage at <a href="http://foosoft.net/mangle"><span style=" text-decoration: underline; color:#0000ff;">http://foosoft.net/mangle</span></a>.</p></body></html> +</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans'; font-size:14pt;">Mangle</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans';">Version 2.3</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans';"></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans';">Manga processor by Alex Yatskov for the Kindle e-book reader. Please see </span><span style=" font-family:'Sans'; font-style:italic;">license.txt</span><span style=" font-family:'Sans';"> for licensing information. Visit the homepage at </span><a href="http://foosoft.net/mangle"><span style=" font-family:'Sans'; text-decoration: underline; color:#0000ff;">http://foosoft.net/mangle</span></a><span style=" font-family:'Sans';">.</span></p></body></html> true diff --git a/mangle/resource/ui/options.ui b/mangle/resource/ui/options.ui index 6837667..47f0099 100644 --- a/mangle/resource/ui/options.ui +++ b/mangle/resource/ui/options.ui @@ -97,6 +97,11 @@ + + + Images & CBZ + + Images only @@ -107,11 +112,6 @@ CBZ only - - - Images & CBZ - -