simplified and fixed a couple of things

This commit is contained in:
Alex Yatskov 2011-10-30 14:19:49 -07:00
parent 1a2db4fb5d
commit 7fa3d39b8a
5 changed files with 33 additions and 31 deletions

View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -47,11 +47,11 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:14pt;&quot;&gt;Mangle&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Version 2.2&lt;/p&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Manga processor by Alex Yatskov for the Kindle e-book reader. Please see &lt;span style=&quot; font-style:italic;&quot;&gt;license.txt&lt;/span&gt; for licensing information. Visit the homepage at &lt;a href=&quot;http://foosoft.net/mangle&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;http://foosoft.net/mangle&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans'; font-size:14pt;&quot;&gt;Mangle&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;Version 2.3&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;-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';&quot;&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;Manga processor by Alex Yatskov for the Kindle e-book reader. Please see &lt;/span&gt;&lt;span style=&quot; font-family:'Sans'; font-style:italic;&quot;&gt;license.txt&lt;/span&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt; for licensing information. Visit the homepage at &lt;/span&gt;&lt;a href=&quot;http://foosoft.net/mangle&quot;&gt;&lt;span style=&quot; font-family:'Sans'; text-decoration: underline; color:#0000ff;&quot;&gt;http://foosoft.net/mangle&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot; font-family:'Sans';&quot;&gt;.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -97,6 +97,11 @@
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxFormat">
<item>
<property name="text">
<string>Images &amp; 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 &amp; CBZ</string>
</property>
</item>
</widget>
</item>
</layout>