Skip to content

Commit

Permalink
PlugValueWidget : Remove registerCreator() method
Browse files Browse the repository at this point in the history
This has been deprecated for almost 3 years, and recent improvements in metadata matching should have rendered it totally unnecessary. This removes one of the main hurdles in completing GafferHQ#707.

Breaking Change :

- Removed `PlugValueWidget.registerCreator()`. Use metadata instead.
  • Loading branch information
johnhaddon committed Apr 6, 2018
1 parent 654fae6 commit 53e8b5a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 108 deletions.
7 changes: 1 addition & 6 deletions python/GafferCortexUI/ObjectWriterUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,14 @@
""",

"nodule:type", "",
"plugValueWidget:type", "GafferCortexUI.ObjectWriterUI.__createParameterWidget",

],

}

)

##########################################################################
# PlugValueWidgets
##########################################################################

def __createParameterWidget( plug ) :

return GafferCortexUI.CompoundParameterValueWidget( plug.node().parameterHandler(), collapsible=False )

GafferUI.PlugValueWidget.registerCreator( GafferCortex.ObjectWriter, "parameters", __createParameterWidget )
56 changes: 0 additions & 56 deletions python/GafferUI/BoxUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,62 +194,6 @@ def __upgradeToUseBoxIO( node ) :
with Gaffer.UndoScope( node.scriptNode() ) :
Gaffer.BoxIO.insert( node )

# PlugValueWidget registrations
##########################################################################

GafferUI.PlugValueWidget.registerCreator( Gaffer.Box, re.compile( "in[0-9]*" ), None )
GafferUI.PlugValueWidget.registerCreator( Gaffer.Box, re.compile( "out[0-9]*" ), None )

def __correspondingInternalPlug( plug ) :

node = plug.node()
if plug.direction() == plug.Direction.In :
for output in plug.outputs() :
if node.isAncestorOf( output.node() ) :
return output
elif plug.direction() == plug.Direction.Out :
input = plug.getInput()
if input is not None and node.isAncestorOf( input.node() ) :
return input

return None

def __plugValueWidgetCreator( plug ) :

# When a plug has been promoted, we get the widget that would
# have been used to represent the internal plug, and then
# call setPlug() with the external plug. This allows us to
# transfer custom uis from inside the node to outside the node.
#
# But If the types don't match, we can't expect the
# UI for the internal plug to work with the external
# plug. Typically the types will match, because the
# external plug was created by PlugAlgo.promote(), but
# it's possible to use scripting to connect different
# types, for instance to drive an internal IntPlug with
# an external BoolPlug. In this case we make no attempt
# to transfer the internal UI.
#
# \todo A better solution may be to mandate the use of Metadata to
# choose a widget type for each plug, and then just make sure we
# pass on the internal Metadata.
internalPlug = __correspondingInternalPlug( plug )
if type( internalPlug ) is type( plug ) :
widget = GafferUI.PlugValueWidget.create( internalPlug )
if widget is not None :
widget.setPlug( plug )
return widget

return GafferUI.PlugValueWidget.create( plug, useTypeOnly=True )

## \todo We're registering the Box PlugValueWidget creator for the Reference node too, because
# we want the two to have the same appearance. We perhaps should just have one registration for
# the SubGraph (the base class for Box and Reference) instead, but it's not yet totally clear
# whether or not we'll have future SubGraph subclasses that will want a different behaviour.
for nodeType in ( Gaffer.Box, Gaffer.Reference ) :

GafferUI.PlugValueWidget.registerCreator( nodeType, "*" , __plugValueWidgetCreator )

# Shared menu code
##########################################################################

Expand Down
48 changes: 2 additions & 46 deletions python/GafferUI/PlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
#
##########################################################################

import re
import fnmatch
import functools
import warnings

Expand Down Expand Up @@ -364,9 +362,8 @@ def popupMenuSignal( cls ) :
# "plugValueWidget:type" metadata value, specifying the fully qualified
# python type name for a widget class. To suppress the creation of a widget,
# a value of "" may be registered - in this case None will be returned from
# create(). If useTypeOnly is True, then custom registrations made by
# registerCreator() will be ignored and only the plug type will be taken into
# account in creating a PlugValueWidget.
# create(). If useTypeOnly is True, then the metadata will be ignored and
# only the plug type will be taken into account in creating a PlugValueWidget.
@classmethod
def create( cls, plug, useTypeOnly=False ) :

Expand All @@ -390,20 +387,6 @@ def create( cls, plug, useTypeOnly=False ) :
widgetClass = getattr( widgetClass, n )
return widgetClass( plug )

node = plug.node()
if node is not None :
plugPath = plug.relativeName( node )
nodeHierarchy = IECore.RunTimeTyped.baseTypeIds( node.typeId() )
for nodeTypeId in [ node.typeId() ] + nodeHierarchy :
creators = cls.__nodeTypesToCreators.get( nodeTypeId, None )
if creators :
for creator in creators :
if creator.plugPathMatcher.match( plugPath ) :
if creator.creator is not None :
return creator.creator( plug, **(creator.creatorKeywordArgs) )
else :
return None

# if that failed, then just create something based on the type of the plug
typeId = plug.typeId()
for plugTypeId in [ plug.typeId() ] + IECore.RunTimeTyped.baseTypeIds( plug.typeId() ) :
Expand All @@ -427,34 +410,7 @@ def registerType( cls, plugClassOrTypeId, creator ) :

cls.__plugTypesToCreators[plugTypeId] = creator

## \deprecated
## \todo Use "plugValueWidget:type" metadata everywhere instead of
# using this. Then remove this method.
@classmethod
def registerCreator( cls, nodeClassOrTypeId, plugPath, creator, **creatorKeywordArgs ) :

if isinstance( nodeClassOrTypeId, IECore.TypeId ) :
nodeTypeId = nodeClassOrTypeId
else :
nodeTypeId = nodeClassOrTypeId.staticTypeId()

if isinstance( plugPath, basestring ) :
plugPath = re.compile( fnmatch.translate( plugPath ) )
else :
assert( type( plugPath ) is type( re.compile( "" ) ) )

creators = cls.__nodeTypesToCreators.setdefault( nodeTypeId, [] )

creator = IECore.Struct(
plugPathMatcher = plugPath,
creator = creator,
creatorKeywordArgs = creatorKeywordArgs,
)

creators.insert( 0, creator )

__plugTypesToCreators = {}
__nodeTypesToCreators = {}

def __plugDirtied( self, plug ) :

Expand Down

0 comments on commit 53e8b5a

Please sign in to comment.