Permalink
Browse files

some cleanup and reorg

  • Loading branch information...
1 parent 68874e8 commit 1a2db4fb5da5e700d40b611b334e68d166c69b52 @FooSoft committed Oct 30, 2011
View
@@ -18,7 +18,6 @@
import sys
from PyQt4 import QtGui
-
from mangle.book import MainWindowBook
View
@@ -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
@@ -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 @@ def load(self, filename):
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 @@ def onBookExport(self):
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 @@ def saveIfNeeded(self):
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
@@ -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
+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 @@ def onAccept(self):
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 @@ def moveOptionsToDialog(self):
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
File renamed without changes.
@@ -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>
@@ -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>
Oops, something went wrong.

0 comments on commit 1a2db4f

Please sign in to comment.