Use the following code to show PyQt *.ui in Autodesk maya. It will load all stuff located in ui file and create window attached to maya-window. Copy this code to maya script editor, replace string uifile = 'c:/test.ui' with real path to your ui-file (use forward slash even on windows). Now execute this code, and you will get your UI-window in maya.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import maya.OpenMayaUI as apiUI from PyQt4 import QtCore, uic import sip uifile = 'c:/test.ui' form, base = uic.loadUiType(uifile) 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 sip.wrapinstance(long(ptr), QtCore.QObject) class testQtWindow(form, base): def __init__(self, parent = getMayaWindow()): super(testQtWindow,self).__init__(parent) self.setupUi(self) def main(): global win try: win.close() except: pass win = testQtWindow() win.show() if __name__=="__main__": main() |
No comments:
Post a Comment