I am trying to write a UI with Pyside2 for maya, but for some reason I could not connect QPushButton with the function within the same class.
In this case I wrote a simple UI with 1 button to trigger template_btnCmd within the same class.
Thank you.
import pymel.core as pm ;
import maya.OpenMayaUI as mui ;
from PySide2 import QtCore , QtGui , QtWidgets ;
from shiboken2 import wrapInstance ;
class Gui ( object ) :
def __init__ ( self ) :
super ( Gui , self ).__init__() ;
self.ui = 'template_uiE' ;
self.w = 500.00 ;
self.h = 300.00 ;
def deleteUI ( self , ui ) :
if pm.window ( ui , ex = True ) :
pm.deleteUI ( ui ) ;
self.deleteUI ( ui ) ;
def show ( self ) :
self.deleteUI ( self.ui ) ;
# Pointer
mayaMainWindow_ptr = mui.MQtUtil.mainWindow();
mayaMainWindow = wrapInstance(long(mayaMainWindow_ptr), QtWidgets.QWidget);
self.mayaMainWindow_ptr = mayaMainWindow_ptr;
self.mayaMainWindow = mayaMainWindow;
window = QtWidgets.QWidget(parent=mayaMainWindow);
self.window = window;
window.setObjectName(self.ui);
window.resize(self.w, self.h);
window.setWindowFlags(QtCore.Qt.Window);
main_QHBoxLayout = QtWidgets.QHBoxLayout(window);
main_QHBoxLayout.setObjectName('main_QHBoxLayout_uiE');
self.main_QHBoxLayout = main_QHBoxLayout;
### Grid Layout
button_QPushButton = QtWidgets.QPushButton() ;
button_QPushButton.setObjectName ( 'button_QPushButton_uiE' ) ;
button_QPushButton.setText ( 'Template Button' ) ;
button_QPushButton.clicked.connect ( self.template_btnCmd ) ;
# --> Insert
main_QHBoxLayout.addWidget ( button_QPushButton ) ;
window.show() ;
def template_btnCmd ( self ) :
print ( 'This is working...?' ) ;
def run ( *args ) :
gui = Gui() ;
gui.show() ;
run() ;