I created a Qt resource file with all my ui files inside of it, I compiled that with pyrcc4 command-line in a python file, and then I loaded the ui files using loadUi. Here an example:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import sys
from PyQt4.QtCore import Qt, QFile
from PyQt4.uic import loadUi
from PyQt4.QtGui import QDialog
from xarphus.gui import ui_rc
# I import the compiled qt resource file named ui_rc
BASE_PATH = os.path.dirname(os.path.abspath(__file__))
#UI_PATH = os.path.join(BASE_PATH, 'gui', 'create_user.ui')
UI_PATH = QFile(":/ui_file/create_user.ui")
# I want to load those compiled ui files,
# so I just create QFile.
class CreateUser_Window(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent)
# I open the created QFile
UI_PATH.open(QFile.ReadOnly)
# I read the QFile and load the ui file
self.ui_create_user = loadUi(UI_PATH, self)
# After then I close it
UI_PATH.close()
Well its works fine, but I have a problem. When I open the GUI-window once, everything works fine. After closing the window I try to open the same GUI-window again, I get ja long traceback.
Traceback (most recent call last): File "D:\Dan\Python\xarphus\xarphus\frm_mdi.py", line 359, in create_update_form self.update_form = Update_Window(self) File "D:\Dan\Python\xarphus\xarphus\frm_update.py", line 135, in init self.ui_update = loadUi(UI_PATH, self) File "C:\Python27\lib\site-packages\PyQt4\uic__init__.py", line 238, in loadUi return DynamicUILoader(package).loadUi(uifile, baseinstance, resource_suffix) File "C:\Python27\lib\site-packages\PyQt4\uic\Loader\loader.py", line 71, in loadUi return self.parse(filename, resource_suffix, basedir) File "C:\Python27\lib\site-packages\PyQt4\uic\uiparser.py", line 984, in parse document = parse(filename) File "C:\Python27\lib\xml\etree\ElementTree.py", line 1182, in parse tree.parse(source, parser) File "C:\Python27\lib\xml\etree\ElementTree.py", line 657, in parse self._root = parser.close() File "C:\Python27\lib\xml\etree\ElementTree.py", line 1654, in close self._raiseerror(v) File "C:\Python27\lib\xml\etree\ElementTree.py", line 1506, in _raiseerror raise err xml.etree.ElementTree.ParseError: no element found: line 1, column 0
Can everyone help me?