qt - Use Python class in another file, with packages it uses -
i'm new python , usage.
i created python ui 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 when run command python main1.py want seperate ui class file use multiple ui classes single __main__
i removed parts except ui_mainwindow class , created new main.py file such that:
from main1 import * 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 class , create object. when run python main.py command, see error.
traceback (most recent call last): file "main.py", line 1, in <module> main1 import * file "/home/x/main1.py", line 38 syntaxerror: non-ascii character '\xc4' in file /home/x/main1.py on line 38, no encoding declared; see http://www.python.org/peps/pep-0263.html details i think problem wrong usage of _fromutf8 variable. how can solved or how should approach problem? thank you.
it question of encoding use in editor in file main1.py.
there character hexadecimal c4 > 128 ascii can not used.
try put 1 of following encoding lines 1 of first lines of main1.py. (i recommend last one) , try find out encoding of file , set it.
# -*- coding: latin-1 -*- #!/usr/bin/python # -*- coding: iso-8859-15 -*- #!/usr/bin/python # -*- coding: utf-8 -*- # recommend utf8!
Comments
Post a Comment