some cleanup and reorg

This commit is contained in:
Alex Yatskov 2011-10-30 13:55:55 -07:00
parent 68874e8648
commit 1a2db4fb5d
22 changed files with 116 additions and 1419 deletions

View File

@ -18,7 +18,6 @@
import sys
from PyQt4 import QtGui
from mangle.book import MainWindowBook

View File

@ -15,13 +15,10 @@
import os.path
from PyQt4 import QtGui, uic
import resources
class DialogAbout(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
ui = uic.loadUi(os.path.join(resources.get_ui_path(), 'about.ui'), self)
self.label.setPixmap(QtGui.QPixmap(os.path.join(resources.get_image_path(), 'banner_about.png')))
uic.loadUi('mangle/resource/ui/about.ui', self)

View File

@ -14,21 +14,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, os.path
import os
import os.path
from PyQt4 import QtGui, QtCore, QtXml, uic
import image
from resources import get_ui_path, get_image_path
from image import ImageFlags
from about import DialogAbout
from options import DialogOptions
from convert import DialogConvert
class Book(object):
DefaultDevice = 'Kindle 3'
DefaultDevice = 'Kindle 4'
DefaultOutputFormat = 'Images only'
DefaultOverwrite = True
DefaultImageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize
DefaultOutputFormat = 'image+cbz'
def __init__(self):
@ -111,43 +110,30 @@ class Book(object):
class MainWindowBook(QtGui.QMainWindow):
def __init__(self, filename=None):
QtGui.QMainWindow.__init__(self)
ui = uic.loadUi(os.path.join(get_ui_path(), 'book.ui'), self)
self._setIcon(self.actionFileNew, 'file_new')
self._setIcon(self.actionFileOpen, 'file_open')
self._setIcon(self.actionFileSave, 'save_file')
self._setIcon(self.actionBookAddFiles, 'add_file')
self._setIcon(self.actionBookAddDirectory, 'add_directory')
self._setIcon(self.actionBookRemove, 'remove_files')
self._setIcon(self.actionBookShiftUp, 'shift_up')
self._setIcon(self.actionBookShiftDown, 'shift_down')
self._setIcon(self.actionBookExport, 'export_book')
self.connect(self.actionFileNew, QtCore.SIGNAL('triggered()'), self.onFileNew)
self.connect(self.actionFileOpen, QtCore.SIGNAL('triggered()'), self.onFileOpen)
self.connect(self.actionFileSave, QtCore.SIGNAL('triggered()'), self.onFileSave)
self.connect(self.actionFileSaveAs, QtCore.SIGNAL('triggered()'), self.onFileSaveAs)
self.connect(self.actionBookOptions, QtCore.SIGNAL('triggered()'), self.onBookOptions)
self.connect(self.actionBookAddFiles, QtCore.SIGNAL('triggered()'), self.onBookAddFiles)
self.connect(self.actionBookAddDirectory, QtCore.SIGNAL('triggered()'), self.onBookAddDirectory)
self.connect(self.actionBookShiftUp, QtCore.SIGNAL('triggered()'), self.onBookShiftUp)
self.connect(self.actionBookShiftDown, QtCore.SIGNAL('triggered()'), self.onBookShiftDown)
self.connect(self.actionBookRemove, QtCore.SIGNAL('triggered()'), self.onBookRemove)
self.connect(self.actionBookExport, QtCore.SIGNAL('triggered()'), self.onBookExport)
self.connect(self.actionHelpAbout, QtCore.SIGNAL('triggered()'), self.onHelpAbout)
self.connect(self.actionHelpHomepage, QtCore.SIGNAL('triggered()'), self.onHelpHomepage)
self.connect(self.listWidgetFiles, QtCore.SIGNAL('customContextMenuRequested(const QPoint&)'), self.onFilesContextMenu)
self.connect(self.listWidgetFiles, QtCore.SIGNAL('itemDoubleClicked (QListWidgetItem *)'), self.onFilesDoubleClick)
uic.loadUi('mangle/resource/ui/book.ui', self)
self.listWidgetFiles.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.actionFileNew.triggered.connect(self.onFileNew)
self.actionFileOpen.triggered.connect(self.onFileOpen)
self.actionFileSave.triggered.connect(self.onFileSave)
self.actionFileSaveAs.triggered.connect(self.onFileSaveAs)
self.actionBookOptions.triggered.connect(self.onBookOptions)
self.actionBookAddFiles.triggered.connect(self.onBookAddFiles)
self.actionBookAddDirectory.triggered.connect(self.onBookAddDirectory)
self.actionBookShiftUp.triggered.connect(self.onBookShiftUp)
self.actionBookShiftDown.triggered.connect(self.onBookShiftDown)
self.actionBookRemove.triggered.connect(self.onBookRemove)
self.actionBookExport.triggered.connect(self.onBookExport)
self.actionHelpAbout.triggered.connect(self.onHelpAbout)
self.actionHelpHomepage.triggered.connect(self.onHelpHomepage)
self.listWidgetFiles.customContextMenuRequested.connect(self.onFilesContextMenu)
self.listWidgetFiles.itemDoubleClicked.connect(self.onFilesDoubleClick)
self.book = Book()
if filename != None:
if filename is not None:
self.loadBook(filename)
@staticmethod
def _setIcon(action, name):
action.setIcon(QtGui.QIcon(os.path.join(get_image_path(), '%s.png' % name)))
def closeEvent(self, event):
if not self.saveIfNeeded():
event.ignore()
@ -253,7 +239,7 @@ class MainWindowBook(QtGui.QMainWindow):
QtGui.QMessageBox.warning(self, 'Mangle', 'This book has no images to export')
return
if self.book.title == None:
if self.book.title is None:
dialog = DialogOptions(self, self.book)
if dialog.exec_() == QtGui.QDialog.Rejected:
return
@ -293,12 +279,12 @@ class MainWindowBook(QtGui.QMainWindow):
def saveBook(self, browse=False):
if self.book.title == None:
if self.book.title is None:
QtGui.QMessageBox.warning(self, 'Mangle', 'You must specify a title for this book before saving')
return False
filename = self.book.filename
if filename == None or browse:
if filename is None or browse:
filename = QtGui.QFileDialog.getSaveFileName(
parent=self,
caption='Select a book file to save as',

View File

@ -13,22 +13,20 @@
# 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.path
from PyQt4 import QtGui, QtCore, uic
from image import ImageFlags
import resources
class DialogOptions(QtGui.QDialog):
def __init__(self, parent, book):
QtGui.QDialog.__init__(self, parent)
uic.loadUi('mangle/resource/ui/options.ui', self)
self.accepted.connect(self.onAccept)
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()
@ -39,7 +37,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))
self.comboBoxFormat.setCurrentIndex(self.formats.get(self.book.outputFormat, self.formats['image+cbz']))
self.comboBoxFormat.setCurrentIndex(max(self.comboBoxFormat.findText(self.book.outputFormat), 0))
self.checkboxOverwrite.setChecked(self.book.overwrite)
self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient)
self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize)
@ -49,8 +47,8 @@ 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()]
device = self.comboBoxDevice.currentText()
outputFormat = self.comboBoxFormat.currentText()
overwrite = self.checkboxOverwrite.isChecked()
imageFlags = 0

