--
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/e0d9289e-4208-44f4-8e6d-15a74125c401%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import random
class MainWin(QtGui.QMainWindow):
def __init__(self):
super(MainWin, self).__init__()
prev = None
for i in xrange(5):
d = QtGui.QDockWidget("Dock %d" % i, self)
self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, d)
if prev:
self.tabifyDockWidget(prev, d)
prev = d
t = QtCore.QTimer(self)
t.timeout.connect(self.randomTab)
t.start(2000)
def randomTab(self):
a, b = random.sample(self.findChildren(QtGui.QDockWidget), 2)
print "Setting %s over %s" % (b.windowTitle(), a.windowTitle())
self.tabifyDockWidget(a, b)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpymBonZFOtmvmGNjsf%3Dpc4FYt_WihLZh3SvrE6hjKSLaw%40mail.gmail.com.
def createPopupMenu(self):
pass
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2iz%3DbPvY8x38iQ5zCyUkSg7UTk4htkbSfYcLjWALSAeA%40mail.gmail.com.
Thanks Justin. I didn't realize that I could use that same method!
I have a couple of questions:
- Do you know if there is a way to get the results of self.findChildren(QtGui.QDockWidget) in order of visual appearance? I'm not sure what's defining the order in which they appear but they seem to be different every tme that I select one of the Docks. Ideally, I'd like to get the current Dock and know which docks I have to each side to determine if I can/should use self.tabifyDocWidget().
- When I right click on the title of a Dock, it triggers a menu. This menu is also shared with toolbars to define what's visible and whatnot. Ideally I want to have different menus depending on which is the item in which I right click. I've been able to get rid of the menu by using the following in my QMainWindow:
def createPopupMenu(self):
passDoes that mean that I will need to overload this method, check what's under the cursor and depending on that, create the menu? Or is there another way to do this?
aDock.installEventFilter(self)
...
def eventFilter(self, obj, event):
if event.type() == event.ContextMenu and isinstance(obj, QtGui.QDockWidget):
print "Show menu for", obj.windowTitle()
event.accept()
return True
return False
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpwqh8Y5D2n-ZxrdZdEF3tmm1ZjmjXiz4O6BDRr%3DGh%2BPgw%40mail.gmail.com.
The context menu event bubbles up to the main window by default. But if you want custom context menus for each QDockWidget, then you just need to implement it in either contextMenuEvent() on the dock widget, or via an event filter:aDock.installEventFilter(self) ... def eventFilter(self, obj, event): if event.type() == event.ContextMenu and isinstance(obj, QtGui.QDockWidget): print "Show menu for", obj.windowTitle() event.accept() return True return False
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA09B8DLCFd6gERZngJOZ4-g9O_PrR9mRDfEX7YheTn9jQ%40mail.gmail.com.
class Dock(QtGui.QDockWidget):
def eventFilter(self, obj, event):
if event.type() == event.ContextMenu:
# Let the widget do whatever it wants
obj.contextMenuEvent(event)
# But ensure the result is an accepted event
# to prevent it from bubbling up.
event.accept()
# Don't redeliver the event
return True
return False
def setWidget(self, widget):
super(Dock, self).setWidget(widget)
widget.installEventFilter(self)
def contextMenuEvent(self, event):
event.accept()
print "Context menu for", self.windowTitle()
# Either do the context menu right here..
# Or emit a custom signal, and let another object
# like the main window parent create the menus
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpzc44yYggacUL9KiZdtR88GJAizaq6Z4Luvg%3DnhRX9Cow%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2n_Y9G%2Bx7EjJmDZb2N%3D%3DCkfvBFJT-yigg6aGK6zsrmLg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpyZo_BnQv5J_WGnxXS0D%2BJssFP2-9x0DeRFS8SNk2L8hw%40mail.gmail.com.