Skip to content

Commit

Permalink
Merge pull request #6000 from murraystevenson/uiEditorIconScale
Browse files Browse the repository at this point in the history
UIEditor : Add support for editing `iconScale` node metadata
  • Loading branch information
murraystevenson authored Aug 22, 2024
2 parents b595720 + c413482 commit 2f418eb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
1.4.x.x (relative to 1.4.11.0)
=======

Improvements
------------

- UI Editor :
- Added the ability to edit the scale of node icons.
- Improved layout of Box node plug creator visibility toggles.

API
---

- MetadataWidget : Added `NumericMetadataWidget` class.

1.4.11.0 (relative to 1.4.10.0)
========
Expand Down
44 changes: 42 additions & 2 deletions python/GafferUI/MetadataWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ def _updateFromValue( self, value ) :

## Must be called by derived classes to update
# the Metadata value when the widget value changes.
def _updateFromWidget( self, value ) :
def _updateFromWidget( self, value, mergeGroup = "" ) :

if self.__target is None :
return

with Gaffer.UndoScope( self.__target.ancestor( Gaffer.ScriptNode ) ) :
with Gaffer.UndoScope( self.__target.ancestor( Gaffer.ScriptNode ), mergeGroup = mergeGroup ) :
Gaffer.Metadata.registerValue( self.__target, self.__key, value )

## May be called by derived classes to deregister the
Expand Down Expand Up @@ -347,3 +347,43 @@ def __buttonClicked( self, widget ) :
if chosenPath is not None :
self.__path.setFromString( str( chosenPath ) )
self.__editingFinished()

class NumericMetadataWidget( MetadataWidget ) :

def __init__( self, key, target = None, defaultValue = 0, **kw ) :

self.__numericWidget = GafferUI.NumericWidget( value = defaultValue )

self.__defaultValue = defaultValue
# we use these to decide which actions to merge into a single undo
self.__lastChangedReason = None
self.__mergeGroupId = 0

MetadataWidget.__init__( self, self.__numericWidget, key, target, defaultValue = defaultValue, **kw )

self.__numericWidget.valueChangedSignal().connect(
Gaffer.WeakMethod( self.__valueChanged ), scoped = False
)

def numericWidget( self ) :

return self.__numericWidget

def _updateFromValue( self, value ) :

self.__numericWidget.setValue( type( self.__defaultValue )( value ) )

def __valueChanged( self, widget, reason ) :

if reason == GafferUI.NumericWidget.ValueChangedReason.InvalidEdit :
self._updateFromValue( self.defaultValue() )
return

if not widget.changesShouldBeMerged( self.__lastChangedReason, reason ) :
self.__mergeGroupId += 1
self.__lastChangedReason = reason

self._updateFromWidget(
self.__numericWidget.getValue(),
mergeGroup = "NumericMetadataWidget{}{}".format( id( self, ), self.__mergeGroupId )
)
10 changes: 8 additions & 2 deletions python/GafferUI/UIEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ def __init__( self, scriptNode, **kw ) :
MetadataWidget.FileSystemPathMetadataWidget( key = "icon" )
)

GafferUI.Label( "Scale" )

scaleWidget = MetadataWidget.NumericMetadataWidget( key = "iconScale", defaultValue = 1.5 )
scaleWidget.numericWidget()._qtWidget().setMaximumWidth( 60 )
self.__nodeMetadataWidgets.append( scaleWidget )

with _Row() as self.__plugAddButtons :

_Label( "Plug Creators" )

for side in ( "Top", "Bottom", "Left", "Right" ) :
_Label( side )._qtWidget().setFixedWidth( 40 )
GafferUI.Label( side )
self.__nodeMetadataWidgets.append( MetadataWidget.BoolMetadataWidget(
key = "noduleLayout:customGadget:addButton%s:visible" % side,
defaultValue = True
Expand Down Expand Up @@ -400,7 +406,7 @@ class _Row( GafferUI.ListContainer ) :

def __init__( self, *args, **kw ) :

GafferUI.ListContainer.__init__( self, GafferUI.ListContainer.Orientation.Horizontal, spacing = 4, *args, **kw )
GafferUI.ListContainer.__init__( self, GafferUI.ListContainer.Orientation.Horizontal, spacing = 8, *args, **kw )

##########################################################################
# Hierarchical representation of a plug layout, suitable for manipulating
Expand Down

0 comments on commit 2f418eb

Please sign in to comment.