Search code examples
pythonqt4pyqtmaya

PyQt - Loading multiple UI files


I have multiple ui files, each created in Qt Designer. I have a function (main) that calls the first UI. There is a button on this first UI that calls the second UI and closes the first one.

from PyQt4 import QtGui,QtCore, uic

uifile_1 = '/Users/Shared/Autodesk/maya/scripts/python/Intro_UI.ui'
form_1, base_1 = uic.loadUiType(uifile_1)

uifile_2 = '/Users/Shared/Autodesk/maya/scripts/python/objtemplate_tuner.ui'
form_2, base_2 = uic.loadUiType(uifile_2)

class CreateUI_2(base_2, form_2):
    def __init__(self):
        super(base_2,self).__init__()
        self.setupUi(self)

class CreateUI_1(base_1, form_1):
    def __init__(self):
        super(base_1,self).__init__()
        self.setupUi(self)
        self.Establish_Connections()

    def Do_ButtonPress(self):        
        UI_2=CreateUI_2()
        UI_2.show()
        self.close()
    def Establish_Connections(self):
        QtCore.QObject.connect(self.noncharactermeshes_Button, QtCore.SIGNAL("clicked()"),self.Do_ButtonPress)      

def main():       
    UI_1 = CreateUI_1()
    UI_1.show()

main()

The problem is that when I run main() nothing happens. Also note I'm creating this script for Maya and using PyQt4.


Solution

  • I found an answer, turns out I needed to use a global variable for my ui.

        def Do_ButtonPress(self):
            global UI_2
            UI_2=CreateUI_2()
            UI_2.show()
    

    ...

    def main():
        global UI_1
        UI_1 = CreateUI_1()
        UI_1.show()