Added a shortcut function to set icons easier

This commit is contained in:
Marek Kubica 2011-10-30 03:29:52 +09:00
parent 3a914a97ee
commit e82fce3c03

View File

@ -14,10 +14,8 @@
# 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 import os, os.path
from os.path import join as pjoin
from PyQt4 import QtGui, QtCore, QtXml, uic from PyQt4 import QtGui, QtCore, QtXml, uic
from PyQt4.QtGui import QIcon
import image import image
from resources import get_ui_path, get_image_path from resources import get_ui_path, get_image_path
@ -110,15 +108,15 @@ 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) ui = uic.loadUi(os.path.join(get_ui_path(), 'book.ui'), self)
self.actionFileNew.setIcon(QIcon(pjoin(get_image_path(), 'file_new.png'))) self._setIcon(self.actionFileNew, 'file_new')
self.actionFileOpen.setIcon(QIcon(pjoin(get_image_path(), 'file_open.png'))) self._setIcon(self.actionFileOpen, 'file_open')
self.actionFileSave.setIcon(QIcon(pjoin(get_image_path(), 'save_file.png'))) self._setIcon(self.actionFileSave, 'save_file')
self.actionBookAddFiles.setIcon(QIcon(pjoin(get_image_path(), 'add_file.png'))) self._setIcon(self.actionBookAddFiles, 'add_file')
self.actionBookAddDirectory.setIcon(QIcon(pjoin(get_image_path(), 'add_directory.png'))) self._setIcon(self.actionBookAddDirectory, 'add_directory')
self.actionBookRemove.setIcon(QIcon(pjoin(get_image_path(), 'remove_files.png'))) self._setIcon(self.actionBookRemove, 'remove_files')
self.actionBookShiftUp.setIcon(QIcon(pjoin(get_image_path(), 'shift_up.png'))) self._setIcon(self.actionBookShiftUp, 'shift_up')
self.actionBookShiftDown.setIcon(QIcon(pjoin(get_image_path(), 'shift_down.png'))) self._setIcon(self.actionBookShiftDown, 'shift_down')
self.actionBookExport.setIcon(QIcon(pjoin(get_image_path(), 'export_book.png'))) self._setIcon(self.actionBookExport, 'export_book')
self.connect(self.actionFileNew, QtCore.SIGNAL('triggered()'), self.onFileNew) self.connect(self.actionFileNew, QtCore.SIGNAL('triggered()'), self.onFileNew)
self.connect(self.actionFileOpen, QtCore.SIGNAL('triggered()'), self.onFileOpen) self.connect(self.actionFileOpen, QtCore.SIGNAL('triggered()'), self.onFileOpen)
self.connect(self.actionFileSave, QtCore.SIGNAL('triggered()'), self.onFileSave) self.connect(self.actionFileSave, QtCore.SIGNAL('triggered()'), self.onFileSave)
@ -141,6 +139,11 @@ class MainWindowBook(QtGui.QMainWindow):
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()