Fixed unicode issues with PySide loadUiType
Added unit test for loadUiType
This commit is contained in:
parent
4e555e0bf3
commit
5a8d77d6f2
@ -11,6 +11,8 @@ This module exists to smooth out some of the differences between PySide and PyQt
|
|||||||
|
|
||||||
import sys, re
|
import sys, re
|
||||||
|
|
||||||
|
from .python2_3 import asUnicode
|
||||||
|
|
||||||
## Automatically determine whether to use PyQt or PySide.
|
## Automatically determine whether to use PyQt or PySide.
|
||||||
## This is done by first checking to see whether one of the libraries
|
## 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.
|
## is already imported. If not, then attempt to import PyQt4, then PySide.
|
||||||
@ -56,13 +58,24 @@ if USE_PYSIDE:
|
|||||||
# Credit:
|
# Credit:
|
||||||
# http://stackoverflow.com/questions/4442286/python-code-genration-with-pyside-uic/14195313#14195313
|
# 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):
|
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.
|
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 pysideuic
|
||||||
import xml.etree.ElementTree as xml
|
import xml.etree.ElementTree as xml
|
||||||
from io import StringIO
|
#from io import StringIO
|
||||||
|
|
||||||
parsed = xml.parse(uiFile)
|
parsed = xml.parse(uiFile)
|
||||||
widget_class = parsed.find('widget').get('class')
|
widget_class = parsed.find('widget').get('class')
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
import gc
|
import gc, os
|
||||||
|
|
||||||
|
app = pg.mkQApp()
|
||||||
|
|
||||||
def test_isQObjectAlive():
|
def test_isQObjectAlive():
|
||||||
o1 = pg.QtCore.QObject()
|
o1 = pg.QtCore.QObject()
|
||||||
@ -8,3 +10,14 @@ def test_isQObjectAlive():
|
|||||||
del o1
|
del o1
|
||||||
gc.collect()
|
gc.collect()
|
||||||
assert not pg.Qt.isQObjectAlive(o2)
|
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()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user