[Maya] Bridging a UI class with the sdk and python

Hey guys I have a helper module that contains a ui class


class Window(OpenMayaMPx.MPxCommand):
def doIt(self, argList):
     CreateWindow('blah')

def CreateWindow(self, title, width = 400, height = 400):

		if cmds.window(title, exists = True):
			self.uiDelete(title)

		self._width = width
		self._height = height

		window = cmds.window(title, title=title, menuBar=True, widthHeight=(width, height), height=self._height, resizeToFitChildren=True )

def AttachButton(self, label, width, height):
                ....
...

As you can see I have registered it as a command in maya so if I call

cmds.ui(‘myWindow’, 200, 300)

I can create a window, but because I don’t have any return of the instance from the “doit”, I’m unable to call any inner methods like ‘AttachButton’, ‘AttachTextField’ etc’ Do you guys have some suggestions as to how I would go about calling these methods?

My first thought was just to create a “Global” property of that object, but I run into a whole other set of problems, that I would like to stay away from. Mainly calling static functions for a UI object…

Another thought is to just convert it to c++ on the SDK, has anyone experienced UI with the sdk ‘Not QT’

Thanks in advance!

I’ve not done any UI work through the SDK or the python wrapper.
But most plugins I’ve noticed will ship with some python or mel files to define the UI. Or as you said, do something with QT.

The only chunk of full on non-Qt UI examples I’ve seen from any of the APIs was one of the old .Net examples where you could build the UI with WPF. Not sure if that’s still in the devkit or not, but it was back around 2014ish.

In the example you’ve provided, you can just make your MPXCommand return the string name of your new window using SetResult(). Other commands or scene operations can grab your window that way, and work with it like any other maya window; the string name “is” the window as far as the API is concerned. There’s no other API exposure of the underlying object unless you go through QT and get the QWidget that implements that actual window.

In general, though, Bob’s right: it’s not worth doing this kind of stuff in a plugin: it’s just going to be a more cumbersome and error prone version of doing it in mel or python and the perf gains are basically zero since all the work is really being done by QT anyway

@R.White: Yeah, I come to the realization I have to do it with python, QT is unreal to build… and WPF is out of the question, The reason why I am trying to use this python wrapper is because it’s already done, and, well it’s working. in that case off the top of your head, do you know if it’s possible to create this UI class that can get and set the C++ properties?

@Theodox: PLEASE tell me how I can return a string, I have no idea how I can call any inner functions from my class. All that I know I can do is trigger a “doit” constructor. From my understanding* I was thinking about using a static property to return the window, but this won’t help if I have multiple instances.
Do I just toss ui.SetResult()?!?
This would help me out a lot!

--------------------------EDIT-----------------------------------------------
I did figure it out,
Thanks for your help!
OpenMayaMPx.MPxCommand.clearResult()
OpenMayaMPx.MPxCommand.setResult(self.windowName)

This was perfect man! I had no idea about it!!!