wrapping ramp parameter in Qt interface

wrapping ramp parameter in Qt interface

Anonymous
Not applicable
1,810 Views
7 Replies
Message 1 of 8

wrapping ramp parameter in Qt interface

Anonymous
Not applicable

This code shows my ramp parameter, but if I uncomment out the show line at the end and comment out the "self.w.show()" inside the class definition I get an empty box without the ramp. Basically,  can create a ramp parameter but not get it "out" from the class defenition. Is there something wrong with how I define the window?

 

from PySide.QtCore import *
from PySide.QtGui import *
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin
import pymel.core as pm
from maya import cmds
from maya import OpenMayaUI as omui
import shiboken


class dice_objectScatter(MayaQWidgetBaseMixin, QTreeView):
def __init__(self, parent=None, *args, **kwargs):
super(dice_objectScatter, self).__init__(*args, **kwargs)

# Destroy this widget when closed. Otherwise it will stay around
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.setupUi()

def setupUi(self):
self.setObjectName("Form")
self.resize(400, 400)
self.setWindowTitle("ramp test")
self.verticalLayout = QVBoxLayout(self)
self.setLayout(self.verticalLayout)
self.verticalLayout.setObjectName("mainLayout")
layout = omui.MQtUtil.fullName(long(shiboken.getCppPointer(self.verticalLayout)[0])) # get maya pointer
cmds.setParent(layout)
self.w = QWidget()
rampWidgetName = "rampWidget3"
self.w.setObjectName(rampWidgetName)
self.l = QVBoxLayout(self.w)
self.l.setObjectName("ramp_layout")
self.w_ptr = omui.MQtUtil.findWindow(rampWidgetName)
self.w_name = omui.MQtUtil.fullName(long(self.w_ptr))
cmds.setParent(self.w_name)
self.ramp_eval_string = 'source AEaddRampControl; AEmakeLargeRamp("|rampTest1.houdiniAssetParm_ramp__ramp", 0, 0, 0, 0, 0);'
mel.eval(self.ramp_eval_string)
self.w.show()

 

ptr = omui.MQtUtil.mainWindow()
mainWin = shiboken.wrapInstance(long(ptr), QWidget)
window = dice_objectScatter()
#window.show()

 

0 Likes
Accepted solutions (1)
1,811 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

Solved. Not sure how, nothing different in my working code. Probably path collision to  some old widget. 

0 Likes
Message 3 of 8

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

There are several errors in your code.

 

1.AE*ramp work with node

2.You should add ramp after window is created.

 

gradientControlNoAttr  is the MEL command for creating ramp controls.

 

Here is an updated version:

 

from PySide.QtCore import *
from PySide.QtGui import *
from maya.app.general.mayaMixin import MayaQWidgetBaseMixin
import pymel.core as pm
from maya import cmds
from maya import OpenMayaUI as omui
import shiboken

class dice_objectScatter(MayaQWidgetBaseMixin, QTreeView):
		def __init__(self, parent=None, *args, **kwargs):
				super(dice_objectScatter, self).__init__(*args, **kwargs)
				# Destroy this widget when closed. Otherwise it will stay around
				self.setAttribute(Qt.WA_DeleteOnClose, True)
				self.setupUi()

		def setupUi(self):
				self.setObjectName("Form")
				self.resize(400, 400)
				self.setWindowTitle("ramp test")
				self.verticalLayout = QVBoxLayout()
				self.verticalLayout.setObjectName("mainLayout")

				self.w = QWidget(self)
				rampWidgetName = "rampWidget3"
				self.w.setObjectName(rampWidgetName)
				self.l = QVBoxLayout()
				self.l.setObjectName("ramp_layout")				
				self.w.setLayout(self.l)
				self.w.resize(400,400)
			
				self.verticalLayout.addWidget(self.w)
				self.setLayout(self.verticalLayout)

	
                
 
ptr = omui.MQtUtil.mainWindow()
mainWin = shiboken.wrapInstance(long(ptr), QWidget)
window = dice_objectScatter()
window.show()

#Please notice the fullname is not Form|mainLayout|ramp_layout here. Adding a control to desired layout and use MQtUtil::findControl could get you correct path. cmds.setParent('Form|mainLayout|ramp_layout') ramp_eval_string = """gradientControlNoAttr -h 90 falloffCurve5; gradientControlNoAttr -e -optionVar "falloffCurveOptionVar" falloffCurve5;""" mel.eval(ramp_eval_string)

Yours,

Li

0 Likes
Message 4 of 8

Anonymous
Not applicable

Nice one! Really appreciate the clean up and style directions. 

 

Shouldn't I pass the name to the attribute I want to control? What I'm doing here is wrapping an existing node to a custom GUI. 

 

How come I have to display them before populating them? Haven't seen anything on this in the docs. 

0 Likes
Message 5 of 8

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I was thinking about you are trying to add a maya ramp control into a custom widget window. So it should be displayed first.

 

Since you are adding to a node, i think using nodename with that AE*Ramp command should be all right.

 

Yours,

Li

 

0 Likes
Message 6 of 8

Anonymous
Not applicable

No you were correct initally, it is for a custom widget but I'm linking it to the node's ramp parameter which I get from this AE command. Not sure if I should skip this intermediate AE step and create a ramp myself and hook it to the node directly?

0 Likes
Message 7 of 8

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I think if you could make AE work it should be simpler, because it should be linked to node already. 

 

Actually there is an attribute version named just gradientControl. You may also want to check it out.

 

Yours,

Li

0 Likes
Message 8 of 8

Anonymous
Not applicable
Will do! Thanks again Li.
0 Likes