simplified and fixed a couple of things
This commit is contained in:
parent
1a2db4fb5d
commit
7fa3d39b8a
@ -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
|
||||
|
@ -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()
|
||||
|
@ -13,10 +13,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
@ -47,11 +47,11 @@
|
||||
<string><!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></string>
|
||||
</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></string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
|
@ -97,6 +97,11 @@
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="comboBoxFormat">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Images & CBZ</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Images only</string>
|
||||
@ -107,11 +112,6 @@
|
||||
<string>CBZ only</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Images & CBZ</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
Reference in New Issue
Block a user