hey guys, sorry for digging in old threads,
I picked up this code from a previous poster and tried to make it work.
And actually it works quiet well except when you click outside the gnerated window it will lose it’s focus and you can’t cancel it anymore or do anything.
Any idea how to wrap it to not lose focus?
pyside only of course since it’s supported by maya now, also I can’t have pyQt in our studio, we need to go out of the box due to whatever politics things.
that’s for the python code
import pysideuic
import xml.etree.ElementTree as xml
from cStringIO import StringIO
from PySide import QtGui, QtCore
from shiboken import wrapInstance
import maya.OpenMayaUI as apiUI
from pprint import pprint as pp
def getMayaWindow():
"""
Get the main Maya window as a QtGui.QMainWindow instance
@return: QtGui.QMainWindow instance of the top level Maya windows
"""
ptr = apiUI.MQtUtil.mainWindow()
if ptr is not None:
return wrapInstance(long(ptr),QtGui.QWidget)
def loadUiType(uiFile):
"""
Pyside lacks the "loadUiType" command, 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.
"""
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 = {}
pysideuic.compileUi(f, o, indent=0)
pyc = compile(o.getvalue(), '<string>', 'exec')
exec pyc in frame
#Fetch the base_class and form class based on their type in the xml from designer
form_class = frame['Ui_%s'%form_class]
base_class = eval('QtGui.%s'%widget_class)
return form_class, base_class
listExample_form, listExample_base = loadUiType('C://PATH_TO_YOUR_UI_FILE.ui')
class ListExample(listExample_form, listExample_base):
def __init__(self, parent=getMayaWindow()):
super(ListExample, self).__init__(parent)
self.setupUi(self)
if __name__ == "__main__":
le = ListExample()
le.show()
and for qt designer ui file, just try with some empty design or something random test.