I'm really new to Python and its usage.
I created a Python UI with PyQt.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(1000, 692)
MainWindow.setStyleSheet(_fromUtf8(""))
...
...
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "x", None))
self.pushButton_2.setText(_translate("MainWindow", "x", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
It works well when I run the command python main1.py
Now I want the seperate UI class from the file to use multiple UI classes with a single __main__
I removed all parts except the Ui_MainWindow class and created a new main.py
file such that:
from main1 import *
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
I can reach the class and create object. But when I run the python main.py
command, I see this error.
Traceback (most recent call last):
File "main.py", line 1, in <module>
from main1 import *
File "/home/x/main1.py", line 38
SyntaxError: Non-ASCII character '\xc4' in file /home/x/main1.py on line 38, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
I think the problem is wrong usage of the _fromUtf8
variable. How can it be solved or how should I approach the problem?
Thank you.