View File

Before

Width:  |  Height:  |  Size: 667 B

After

Width:  |  Height:  |  Size: 667 B

View File

Before

Width:  |  Height:  |  Size: 570 B

After

Width:  |  Height:  |  Size: 570 B

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 827 B

After

Width:  |  Height:  |  Size: 827 B

View File

Before

Width:  |  Height:  |  Size: 438 B

After

Width:  |  Height:  |  Size: 438 B

View File

Before

Width:  |  Height:  |  Size: 504 B

After

Width:  |  Height:  |  Size: 504 B

View File

Before

Width:  |  Height:  |  Size: 709 B

After

Width:  |  Height:  |  Size: 709 B

View File

Before

Width:  |  Height:  |  Size: 719 B

After

Width:  |  Height:  |  Size: 719 B

View File

Before

Width:  |  Height:  |  Size: 646 B

After

Width:  |  Height:  |  Size: 646 B

View File

Before

Width:  |  Height:  |  Size: 615 B

After

Width:  |  Height:  |  Size: 615 B

View File

@ -24,7 +24,11 @@
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label"/>
<widget class="QLabel" name="label">
<property name="pixmap">
<pixmap>../../../../../../../mnt/izumi/projects/mangle/mangle/resource/img/banner_about.png</pixmap>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
@ -100,9 +104,7 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<resources>
<include location="../res/resources.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>

