예제 #1
0
    def test(self):

        n = Gaffer.Node()
        n["user"]["p1"] = Gaffer.BoolPlug(flags=Gaffer.Plug.Flags.Default
                                          | Gaffer.Plug.Flags.Dynamic)
        n["user"]["p2"] = Gaffer.BoolPlug(flags=Gaffer.Plug.Flags.Default
                                          | Gaffer.Plug.Flags.Dynamic)

        w = GafferUI.BoolPlugValueWidget(n["user"]["p1"])
        self.assertEqual(w.getPlug(), n["user"]["p1"])
        self.assertEqual(w.getPlugs(), {n["user"]["p1"]})
        self.assertEqual(w.boolWidget().getState(), False)

        n["user"]["p1"].setValue(True)
        self.assertEqual(w.boolWidget().getState(), True)

        w.setPlugs(n["user"].children())
        self.assertEqual(w.boolWidget().getState(),
                         w.boolWidget().State.Indeterminate)

        n["user"]["p2"].setValue(True)
        self.assertEqual(w.boolWidget().getState(), True)

        w.setPlugs([])
        self.assertEqual(w.boolWidget().getState(),
                         w.boolWidget().State.Indeterminate)
예제 #2
0
파일: Viewer.py 프로젝트: Red1977/gaffer
		def __init__( self, view ) :

			self.tools = [ GafferUI.Tool.create( n, view ) for n in GafferUI.Tool.registeredTools( view.typeId() ) ]
			self.tools.sort( key = lambda v : Gaffer.Metadata.nodeValue( v, "order" ) if Gaffer.Metadata.nodeValue( v, "order" ) is not None else 999 )

			self.__toolPlugSetConnections = [
				t.plugSetSignal().connect( Gaffer.WeakMethod( self.__toolPlugSet ) ) for t in self.tools
			]

			with GafferUI.ListContainer( spacing = 1 ) as self.widgets :

				for tool in self.tools :

					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.BoolPlugValueWidget( tool["active"], toolTip = toolTip )

			GafferUI.WidgetAlgo.joinEdges( self.widgets )

			self.primaryTool = None
			self.primaryToolChangedSignal = Gaffer.Signal0()

			if len( self.tools ) :
				self.tools[0]["active"].setValue( True )
예제 #3
0
    def __init__(self, plug, **kw):

        row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal)

        GafferUI.PlugValueWidget.__init__(self, row, plug, **kw)

        with row:
            self.__enabledWidget = GafferUI.BoolPlugValueWidget(
                plug["enabled"],
                displayMode=GafferUI.BoolWidget.DisplayMode.Switch)
            self.__cameraWidget = GafferSceneUI.ScenePathPlugValueWidget(
                plug["camera"],
                path=GafferScene.ScenePath(plug.node()["in"],
                                           plug.node().getContext(),
                                           "/",
                                           filter=self.__pathFilter()),
            )
            self.__cameraWidget.pathWidget().setFixedCharacterWidth(13)
            if hasattr(self.__cameraWidget.pathWidget()._qtWidget(),
                       "setPlaceholderText"):
                self.__cameraWidget.pathWidget()._qtWidget(
                ).setPlaceholderText("Render Camera")

        self._updateFromPlug()
예제 #4
0
    def __init__(self, plug):

        self.__row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal, spacing=4)

        GafferUI.PlugValueWidget.__init__(self, self.__row, plug)

        nameWidget = GafferUI.StringPlugValueWidget(plug["name"])
        nameWidget.textWidget()._qtWidget().setFixedWidth(
            GafferUI.PlugWidget.labelWidth())

        self.__row.append(
            nameWidget, verticalAlignment=GafferUI.Label.VerticalAlignment.Top)

        self.__row.append(
            GafferUI.BoolPlugValueWidget(
                plug["enabled"],
                displayMode=GafferUI.BoolWidget.DisplayMode.Switch),
            verticalAlignment=GafferUI.Label.VerticalAlignment.Top,
        )

        self.__row.append(GafferUI.PlugValueWidget.create(plug["mode"]))
        self.__row.append(GafferUI.PlugValueWidget.create(plug["value"]),
                          expand=True)

        self._updateFromPlug()
