Hi,
You know how the save dialog locks up the Maya UI and only allows you to interact with the save dialog… do you know how can this be achieved when loading up a custom PySide window?
I’m doing this at the moment, which makes sure that the custom ui stays on top of Maya, but it doesn’t lock up the main Maya window in the same way the save dialog does:
from PySide import QtGui
class MyApp(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyApp, self).__init__(parent)
self.centralWidget = QtGui.QWidget(self)
self.setCentralWidget(self.centralWidget)
self.mainLayout=QtGui.QVBoxLayout(self.centralWidget)
self.list_widget = QtGui.QListWidget()
self.mainLayout.addWidget(self.list_widget)
my_app = MyApp( parent=QtGui.QApplication.activeWindow() )
my_app.show()
Cheers,
Fredrik
Hi Fredrik,
This behaviour is called “modality”. Have a look here:
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWMVD1vAj3pyJLBEjmNRm0R5p5%2BuaTDzxD7oOEW%3D0MvfgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
You can either set the modality setting as Marcus mentioned, or you can use exec_() instead of show() which automatically does a modal window and also blocks on the call until it is accepted or rejected.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB7%2BT%2By%2BnHu%2BwDTetFpa_6YSJempYLPmwC_yYSYmoXzQw%40mail.gmail.com.
I use this:
"""This Is A Template Of PySide Programs In Maya"""
from PySide.QtCore import *
from PySide.QtGui import *
from maya import OpenMayaUI
from maya import cmds
import shiboken
class Window(QDialog):
"""docstring for Window"""
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
# custom code here
self.resize(500, 500)
def getMainWindow():
ptr = OpenMayaUI.MQtUtil.mainWindow()
mainWin = shiboken.wrapInstance(long(ptr), QMainWindow)
return mainWin
def show():
win = Window(parent = getMainWindow())
win.show()
win.raise_()
show()
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2vqmBwbSR6v95WSSkhEkv7Ua%2BhLRbg%3D%2B%2BCbqKGEN3WDQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWOednuVD8LBLOe0h%2BJGYn5HQ4p3e2UNuR7uf1XxU%2BdvXQ%40mail.gmail.com.
Guys, I was wrong (again). You can set a QMainWindow to modal using setWindowModality(). The code below works for me in Maya:
class MyApp(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyApp, self).__init__(parent)
self.centralWidget = QtGui.QWidget(self)
self.setCentralWidget(self.centralWidget)
self.mainLayout=QtGui.QVBoxLayout(self.centralWidget)
self.list_widget = QtGui.QListWidget()
self.mainLayout.addWidget(self.list_widget)
my_app = MyApp( parent=QtGui.QApplication.activeWindow() )
my_app.setWindowModality(QtCore.Qt.WindowModal)
my_app.show()
The difference here is that exec_(), as mentioned by Justin, will block until the window closes. Can be useful if you expect results from a window, such as in a save-dialog returning a path. However I think exec_ is only available on QDialog subclasses.
What’s that QtGui.QApplication.activeWindow() you’ve got there? Is that an alternative to getting the shiboken handle, as in Mahmood’s example?
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWMKmYNAy3CpUtPnmA_T5HSv3TJ02j4iQmNy8uN0Q7JnYA%40mail.gmail.com.
The difference here is that
exec_(), as mentioned by Justin, will block until the window closes. Can be useful if you expect results from a window, such as in a save-dialog returning a path. However I thinkexec_is only available on QDialog subclasses.
Ah yes. In my particular case, I don’t need that - so I was very happy to find this setWindowModality() solution. I may be wrong here but I also think exec_() available for QtGui.QWidget.
What’s that
QtGui.QApplication.activeWindow()you’ve got there? Is that an alternative to getting the shiboken handle, as in Mahmood’s example?
It was something I came by over at stackoverflow… works great for me in both Maya and Nuke (PySide), returns the active Maya window.
http://qt-project.org/doc/qt-4.8/qapplication.html#activeWindow
It was something I came by over at stackoverflow… works great for me in both Maya and Nuke (PySide), returns the active Maya window.
http://qt-project.org/doc/qt-4.8/qapplication.html#activeWindow
Then it looks like you just stumbled upon a holy grail. :) Fetching this handle has always been a PITA and this looks simple and logical. Will be trying this out next. Thanks!
I may be wrong here but I also think exec_() available for QtGui.QWidget.
You can see everything it supports here:
http://qt-project.org/doc/qt-4.8/qwidget-members.html
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWN5_aszKM3w4i%3D4%2Bazk8EqS18c8AOaK5vBtTdzUReULaw%40mail.gmail.com.
Then it looks like you just stumbled upon a holy grail. :) Fetching this handle has always been a PITA and this looks simple and logical. Will be trying this out next. Thanks!
I may be wrong here but I also think exec_() available for QtGui.QWidget.
You can see everything it supports here:
http://qt-project.org/doc/qt-4.8/qwidget-members.htm
That’s brilliant, Fredrik.
I did some tests and it looks like it’s returning the currently active window (duh!), which in the case of running from the Script Editor is the Script Editor window. Not sure it has any repercussions and shouldn’t be an issue when not running from the Script Editor.
However, I also tried this.
from PySide import QtGui
# Returns the Script Editor, sometimes.
window = QtGui.QApplication.activeWindow()
assert window.objectName() == 'scriptEditorPanel1Window'
# Returns the Maya Window, for sure
widgets = dict((w.objectName(), w) for w in QtGui.QApplication.allWidgets())
window = widgets['MayaWindow']
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNV2JDE%3DDxZ1GjjYmYaKsuuTaJCEjsQfXLwud5QgkNAWg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAw_CeoaX3KCrp%3DufRJ5yh%2B3HzUMLyC0y2T%3Dk%2BgZNF_ag%40mail.gmail.com.
QApplication.topLevelWidgets()
Perfect, looks great to me. Why go through a PySide/PyQt-dependent extra layer of shiboken/sip wrapping when you could do this? And don’t tell me it’s for performance, as this is a one-off. ;)
After all, looping through allWidgets() takes ~0.018 seconds.
start = time.time()
dict((w.objectName(), w) for w in QtGui.QApplication.allWidgets())
print time.time() - start
Whereas topLevelWidgets() takes ~0.002 seconds.
start = time.time()
dict((w.objectName(), w) for w in QtGui.QApplication.topLevelWidgets())
print time.time() - start
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3MbMv50%3DWRqjCTX%2BQ96O-MLvG0xaCAE4rjEeb-yQf7cA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODQYJfEDQOkAL1K%2BUQQ3eCwaLy4ZsChEsCPEtC%3DYO8%2BXw%40mail.gmail.com.
That’s a good point. I suppose the API is less likely to change, than the objectName of the Maya window, which might even have that name set by coincidence as many of Maya’s other widgets don’t have any namy, as can be seen by the allWidgets() command.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3Xk8kOoHZumsZ%2BRJe7sQzJupMFhWOygBoAJEgNFOH3AA%40mail.gmail.com.
I second that you should ask the API if you are not 100% certain from where you are launching the UI. I know for a fact that this application I’m developing can only be launched from the Maya/Nuke file menus (or the Maya shelf) by the user. So in this case, it works fine to set the parent of my UI to QtGui.QApplication.activeWindow().
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODW0TQ4D%2B_CvN9gwpKnUQbkwvi27W%2BqSsVMAnbi2d6NeQ%40mail.gmail.com.
I know for a fact that this application I’m developing can only be launched from the Maya/Nuke file menus (or the Maya shelf) by the user.
Until someone would like to extend your tool and try to script it. :) I’d be careful, this is how tight-coupling is born.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNDR7mgeQN%2BP7%2BR8R9LDdF56oaDRtAvscFQ6yFPdHLa_Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCTnDUrwLNP6p6N1GhFo6zib97GfMYH8h8HPZTR_bQizw%40mail.gmail.com.
Hm. That makes sense. I might revise that code, but any modal dialogs that open up from it, I probably won't change.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPNomDEFvnS9AxzXR_zZVtnJB9XTHdxsxb5-Zn%2BnMEZsA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWPO6ob%2BvQFCe7x88EmL0bVWUcUt8MikVCxq5FT%2BoYXPxA%40mail.gmail.com.