Getting the main window for PyQt

I’m a non-blender user but im going to start doing UI work in it with pyqt. I compiled pyqt against python 3.2 and dropped it in the blender folder. I can bring up a qt widget with the “system” method but ofc then its not parented to the window and it will close the main app on close.

So, Im looking into reproducing the trusty getMayaWindow(). I had a look at some source for the softimage blur pyqt plugin and it does the following. However, my main question is:

Do i really need to go through the trouble of doing all this to get the ptr to themain window since I have all the source? Should i look harder at the source or should I try to imitate blur? Is doing this C step the only way to get a main window?

I went onto the blender forums and didnt find anything - its weird. Its so much better for gui work than regular python. I added it in in about an hour without trouble except for this ptr issue.


def getSoftimageWindow():
    ptr = Application.getQtSoftimageAnchor()
    ptr = sip.wrapinstance(long(ptr), QtGui.QWidget )
    dialog = ExampleDialog(ptr)
    dialog.show()

#include <Windows.h>
#include <xsi_application.h>
#include <xsi_pluginregistrar.h>
#include <xsi_context.h>
#include <xsi_command.h>
#include <xsi_desktop.h>
#include <QWidget>
#include <QApplication>
#include <QEvent>
#include <QKeyEvent>
#include <Qt>

	[B]QWidget * getQtSoftimageAnchor()[/B]
	{
		if (! qApp) {
			xsihandle = (HWND)XSI::Application().GetDesktop().GetApplicationWindowHandle();
			if (! hook)
				hook = SetWindowsHookExW(WH_KEYBOARD, listener, 0, GetCurrentThreadId());
			int argc = 0;
			new QApplication(argc, 0);
		}

		if (! sianchor) {
			sianchor = new QWidget;
			sianchor->setObjectName("QtSoftimageAnchor");
			SetWindowLong((HWND)sianchor->winId(), GWL_STYLE, WS_CHILD);
			SetParent((HWND)sianchor->winId(), xsihandle);
			sianchor->setAttribute(Qt::WA_DeleteOnClose);
		}
		return sianchor;
	}


When you think PyQt. Think Nathan Horne.

http://nathanhorne.com/?p=183

[QUOTE=btribble;18456]When you think PyQt. Think Nathan Horne.[/QUOTE]

Thanks for the link but that eample is dependant on using the maya-specific method MQtUtil to get the main window. Im asking about whether I need to reproduce it in C as well or use a “shortcut” instead since I have access to all the code.

Might be best to ask on the blender dev forum.
But as I understand it, Blender doesn’t use a Qt window (rather they use their own framework)
Essentially all you need is for Blender to give you back a window memory id, but that still may not be enough.

Also I find it weird that you compiled Qt against Py3.2
I thought blender like most apps was in a py2.x version

I believe the current Blender uses 3.2…

Oh, BTW if you are on Windows (you didn’t say), you can use the win32gui module to get a window handle. I have no idea what is required to make this a QT friendly handle if anything. http://docs.activestate.com/activepython/2.4/pywin32/win32gui.html

[QUOTE=dgovil;18460]
Essentially all you need is for Blender to give you back a window memory id, but that still may not be enough.[/QUOTE]

Thanks for the hint. Do you know how to do this in ubuntu?

I have no experience with this stuff in Ubuntu, but I’m decent with Google. Take a look at pyGTK:

http://www.pygtk.org/downloads.html
http://www.daa.com.au/pipermail/pygtk/2002-January/002347.html

(I assume you aren’t running KDE…)

Maybe this might point you in the right direction?
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qx11embedcontainer.html

My brains a little fried after work so I might be sending you up the wrong tree, but it sounds right to me.

Blender doesn’t use Qt. You can make PyQt windows with Blender because it uses python but the interface itself is not written with Qt.

I’m not sure if there’s a way to deal with the window-parenting issues in this case (ie, your tool will go behind the main blender window, probably, but they may have a workaround for this).