예제 #5
0
    def __init__(self, plug, overrideName=None):

        self.__row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal, spacing=4)

        GafferUI.PlugValueWidget.__init__(self, self.__row, plug)

        with self.__row:
            GafferUI.StringPlugValueWidget(
                self.getPlug()["name"]).textWidget()._qtWidget().setFixedWidth(
                    GafferUI.PlugWidget.labelWidth())

            GafferUI.BoolPlugValueWidget(
                self.getPlug()["enabled"],
                displayMode=GafferUI.BoolWidget.DisplayMode.Switch)

            GafferUI.PlugValueWidget.create(self.getPlug()["quantize"])
            toolTipPrefix = "Number of unique values of this context variable, which contribute to the total number of evaluations of the `prototypes` scene."
            if overrideName:
                _VariationsPlugValueWidget(self.getPlug().node()["variations"],
                                           overrideName, "", toolTipPrefix)
            else:
                _VariationsPlugValueWidget(self.getPlug().node()["variations"],
                                           self.getPlug()["name"], "",
                                           toolTipPrefix)

        self._updateFromPlugs()
예제 #6
0
    def __init__(self, childPlug):

        self.__row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal, spacing=4)

        GafferUI.PlugValueWidget.__init__(self, self.__row, childPlug)

        ## \todo We should support no plugs here. Move the UI configuration into setPlugs
        assert (len(self.getPlugs()) > 0)

        # We use a non-editable label for the name for non-dynamic plugs, or any that request it

        anyStatic = any([
            not p.getFlags(Gaffer.Plug.Flags.Dynamic) for p in self.getPlugs()
        ])
        anyIgnoreName = any([
            Gaffer.Metadata.value(
                p, "nameValuePlugPlugValueWidget:ignoreNamePlug")
            for p in self.getPlugs()
        ])

        if anyStatic or anyIgnoreName:
            nameWidget = GafferUI.LabelPlugValueWidget(
                self.getPlugs(),
                horizontalAlignment=GafferUI.Label.HorizontalAlignment.Right,
                verticalAlignment=GafferUI.Label.VerticalAlignment.Center,
            )
            nameWidget.label()._qtWidget().setFixedWidth(
                GafferUI.PlugWidget.labelWidth())
            # cheat to get the height of the label to match the height of a line edit
            # so the label and plug widgets align nicely. ideally we'd get the stylesheet
            # sorted for the QLabel so that that happened naturally, but QLabel sizing appears
            # somewhat unpredictable (and is sensitive to HTML in the text as well), making this
            # a tricky task.
            nameWidget.label()._qtWidget().setFixedHeight(20)
        else:
            nameWidget = GafferUI.StringPlugValueWidget(
                {plug["name"]
                 for plug in self.getPlugs()})
            nameWidget.textWidget()._qtWidget().setFixedWidth(
                GafferUI.PlugWidget.labelWidth())

        self.__row.append(
            nameWidget, verticalAlignment=GafferUI.Label.VerticalAlignment.Top)

        if all(["enabled" in plug for plug in self.getPlugs()]):
            self.__row.append(
                GafferUI.BoolPlugValueWidget(
                    {plug["enabled"]
                     for plug in self.getPlugs()},
                    displayMode=GafferUI.BoolWidget.DisplayMode.Switch),
                verticalAlignment=GafferUI.Label.VerticalAlignment.Top,
            )

        self.__row.append(GafferUI.PlugValueWidget.create(
            {plug["value"]
             for plug in self.getPlugs()}),
                          expand=True)

        self._updateFromPlugs()
예제 #7
0
    def __init__(self, plug):

        # TODO - would be nice if this stuff didn't need to be added to the instance as metadata
        # John has said that in the future we may be able to use match patterns to register metadata
        # to children of a plug type, like we can do with nodes.
        # This would allow us to use dynamic metadata to hide the value plug when in "Remove" mode

        Gaffer.Metadata.registerValue(
            plug['name'],
            "description",
            "The name of the parameter to apply the tweak to.",
            persistent=False)
        Gaffer.Metadata.registerValue(plug['mode'],
                                      "plugValueWidget:type",
                                      "GafferUI.PresetsPlugValueWidget",
                                      persistent=False)

        presetNames = ["Replace"]

        # Identify plugs which are derived from NumericPlug or CompoundNumericPlug
        plugIsNumeric = hasattr(plug["value"], "hasMinValue")
        if plugIsNumeric:
            presetNames += ["Add", "Subtract", "Multiply"]

        if Gaffer.Metadata.value(plug, "tweakPlugValueWidget:allowRemove"):
            presetNames += ["Remove"]

        for name in presetNames:
            Gaffer.Metadata.registerValue(
                plug['mode'],
                "preset:" + name,
                GafferScene.TweakPlug.Mode.names[name],
                persistent=False)

        self.__row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal, spacing=4)

        GafferUI.PlugValueWidget.__init__(self, self.__row, plug)

        nameWidget = GafferUI.StringPlugValueWidget(plug["name"])
        nameWidget.textWidget()._qtWidget().setFixedWidth(
            GafferUI.PlugWidget.labelWidth())

        self.__row.append(
            nameWidget, verticalAlignment=GafferUI.Label.VerticalAlignment.Top)

        self.__row.append(
            GafferUI.BoolPlugValueWidget(
                plug["enabled"],
                displayMode=GafferUI.BoolWidget.DisplayMode.Switch),
            verticalAlignment=GafferUI.Label.VerticalAlignment.Top,
        )

        self.__row.append(GafferUI.PlugValueWidget.create(plug["mode"]))
        self.__row.append(GafferUI.PlugValueWidget.create(plug["value"]),
                          expand=True)

        self._updateFromPlug()
