私は現在、PythonでMaya用のUIスクリプトを作成しています。ファイルから別のUIオブジェクトへの呼び出し
私は上部に異なるタブを持つUIを持っていて、それはあまりにも厄介で長くなるので、コードのすべての部分をMainClass
に入れたくありません。すべてのタブについて、そのスクリプトを別の.py
ファイルに書きたいと思います。私は__init__
の機能の下に接続を作成したい、同時に、このMainClass
に別のスクリプトから関数を読み込みます。
質問:新しいファイルのUIからobjectNameを呼び出すにはどうすればよいですか? MainClass
コードをインポートしようとしましたが、うまく機能せず、新しい.py
ファイルのUIウィンドウを初期化したくありません。これを行うには良い方法がありますか?
EDIT
例:
test.uiファイルには、1つのボタンラベルされた "印刷" とリストウィジェットを持っています。 「Print」ボタンを押すたびに、リストウィジェットに「Hello World」と表示されます。
loadUi_test.pyではこれは動作しませんの.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))
のinitでfunction_test.py
def printFunc():
listWidget.clear()
listWidget.addItem("Hello World!")
で
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)
ファイル、私は "エラーが出ますタプルオブジェクトには属性がありませんlistWidget "
私が代わりにこれを行う場合:a.pushButton.clicked.connect(function_test.printFunc(a))
を、私はエラーを取得するには、「信号を接続に失敗しました)(クリック、」一般的に
[別のファイルからクラスをインポートする](https://stackoverflow.com/questions/41276067/importing-class-from-another -file) – Matho