Discussion:
[Maya-Python] PySide and channelBox customize
Rémi Deletrain
2015-03-13 17:09:28 UTC
Permalink
Hello everyone,

I am trying to change the maya channelBox.
Until now addin PySide window easily.


that is my code:
____________________________________________________________________________________________________________________________________

#===========================================================================
# Import Modules
#===========================================================================
import pymel.core as pmc

from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil


#===========================================================================
# My Channel Box
#===========================================================================
class MyChannelBox(QtGui.QMainWindow):


#=======================================================================
# Init and ui
#=======================================================================
def __init__(self, parent_name=None):

parent_name = wrapInstance(long(MQtUtil.mainWindow()),
QtGui.QWidget)
super(MyChannelBox, self).__init__(parent_name)

self.setFixedSize(300, 500)

# Add Widget
self.__masterWidget = QtGui.QWidget()
self.setCentralWidget(self.__masterWidget)

# Add a layout
self.__masterLayout = QtGui.QVBoxLayout(self)
self.__masterLayout.setContentsMargins(0, 0, 0, 0)
self.__masterLayout.setSpacing(0)
self.__masterWidget.setLayout(self.__masterLayout)

# Add ChannelBox
if not pmc.channelBox('myChanelBox', exists=True):
pmc.channelBox(
'myChanelBox',
width=300,
height=500,
attrColor=(1.0, 0.0, 0.0),
attrBgColor=(1.0, 0.0, 0.0),
)

self.__popup = pmc.popupMenu()
pmc.popupMenu(
self.__popup,
edit=True,
postMenuCommand=lambda *x:
pmc.mel.generateChannelMenu(self.__popup, True)
)

channelBox_widget =
wrapInstance(long(MQtUtil.findControl('myChanelBox')), QtGui.QWidget)
self.__masterLayout.addWidget(channelBox_widget)




def main():

windowIS = MyChannelBox()
channelBox_widget =
wrapInstance(long(MQtUtil.findControl('myChanelBox')), QtGui.QWidget)

windowIS.show()
channelBox_widget.show()

____________________________________________________________________________________________________________________________________



I try to do it in pyside with shiboken wrapInstance and maya.OpenMayaUI. I
can trace the differente widget but not change the items. I wish I could
add icons or change the background color.

Has someone already done this exercise with PySide or other?
The objectif is not to transform the functionalities of the channel box but
just to change a little bit the display for my animator
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0b39a7de-136a-4328-9de8-b1353bc9cb41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Joe Weidenbach
2015-03-13 17:34:45 UTC
Permalink
Generally, it's better to create your own setup than trying to modify
Maya's setup. If you look at Justin's cmivfx videos on PyQt, he
actually creates a replacement for the channel box as part of it, you
could probably use that as a starting point.
Post by Rémi Deletrain
Hello everyone,
I am trying to change the maya channelBox.
Until now addin PySide window easily.
____________________________________________________________________________________________________________________________________
#===========================================================================
# Import Modules
#===========================================================================
import pymel.core as pmc
from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil
#===========================================================================
# My Channel Box
#===========================================================================
#=======================================================================
# Init and ui
#=======================================================================
parent_name = wrapInstance(long(MQtUtil.mainWindow()),
QtGui.QWidget)
super(MyChannelBox, self).__init__(parent_name)
self.setFixedSize(300, 500)
# Add Widget
self.__masterWidget = QtGui.QWidget()
self.setCentralWidget(self.__masterWidget)
# Add a layout
self.__masterLayout = QtGui.QVBoxLayout(self)
self.__masterLayout.setContentsMargins(0, 0, 0, 0)
self.__masterLayout.setSpacing(0)
self.__masterWidget.setLayout(self.__masterLayout)
# Add ChannelBox
pmc.channelBox(
'myChanelBox',
width=300,
height=500,
attrColor=(1.0, 0.0, 0.0),
attrBgColor=(1.0, 0.0, 0.0),
)
self.__popup = pmc.popupMenu()
pmc.popupMenu(
self.__popup,
edit=True,
pmc.mel.generateChannelMenu(self.__popup, True)
)
channelBox_widget =
wrapInstance(long(MQtUtil.findControl('myChanelBox')), QtGui.QWidget)
self.__masterLayout.addWidget(channelBox_widget)
windowIS = MyChannelBox()
channelBox_widget =
wrapInstance(long(MQtUtil.findControl('myChanelBox')), QtGui.QWidget)
windowIS.show()
channelBox_widget.show()
____________________________________________________________________________________________________________________________________
I try to do it in pyside with shiboken wrapInstance and
maya.OpenMayaUI. I can trace the differente widget but not change the
items. I wish I could add icons or change the background color.
Has someone already done this exercise with PySide or other?
The objectif is not to transform the functionalities of the channel
box but just to change a little bit the display for my animator
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/0b39a7de-136a-4328-9de8-b1353bc9cb41%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/0b39a7de-136a-4328-9de8-b1353bc9cb41%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/55031FB5.1000103%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2015-03-13 18:01:29 UTC
Permalink
Not sure I can agree with that, to be honest. In this case, it sounds like
he merely wants to make a quick change to what is already working well; no
need to go implementing things from scratch.