예제 #8
0
    def __init__(self, plugOrPlugs, **kw):

        self.__row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal, spacing=4)
        GafferUI.PlugValueWidget.__init__(self, self.__row, plugOrPlugs)

        plugs = self.getPlugs()

        # If all cells have enabled plugs, we need to add a switch for them.
        # If cells adopt the enabled plug from their value plug, we rely on the
        # PlugValueWidget drawing the switch for us.
        # However, in cases where the widget for the value plug doesn't support
        # multiple plugs, we don't show a value, and so need to add our own
        # switch so people can at least edit enabled state the cells.

        cellEnabledPlugs = {p["enabled"] for p in plugs if "enabled" in p}
        valuePlugs = {p["value"] for p in plugs}

        addCellEnabledSwitch = len(cellEnabledPlugs) == len(valuePlugs)

        if self.canEdit(plugs):

            plugValueWidget = self.__createValueWidget(valuePlugs)
            if plugValueWidget is not None:
                # Apply some fixed widths for some widgets, otherwise they're
                # a bit too eager to grow. \todo Should we change the underlying
                # behaviour of the widgets themselves?
                self.__applyFixedWidths(plugValueWidget)
                self.__row.append(plugValueWidget)
            else:
                self.__row.append(
                    GafferUI.Label(
                        "Unable to edit multiple plugs of this type"))
                addCellEnabledSwitch = True

        else:
            self.__row.append(
                GafferUI.Label("Unable to edit plugs with mixed types"))
            addCellEnabledSwitch = True

        if addCellEnabledSwitch:
            self.__enabledPlugValueWidget = GafferUI.BoolPlugValueWidget(
                [p.enabledPlug() for p in plugs],
                displayMode=GafferUI.BoolWidget.DisplayMode.Switch)
            self.__enabledPlugValueWidget.setEnabled(
                _Algo.cellsCanBeDisabled(plugs))
            self.__row.insert(0,
                              self.__enabledPlugValueWidget,
                              verticalAlignment=GafferUI.VerticalAlignment.Top)
        else:
            self.__enabledPlugValueWidget = None

        self._updateFromPlugs()
예제 #9
0
    def __init__(self, childPlug, label=None):

        self.__row = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Horizontal, spacing=4)

        GafferUI.PlugValueWidget.__init__(self, self.__row, childPlug)

        if label is not None or not childPlug.getFlags(
                Gaffer.Plug.Flags.Dynamic):
            nameWidget = GafferUI.LabelPlugValueWidget(
                childPlug,
                horizontalAlignment=GafferUI.Label.HorizontalAlignment.Right,
                verticalAlignment=GafferUI.Label.VerticalAlignment.Center,
            )
            if label is not None:
                nameWidget.label().setText(label)
            nameWidget.label()._qtWidget().setFixedWidth(
                GafferUI.PlugWidget.labelWidth())
            # cheat to get the height of the label to match the height of a line edit
            # so the label and plug widgets align nicely. ideally we'd get the stylesheet
            # sorted for the QLabel so that that happened naturally, but QLabel sizing appears
            # somewhat unpredictable (and is sensitive to HTML in the text as well), making this
            # a tricky task.
            nameWidget.label()._qtWidget().setFixedHeight(20)
        else:
            nameWidget = GafferUI.StringPlugValueWidget(childPlug["name"])
            nameWidget.textWidget()._qtWidget().setFixedWidth(
                GafferUI.PlugWidget.labelWidth())

        self.__row.append(
            nameWidget, verticalAlignment=GafferUI.Label.VerticalAlignment.Top)

        if "enabled" in childPlug:
            self.__row.append(
                GafferUI.BoolPlugValueWidget(
                    childPlug["enabled"],
                    displayMode=GafferUI.BoolWidget.DisplayMode.Switch),
                verticalAlignment=GafferUI.Label.VerticalAlignment.Top,
            )

        self.__row.append(GafferUI.PlugValueWidget.create(childPlug["value"]),
                          expand=True)

        self._updateFromPlug()
