PySide and channelBox customize

429 views
Skip to first unread message

Rémi Deletrain

unread,
Mar 13, 2015, 1:09:28 PM3/13/15
to python_in...@googlegroups.com
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

Joe Weidenbach

unread,
Mar 13, 2015, 1:35:24 PM3/13/15
to python_in...@googlegroups.com
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.
--
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/0b39a7de-136a-4328-9de8-b1353bc9cb41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




This email is free from viruses and malware because avast! Antivirus protection is active.


Marcus Ottosson

unread,
Mar 13, 2015, 2:01:35 PM3/13/15
to python_in...@googlegroups.com
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.

Justin Israel

unread,
Mar 13, 2015, 3:19:04 PM3/13/15
to python_in...@googlegroups.com

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.


On Sat, 14 Mar 2015 7:01 AM Marcus Ottosson <konstr...@gmail.com> wrote:
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_m...@googlegroups.com.

Joe Weidenbach

unread,
Mar 14, 2015, 3:16:10 PM3/14/15
to python_in...@googlegroups.com
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. :)

For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Mar 15, 2015, 7:55:39 AM3/15/15
to python_in...@googlegroups.com

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

Rémi Deletrain

unread,
Mar 16, 2015, 9:08:54 AM3/16/15
to python_in...@googlegroups.com
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

Joe Weidenbach

unread,
Mar 16, 2015, 4:58:14 PM3/16/15
to python_in...@googlegroups.com
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.

--
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.

Rémi Deletrain

unread,
Mar 17, 2015, 4:17:19 AM3/17/15
to python_in...@googlegroups.com
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'
---------------------------------------------------------------------------------------------------------------

Rémi Deletrain

unread,
Mar 17, 2015, 4:20:40 AM3/17/15
to python_in...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages