def testExpandedPathsWhenPathChangesWithSelection(self): d = { "a": { "e": 10, }, "b": { "f": "g", }, } p = Gaffer.DictPath(d, "/") pa = Gaffer.DictPath(d, "/a") pae = Gaffer.DictPath(d, "/a/e") w = GafferUI.PathListingWidget( p, displayMode=GafferUI.PathListingWidget.DisplayMode.Tree) _GafferUI._pathListingWidgetAttachTester( GafferUI._qtAddress(w._qtWidget())) self.assertEqual(w.getPathExpanded(pa), False) self.assertEqual(w.getPathExpanded(pae), False) w.setSelectedPaths([pa], expandNonLeaf=False) self.assertEqual(w.getPathExpanded(pa), False) self.assertEqual(w.getPathExpanded(pae), False) # Fake a change to the path and check that the expansion is exactly as # it was. self.__emitPathChanged(w) self.assertEqual(w.getPathExpanded(pa), False) self.assertEqual(w.getPathExpanded(pae), False)
def testSelectionExpansion(self): d = {} for i in range(0, 10): dd = {} for j in range(0, 10): dd[str(j)] = j d[str(i)] = dd p = Gaffer.DictPath(d, "/") w = GafferUI.PathListingWidget( p, allowMultipleSelection=True, displayMode=GafferUI.PathListingWidget.DisplayMode.Tree) _GafferUI._pathListingWidgetAttachTester( GafferUI._qtAddress(w._qtWidget())) self.assertTrue(w.getSelection().isEmpty()) self.assertTrue(w.getExpansion().isEmpty()) s = IECore.PathMatcher(["/1", "/2", "/9", "/2/5"]) w.setSelection(s, expandNonLeaf=True, scrollToFirst=False) self.assertEqual(w.getSelection(), s) _GafferUI._pathModelWaitForPendingUpdates( GafferUI._qtAddress(w._qtWidget().model())) self.assertEqual(w.getExpansion(), IECore.PathMatcher(["/1", "/2", "/9"]))
def testExpandedPathsWhenPathChanges(self): d = { "a": { "e": 10, }, "b": { "f": "g", }, } p = Gaffer.DictPath(d, "/") p1 = Gaffer.DictPath(d, "/a") w = GafferUI.PathListingWidget( p, displayMode=GafferUI.PathListingWidget.DisplayMode.Tree) _GafferUI._pathListingWidgetAttachTester( GafferUI._qtAddress(w._qtWidget())) self.assertEqual(w.getPathExpanded(p1), False) w.setPathExpanded(p1, True) self.assertEqual(w.getPathExpanded(p1), True) # Fake a change to the path and check that the expansion is exactly as # it was. self.__emitPathChanged(w) self.assertEqual(w.getPathExpanded(p1), True) self.assertEqual(self.__expansionFromQt(w), IECore.PathMatcher(["/a"]))
def testSelection(self): d = {} for i in range(0, 10): dd = {} for j in range(0, 10): dd[str(j)] = j d[str(i)] = dd p = Gaffer.DictPath(d, "/") w = GafferUI.PathListingWidget( p, allowMultipleSelection=True, displayMode=GafferUI.PathListingWidget.DisplayMode.Tree) _GafferUI._pathListingWidgetAttachTester( GafferUI._qtAddress(w._qtWidget())) self.assertTrue(w.getSelection().isEmpty()) # Set selection. This should be immediately reflected in # the `selectionChangedSignal` and the result of `getSelection()`. cs = GafferTest.CapturingSlot(w.selectionChangedSignal()) s = IECore.PathMatcher(["/1", "/2", "/9", "/2/5", "/3/1"]) w.setSelection(s) self.assertEqual(w.getSelection(), s) self.assertEqual(len(cs), 1) # Delete a path that was selected. d2 = d["2"] del d["2"] self.__emitPathChanged(w) # We don't expect this to affect the result of `getSelection()` because # the selection state is independent of the model contents. self.assertEqual(w.getSelection(), s) # Now try to set selection twice in succession, so the model doesn't have # chance to finish one update before starting the next. s1 = IECore.PathMatcher(["/9", "/9/10", "/8/6"]) s2 = IECore.PathMatcher(["/9", "/9/9", "/5/6", "3"]) w.setSelection(s1) w.setSelection(s2) self.assertEqual(w.getSelection(), s2)