That said, Justin's dvd does a very good job at explaining how you could do
exactly that if you need to.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD8zq0FDGc%2BUSciqpry1k6JrpLWvUcuqWqWm4TY_9jYDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2015-03-13 19:18:58 UTC
Permalink
Maybe others have had a different experience, but I found it to be a bit
dodgy to try and modify builtin widgets of the Maya UI by finding them
through PyQt and operating on them informally. You don't always know when
they will tear them down and rebuild them, or if something will change
between versions. If you can get it working the way you want, great. But it
should kind of be expected that it may not always work reliably.
Post by Marcus Ottosson
Not sure I can agree with that, to be honest. In this case, it sounds like
he merely wants to make a quick change to what is already working well; no
need to go implementing things from scratch.
That said, Justin's dvd does a very good job at explaining how you could
do exactly that if you need to.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD8zq0FDGc%2BUSciqpry1k6JrpLWvUcuqWqWm4TY_9jYDQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD8zq0FDGc%2BUSciqpry1k6JrpLWvUcuqWqWm4TY_9jYDQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1vV0hT93Y4EbDbxejhXqqWAe_eE5sOe4KYzc4nrUBa%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Joe Weidenbach
2015-03-14 19:15:21 UTC
Permalink
Yeah, that's my experience as well. Autodesk seems to like changing
things around :)

I probably worded that poorly, Marcus. I have pulled in Maya elements
in the past, but it's given me nothing but headaches, and in most cases
has ended up being easier to re-implement myself (and would have saved
me time to just do so) than it would have been to try and modify what's
there. I also found that as I got more comfortable with PyQt/PySide, I
was actually limiting myself by trying to just duplicate what Maya
already had. In many cases, I could actually get a nicer solution if I
took the time to think out what I was actually trying to do. There are
some nice things that I've reimplemented almost exactly as time's gone
by (like FrameLayout), but I actually prefer the interface my custom
version gives me over the one that's default in Maya. That's where I
was coming from, I should probably have left out the "Generally" term
and said "in my experience", much like Justin said.

With that said, I still do pull in Maya elements from time to time (the
model panel is an example), mostly for convenience, if I have no
intention of editing whats there, or in the model panel's case, because
I have no desire to implement my own OpenGL or DirectX viewport when
Maya's already giving me that. :)
Post by Justin Israel
Maybe others have had a different experience, but I found it to be a
bit dodgy to try and modify builtin widgets of the Maya UI by finding
them through PyQt and operating on them informally. You don't always
know when they will tear them down and rebuild them, or if something
will change between versions. If you can get it working the way you
want, great. But it should kind of be expected that it may not always
work reliably.
Not sure I can agree with that, to be honest. In this case, it
sounds like he merely wants to make a quick change to what is
already working well; no need to go implementing things from scratch.
That said, Justin's dvd does a very good job at explaining how you
could do exactly that if you need to.
--
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,
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD8zq0FDGc%2BUSciqpry1k6JrpLWvUcuqWqWm4TY_9jYDQ%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD8zq0FDGc%2BUSciqpry1k6JrpLWvUcuqWqWm4TY_9jYDQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1vV0hT93Y4EbDbxejhXqqWAe_eE5sOe4KYzc4nrUBa%2Bw%40mail.gmail.com
<https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1vV0hT93Y4EbDbxejhXqqWAe_eE5sOe4KYzc4nrUBa%2Bw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/550488C9.1090702%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Marcus Ottosson
2015-03-15 11:55:31 UTC
Permalink
Agreed; I was referring to the use of “general” which didn’t feel to be
completely true.

I wish I could add icons or change the background color.

To answer the original question; once you’ve got a reference to the Channel
Box, you can apply a Stylesheet that might give you enough control; though
it’s limited when working with the Channel Box in particular, due to it’s
internal widgets (QTableView using QStyledItemDelegates) not utilising
QPalette or an existing stylesheets but rather calling paint() directly
from which you can’t (?) take control.

As we’ve had similar experiences in this regard, it’d be interesting to see
what your experiences are specifically. Here’s a few nuggets of how I’ve
attempted it, more or less successfully, if you have something to share, I
would be most interested in having a look!

https://gist.github.com/mottosso/1c9846e48f50bfe24408
​
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB9D9euynQ8%3DtrMRe2aPvTi_8%2B6XJ0w1%2B1vTR%3Dwg12uOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Rémi Deletrain
2015-03-16 13:08:54 UTC
Permalink
Thank you for your reply,

