From fa5c378cb8828d55603d5fda913f71fee6bdaf25 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Sun, 30 Oct 2011 18:24:48 +0900 Subject: [PATCH] Made CBZ-only format work properly --- mangle/convert.py | 17 +++++++++++------ mangle/options.py | 10 +++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mangle/convert.py b/mangle/convert.py index b8478c3..d51a300 100644 --- a/mangle/convert.py +++ b/mangle/convert.py @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os +import os, shutil + from PyQt4 import QtGui, QtCore import image @@ -23,7 +24,6 @@ import cbz class DialogConvert(QtGui.QProgressDialog): def __init__(self, parent, book, directory): QtGui.QProgressDialog.__init__(self) - #self.setAutoReset(False) self.book = book self.directory = directory @@ -47,10 +47,15 @@ class DialogConvert(QtGui.QProgressDialog): self.timer.start(0) - def closeEvent(self, event): - print "closeEvent" - self.closing.emit() - event.accept() + def hideEvent(self, event): + """Called when the dialog finishes processing.""" + # 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) def onTimer(self): index = self.value() diff --git a/mangle/options.py b/mangle/options.py index 38549da..87855b1 100644 --- a/mangle/options.py +++ b/mangle/options.py @@ -25,6 +25,8 @@ class DialogOptions(QtGui.QDialog): def __init__(self, parent, book): QtGui.QDialog.__init__(self, parent) self.book = book + self.formats = {'image+cbz' : 0, 'image' : 1, 'cbz' : 2} + self.reverse_formats = dict((v,k) for k, v in self.formats.iteritems()) ui = uic.loadUi(os.path.join(resources.get_ui_path(), 'options.ui'), self) self.connect(self, QtCore.SIGNAL('accepted()'), self.onAccept) self.moveOptionsToDialog() @@ -37,8 +39,7 @@ class DialogOptions(QtGui.QDialog): def moveOptionsToDialog(self): self.lineEditTitle.setText(self.book.title or 'Untitled') self.comboBoxDevice.setCurrentIndex(max(self.comboBoxDevice.findText(self.book.device), 0)) - formats = {'image+cbz' : 0, 'image' : 1, 'cbz' : 2} - self.comboBoxFormat.setCurrentIndex(formats.get(self.book.outputFormat, formats['image+cbz'])) + self.comboBoxFormat.setCurrentIndex(self.formats.get(self.book.outputFormat, self.formats['image+cbz'])) self.checkboxOverwrite.setChecked(self.book.overwrite) self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient) self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize) @@ -49,6 +50,7 @@ class DialogOptions(QtGui.QDialog): def moveDialogToOptions(self): title = self.lineEditTitle.text() device = self.comboBoxDevice.itemText(self.comboBoxDevice.currentIndex()) + outputFormat = self.reverse_formats[self.comboBoxFormat.currentIndex()] overwrite = self.checkboxOverwrite.isChecked() imageFlags = 0 @@ -65,7 +67,8 @@ class DialogOptions(QtGui.QDialog): self.book.title != title or self.book.device != device or self.book.overwrite != overwrite or - self.book.imageFlags != imageFlags + self.book.imageFlags != imageFlags or + self.book.outputFormat != outputFormat ) if modified: @@ -74,3 +77,4 @@ class DialogOptions(QtGui.QDialog): self.book.device = device self.book.overwrite = overwrite self.book.imageFlags = imageFlags + self.book.outputFormat = outputFormat