From a8b3ae57c788542cf37055d181e0b14293fd3f15 Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Sun, 30 Oct 2011 02:25:37 +0900 Subject: [PATCH] Added code to load UI files from package --- mangle/about.py | 5 ++++- mangle/book.py | 6 +++--- mangle/options.py | 4 +++- mangle/resources/__init__.py | 25 +++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/mangle/about.py b/mangle/about.py index 3cd0c26..0c5770d 100644 --- a/mangle/about.py +++ b/mangle/about.py @@ -14,10 +14,13 @@ # along with this program. If not, see . +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('dev/ui/about.ui', self) + ui = uic.loadUi(os.path.join(resources.get_ui_path(), 'about.ui'), self) diff --git a/mangle/book.py b/mangle/book.py index 2f86c9c..e90c6c5 100644 --- a/mangle/book.py +++ b/mangle/book.py @@ -14,16 +14,16 @@ # along with this program. If not, see . -import os +import os, os.path from PyQt4 import QtGui, QtCore, QtXml, uic import image +import resources from image import ImageFlags from about import DialogAbout from options import DialogOptions from convert import DialogConvert - class Book: DefaultDevice = 'Kindle 3' DefaultOverwrite = True @@ -107,7 +107,7 @@ class Book: class MainWindowBook(QtGui.QMainWindow): def __init__(self, filename=None): QtGui.QMainWindow.__init__(self) - ui = uic.loadUi('dev/ui/book.ui', self) + ui = uic.loadUi(os.path.join(resources.get_ui_path(), 'book.ui'), self) 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) diff --git a/mangle/options.py b/mangle/options.py index baefb3c..86926f0 100644 --- a/mangle/options.py +++ b/mangle/options.py @@ -13,17 +13,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +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) self.book = book - ui = uic.loadUi('dev/ui/options.ui', self) + ui = uic.loadUi(os.path.join(resources.get_ui_path(), 'options.ui'), self) self.connect(self, QtCore.SIGNAL('accepted()'), self.onAccept) self.moveOptionsToDialog() diff --git a/mangle/resources/__init__.py b/mangle/resources/__init__.py index e69de29..de9752d 100644 --- a/mangle/resources/__init__.py +++ b/mangle/resources/__init__.py @@ -0,0 +1,25 @@ +# Copyright (C) 2011 Marek Kubica +# +# 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 . + +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')