Пример #1
0
	def __pathFilter() :

		# First make a filter that strips the scene down to
		# only things it is valid to look through - the union
		# of lights and cameras.

		validFilter = GafferScene.UnionFilter()

		# Must parent this filter to validFilter so it remains alive
		# after returning from this method.
		validFilter["__camerasFilter"] = GafferScene.SetFilter()
		validFilter["__camerasFilter"]["setExpression"].setValue( "__cameras" )

		validFilter["__lightsFilter"] = GafferScene.SetFilter()
		validFilter["__lightsFilter"]["setExpression"].setValue( "__lights" )

		validFilter["in"][0].setInput( validFilter["__camerasFilter"]["out"] )
		validFilter["in"][1].setInput( validFilter["__lightsFilter"]["out"] )

		validPathFilter = GafferScene.SceneFilterPathFilter( validFilter )
		validPathFilter.userData()["UI"] = { "visible" : False }

		# Now intersect that with a filter to show only cameras.
		# By turning this second filter on and off, we can give the
		# user a "Show Lights" toggle.

		camerasPathFilter = GafferScene.SceneFilterPathFilter( validFilter["__camerasFilter"] )
		camerasPathFilter.userData()["UI"] = { "label" : "Show Lights", "invertEnabled" : True }

		return Gaffer.CompoundPathFilter( [ validPathFilter, camerasPathFilter ] )
Пример #2
0
    def __updateFilter(self):

        newFilter = self.__path.getFilter()
        if self.__filter is not None and self.__filter.isSame(newFilter):
            return

        # update the directory path filter to include
        # the new filter, but with the additional removal
        # of leaf paths. block the signal because otherwise
        # we'd end up truncating the main path in __dirPathChanged.
        with Gaffer.BlockedConnection(self.__dirPathChangedConnection):
            if newFilter is not None:
                self.__dirPath.setFilter(
                    Gaffer.CompoundPathFilter([
                        Gaffer.LeafPathFilter(),
                        newFilter,
                    ]))
            else:
                self.__dirPath.setFilter(Gaffer.LeafPathFilter())

        # update ui for displaying the filter
        newFilterUI = None
        if newFilter is not None:
            newFilterUI = GafferUI.PathFilterWidget.create(newFilter)

        self.__filterFrame.setChild(newFilterUI)
        self.__filterFrame.setVisible(newFilterUI is not None)

        self.__filter = newFilter
Пример #3
0
	def __init__( self, scriptNode, **kw ) :

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

		GafferUI.NodeSetEditor.__init__( self, column, scriptNode, **kw )

		searchFilter = _GafferSceneUI._SceneHierarchySearchFilter()
		setFilter = _GafferSceneUI._SceneHierarchySetFilter()
		setFilter.setEnabled( False )

		self.__filter = Gaffer.CompoundPathFilter( [ searchFilter, setFilter ] )

		with column :

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

				_SearchFilterWidget( searchFilter )
				_SetFilterWidget( setFilter )

			self.__pathListing = GafferUI.PathListingWidget(
				Gaffer.DictPath( {}, "/" ), # temp till we make a ScenePath
				columns = [ GafferUI.PathListingWidget.defaultNameColumn ],
				allowMultipleSelection = True,
				displayMode = GafferUI.PathListingWidget.DisplayMode.Tree,
			)
			self.__pathListing.setDragPointer( "objects" )
			self.__pathListing.setSortable( False )

			self.__selectionChangedConnection = self.__pathListing.selectionChangedSignal().connect( Gaffer.WeakMethod( self.__selectionChanged ) )
			self.__expansionChangedConnection = self.__pathListing.expansionChangedSignal().connect( Gaffer.WeakMethod( self.__expansionChanged ) )

		self.__plug = None
		self._updateFromSet()
Пример #4
0
    def testConstructFromList(self):

        f1 = Gaffer.FileNamePathFilter(["a.*"])
        f2 = Gaffer.FileNamePathFilter(["b.*"])

        f = Gaffer.CompoundPathFilter([f1, f2])
        self.assertFilterListsEqual(f.getFilters(), [f1, f2])
