I make a simple window and added the menu and toolbar. And I got the strange behavior of the function connected to action. Here's the code:
import os
import sys
import sip
import maya.OpenMayaUI as mui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
#----------------------------------------------------------------------
def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QObject)
#----------------------------------------------------------------------
class MainForm(QMainWindow):
def __init__(self):
super(MainForm, self).__init__(getMayaWindow())
self.setGeometry(50,50,600,600)
mdiArea = QMdiArea()
self.setCentralWidget(mdiArea)
self.testAction = QAction(QIcon('ico.png'), '&Test', self)
self.testAction.triggered.connect(self.aaaaa)
self.menubar = self.menuBar()
fileMenu = self.menubar.addMenu('&File')
fileMenu.addAction(self.testAction)
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(self.testAction)
self.statusBar()
def aaaaa(self):
print('test')
#----------------------------------------------------------------------
# window
def cacheWnd():
wnd = MainForm()
wnd.show()
cacheWnd()
when you press the menu or the toolbar icon - the associated function is not called. but it is necessary to make a global function outside the class and make a call without self how everything starts to work immediately.
i correct line:
self.testAction.triggered.connect(aaaaa)
and drag the function outside the class:
def aaaaa():
print('test')
and all at once started, is called up and running...
Why it does not work until the function is a member of a class?