View File

@ -33,7 +33,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>29</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@ -107,6 +107,10 @@
<addaction name="actionBookExport"/>
</widget>
<action name="actionFileNew">
<property name="icon">
<iconset>
<normaloff>../img/file_new.png</normaloff>../img/file_new.png</iconset>
</property>
<property name="text">
<string>&amp;New</string>
</property>
@ -116,8 +120,15 @@
<property name="shortcut">
<string>Ctrl+N</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionFileOpen">
<property name="icon">
<iconset>
<normaloff>../img/file_open.png</normaloff>../img/file_open.png</iconset>
</property>
<property name="text">
<string>&amp;Open...</string>
</property>
@ -127,8 +138,15 @@
<property name="shortcut">
<string>Ctrl+O</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionFileSave">
<property name="icon">
<iconset>
<normaloff>../img/save_file.png</normaloff>../img/save_file.png</iconset>
</property>
<property name="text">
<string>&amp;Save</string>
</property>
@ -138,6 +156,9 @@
<property name="shortcut">
<string>Ctrl+S</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionFileSaveAs">
<property name="text">
@ -164,6 +185,10 @@
</property>
</action>
<action name="actionBookRemove">
<property name="icon">
<iconset>
<normaloff>../img/remove_files.png</normaloff>../img/remove_files.png</iconset>
</property>
<property name="text">
<string>&amp;Remove</string>
</property>
@ -173,8 +198,15 @@
<property name="shortcut">
<string>Del</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionBookExport">
<property name="icon">
<iconset>
<normaloff>../img/export_book.png</normaloff>../img/export_book.png</iconset>
</property>
<property name="text">
<string>&amp;Export...</string>
</property>
@ -184,6 +216,9 @@
<property name="shortcut">
<string>Ctrl+E</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionHelpHomepage">
<property name="text">
@ -202,6 +237,10 @@
</property>
</action>
<action name="actionBookAddFiles">
<property name="icon">
<iconset>
<normaloff>../img/add_file.png</normaloff>../img/add_file.png</iconset>
</property>
<property name="text">
<string>&amp;Files...</string>
</property>
@ -211,8 +250,15 @@
<property name="shortcut">
<string>Ctrl+F</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionBookAddDirectory">
<property name="icon">
<iconset>
<normaloff>../img/add_directory.png</normaloff>../img/add_directory.png</iconset>
</property>
<property name="text">
<string>&amp;Directory...</string>
</property>
@ -222,8 +268,15 @@
<property name="shortcut">
<string>Ctrl+D</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionBookShiftUp">
<property name="icon">
<iconset>
<normaloff>../img/shift_up.png</normaloff>../img/shift_up.png</iconset>
</property>
<property name="text">
<string>&amp;Up</string>
</property>
@ -233,8 +286,15 @@
<property name="shortcut">
<string>Ctrl+PgUp</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionBookShiftDown">
<property name="icon">
<iconset>
<normaloff>../img/shift_down.png</normaloff>../img/shift_down.png</iconset>
</property>
<property name="text">
<string>&amp;Down</string>
</property>
@ -244,11 +304,12 @@
<property name="shortcut">
<string>Ctrl+PgDown</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
</widget>
<resources>
<include location="../res/resources.qrc"/>
</resources>
<resources/>
<connections>
<connection>
<sender>actionFileExit</sender>

View File

@ -71,6 +71,11 @@
<string>Kindle 3</string>
</property>
</item>
<item>
<property name="text">
<string>Kindle 4</string>
</property>
</item>
<item>
<property name="text">
<string>Kindle DX</string>
@ -92,11 +97,6 @@
</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,6 +107,11 @@
<string>CBZ only</string>
</property>
</item>
<item>
<property name="text">
<string>Images &amp; CBZ</string>
</property>
</item>
</widget>
</item>
</layout>

View File

@ -1,25 +0,0 @@
# Copyright (C) 2011 Marek Kubica <marek@xivilization.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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.path
def get_resource_path():
return os.path.dirname(__file__)
def get_ui_path():
return os.path.join(get_resource_path(), 'ui')
def get_image_path():
return os.path.join(get_resource_path(), 'images')

View File

File diff suppressed because it is too large Load Diff