I am currently writing a UI script for Maya in Python.
So, I have UI that has different tabs at the top and I do not want to put every single piece of code in the MainClass
because that would be too messy and long. For every tab, I want to write its script in a different .py
file. I want to create the connections under the __init__
function, at the same time, load functions from another script into this MainClass
to be used.
Question is, how should I go about calling objectName from the UI in a new file? I tried to import the MainClass
code but that didn't work and I don't want the initialize the UI window in the new .py
file. What's a good way to go about this?
EDIT
Example:
test.ui file has one button labelled "Print" and a list Widget. Every time 'Print' button is pressed, the words "Hello World" will appear on the list widget.
In loadUi_test.py file
def loadUi(uiFile):
#code that loads ui
def getMayaWindow():
#gets main Maya Window
ptr = apiUI.MQtUtil.mainWindow()
if ptr is not None:
return shiboken.wrapInstance(long(ptr), QtGui.QMainWindow)
class mainClass():
def __init__(self, parent = getMayaWindow()):
super(pipeWindow,self).__init__(parent)
self.setupUi(self)
def closeEvent(self,event):
super(mainClass, self).closeEvent(event)
In function_test.py
def printFunc():
listWidget.clear()
listWidget.addItem("Hello World!")
In init.py
from pipeline import loadUi_test
from pipeline import function_test
uiFile = "test.ui"
b = loadUi_test.loadUi(uiFile)
a = loadUi_test.mainClass()
a.pushButton.clicked.connect(function_test.printFunc(b))
This does not work, I get an error " tuple object has no attribute listWidget "
If I do this instead: a.pushButton.clicked.connect(function_test.printFunc(a))
, I get the error "Failed to connect signal clicked()"