def testDisplayMode( self ) : w = GafferUI.BoolWidget() self.assertEqual( w.getDisplayMode(), w.DisplayMode.CheckBox ) w.setDisplayMode( w.DisplayMode.Switch ) self.assertEqual( w.getDisplayMode(), w.DisplayMode.Switch ) w.setDisplayMode( w.DisplayMode.CheckBox ) self.assertEqual( w.getDisplayMode(), w.DisplayMode.CheckBox ) w = GafferUI.BoolWidget( displayMode = GafferUI.BoolWidget.DisplayMode.Switch ) self.assertEqual( w.getDisplayMode(), w.DisplayMode.Switch )
def __init__(self, key, target=None, **kw): self.__boolWidget = GafferUI.BoolWidget() _MetadataWidget.__init__(self, self.__boolWidget, key, target, **kw) self.__stateChangedConnection = self.__boolWidget.stateChangedSignal( ).connect(Gaffer.WeakMethod(self.__stateChanged))
def __init__(self, pathFilter, **kw): self.__row = GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal, spacing=2, borderWidth=0) GafferUI.PathFilterWidget.__init__(self, self.__row, pathFilter, **kw) with self.__row: self.__enabledWidget = GafferUI.BoolWidget() self.__enabledStateChangedConnection = self.__enabledWidget.stateChangedSignal( ).connect(Gaffer.WeakMethod(self.__enabledStateChanged)) self.__propertyButton = GafferUI.MenuButton( image="collapsibleArrowDown.png", hasFrame=False, menu=GafferUI.Menu( Gaffer.WeakMethod(self.__propertyMenuDefinition)), ) self.__patternWidget = GafferUI.TextWidget() if hasattr(self.__patternWidget._qtWidget(), "setPlaceholderText"): # setPlaceHolderText appeared in qt 4.7, nuke (6.3 at time of writing) is stuck on 4.6. self.__patternWidget._qtWidget().setPlaceholderText( "Filter...") self.__patternEditingFinishedConnection = self.__patternWidget.editingFinishedSignal( ).connect(Gaffer.WeakMethod(self.__patternEditingFinished)) self.__patternTextChangedConnection = self.__patternWidget.textChangedSignal( ).connect(Gaffer.WeakMethod(self.__patternTextChanged)) self._updateFromPathFilter()
def testIndeterminateState(self): w = GafferUI.BoolWidget() w.setState(w.State.Indeterminate) self.assertEqual(w.getState(), w.State.Indeterminate) w.setState(False) self.assertIs(w.getState(), False) w.setState(True) self.assertIs(w.getState(), True) # We don't want users to be able to set the # indeterminate state. It is a display-only # value. w._qtWidget().click() self.assertIs(w.getState(), False) w._qtWidget().click() self.assertIs(w.getState(), True) w._qtWidget().click() self.assertIs(w.getState(), False) # When in the indeterminate state, we expect # a click to take us into the True state. w.setState(w.State.Indeterminate) w._qtWidget().click() self.assertIs(w.getState(), True)
def setView(self, view): if view == self.__view: return if view not in self.__viewEntries: if view is not None: tools = [ GafferUI.Tool.create(n, view) for n in GafferUI.Tool.registeredTools(view.typeId()) ] tools.sort( key=lambda v: Gaffer.Metadata.nodeValue(v, "order") if Gaffer.Metadata.nodeValue(v, "order") is not None else 999) else: tools = [] with GafferUI.ListContainer(spacing=1) as widgets: for tool in tools: image = tool.typeName().replace(":", "") image = image[:1].lower() + image[1:] + ".png" toolTip = tool.getName() description = Gaffer.Metadata.nodeDescription(tool) if description: toolTip += "\n\n" + IECore.StringUtil.wrap( description, 80) shortCut = Gaffer.Metadata.value(tool, "viewer:shortCut") if shortCut is not None: toolTip += "\n\nShortcut : " + shortCut widget = GafferUI.BoolWidget( image=image, toolTip=toolTip, displayMode=GafferUI.BoolWidget.DisplayMode.Tool) widget.__stateChangedConnection = widget.stateChangedSignal( ).connect( functools.partial(Gaffer.WeakMethod( self.__stateChanged), tool=tool)) GafferUI.WidgetAlgo.joinEdges(widgets) self.__viewEntries[view] = self.__ViewEntry(tools, widgets) self.setChild(self.__viewEntries[view].widgets) self.__view = view if self.getTool(): self.toolChangedSignal()(self) elif len(self.tools()): self.setTool(self.tools()[0]) else: self.setTool(None)
def testText(self): w = GafferUI.BoolWidget("a") self.assertEqual(w.getText(), "a") w.setText("b") self.assertEqual(w.getText(), "b") self.failUnless(isinstance(w.getText(), basestring))
def __init__( self, pathFilter, **kw ) : self.__checkBox = GafferUI.BoolWidget( str( pathFilter ) ) GafferUI.PathFilterWidget.__init__( self, self.__checkBox, pathFilter ) self.__stateChangedConnection = self.__checkBox.stateChangedSignal().connect( Gaffer.WeakMethod( self.__stateChanged ) ) self._updateFromPathFilter()
def testText(self): w = GafferUI.BoolWidget("a") self.assertEqual(w.getText(), "a") w.setText("b") self.assertEqual(w.getText(), "b") self.assertIsInstance(w.getText(), str)
def testState(self): w = GafferUI.BoolWidget() self.assertEqual(w.getState(), False) w.setState(True) self.assertEqual(w.getState(), True) w.setState(False) self.assertEqual(w.getState(), False)
def testLifespan(self): w = GafferUI.BoolWidget() r = weakref.ref(w) self.failUnless(r() is w) del w self.failUnless(r() is None)
def testLifespan(self): w = GafferUI.BoolWidget() r = weakref.ref(w) self.assertTrue(r() is w) del w self.assertTrue(r() is None)
def __init__(self, pathFilter): self.__checkBox = GafferUI.BoolWidget(str(pathFilter)) PathFilterWidget.__init__(self, self.__checkBox, pathFilter) self.__checkBox.stateChangedSignal().connect(Gaffer.WeakMethod( self.__stateChanged), scoped=False) self._updateFromPathFilter()
def __init__( self, plug, displayMode=GafferUI.BoolWidget.DisplayMode.CheckBox, **kw ) : self.__boolWidget = GafferUI.BoolWidget( displayMode=displayMode ) GafferUI.PlugValueWidget.__init__( self, self.__boolWidget, plug, **kw ) self._addPopupMenu( self.__boolWidget ) self.__stateChangedConnection = self.__boolWidget.stateChangedSignal().connect( Gaffer.WeakMethod( self.__stateChanged ) ) self._updateFromPlug()
def testStateChangedSignal( self ) : self.emissions = 0 def f( w ) : self.emissions += 1 w = GafferUI.BoolWidget() c = w.stateChangedSignal().connect( f ) w.setState( True ) self.assertEqual( w.getState(), True ) self.assertEqual( self.emissions, 1 )
def __init__(self, key, target=None, defaultValue=False, **kw): self.__boolWidget = GafferUI.BoolWidget() MetadataWidget.__init__(self, self.__boolWidget, key, target, defaultValue=defaultValue, **kw) self.__boolWidget.stateChangedSignal().connect(Gaffer.WeakMethod( self.__stateChanged), scoped=False)
def __init__(self, plugs, displayMode=GafferUI.BoolWidget.DisplayMode.CheckBox, **kw): if plugs is None: plugs = set() elif isinstance(plugs, Gaffer.Plug): plugs = {plugs} self.__boolWidget = GafferUI.BoolWidget( displayMode=displayMode, image=sole( Gaffer.Metadata.value(p, "boolPlugValueWidget:image") for p in plugs)) GafferUI.PlugValueWidget.__init__(self, self.__boolWidget, plugs, **kw) self._addPopupMenu(self.__boolWidget) self.__stateChangedConnection = self.__boolWidget.stateChangedSignal( ).connect(Gaffer.WeakMethod(self.__stateChanged)) self._updateFromPlugs()
def __init__(self, scriptNode, **kw): self.__frame = GafferUI.Frame( borderWidth=4, borderStyle=GafferUI.Frame.BorderStyle.None) GafferUI.NodeSetEditor.__init__(self, self.__frame, scriptNode, **kw) # Build the UI. Initially this isn't connected up to any node - we'll # perform the connections in _updateFromSet(). ###################################################################### self.__nodeMetadataConnections = [] self.__plugMetadataConnections = [] with self.__frame: self.__tabbedContainer = GafferUI.TabbedContainer() with self.__tabbedContainer: # Node tab with GafferUI.GridContainer(spacing=4, borderWidth=8, parenting={"label": "Node"}) as self.__nodeTab: GafferUI.Label("Name", parenting={ "index": (0, 0), "alignment": (GafferUI.HorizontalAlignment.Right, GafferUI.VerticalAlignment.Center) }) self.__nodeNameWidget = GafferUI.NameWidget( None, parenting={"index": (1, 0)}) GafferUI.Label("Description", parenting={ "index": (0, 1), "alignment": (GafferUI.HorizontalAlignment.Right, GafferUI.VerticalAlignment.Top) }) description = GafferUI.MultiLineTextWidget( parenting={"index": (1, 1)}) self.__nodeMetadataConnections.append( _MetadataConnection(description, None, "description")) # Plugs tab with GafferUI.SplitContainer( orientation=GafferUI.SplitContainer.Orientation.Horizontal, borderWidth=8, parenting={"label": "Plugs"}) as self.__plugTab: self.__plugListing = _PlugListing() self.__plugListingSelectionChangedConnection = self.__plugListing.selectionChangedSignal( ).connect(Gaffer.WeakMethod( self.__plugListingSelectionChanged)) with GafferUI.GridContainer( spacing=4, borderWidth=8) as self.__plugEditor: GafferUI.Label("Name", parenting={ "index": (0, 0), "alignment": (GafferUI.HorizontalAlignment.Right, GafferUI.VerticalAlignment.Center) }) self.__plugNameWidget = GafferUI.NameWidget( None, parenting={"index": (1, 0)}) GafferUI.Label("Description", parenting={ "index": (0, 1), "alignment": (GafferUI.HorizontalAlignment.Right, GafferUI.VerticalAlignment.Top) }) description = GafferUI.MultiLineTextWidget( parenting={"index": (1, 1)}) self.__plugMetadataConnections.append( _MetadataConnection(description, None, "description")) GafferUI.Label("Divider", parenting={ "index": (0, 2), "alignment": (GafferUI.HorizontalAlignment.Right, GafferUI.VerticalAlignment.Center) }) divider = GafferUI.BoolWidget( parenting={ "index": (1, 2), "alignment": (GafferUI.HorizontalAlignment.Left, GafferUI.VerticalAlignment.Center) }) self.__plugMetadataConnections.append( _MetadataConnection(divider, None, "divider")) self.__plugTab.setSizes([0.3, 0.7]) # initialise our selection to nothing self.__node = None self.__selectedPlug = None # call __updateFromSetInternal() to populate our selection and connect # the ui to it. we pass lazy==False to avoid the early out if # there is no currently selected node. self.__updateFromSetInternal(lazy=False)
def __init__(self, scriptNode, **kw): # create main two part container (top for actions, bottom for feedback) self.__splittable = GafferUI.SplitContainer(borderWidth=2) GafferUI.Editor.__init__(self, self.__splittable, scriptNode, **kw) with self.__splittable: # create splittable container so we can have actions tabs and a feedback window. GafferUI.Label( "This toolset is designed to make managing graphs simpler and more consistent", horizontalAlignment=GafferUI.Label.HorizontalAlignment.Center, ) ############# TAB CONTAINER ############## with GafferUI.TabbedContainer() as self.__tab1Container: ############# LAYOUT TAB ############## with GafferUI.ListContainer( spacing=5, borderWidth=5) as self.__toolboxContainer1: self.__tab1Container.setLabel(self.__toolboxContainer1, "Layout") directions = ( # direction, ascii, position ("NW", "\xf0\x9f\xa1\xbc", (1, 1)), ("N", "\xf0\x9f\xa1\xb9", (2, 1)), ("NE", "\xf0\x9f\xa1\xbd", (3, 1)), ("W", "\xf0\x9f\xa1\xb8", (1, 2)), (None, None, (2, 2)), ("E", "\xf0\x9f\xa1\xba", (3, 2)), ("SW", "\xf0\x9f\xa1\xbf", (1, 3)), ("S", "\xf0\x9f\xa1\xbb", (2, 3)), ("SE", "\xf0\x9f\xa1\xbe", (3, 3))) with GafferUI.GridContainer() as self.__moverGrid: GafferUI.Label("Select", parenting={"index": (1, 1)}) GafferUI.Label(" ", parenting={"index": (2, 1)}) GafferUI.Label("Move", parenting={"index": (3, 1)}) GafferUI.Label(" ", parenting={"index": (4, 1)}) ############# SELECTOR ARROW GRID ############## with GafferUI.GridContainer( parenting={"index": ( 1, 2)}) as self.__selectorGrid: for direction in directions: if direction[0] != None: GafferUI.Button( text=direction[1], parenting={"index": (direction[2])}) self.__selectorGrid[direction[ 2]]._qtWidget().setMinimumWidth(25) self.__selectorGrid[direction[ 2]]._qtWidget().setMaximumWidth(25) self.__selectorGrid[ direction[2]]._qtWidget().setProperty( "myDirection", direction[0]) self.__selectorGrid[ direction[2]].clickedSignal().connect( self.__selectorAction, scoped=False) ############# MOVER ARROW GRID ############## with GafferUI.GridContainer( parenting={"index": (3, 2)}) as self.__moverGrid: for direction in directions: if direction[0] != None: GafferUI.Button( text=direction[1], parenting={"index": (direction[2])}) self.__moverGrid[direction[2]]._qtWidget( ).setMinimumWidth(25) self.__moverGrid[direction[2]]._qtWidget( ).setMaximumWidth(25) self.__moverGrid[ direction[2]]._qtWidget().setProperty( "myDirection", direction[0]) self.__moverGrid[ direction[2]].clickedSignal().connect( self.__moverAction, scoped=False) ############# SELECT/MOVE OPTIONS ############## with GafferUI.ListContainer( orientation=GafferUI.ListContainer.Orientation. Vertical, parenting={"index": (5, 2)}) as self.__LayoutOptions: self.__limitToBackdropsCheckbox = GafferUI.BoolWidget( text="Limit Selection to Backdrops", checked=True) self.__extendBackdropsCheckbox = GafferUI.BoolWidget( text="Extend Backdrops", checked=True) ############# COLOUR TAB ############## with GafferUI.ListContainer( spacing=5, borderWidth=5) as self.__toolboxContainer2: self.__tab1Container.setLabel(self.__toolboxContainer2, "Colour") ############# COLOUR GRID ############## with GafferUI.GridContainer() as self.__colorGrid: gridSize = (10, 5) for i in range(0, gridSize[0]): for j in range(0, gridSize[1]): HSV = imath.Color4f( (1.0 / gridSize[0]) * float(i), 0.5, 1.0 - ((1.0 / gridSize[1]) * float(j)), 1.0) RGB = HSV.hsv2rgb() GafferUI.ColorSwatch( RGB, useDisplayTransform=False, parenting={"index": (i, j)}) self.__colorGrid[ i, j]._qtWidget().setMaximumHeight(20) self.__colorGrid[ i, j].buttonPressSignal().connect( self.__setColourAction, scoped=False) ############# SEARCH AND REPLACE TAB ############## with GafferUI.ListContainer( spacing=5, borderWidth=5) as self.__toolboxContainer3: self.__tab1Container.setLabel(self.__toolboxContainer3, "Search and Replace") spacing = 100 with GafferUI.ListContainer( spacing=5, borderWidth=5, orientation=GafferUI.ListContainer.Orientation. Horizontal) as self.__searchList: self.__searchLabel = GafferUI.Label( "Search For", horizontalAlignment=GafferUI.Label. HorizontalAlignment.Right) self.__searchLabel._qtWidget().setMinimumWidth(spacing) self.__searchLabel._qtWidget().setMaximumWidth(spacing) self.__searchWidget = GafferUI.TextWidget( text="myTest") with GafferUI.ListContainer( spacing=5, borderWidth=5, orientation=GafferUI.ListContainer.Orientation. Horizontal) as self.__replaceList: self.__replaceLabel = GafferUI.Label( "Replace With", horizontalAlignment=GafferUI.Label. HorizontalAlignment.Right) self.__replaceLabel._qtWidget().setMinimumWidth( spacing) self.__replaceLabel._qtWidget().setMaximumWidth( spacing) self.__replaceWidget = GafferUI.TextWidget( text="banana") with GafferUI.ListContainer( spacing=5, borderWidth=5, orientation=GafferUI.ListContainer.Orientation. Horizontal) as self.__searchReplaceList: self.__searchReplaceNodePlugsMenu = GafferUI.SelectionMenu( ) self.__searchReplaceNodePlugsMenu.addItem("Node Names") self.__searchReplaceNodePlugsMenu.addItem( "Plug Values") self.__searchReplaceNodePlugsMenu._qtWidget( ).setMinimumWidth(spacing) self.__searchReplaceNodePlugsMenu._qtWidget( ).setMaximumWidth(spacing) self.__searchReplaceScopeMenu = GafferUI.SelectionMenu( ) self.__searchReplaceScopeMenu.addItem( "In Selected Nodes") self.__searchReplaceScopeMenu.addItem( "In Gaffer Scene") self.__searchReplaceScopeMenu._qtWidget( ).setMinimumWidth(spacing + 30) self.__searchReplaceScopeMenu._qtWidget( ).setMaximumWidth(spacing + 30) self.__searchReplaceButton = GafferUI.Button( text="Search and Replace") self.__searchReplaceButton.clickedSignal().connect( self.__findReplaceAction, scoped=False) self.__searchReplaceButton._qtWidget().setMaximumWidth( 150)
def __init__( self, parameterHandler ) : PresetDialogue.__init__( self, "Save Preset", parameterHandler ) with GafferUI.ListContainer( spacing = 8 ) as column : with GafferUI.GridContainer( spacing = 6 ) : GafferUI.Label( "<h3>Location</h3>", parenting = { "index" : ( 0, 0 ), "alignment" : ( GafferUI.Label.HorizontalAlignment.Right, GafferUI.Label.VerticalAlignment.None, ), } ) self._locationMenu( writable=True, parenting = { "index" : ( slice( 1, 3 ), 0 ) } ) GafferUI.Label( "<h3>Name</h3>", parenting = { "index" : ( 0, 1 ), "alignment" : ( GafferUI.Label.HorizontalAlignment.Right, GafferUI.Label.VerticalAlignment.None, ), } ) self.__presetNameWidget = GafferUI.TextWidget( self.__defaultName, parenting = { "index" : ( 1, 1 ) } ) self.__presetNameWidget.setSelection( None, None ) # select all self.__presetNameChangedConnection = self.__presetNameWidget.textChangedSignal().connect( Gaffer.WeakMethod( self.__presetNameChanged ) ) self.__loadAutomaticallyWidget = GafferUI.BoolWidget( "Load automatically", parenting = { "index" : ( 2, 1 ) } ) self.__loadAutomaticallyChangedConnection = self.__loadAutomaticallyWidget.stateChangedSignal().connect( Gaffer.WeakMethod( self.__loadAutomaticallyChanged ) ) GafferUI.Label( "<h3>Description</h3>", parenting = { "index" : ( 0, 2 ), "alignment" : ( GafferUI.Label.HorizontalAlignment.Right, GafferUI.Label.VerticalAlignment.Top, ), } ) self.__presetDescriptionWidget = GafferUI.MultiLineTextWidget( parenting = { "index" : ( slice( 1, 3 ), 2 ) } ) self.__presetDescriptionChangedConnection = self.__presetDescriptionWidget.textChangedSignal().connect( Gaffer.WeakMethod( self.__updateSaveButton ) ) with GafferUI.Collapsible( "Parameters To Save", collapsed=True ) as cl : # forcing CompoundVectorParameter to act as a leaf, because allowing the selection of some children but not others # makes no sense (because they must all have the same length). parameterPath = GafferCortex.ParameterPath( parameterHandler.parameter(), "/", forcedLeafTypes = ( IECore.CompoundVectorParameter, ) ) self.__parameterListing = GafferUI.PathListingWidget( parameterPath, columns = [ GafferUI.PathListingWidget.defaultNameColumn ], allowMultipleSelection = True, displayMode = GafferUI.PathListingWidget.DisplayMode.Tree ) self.__parameterListing.setSelectedPaths( self.__allPaths( parameterPath ) ) self.__haveSelectedParameters = True self.__selectionChangedConnection = self.__parameterListing.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__selectionChanged ) ) self._setWidget( column ) self._addButton( "Cancel" ) self.__saveButton = self._addButton( "Save" ) self.__saveButton.setEnabled( False )