Пример #5
0
    def testConstructFromIterable(self):

        f1 = Gaffer.FileNamePathFilter(["a.*"])
        f2 = Gaffer.FileNamePathFilter(["b.*"])

        f = Gaffer.CompoundPathFilter(itertools.chain([f1], [f2]))
        self.assertFilterListsEqual(f.getFilters(), [f1, f2])
    def _initialPath(self):

        scriptWindow = self.browser().ancestor(GafferUI.ScriptWindow)
        scriptNode = scriptWindow.scriptNode()

        return Gaffer.GraphComponentPath(
            scriptNode,
            "/",
            filter=Gaffer.CompoundPathFilter(
                filters=[
                    Gaffer.FileNamePathFilter([re.compile("^[^__].*")],
                                              leafOnly=False,
                                              userData={
                                                  "UI": {
                                                      "label": "Show hidden",
                                                      "invertEnabled": True,
                                                  }
                                              }),
                    Gaffer.InfoPathFilter(
                        infoKey="name",
                        matcher=None,  # the ui will fill this in
                        leafOnly=False,
                    ),
                ], ),
        )
	def _filter( self ) :
	
		result = Gaffer.CompoundPathFilter()	
		result.addFilter(
			Gaffer.FileNamePathFilter(
				[ re.compile( "^[^.].*" ) ],
				leafOnly=False,
				userData = {
					"UI" : {
						"label" : "Show hidden files",
						"invertEnabled" : True,
					}
				}
			) 
		)
		
		result.addFilter(
			Gaffer.InfoPathFilter(
				infoKey = "name",
				matcher = None, # the ui will fill this in
				leafOnly = False,
			)
		)
		
		return result
Пример #8
0
    def __init__(self, scriptNode, **kw):

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

        GafferUI.NodeSetEditor.__init__(self, column, scriptNode, **kw)

        searchFilter = _GafferSceneUI._HierarchyViewSearchFilter()
        setFilter = _GafferSceneUI._HierarchyViewSetFilter()
        setFilter.setEnabled(False)

        self.__filter = Gaffer.CompoundPathFilter([searchFilter, setFilter])

        with column:

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

                _SearchFilterWidget(searchFilter)
                _SetFilterWidget(setFilter)

            self.__pathListing = GafferUI.PathListingWidget(
                Gaffer.DictPath({}, "/"),  # temp till we make a ScenePath
                columns=[GafferUI.PathListingWidget.defaultNameColumn],
                allowMultipleSelection=True,
                displayMode=GafferUI.PathListingWidget.DisplayMode.Tree,
            )
            self.__pathListing.setDragPointer("objects")
            self.__pathListing.setSortable(False)

            # Work around insanely slow selection of a range containing many
            # objects (using a shift-click). The default selection behaviour
            # is SelectRows and this triggers some terrible performance problems
            # in Qt. Since we only have a single column, there is no difference
            # between SelectItems and SelectRows other than the speed.
            #
            # This workaround isn't going to be sufficient when we come to add
            # additional columns to the HierarchyView. What _might_ work instead
            # is to override `QTreeView.setSelection()` in PathListingWidget.py,
            # so that we manually expand the selected region to include full rows,
            # and then don't have to pass the `QItemSelectionModel::Rows` flag to
            # the subsequent `QItemSelectionModel::select()` call. This would be
            # essentially the same method we used to speed up
            # `PathListingWidget.setSelection()`.
            #
            # Alternatively we could avoid QItemSelectionModel entirely by managing
            # the selection ourself as a persistent PathMatcher.
            self.__pathListing._qtWidget().setSelectionBehavior(
                self.__pathListing._qtWidget().SelectionBehavior.SelectItems)

            self.__selectionChangedConnection = self.__pathListing.selectionChangedSignal(
            ).connect(Gaffer.WeakMethod(self.__selectionChanged))
            self.__expansionChangedConnection = self.__pathListing.expansionChangedSignal(
            ).connect(Gaffer.WeakMethod(self.__expansionChanged))

        self.__plug = None
        self._updateFromSet()
Пример #9
0
    def addFilter(self, pathFilter):

        warnings.warn(
            "Path.addFilter() is deprecated, use Path.setFilter() instead. If you wish to use more than one filter then use a CompoundPathFilter.",
            DeprecationWarning, 2)

        if not isinstance(self.__filter, Gaffer.CompoundPathFilter):
            self.__filter = Gaffer.CompoundPathFilter()

        self.__filter.addFilter(pathFilter)
