From 05aed461ca336ac703c8b445de39632040dd2dd7 Mon Sep 17 00:00:00 2001 From: ymesh Date: Mon, 10 Jun 2013 13:44:16 +0300 Subject: [PATCH] NodeParam new attribute: removable (for removing dynamcally added parameters) --- CHANGES.txt | 6 +- core/nodeParam.py | 6 + core/params/controlParam.py | 3 +- gui/nodeList.py | 4 +- gui/nodeParamView.py | 14 ++ gui/params/paramWidget.py | 55 ++-- lib/nodes/RIB/shaders/ReadShader.xml | 3 + meShaderEd.py | 17 +- samples/shaders/shn/read_shader.xml | 364 ++++++++++++++------------- 9 files changed, 264 insertions(+), 208 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1094db4..cd2af68 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,7 +1,6 @@ - meShaderEd changes log -version 0.3.1 (?? May 2013) +version 0.3.1 (10 Jun 2013) - ControlParam with special section in XML, that allows to execute python code for dynamic parameters manipulation - ShaderInfo class for parsing compiled shaders parameters @@ -9,9 +8,12 @@ version 0.3.1 (?? May 2013) for reloading shader parameters - NodeParam new attributes : enabled, spaceDef, arraySize, defaultArray, valueArray (though arrays parameters support is not fully implemented yet...) + btext (button text for button ControlParam) + removable (for removing dynamcally added parameters) - Fixed some shading nodes, code, shaders and textures for Air, Aqsis, Pixie and RenderDotC compatibility - Tested on PyQt 4.10.2 that was linked with Qt 5.0.2 libraries. - New service nodes in Library + version 0.3.0 (16 Apr 2013) SwatchNode for image preview in shading network diff --git a/core/nodeParam.py b/core/nodeParam.py index e68a963..e63fe79 100644 --- a/core/nodeParam.py +++ b/core/nodeParam.py @@ -37,6 +37,7 @@ def __init__ ( self, xml_param = None, isRibParam = False ) : self.isRibParam = isRibParam self.display = True self.enabled = True + self.removable = False # extra parameter description self.detail = '' # variable, uniform @@ -195,6 +196,10 @@ def parseFromXML ( self, xml_param ) : self.enabled = True if not xml_param.attributes ().namedItem ( 'enabled' ).isNull () : self.enabled = xml_param.attributes ().namedItem ( 'enabled' ).nodeValue () == '1' + + self.removable = False + if not xml_param.attributes ().namedItem ( 'removable' ).isNull () : + self.removable = xml_param.attributes ().namedItem ( 'removable' ).nodeValue () == '1' if not xml_param.attributes ().namedItem ( 'space' ).isNull () : space = str ( xml_param.attributes ().namedItem ( 'space' ).nodeValue () ) @@ -234,6 +239,7 @@ def parseToXML ( self, dom ) : if self.shaderParam : xmlnode.setAttribute ( 'shaderParam', True ) if not self.display : xmlnode.setAttribute ( 'display', False ) if not self.enabled : xmlnode.setAttribute ( 'enabled', False ) + if self.removable : xmlnode.setAttribute ( 'removable', True ) if self.detail != '' : xmlnode.setAttribute ( 'detail', self.detail ) if self.provider != '' : xmlnode.setAttribute ( 'provider', self.provider ) # ui decorative parameters diff --git a/core/params/controlParam.py b/core/params/controlParam.py index 02bcaaa..4739e89 100644 --- a/core/params/controlParam.py +++ b/core/params/controlParam.py @@ -106,7 +106,8 @@ def parseToXML ( self, dom ) : code_text = dom.createTextNode ( self.control_code ) code_tag.appendChild ( code_text ) xmlnode.appendChild ( code_tag ) - if self.btext != '' : xmlnode.setAttribute ( 'btext', self.range ) + + if self.btext != '' : xmlnode.setAttribute ( 'btext', self.btext ) return xmlnode # diff --git a/gui/nodeList.py b/gui/nodeList.py index d16ee65..2ac028f 100644 --- a/gui/nodeList.py +++ b/gui/nodeList.py @@ -18,7 +18,7 @@ from core.node import Node from core.nodeLibrary import NodeLibrary # -# +# NodeList # class NodeList ( QtGui.QWidget ) : # @@ -111,7 +111,7 @@ def showDescription ( self, item ) : description = '' if nodeKind != 'folder' : - if nodeIcon !='' : + if nodeIcon != '' : iconFileName = os.path.join ( os.path.dirname ( str ( nodeFilename ) ), str ( nodeIcon ) ) print str ( iconFileName ) description += '' # width="128" height="128" diff --git a/gui/nodeParamView.py b/gui/nodeParamView.py index 28cfe85..f489ff4 100644 --- a/gui/nodeParamView.py +++ b/gui/nodeParamView.py @@ -109,6 +109,17 @@ def onParamChanged ( self, param ) : print ">> NodeParamView.onParamChanged node = %s param = %s" % ( self.gfxNode.node.label, param.name ) self.emit ( QtCore.SIGNAL ( 'nodeParamChanged' ), self.gfxNode, param ) # .node # + # onParamRemoved + # + def onParamRemoved ( self, param ) : + # + print ">> NodeParamView.onRemoved node = %s param = %s" % ( self.gfxNode.node.label, param.name ) + self.gfxNode.node.removeParam ( param ) + #self.emit ( QtCore.SIGNAL ( 'nodeParamChanged' ), self.gfxNode, param ) # .node + self.disconnectParamSignals () + self.updateGui () + self.connectParamSignals () + # # nodeLabelChanged # def nodeLabelChanged ( self ) : @@ -189,6 +200,9 @@ def updateGui ( self ) : frameLayout.addWidget ( paramWidget ) if not inputParam.enabled : paramWidget.setEnabled ( False ) + + if inputParam.removable : + QtCore.QObject.connect ( paramWidget, QtCore.SIGNAL ( 'nodeParamRemoved' ), self.onParamRemoved ) spacer = QtGui.QSpacerItem ( 20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding ) frameLayout.addItem ( spacer ) diff --git a/gui/params/paramWidget.py b/gui/params/paramWidget.py index 6069191..a9c1c56 100644 --- a/gui/params/paramWidget.py +++ b/gui/params/paramWidget.py @@ -63,7 +63,6 @@ def buildGeneralGui ( self ) : if self.gfxNode is not None : if not self.gfxNode.node.type in INVALID_RSL_PARAM_TYPES : if self.param.provider != 'attribute' : - self.check = QtGui.QCheckBox ( self ) self.check.setMinimumSize ( QtCore.QSize ( UI.CHECK_WIDTH, UI.HEIGHT ) ) self.check.setMaximumSize ( QtCore.QSize ( UI.CHECK_WIDTH, UI.HEIGHT ) ) @@ -76,20 +75,39 @@ def buildGeneralGui ( self ) : else : spacer = QtGui.QSpacerItem ( UI.LT_SPACE, UI.HEIGHT, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum ) self.hl.addItem ( spacer ) - - self.label = QtGui.QLabel ( self ) - font = QtGui.QFont () - font.setBold ( False ) - self.label.setFont ( font ) - - #if self.param.type != 'control' : - self.label.setText ( self.param.label ) - - self.label.setMinimumSize ( QtCore.QSize ( UI.LABEL_WIDTH, UI.HEIGHT ) ) - self.label.setMaximumSize ( QtCore.QSize ( UI.LABEL_WIDTH, UI.HEIGHT ) ) - self.label.setAlignment ( QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter ) - - self.hl.addWidget ( self.label ) + # + # add 'remove' button for removable parameters + # + if self.param.removable : + self.removeButton = QtGui.QToolButton ( self ) + sizePolicy = QtGui.QSizePolicy ( QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed ) + sizePolicy.setHorizontalStretch ( 24 ) + sizePolicy.setVerticalStretch ( 24 ) + sizePolicy.setHeightForWidth ( self.removeButton.sizePolicy().hasHeightForWidth() ) + self.removeButton.setSizePolicy ( sizePolicy ) + self.removeButton.setMaximumSize ( QtCore.QSize ( 24, 24 ) ) + icon1 = QtGui.QIcon() + icon1.addPixmap ( QtGui.QPixmap ( ':/edit_icons/resources/minus.png' ), QtGui.QIcon.Normal, QtGui.QIcon.On ) + self.removeButton.setIcon ( icon1 ) + self.removeButton.setObjectName ( 'removeButton' ) + + QtCore.QObject.connect ( self.removeButton, QtCore.SIGNAL ( 'clicked()' ), self.onRemoveItem ) + + self.hl.addWidget ( self.removeButton ) + + self.label = QtGui.QLabel ( self ) + font = QtGui.QFont () + font.setBold ( False ) + self.label.setFont ( font ) + + #if self.param.type != 'control' : + self.label.setText ( self.param.label ) + + self.label.setMinimumSize ( QtCore.QSize ( UI.LABEL_WIDTH, UI.HEIGHT ) ) + self.label.setMaximumSize ( QtCore.QSize ( UI.LABEL_WIDTH, UI.HEIGHT ) ) + self.label.setAlignment ( QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter ) + + self.hl.addWidget ( self.label ) self.vl.addWidget ( self.gui ) # # onShaderParamChanged @@ -105,4 +123,11 @@ def buildGui ( self ) : # spacer = QtGui.QSpacerItem ( 20, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum ) self.hl.addItem ( spacer ) + + # + # onRemoveItem + # + def onRemoveItem ( self ) : + print '>> ParamWidget( %s ).onRemoveItem ' % self.param.name + self.emit ( QtCore.SIGNAL ( 'nodeParamRemoved' ), self.param ) diff --git a/lib/nodes/RIB/shaders/ReadShader.xml b/lib/nodes/RIB/shaders/ReadShader.xml index 64f909d..1b77ff8 100644 --- a/lib/nodes/RIB/shaders/ReadShader.xml +++ b/lib/nodes/RIB/shaders/ReadShader.xml @@ -26,6 +26,7 @@ if node is not None : lastOutputParamIdx = node.outputParams.index ( lastOutputParam ) print '*** removing input params ***' + while lastInputParamIdx < ( len ( node.inputParams ) - 1 ) : param = node.inputParams.pop () print param.name, param.type @@ -38,12 +39,14 @@ if node is not None : print '*** added input params ***' for param in shaderInfo.inputParams : if param.arraySize is None : + param.removable = True node.addInputParam ( param ) print param.name, param.type print '*** added output params ***' for param in shaderInfo.outputParams : if param.arraySize is None : + param.removable = True node.addOutputParam ( param ) print param.name, param.type diff --git a/meShaderEd.py b/meShaderEd.py index d162f78..de54ed0 100644 --- a/meShaderEd.py +++ b/meShaderEd.py @@ -2,7 +2,7 @@ """ meShaderEd.py - version 0.3.1b (26 Apr 2013) + version 0.3.1 (10 Jun 2013) written by Yuri.Meshalkin (mesh@kpp.kiev.ua) @@ -31,7 +31,7 @@ root = normPath ( sys.path[0] ) -version = '0.3.1b' +version = '0.3.1' app_settings = QtCore.QSettings ( QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, @@ -65,13 +65,11 @@ def getDefaultValue ( settings, group, key ) : defRenderer = setDefaultValue ( 'defRenderer','3Delight' ) app_renderer = meRendererPreset ( os.path.join ( root, 'renderers.xml' ), defRenderer ) #app_renderer.setPresetFile ( os.path.join( root, 'renderers.xml' ), defRenderer ) - -# # +# main routine # -def main (): +def main () : #global root - app = QtGui.QApplication ( sys.argv ) app_settings.setValue ( 'version', version ) @@ -104,7 +102,6 @@ def main (): # setDefaultValue ( 'recent_projects_max', 10 ) setDefaultValue ( 'recent_networks_max', 10 ) - # # setup globals # @@ -150,9 +147,7 @@ def main (): #app_global_vars[ 'RibPath' ] = '' #app_global_vars[ 'DisplayPath' ] = '' - app_settings.beginGroup ( 'WorkArea' ) - #grid_enabled = bool( setDefaultValue( 'grid_enabled', True ).toString() ) grid_enabled = setDefaultValue ( 'grid_enabled', True ) grid_size = int ( setDefaultValue ( 'grid_size', 10 ) ) @@ -170,7 +165,7 @@ def main (): # It's exec_ because exec is a reserved word in Python sys.exit ( app.exec_ () ) # -# +# # if __name__ == "__main__": # @@ -193,4 +188,4 @@ def main (): if QtCore.QT_VERSION < 50000 : QtGui.QApplication.setPalette ( QtGui.QApplication.style ().standardPalette () ) - main() + main () diff --git a/samples/shaders/shn/read_shader.xml b/samples/shaders/shn/read_shader.xml index 6c1847b..dea36dd 100644 --- a/samples/shaders/shn/read_shader.xml +++ b/samples/shaders/shn/read_shader.xml @@ -21,157 +21,6 @@ self.imageName = self.getInputParamValueByName ( 'image' ) - - Read compiled shader - - - -print ":: Hello from (%s) XML control_code !!!" % self.label -if node is not None : - print ":: Node = %s" % node.label - from core.utils.ShaderInfo import ShaderInfo - shaderInfo = ShaderInfo ( node.getInputParamByName ( 'file_name' ).value ) - - print '** shader type = %s' % shaderInfo.type - - node.getInputParamByName ( 'shader_name' ).value = shaderInfo.name - node.getInputParamByName ( 'shader_type' ).value = shaderInfo.type - node.getInputParamByName ( 'rib_shader_type' ).value = node.getRiCallForShaderType ( shaderInfo.type ) - node.getInputParamByName ( 'shader_params' ).value = '' - - lastInputParam = node.getInputParamByName ( 'shader_params' ) - lastOutputParam = node.getOutputParamByName ( 'shader' ) - - lastInputParamIdx = node.inputParams.index ( lastInputParam ) - lastOutputParamIdx = node.outputParams.index ( lastOutputParam ) - - print '*** removing input params ***' - while lastInputParamIdx < ( len ( node.inputParams ) - 1 ) : - param = node.inputParams.pop () - print param.name, param.type - - print '*** removing output params ***' - while lastOutputParamIdx < ( len ( node.outputParams ) - 1 ) : - param = node.outputParams.pop () - print param.name, param.type - - print '*** added input params ***' - for param in shaderInfo.inputParams : - node.addInputParam ( param ) - print param.name, param.type - - print '*** added output params ***' - for param in shaderInfo.outputParams : - node.addOutputParam ( param ) - print param.name, param.type - - node.updateNode () - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 : - self.getInputParamByName ( 'shader_params' ).value = ( ' ' ).join ( ribInputParamsDeclaration ) - - -]]> - - - Basic primitive preview RIB for swatch node @@ -295,6 +144,101 @@ if self.getInputParamByName ( 'BG_surf' ).value == 'stTexture': self.getInputPar ]]> + + Read compiled shader + + + +print ":: Hello from (%s) XML control_code !!!" % self.label +if node is not None : + print ":: Node = %s" % node.label + from core.utils.ShaderInfo import ShaderInfo + shaderInfo = ShaderInfo ( node.getInputParamByName ( 'file_name' ).value ) + + print '** shader type = %s' % shaderInfo.type + + node.getInputParamByName ( 'shader_name' ).value = shaderInfo.name + node.getInputParamByName ( 'shader_type' ).value = shaderInfo.type + node.getInputParamByName ( 'rib_shader_type' ).value = node.getRiCallForShaderType ( shaderInfo.type ) + node.getInputParamByName ( 'shader_params' ).value = '' + + lastInputParam = node.getInputParamByName ( 'shader_params' ) + lastOutputParam = node.getOutputParamByName ( 'shader' ) + + lastInputParamIdx = node.inputParams.index ( lastInputParam ) + lastOutputParamIdx = node.outputParams.index ( lastOutputParam ) + + print '*** removing input params ***' + + while lastInputParamIdx < ( len ( node.inputParams ) - 1 ) : + param = node.inputParams.pop () + print param.name, param.type + + print '*** removing output params ***' + while lastOutputParamIdx < ( len ( node.outputParams ) - 1 ) : + param = node.outputParams.pop () + print param.name, param.type + + print '*** added input params ***' + for param in shaderInfo.inputParams : + if param.arraySize is None : + param.removable = True + node.addInputParam ( param ) + print param.name, param.type + + print '*** added output params ***' + for param in shaderInfo.outputParams : + if param.arraySize is None : + param.removable = True + node.addOutputParam ( param ) + print param.name, param.type + + node.updateNode () + + + + + + + + + + + + + + + + + + + + 0 : + self.getInputParamByName ( 'shader_params' ).value = ( ' ' ).join ( ribInputParamsDeclaration ) + + +]]> + + + Swatch node viewer @@ -314,10 +258,10 @@ self.imageName = self.getInputParamValueByName ( 'image' ) - + Read compiled shader - + print ":: Hello from (%s) XML control_code !!!" % self.label if node is not None : @@ -326,55 +270,121 @@ if node is not None : shaderInfo = ShaderInfo ( node.getInputParamByName ( 'file_name' ).value ) print '** shader type = %s' % shaderInfo.type - + node.getInputParamByName ( 'shader_name' ).value = shaderInfo.name node.getInputParamByName ( 'shader_type' ).value = shaderInfo.type node.getInputParamByName ( 'rib_shader_type' ).value = node.getRiCallForShaderType ( shaderInfo.type ) node.getInputParamByName ( 'shader_params' ).value = '' - + lastInputParam = node.getInputParamByName ( 'shader_params' ) lastOutputParam = node.getOutputParamByName ( 'shader' ) - + lastInputParamIdx = node.inputParams.index ( lastInputParam ) lastOutputParamIdx = node.outputParams.index ( lastOutputParam ) - + print '*** removing input params ***' - while lastInputParamIdx < ( len ( node.inputParams ) - 1 ) : + + while lastInputParamIdx < ( len ( node.inputParams ) - 1 ) : param = node.inputParams.pop () print param.name, param.type - + print '*** removing output params ***' - while lastOutputParamIdx < ( len ( node.outputParams ) - 1 ) : + while lastOutputParamIdx < ( len ( node.outputParams ) - 1 ) : param = node.outputParams.pop () print param.name, param.type - + print '*** added input params ***' for param in shaderInfo.inputParams : - node.addInputParam ( param ) - print param.name, param.type - + if param.arraySize is None : + param.removable = True + node.addInputParam ( param ) + print param.name, param.type + print '*** added output params ***' for param in shaderInfo.outputParams : - node.addOutputParam ( param ) - print param.name, param.type + if param.arraySize is None : + param.removable = True + node.addOutputParam ( param ) + print param.name, param.type node.updateNode () - + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -390,7 +400,7 @@ for i in range ( lastInputParamIdx + 1, len ( self.inputParams ) ) : declStr = self.getParamDeclaration ( self.inputParams [ i ] ) ribInputParamsDeclaration.append ( declStr ) print declStr - + self.getInputParamByName ( 'shader_params' ).value = '' if len ( ribInputParamsDeclaration ) > 0 : self.getInputParamByName ( 'shader_params' ).value = ( ' ' ).join ( ribInputParamsDeclaration ) @@ -402,13 +412,13 @@ if len ( ribInputParamsDeclaration ) > 0 : Opacity [$(Opacity)] $(rib_shader_type) "$(shader_name)" $(shader_params) ]]> - + Basic primitive preview RIB for swatch node - + @@ -420,7 +430,7 @@ if len ( ribInputParamsDeclaration ) > 0 : - + @@ -530,9 +540,9 @@ if self.getInputParamByName ( 'BG_surf' ).value == 'stTexture': self.getInputPar + - + -