From 83251909b31381a130dfa99307b8466489b95122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gab=C3=A8s=20Jean?= Date: Wed, 7 Oct 2015 21:50:47 +0200 Subject: [PATCH] Add: some code styling --- mangle/book.py | 36 ++++++++++++++++++------------------ mangle/cbz.py | 6 +++--- mangle/convert.py | 11 +++++------ mangle/options.py | 23 +++++++++++++++-------- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/mangle/book.py b/mangle/book.py index 2079f8a..1a3e6aa 100644 --- a/mangle/book.py +++ b/mangle/book.py @@ -36,21 +36,21 @@ def natural_key(string_): class Book(object): - DefaultDevice = 'Kindle Paperwhite' + DefaultDevice = 'Kindle Paperwhite' DefaultOutputFormat = 'CBZ only' - DefaultOverwrite = True - DefaultImageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize + DefaultOverwrite = True + DefaultImageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize def __init__(self): - self.images = [] - self.filename = None - self.modified = False - self.title = None - self.titleSet = False - self.device = Book.DefaultDevice - self.overwrite = Book.DefaultOverwrite - self.imageFlags = Book.DefaultImageFlags + self.images = [] + self.filename = None + self.modified = False + self.title = None + self.titleSet = False + self.device = Book.DefaultDevice + self.overwrite = Book.DefaultOverwrite + self.imageFlags = Book.DefaultImageFlags self.outputFormat = Book.DefaultOutputFormat @@ -101,14 +101,14 @@ class Book(object): if root.tagName() != 'book': raise RuntimeError('Unexpected book format in file %s' % filename) - 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.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', Book.DefaultOutputFormat) - self.imageFlags = int(root.attribute('imageFlags', str(Book.DefaultImageFlags))) - self.filename = filename - self.modified = False - self.images = [] + self.imageFlags = int(root.attribute('imageFlags', str(Book.DefaultImageFlags))) + self.filename = filename + self.modified = False + self.images = [] items = root.elementsByTagName('image') if items is None: diff --git a/mangle/cbz.py b/mangle/cbz.py index dc23583..e9c2bbc 100644 --- a/mangle/cbz.py +++ b/mangle/cbz.py @@ -21,9 +21,9 @@ from zipfile import ZipFile, ZIP_STORED class Archive(object): def __init__(self, path): outputDirectory = os.path.dirname(path) - outputFileName = '%s.cbz' % os.path.basename(path) - outputPath = os.path.join(outputDirectory, outputFileName) - self.zipfile = ZipFile(outputPath, 'w', ZIP_STORED) + outputFileName = '%s.cbz' % os.path.basename(path) + outputPath = os.path.join(outputDirectory, outputFileName) + self.zipfile = ZipFile(outputPath, 'w', ZIP_STORED) def addFile(self, filename): diff --git a/mangle/convert.py b/mangle/convert.py index 326f465..6366daa 100644 --- a/mangle/convert.py +++ b/mangle/convert.py @@ -16,10 +16,10 @@ import os import shutil - from PyQt4 import QtGui, QtCore -from image import ImageFlags + +from image import ImageFlags import cbz import image import pdfimage @@ -29,7 +29,7 @@ class DialogConvert(QtGui.QProgressDialog): def __init__(self, parent, book, directory): QtGui.QProgressDialog.__init__(self) - self.book = book + self.book = book self.bookPath = os.path.join(unicode(directory), unicode(self.book.title)) self.timer = None @@ -121,7 +121,6 @@ class DialogConvert(QtGui.QProgressDialog): archive = self.archive pdf = self.pdf - # Maybe the user ask for a split, but the picture is not a large one, so skip # it but only for this picture if (flags & ImageFlags.Split) or (flags & ImageFlags.SplitInverse): @@ -132,7 +131,7 @@ class DialogConvert(QtGui.QProgressDialog): flags &= ~f # For right page (if requested in options and need for this image) - if(flags & ImageFlags.Split): + if (flags & ImageFlags.Split): # New path based on modified index target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 0)) self.convertAndSave(source, target, device, flags ^ ImageFlags.Split | ImageFlags.SplitRight, archive, pdf) @@ -140,7 +139,7 @@ class DialogConvert(QtGui.QProgressDialog): target = os.path.join(self.bookPath, '%05d.png' % (index * 2 + 1)) # For right page (if requested), but in inverted mode - if(flags & ImageFlags.SplitInverse): + if (flags & 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) diff --git a/mangle/options.py b/mangle/options.py index eedfe88..19d6929 100644 --- a/mangle/options.py +++ b/mangle/options.py @@ -35,6 +35,7 @@ class DialogOptions(QtGui.QDialog): self.moveDialogToOptions() + # Get options from current book (like a loaded one) and set the dialog values def moveOptionsToDialog(self): self.lineEditTitle.setText(self.book.title or 'Untitled') self.comboBoxDevice.setCurrentIndex(max(self.comboBoxDevice.findText(self.book.device), 0)) @@ -47,12 +48,15 @@ class DialogOptions(QtGui.QDialog): self.checkboxFrame.setChecked(self.book.imageFlags & ImageFlags.Frame) + # Save parameters set on the dialogs to the book object if need def moveDialogToOptions(self): - title = self.lineEditTitle.text() - device = self.comboBoxDevice.currentText() + # First get dialog values + title = self.lineEditTitle.text() + device = self.comboBoxDevice.currentText() outputFormat = self.comboBoxFormat.currentText() - overwrite = self.checkboxOverwrite.isChecked() + overwrite = self.checkboxOverwrite.isChecked() + # Now compute flags imageFlags = 0 if self.checkboxOrient.isChecked(): imageFlags |= ImageFlags.Orient @@ -69,6 +73,9 @@ class DialogOptions(QtGui.QDialog): if self.checkboxSplitInverse.isChecked(): imageFlags |= ImageFlags.SplitInverse + # If we did modified a value, update the book + # and only if we did change something to not + # warn for nothing the user modified = ( self.book.title != title or self.book.device != device or @@ -78,9 +85,9 @@ class DialogOptions(QtGui.QDialog): ) if modified: - self.book.modified = True - self.book.title = title - self.book.device = device - self.book.overwrite = overwrite - self.book.imageFlags = imageFlags + self.book.modified = True + self.book.title = title + self.book.device = device + self.book.overwrite = overwrite + self.book.imageFlags = imageFlags self.book.outputFormat = outputFormat