예제 #10
0
    def __init__(self, plug):

        column = GafferUI.ListContainer(
            GafferUI.ListContainer.Orientation.Vertical, spacing=4)

        GafferUI.PlugValueWidget.__init__(self, column, plug)

        with column:

            with GafferUI.ListContainer(
                    GafferUI.ListContainer.Orientation.Horizontal, spacing=4):

                self.__dragHandle = _DragHandle()
                with GafferUI.ListContainer(
                        GafferUI.ListContainer.Orientation.Horizontal,
                        spacing=4) as self.__defaultLabel:
                    # Spacers on default row occupy the space taken by PlugValueWidgets on
                    # non-default rows. This keeps the ConnectionPlugValueWidgets in alignment.
                    GafferUI.Spacer(imath.V2i(11, 1))
                    label = GafferUI.Label(
                        "Default",
                        horizontalAlignment=GafferUI.HorizontalAlignment.Left)
                    label._qtWidget().setFixedWidth(self.__labelWidth)
                    GafferUI.Spacer(imath.V2i(25, 1))

                self.__plugValueWidgets = []
                self.__plugValueWidgets.append(
                    GafferUI.StringPlugValueWidget(plug["name"]))
                self.__plugValueWidgets.append(
                    GafferUI.BoolPlugValueWidget(
                        plug["enabled"],
                        displayMode=GafferUI.BoolWidget.DisplayMode.Switch))
                self.__plugValueWidgets.append(
                    GafferUI.PlugValueWidget.create(plug["value"]))

                self.__plugValueWidgets[0].textWidget()._qtWidget(
                ).setFixedWidth(self.__labelWidth)

            self.__dragDivider = GafferUI.Divider()

        self.__updateWidgetVisibility()
        self._updateFromPlug()
예제 #11
0
    def __init__(self, tool, **kw):

        GafferUI.Frame.__init__(self, borderWidth=4, **kw)

        self.__tool = tool

        with self:
            with GafferUI.ListContainer(orientation=GafferUI.ListContainer.
                                        Orientation.Horizontal) as self.__row:

                self.__infoIcon = GafferUI.Image("infoSmall.png")
                self.__errorIcon = GafferUI.Image("errorSmall.png")
                self.__warningIcon = GafferUI.Image("warningSmall.png")
                GafferUI.Spacer(size=imath.V2i(4), maximumSize=imath.V2i(4))
                self.__label = GafferUI.Label("")

                GafferUI.Spacer(size=imath.V2i(8), maximumSize=imath.V2i(8))
                GafferUI.Divider(
                    orientation=GafferUI.Divider.Orientation.Vertical)
                GafferUI.Spacer(size=imath.V2i(8), maximumSize=imath.V2i(8))

                with GafferUI.ListContainer(
                        orientation=GafferUI.ListContainer.Orientation.
                        Horizontal) as self.__controls:

                    self.__enabledLabel = GafferUI.Label("Enabled")
                    self.__enabled = GafferUI.BoolPlugValueWidget(None)
                    self.__enabled.boolWidget().setDisplayMode(
                        GafferUI.BoolWidget.DisplayMode.Switch)

                    button = GafferUI.Button("Reset")
                    button._qtWidget().setFixedWidth(50)
                    button.clickedSignal().connect(Gaffer.WeakMethod(
                        self.__buttonClicked),
                                                   scoped=False)

        self.__tool.statusChangedSignal().connect(Gaffer.WeakMethod(
            self.__update, fallbackResult=None),
                                                  scoped=False)

        self.__update()
예제 #12
0
	def __init__( self, plug, **kw ) :

		self.__row = GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Horizontal, spacing = 4 )
		GafferUI.PlugValueWidget.__init__( self, self.__row, plug )

		rowPlug = plug.ancestor( Gaffer.Spreadsheet.RowPlug )
		if "enabled" in plug and rowPlug != rowPlug.parent().defaultRow() :
			enabledPlugValueWidget = GafferUI.BoolPlugValueWidget(
				plug["enabled"],
				displayMode=GafferUI.BoolWidget.DisplayMode.Switch
			)
			self.__row.append( enabledPlugValueWidget, verticalAlignment=GafferUI.VerticalAlignment.Top )

		plugValueWidget = self.__createValueWidget( plug["value"] )

		# Apply some fixed widths for some widgets, otherwise they're
		# a bit too eager to grow. \todo Should we change the underlying
		# behaviour of the widgets themselves?
		self.__applyFixedWidths( plugValueWidget )

		self.__row.append( plugValueWidget )

		self._updateFromPlug()
예제 #13
0
def __booleanCreator(plug, annotations):

    return GafferUI.BoolPlugValueWidget(plug)