MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PySide Window Parented to Motionbuilder Main Window

3 REPLIES 3
Reply
Message 1 of 4
robotProdigy
4010 Views, 3 Replies

PySide Window Parented to Motionbuilder Main Window

Motionbuilder documents a way to put a QWidget into a native Motionbuilder widget holder. This works, but has issues that I would rather not go into at the moment.

 

Another way to build PySide windows is by parenting a QMainWindow or QDialog to motionbuilder’s main Qt window. The code below shows how. Everything seems to work ok except for the fact that once the PySide window is shown, the user can’t select objects in the viewport until he right clicks in the view port first (or selects a menu and cancels).

 

Anyone know a way around this?

 

import sys
from PySide import QtCore, QtGui


class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.resize(200, 100)
        QtCore.QMetaObject.connectSlotsByName(Dialog)


class ControlMainWindow(QtGui.QDialog):
	def __init__(self, parent=None):
		super(ControlMainWindow, self).__init__(parent)
		self.ui =  Ui_Dialog()
		self.ui.setupUi(self)


def _get_dialog_parent():
	"""
	Find the main Motionbuilder window/QWidget.  This
	will be used as the parent for all dialogs created
	by show_modal or show_dialog
	
	:returns: QWidget if found or None if not
	"""
	from PySide import QtGui
	
	# get all top level windows:
	top_level_windows = QtGui.QApplication.topLevelWidgets()
	
	# from this list, find the main application window.
	for w in top_level_windows:
		if (type(w) == QtGui.QWidget        # window is always QWidget 
			and len(w.windowTitle()) > 0    # window always has a title/caption
			and w.parentWidget() == None):  # parent widget is always None
			return w
	return None


mobu_main_window = _get_dialog_parent()
tool_window = ControlMainWindow(mobu_main_window)
tool_window.show()

 

 

Cheers,

Paul

3 REPLIES 3
Message 2 of 4

necro-posting out of morbid curiosity as it seems odd that this has never been solved...

Message 3 of 4

The issue still occurs with PySide2 in Motionbuilder19 😞

Message 4 of 4
Anonymous
in reply to: morten_bohne

This only happen if you launch your tool from the python IDE, if you wrap your tool in a menu it should be fine.  Also it also depends on which type of widget is in UI, Qbutton won't cause this where as a QComboBox will always do it.

 

Again this doesn't happen if you launch from the menu 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report