Thanks for the link John. I did replace Nathans code to work with Pyside,
but still cannot get it working. Secondly, I have changed it to use the
shiboken module to get the Maya window. Here's what I have :
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
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
#If you put the .ui file for this example elsewhere, just change this path.
listExample_form, listExample_base = loadUiType('E:/example1.ui')
class ListExample(listExample_form, listExample_base):
def __init__(self, parent=getMayaWindow()):
super(ListExample, self).__init__(parent)
self.setupUi(self)
#The names "addItemBtn" and "removeItemBtn"
#come from the "objectName" attribute in Qt Designer
#the attributes to access them are automatically created
#for us when we call setupUi()
#Designer ensures that the names are unique for us.
self.addItemBtn.clicked.connect(self.addItem)
self.removeItemBtn.clicked.connect(self.removeItem)
def addItem(self):
"""
Add a new item to the end of the listWidget
"""
item = QtGui.QListWidgetItem(self.listWidget)
item.setText('Item #%s!'%self.listWidget.count())
def removeItem(self):
"""
Remove the last item from the listWidget
"""
count = self.listWidget.count()
if count:
self.listWidget.takeItem(count-1)
Any ideas?
Thanks you,
Vikram.
On Wed, Oct 2, 2013 at 2:14 AM, johnvdz <[email protected]> wrote:
> have a look at nathans Horne's page. theres a link to a code file he
> offers for uic replacement using pysideuic. should be all you need.
>
> http://nathanhorne.com/?p=451
>
> john
>
>
> On 30/09/2013 5:06 AM, floyd1510 wrote:
>
>> Hello,
>>
>> Can I get an example of getting a .ui (created from the qt designer)
>> loading with Pyside in Maya 2014. I tried to replace the loadUi function of
>> PyQt but somehow I cannot get the UI window up (Maya does not complain
>> about anything when I execute the code, just no result)
>>
>> This link : http://stackoverflow.com/**questions/14892713/how-do-you-**
>> load-ui-files-onto-python-**classes-with-pyside<http://stackoverflow.com/questions/14892713/how-do-you-load-ui-files-onto-python-classes-with-pyside>asks
>> you to override the default function, which I tried, but still could
>> not manage to load the UI
>>
>> Thank you for the help,
>> Vikram.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> python_inside_maya+**[email protected]<python_inside_maya%[email protected]>
> .
> To post to this group, send email to
> python_inside_maya@**googlegroups.com<[email protected]>
> .
> For more options, visit
> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
> .
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.