diff --git a/pyqtgraph/Qt.py b/pyqtgraph/Qt.py index 2fcff32f..4fe8c3ab 100644 --- a/pyqtgraph/Qt.py +++ b/pyqtgraph/Qt.py @@ -11,6 +11,8 @@ This module exists to smooth out some of the differences between PySide and PyQt import sys, re +from .python2_3 import asUnicode + ## Automatically determine whether to use PyQt or PySide. ## This is done by first checking to see whether one of the libraries ## is already imported. If not, then attempt to import PyQt4, then PySide. @@ -56,18 +58,29 @@ if USE_PYSIDE: # Credit: # http://stackoverflow.com/questions/4442286/python-code-genration-with-pyside-uic/14195313#14195313 + class StringIO(object): + """Alternative to built-in StringIO needed to circumvent unicode/ascii issues""" + def __init__(self): + self.data = [] + + def write(self, data): + self.data.append(data) + + def getvalue(self): + return ''.join(map(asUnicode, self.data)).encode('utf8') + def loadUiType(uiFile): """ Pyside "loadUiType" command like PyQt4 has one, so we have to convert the ui file to py code in-memory first and then execute it in a special frame to retrieve the form_class. """ import pysideuic import xml.etree.ElementTree as xml - from io import StringIO + #from io import StringIO parsed = xml.parse(uiFile) widget_class = parsed.find('widget').get('class') form_class = parsed.find('class').text - + with open(uiFile, 'r') as f: o = StringIO() frame = {} diff --git a/pyqtgraph/tests/test_qt.py b/pyqtgraph/tests/test_qt.py index cef54777..729bf695 100644 --- a/pyqtgraph/tests/test_qt.py +++ b/pyqtgraph/tests/test_qt.py @@ -1,5 +1,7 @@ import pyqtgraph as pg -import gc +import gc, os + +app = pg.mkQApp() def test_isQObjectAlive(): o1 = pg.QtCore.QObject() @@ -8,3 +10,14 @@ def test_isQObjectAlive(): del o1 gc.collect() assert not pg.Qt.isQObjectAlive(o2) + + +def test_loadUiType(): + path = os.path.dirname(__file__) + formClass, baseClass = pg.Qt.loadUiType(os.path.join(path, 'uictest.ui')) + w = baseClass() + ui = formClass() + ui.setupUi(w) + w.show() + app.processEvents() +