Skip to content

Commit

Permalink
Merge pull request #5976 from ivanimanishi/plugValueWidgetMethodDepre…
Browse files Browse the repository at this point in the history
…cation

GafferCortexUI : Adapt to new PlugValueWidget API
  • Loading branch information
johnhaddon authored Jul 30, 2024
2 parents 7bf265c + 6134e34 commit b14fa99
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Fixes
- PrimitiveInspector : Fixed failure to update when the location being viewed ceases to exist, or is recreated.
- Shuffle, ShuffleAttributes, ShufflePrimitiveVariables : Fixed some special cases where shuffling a source to itself would fail to have the expected effect.
- GraphEditor : Fixed dimming of labels for BoxIn and BoxOut nodes.
- GafferCortexUI : Removed usage of legacy PlugValueWidget API.

API
---
Expand Down
4 changes: 1 addition & 3 deletions python/GafferCortexUI/CompoundPlugValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def __init__( self, plug, collapsed=True, label=None, summary=None, **kw ) :

self.__summary = summary

CompoundPlugValueWidget._updateFromPlug( self )

## Returns a PlugValueWidget representing the specified child plug.
def childPlugValueWidget( self, childPlug ) :

Expand All @@ -126,7 +124,7 @@ def hasLabel( self ) :

return True

def _updateFromPlug( self ) :
def _updateFromValues( self, values, exception ) :

if self.__summary is not None and self.__collapsible is not None :
with self.getContext() :
Expand Down
35 changes: 16 additions & 19 deletions python/GafferCortexUI/CompoundVectorParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import GafferUI
import GafferCortexUI

from GafferUI.PlugValueWidget import sole

## Supported userData entries :
#
# ["UI"]["sizeEditable"]
Expand Down Expand Up @@ -98,7 +100,7 @@ def _headerWidget( self ) :
self.__vectorDataWidget.editSignal().connect( Gaffer.WeakMethod( self.__edit ), scoped = False )
self.__vectorDataWidget.dataChangedSignal().connect( Gaffer.WeakMethod( self.__dataChanged ), scoped = False )

self._updateFromPlug()
self._requestUpdateFromValues()

return self.__vectorDataWidget

Expand All @@ -108,30 +110,25 @@ def _childPlugs( self ) :
# need any plug widgets made by the base class.
return []

def _updateFromPlug( self ) :
@staticmethod
def _valuesForUpdate( plugs, auxiliaryPlugs ) :

result = []
for plug in plugs :
data = [ childPlug.getValue() for childPlug in plug.children() ]
result.append( data )

GafferCortexUI.CompoundParameterValueWidget._PlugValueWidget._updateFromPlug( self )
return result

def _updateFromValues( self, values, exception ) :

if self.__vectorDataWidget is None:
return

data = []
for plug in self._parameterHandler().plug().children() :
plugData = plug.getValue()
if len( data ) and len( plugData ) != len( data[0] ) :
# in __dataChanged we have to update the child plug values
# one at a time. when adding or removing rows, this means that the
# columns will have differing lengths until the last plug
# has been set. in this case we shortcut ourselves, and wait
# for the final plug to be set before updating the VectorDataWidget.
# \todo Now dirty propagation is batched via the UndoScope,
# we should remove this workaround, since _updateFromPlug()
# will only be called when the plug is in a valid state.
return
data.append( plugData )

data = sole( values ) or []
self.__vectorDataWidget.setData( data )
self.__vectorDataWidget.setEditable( self._editable() )
self.__vectorDataWidget.setErrored( exception is not None )

for columnIndex, childParameter in enumerate( self._parameter().values() ) :

Expand Down Expand Up @@ -163,7 +160,7 @@ def __dataChanged( self, vectorDataWidget ) :

data = vectorDataWidget.getData()

with Gaffer.Signals.BlockedConnection( self._plugConnections() ) :
with self._blockedUpdateFromValues() :
with Gaffer.UndoScope( self.getPlug().ancestor( Gaffer.ScriptNode ) ) :
for d, p in zip( data, self._parameterHandler().plug().children() ) :
p.setValue( d )
Expand Down
10 changes: 6 additions & 4 deletions python/GafferCortexUI/DateTimeParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
#
##########################################################################

import datetime

import IECore

import Gaffer
import GafferUI
import GafferCortexUI

from GafferUI.PlugValueWidget import sole

from Qt import QtCore
from Qt import QtGui
from Qt import QtWidgets
Expand Down Expand Up @@ -75,13 +79,11 @@ def __init__( self, plug, **kw ) :

self._addPopupMenu()

self._updateFromPlug()

def _updateFromPlug( self ) :
def _updateFromValues( self, values, exception ) :

# convert from the undelimited form boost likes (and the DateTimeParameterHandler uses)
# to the delimited form qt likes
undelimited = self.getPlug().getValue()
undelimited = sole( values ) or datetime.datetime.utcfromtimestamp( 0 ).strftime( "%Y%m%dT%H%M%S.%fZ" )
delimited = "%s-%s-%sT%s:%s:%s" % (
undelimited[0:4],
undelimited[4:6],
Expand Down
9 changes: 5 additions & 4 deletions python/GafferCortexUI/PresetsOnlyParameterValueWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,23 @@ def __init__( self, parameterHandler, **kw ) :
GafferUI.PlugValueWidget.__init__( self, self.__menuButton, self.__parameterHandler.plug(), **kw )

self._addPopupMenu( self.__menuButton )
self._updateFromPlug()

def _updateFromPlug( self ) :
def _updateFromValues( self, values, exception ) :

with self.getContext() :
self.__parameterHandler.setParameterValue()

self.__menuButton.setEnabled( self._editable() )

text = ""
if self.getPlug() is not None :
with self.getContext() :
text = self.__parameterHandler.parameter().getCurrentPresetName() or "Invalid"

self.__menuButton.setText( text )

def _updateFromEditable( self ) :

self.__menuButton.setEnabled( self._editable() )

def __menuDefinition( self ) :

result = IECore.MenuDefinition()
Expand Down

0 comments on commit b14fa99

Please sign in to comment.