Sure...
ref: http://pyqt.sourceforge.net/Docs/PyQt4/designer.html
#---- Multiple inheritance ---
from PySide import QtCore, QtGui
# COMMAND: pyside-uic test.ui -o test_ui.py
from test_ui import Ui_MainWindow
class MyWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, *args, **kwargs):
super(MyWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication([])
window = MyWindow()
window.show()
window.raise_()
app.exec_()
#-------------------------
Once you generate the ui -> py module, you no longer have to do it
dynamically at each run.
This is just one of the available patterns for using a ui file. Some
people prefer to not subclass directly from the UI class, and instead
make it a member of the class to namespace all of the widgets:
#----Single inheritance ----
class MyWindow(QtGui.QMainWindow):
def __init__(self, *args, **kwargs):
super(MyWindow, self).__init__(*args, **kwargs)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#-------------------------
On Tue, Oct 1, 2013 at 6:47 PM, Vikram Shingrani <[email protected]
<mailto:[email protected]>> wrote:
Can I get a simple running example please?
Thank you
On Tue, Oct 1, 2013 at 3:30 PM, Justin Israel
<[email protected] <mailto:[email protected]>> wrote:
Not sure off hand why it doesn't work, but as a side note,
this is kind of the reason why I always preferred to just use
pyside-uic / pyuic to convert the ui files. Then there is no
converting and parsing going on at runtime.
You would normally do the same thing anyways (at least I do)
with resource files, having to use pyside-rcc to convert from
rcc -> .py
On Tue, Oct 1, 2013 at 3:56 PM, Vikram Shingrani
<[email protected] <mailto:[email protected]>> wrote:
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]
<mailto:[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
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
[email protected]
<mailto:python_inside_maya%[email protected]>.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit
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]
<mailto:python_inside_maya%[email protected]>.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit
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]
<mailto:python_inside_maya%[email protected]>.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit 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]
<mailto:python_inside_maya%[email protected]>.
To post to this group, send email to
[email protected]
<mailto:[email protected]>.
For more options, visit 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.