I also find that changing the Maya interface is a big fuss. It often start
after each release.
I wanted to try to do that to keep the functionality of the channelBox.
Drag and drop in the view port with the middle click for example, and other
functionality.

I also edited style sheets but the real widget concerned of the channel box
is inaccessible ... I tried many things but nothing there.

I'll watch Justin DVD and see what I can find what I want to do.

I poseterai what I found here
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/591ee90a-1dbd-4826-9c43-b817a8bf0132%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Joe Weidenbach
2015-03-16 20:58:07 UTC
Permalink
Well, I unfortunately don't have any of my old attempts just sitting around
anymore, but I did look over your samples, Marcus, and I found something
interesting:

In the second sample, where you set a new StyledItemDelegate, I did some
debugging on the tree. I've not had time to dive deep yet and find an
answer, but the rowCount() of the model for the found QTableView is showing
as 1 regardless of how many objects are selected or how many attributes are
shown, which indicates to me that we've got some deeper nesting going on
before we can properly assign a different delegate. I tried a findChildren
instead of a findChild, but it only seemed to find the one, which leads me
to wonder if it's not using something other than a QTableView to display.
I looked at the children of the QWidgets in the list, and found a lot more
items, so I'm definitely going to need to spend some time digging deeper
into the widget hierarchy, but I suspect you're trying to style the wrong
item, although it makes perfect sense that it would be a QTableView.

With that said, the delegate in question STILL doesn't seem to be called,
but that could just be due to something else. I did notice that there's a
raw ItemDelegate in the overall structure as well, possibly that has
something to do with it.
Post by Rémi Deletrain
Thank you for your reply,
I also find that changing the Maya interface is a big fuss. It often start
after each release.
I wanted to try to do that to keep the functionality of the channelBox.
Drag and drop in the view port with the middle click for example, and other
functionality.
I also edited style sheets but the real widget concerned of the channel
box is inaccessible ... I tried many things but nothing there.
I'll watch Justin DVD and see what I can find what I want to do.
I poseterai what I found here
--
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
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/591ee90a-1dbd-4826-9c43-b817a8bf0132%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/591ee90a-1dbd-4826-9c43-b817a8bf0132%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM33%3Da6SoXAqxQXPyEL8v8O2ox0OkMW_kuhhaDsMEg6c%3DxOs6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Rémi Deletrain
2015-03-17 08:17:19 UTC
Permalink
De ce que j'ai pu voir la channel Box se trouve dans le premier widget.


avec ce code on peu voir que tout est dans le premier Widget.
---------------------------------------------------------------------------------------------------------------
from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil


channelbox = wrapInstance(long(MQtUtil.findControl('mainChannelBox')),
QtGui.QWidget)
channelbox_children = channelbox.children()

first_widget = channelbox_children[0]
first_widget.hide()
---------------------------------------------------------------------------------------------------------------


To review the channelbox
---------------------------------------------------------------------------------------------------------------
first_widget.show()
---------------------------------------------------------------------------------------------------------------


If we use this code we see that is in the right widget:
---------------------------------------------------------------------------------------------------------------
new_button = QtGui.QPushButton()
new_layout = QtGui.QVBoxLayout()
first_widget.setLayout(new_layout)
new_layout.addWidget(new_button)

new_button.clicked.connect(print_hodor)

def print_hodor():
print 'HODOR'
---------------------------------------------------------------------------------------------------------------
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/22532216-3880-456c-ba7d-fc707babe148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rémi Deletrain
2015-03-17 08:20:40 UTC
Permalink
oups.....

the first line in english:
From what I could see the Channel Box is in the first widget.
with this code we just see that everything is in the first Widget.



But it was after I came not to enter following the widget layout and other
elements pyside
Post by Rémi Deletrain
De ce que j'ai pu voir la channel Box se trouve dans le premier widget.
avec ce code on peu voir que tout est dans le premier Widget.
---------------------------------------------------------------------------------------------------------------
from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya.OpenMayaUI import MQtUtil
channelbox = wrapInstance(long(MQtUtil.findControl('mainChannelBox')),
QtGui.QWidget)
channelbox_children = channelbox.children()
first_widget = channelbox_children[0]
first_widget.hide()
---------------------------------------------------------------------------------------------------------------
To review the channelbox
---------------------------------------------------------------------------------------------------------------
first_widget.show()
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
new_button = QtGui.QPushButton()
new_layout = QtGui.QVBoxLayout()
first_widget.setLayout(new_layout)
new_layout.addWidget(new_button)
new_button.clicked.connect(print_hodor)
print 'HODOR'
---------------------------------------------------------------------------------------------------------------
--
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_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9eb88f93-fda7-425a-8ba9-772042a2c990%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...