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 import sys
from PyQt4 import QtGui from PyQt4 import QtGui
from mangle.book import MainWindowBook from mangle.book import MainWindowBook

View File

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

View File

@ -14,21 +14,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # 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 from PyQt4 import QtGui, QtCore, QtXml, uic
import image
from resources import get_ui_path, get_image_path
from image import ImageFlags from image import ImageFlags
from about import DialogAbout from about import DialogAbout
from options import DialogOptions from options import DialogOptions
from convert import DialogConvert from convert import DialogConvert
class Book(object): class Book(object):
DefaultDevice = 'Kindle 3' DefaultDevice = 'Kindle 4'
DefaultOutputFormat = 'Images only'
DefaultOverwrite = True DefaultOverwrite = True
DefaultImageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize DefaultImageFlags = ImageFlags.Orient | ImageFlags.Resize | ImageFlags.Quantize
DefaultOutputFormat = 'image+cbz'
def __init__(self): def __init__(self):
@ -111,43 +110,30 @@ class Book(object):
class MainWindowBook(QtGui.QMainWindow): class MainWindowBook(QtGui.QMainWindow):
def __init__(self, filename=None): def __init__(self, filename=None):
QtGui.QMainWindow.__init__(self) QtGui.QMainWindow.__init__(self)
ui = uic.loadUi(os.path.join(get_ui_path(), 'book.ui'), self)
self._setIcon(self.actionFileNew, 'file_new') uic.loadUi('mangle/resource/ui/book.ui', self)
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)
self.listWidgetFiles.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) 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() self.book = Book()
if filename != None: if filename is not None:
self.loadBook(filename) 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): def closeEvent(self, event):
if not self.saveIfNeeded(): if not self.saveIfNeeded():
event.ignore() event.ignore()
@ -253,7 +239,7 @@ class MainWindowBook(QtGui.QMainWindow):
QtGui.QMessageBox.warning(self, 'Mangle', 'This book has no images to export') QtGui.QMessageBox.warning(self, 'Mangle', 'This book has no images to export')
return return
if self.book.title == None: if self.book.title is None:
dialog = DialogOptions(self, self.book) dialog = DialogOptions(self, self.book)
if dialog.exec_() == QtGui.QDialog.Rejected: if dialog.exec_() == QtGui.QDialog.Rejected:
return return
@ -293,12 +279,12 @@ class MainWindowBook(QtGui.QMainWindow):
def saveBook(self, browse=False): 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') QtGui.QMessageBox.warning(self, 'Mangle', 'You must specify a title for this book before saving')
return False return False
filename = self.book.filename filename = self.book.filename
if filename == None or browse: if filename is None or browse:
filename = QtGui.QFileDialog.getSaveFileName( filename = QtGui.QFileDialog.getSaveFileName(
parent=self, parent=self,
caption='Select a book file to save as', 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 # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os.path import os.path
from PyQt4 import QtGui, QtCore, uic from PyQt4 import QtGui, QtCore, uic
from image import ImageFlags from image import ImageFlags
import resources
class DialogOptions(QtGui.QDialog): class DialogOptions(QtGui.QDialog):
def __init__(self, parent, book): def __init__(self, parent, book):
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, parent)
uic.loadUi('mangle/resource/ui/options.ui', self)
self.accepted.connect(self.onAccept)
self.book = book 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() self.moveOptionsToDialog()
@ -39,7 +37,7 @@ class DialogOptions(QtGui.QDialog):
def moveOptionsToDialog(self): def moveOptionsToDialog(self):
self.lineEditTitle.setText(self.book.title or 'Untitled') self.lineEditTitle.setText(self.book.title or 'Untitled')
self.comboBoxDevice.setCurrentIndex(max(self.comboBoxDevice.findText(self.book.device), 0)) 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.checkboxOverwrite.setChecked(self.book.overwrite)
self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient) self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient)
self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize) self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize)
@ -49,8 +47,8 @@ class DialogOptions(QtGui.QDialog):
def moveDialogToOptions(self): def moveDialogToOptions(self):
title = self.lineEditTitle.text() title = self.lineEditTitle.text()
device = self.comboBoxDevice.itemText(self.comboBoxDevice.currentIndex()) device = self.comboBoxDevice.currentText()
outputFormat = self.reverse_formats[self.comboBoxFormat.currentIndex()] outputFormat = self.comboBoxFormat.currentText()
overwrite = self.checkboxOverwrite.isChecked() overwrite = self.checkboxOverwrite.isChecked()
imageFlags = 0 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> <number>0</number>
</property> </property>
<item> <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>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@ -100,9 +104,7 @@ p, li { white-space: pre-wrap; }
</item> </item>
</layout> </layout>
</widget> </widget>
<resources> <resources/>
<include location="../res/resources.qrc"/>
</resources>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>

View File

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

View File

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