Пример #10
0
	def createStandardFilter( extensions=[], extensionsLabel=None ) :
	
		result = Gaffer.CompoundPathFilter()
		
		if extensions :
			extensions = [ e.lower() for e in extensions ]
			if extensionsLabel is None :
				extensionsLabel = "Show only " + ", ".join( [ "." + e for e in extensions ] ) + " files"
			extensions += [ e.upper() for e in extensions ]
			extensions = [ "*." + e for e in extensions ]
			# the form below is for file sequences, where the frame range will
			# come after the extension
			extensions += [ "*.%s *" % e for e in extensions ]
			result.addFilter(
				Gaffer.FileNamePathFilter(
					extensions,
					userData = {
						"UI" : {
							"label" : extensionsLabel,
						}
					}
				)
			)
		
		result.addFilter(
			Gaffer.FileNamePathFilter(
				[ re.compile( "^[^.].*" ) ],
				leafOnly=False,
				userData = {
					"UI" : {
						"label" : "Show hidden files",
						"invertEnabled" : True,
					}
				}
			) 
		)
		
		result.addFilter(
			Gaffer.InfoPathFilter(
				infoKey = "name",
				matcher = None, # the ui will fill this in
				leafOnly = False,
			)
		)
		
		return result
Пример #11
0
    def test(self):

        f1 = Gaffer.FileNamePathFilter(["*.gfr"])
        f2 = Gaffer.FileNamePathFilter(["*.tif"])

        c = Gaffer.CompoundPathFilter()
        self.assertEqual(c.getFilters(), [])

        c.addFilter(f1)
        self.assertEqual(c.getFilters(), [f1])

        c.addFilter(f2)
        self.assertEqual(c.getFilters(), [f1, f2])

        c.removeFilter(f1)
        self.assertEqual(c.getFilters(), [f2])

        c.setFilters([f1, f2])
        self.assertEqual(c.getFilters(), [f1, f2])
Пример #12
0
    def testFiltering(self):

        p = Gaffer.DictPath({
            "a.txt": 1,
            "b.txt": 2,
            "c.exr": 3,
        }, "/")

        self.assertEqual(len(p.children()), 3)

        f = Gaffer.CompoundPathFilter()
        p.setFilter(f)
        self.assertEqual(len(p.children()), 3)

        f.addFilter(Gaffer.FileNamePathFilter(["*.txt"]))
        self.assertEqual(len(p.children()), 2)

        f.addFilter(Gaffer.FileNamePathFilter(["a.*"]))
        self.assertEqual(len(p.children()), 1)
Пример #13
0
    def testChangedSignalPropagation(self):

        cf = Gaffer.CompoundPathFilter()

        self.__numChanges = 0

        def f(filter):
            self.failUnless(filter is cf)
            self.__numChanges += 1

        f1 = Gaffer.FileNamePathFilter(["*.gfr"])
        f2 = Gaffer.FileNamePathFilter(["*.tif"])

        c = cf.changedSignal().connect(f)
        self.assertEqual(self.__numChanges, 0)

        cf.setFilters([f1, f2])
        self.assertEqual(self.__numChanges, 1)

        f1.changedSignal()(f1)
        self.assertEqual(self.__numChanges, 2)

        f2.changedSignal()(f2)
        self.assertEqual(self.__numChanges, 3)

        cf.removeFilter(f1)
        self.assertEqual(self.__numChanges, 4)
        f1.changedSignal()(f1)
        self.assertEqual(self.__numChanges, 4)

        cf.removeFilter(f2)
        self.assertEqual(self.__numChanges, 5)
        f2.changedSignal()(f2)
        self.assertEqual(self.__numChanges, 5)

        cf.addFilter(f1)
        self.assertEqual(self.__numChanges, 6)
        f1.changedSignal()(f1)
        self.assertEqual(self.__numChanges, 7)
Пример #14
0
    def testChangedSignal(self):

        cf = Gaffer.CompoundPathFilter()

        self.__numChanges = 0

        def f(filter):
            self.failUnless(filter is cf)
            self.__numChanges += 1

        f1 = Gaffer.FileNamePathFilter(["*.gfr"])
        f2 = Gaffer.FileNamePathFilter(["*.tif"])

        c = cf.changedSignal().connect(f)
        self.assertEqual(self.__numChanges, 0)

        cf.addFilter(f1)
        self.assertEqual(self.__numChanges, 1)

        cf.setFilters([f1])
        self.assertEqual(self.__numChanges, 1)

        cf.setFilters([f1, f2])
        self.assertEqual(self.__numChanges, 2)

        cf.removeFilter(f1)
        self.assertEqual(self.__numChanges, 3)

        # changing filters while not enabled shouldn't emit the signal

        cf.setEnabled(False)
        self.assertEqual(self.__numChanges, 4)

        cf.setFilters([])
        self.assertEqual(self.__numChanges, 4)

        cf.setFilters([f1, f2])
        self.assertEqual(self.__numChanges, 4)