def testRevokedListener(self): self.listener.Revoke() with UsdQt.UndoBlock(): self.stage.DefinePrim('/World') with UsdQt.UndoBlock(): self.stage.DefinePrim('/World/Child') self.assertEqual(self.localUndoStack, [])
def testEmptyUndoBlock(self): with UsdQt.UndoBlock(): pass self.assertEqual(self.localUndoStack, []) with UsdQt.UndoBlock(): with UsdQt.UndoBlock(): with UsdQt.UndoBlock(): pass self.assertEqual(self.localUndoStack, [])
def __init__(self, delegate=None, parent=None): super(OpinionEditor, self).__init__(parent=parent) self.__menuBar = QtWidgets.QMenuBar() self.__layout = QtWidgets.QVBoxLayout() self.setLayout(self.__layout) self.__layout.addWidget(self.__menuBar) self.__SetupActions() self.__SetupOptionsMenu() self.__SetupEditMenu() self.__filterLineEdit = QtWidgets.QLineEdit() self.__view = treeView.TreeView() itemDelegate = delegate if delegate else UsdQt.ValueDelegate() self.__view.setItemDelegate(itemDelegate) self.__view.setEditTriggers( QtWidgets.QAbstractItemView.CurrentChanged | QtWidgets.QAbstractItemView.SelectedClicked | QtWidgets.QAbstractItemView.EditKeyPressed) self.__splitter = QtWidgets.QSplitter(QtCore.Qt.Vertical, self) self.__layout.addWidget(self.__filterLineEdit) self.__layout.addWidget(self.__splitter) self.__splitter.addWidget(self.__view) self.__view.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.__SetupOpinionViewWidget()
def testExpiredStage(self): with UsdQt.UndoBlock(): self.stage.DefinePrim('/World') self.stage = None with self.assertRaises(Tf.ErrorException): self.localUndoStack[-1].Invert()
def setUp(self): stagePath = 'simpleFilter.usda' stagePath = stagePath if os.path.isfile(stagePath) else \ os.path.join(os.path.splitext(__file__)[0], stagePath) self.stage = Usd.Stage.Open(stagePath) self.cache = UsdQt.PrimFilterCache()
def testMidEditBlockInversion(self): self.stage.DefinePrim('/World') with UsdQt.UndoBlock(): with self.assertRaisesRegexp( Tf.ErrorException, 'Inversion during \ open edit block may result in corrupted undo stack.'): self.localUndoStack[-1].Invert()
def test_invalidModel(self): invalidModel = UsdQt.LayerBaseModel() self.assertEqual(invalidModel.rowCount(), 0) with self.assertRaises(Exception): invalidModel.data(invalidModel.createIndex(0, 0)) with self.assertRaises(Exception): invalidModel.GetLayerFromIndex(self.createIndex(0, 0))
def test_UnmodifiedFilterModel(self): filterModel = UsdQt.HierarchyStandardFilterModel() filterModel.setSourceModel(self.model) pseudoRootIndex = filterModel.index(0, 0, QtCore.QModelIndex()) filterIndex = filterModel.index(0, 0, pseudoRootIndex) sourceIndex = filterModel.mapToSource(filterIndex) self.assertEqual(self.world, self.model._GetPrimForIndex(sourceIndex))
def __init__(self, parent=None): super(HierarchyEditor, self).__init__(parent=parent) self.menuBar = QtWidgets.QMenuBar() self.showMenu = QtWidgets.QMenu("Show") self.menuBar.addMenu(self.showMenu) self.__filterLineEdit = QtWidgets.QLineEdit() self.__hierarchyView = QtWidgets.QTreeView() self.__showMenuItems = OrderedDict([ (HierarchyEditor.ShowInactive, QtWidgets.QAction(HierarchyEditor.ShowInactive, self)), (HierarchyEditor.ShowUndefined, QtWidgets.QAction(HierarchyEditor.ShowUndefined, self)), (HierarchyEditor.ShowAbstract, QtWidgets.QAction(HierarchyEditor.ShowAbstract, self)), (HierarchyEditor.FilterAcrossArcs, QtWidgets.QAction(HierarchyEditor.FilterAcrossArcs, self)), ]) for item in self.__showMenuItems: self.__showMenuItems[item].setCheckable(True) self.showMenu.addAction(self.__showMenuItems[item]) self.__filterModel = UsdQt.HierarchyStandardFilterModel() self.__showMenuItems[HierarchyEditor.ShowInactive].toggled.connect( self.__filterModel.TogglePrimInactive) self.__showMenuItems[HierarchyEditor.ShowUndefined].toggled.connect( self.__filterModel.TogglePrimUndefined) self.__showMenuItems[HierarchyEditor.ShowAbstract].toggled.connect( self.__filterModel.TogglePrimAbstract) self.__showMenuItems[HierarchyEditor.FilterAcrossArcs].toggled.connect( self.__filterModel.ToggleFilterAcrossArcs) self.__showMenuItems[HierarchyEditor.FilterAcrossArcs].setChecked(True) self.__showMenuItems[HierarchyEditor.ShowInactive].setChecked(False) self.__showMenuItems[HierarchyEditor.ShowUndefined].setChecked(False) self.__showMenuItems[HierarchyEditor.ShowAbstract].setChecked(False) self.__layout = QtWidgets.QVBoxLayout() self.__layout.addWidget(self.menuBar) self.__layout.addWidget(self.__filterLineEdit) self.__layout.addWidget(self.__hierarchyView) self.__hierarchyView.setModel(self.__filterModel) self.__hierarchyView.setSelectionMode( QtWidgets.QAbstractItemView.ExtendedSelection) self.__filterLineEdit.returnPressed.connect( self.__OnFilterReturnPressed) self.setLayout(self.__layout) self.__SetupContextMenu()
def setUp(self): stageFilePath = "simpleHierarchy.usda" stageFilePath = stageFilePath if os.path.isfile(stageFilePath) else \ os.path.join(os.path.splitext(__file__)[0], stageFilePath) self.stage = Usd.Stage.Open(stageFilePath) self.stage.Reload() self.model = UsdQt.HierarchyStandardModel(self.stage) self.world = self.stage.GetPrimAtPath('/World') self.pseudoRootIndex = self.model.index(0, 0, QtCore.QModelIndex()) self.worldIndex = self.model.index(0, 0, self.pseudoRootIndex) self.primToDeactivate = self.stage.GetPrimAtPath( '/World/PrimToDeactivate') self.primToActivate = self.stage.GetPrimAtPath('/World/PrimToActivate') self.primWithVariants = self.stage.GetPrimAtPath( '/World/PrimWithVariants')
def testProperties(self): prims = [ self.stage.GetPrimAtPath(path) for path in [ '/MyPrim1/Child1', '/MyPrim1/Child2', '/MyPrim1/Child3', '/MyPrim1/Child4' ] ] model = UsdQt.OpinionStandardModel(prims) primIndex = model.index(0, 0, QtCore.QModelIndex()) proxy = model.GetProxyForIndex(primIndex) self.assertEqual(proxy.GetNames(), ['Child1', 'Child2', 'Child3', 'Child4']) self.assertEqual(model.data(primIndex), 'Child1, Child2, Child3, Child4') metadataGroupIndex = model.index(0, 0, primIndex) attributeGroupIndex = model.index(1, 0, primIndex) relationshipGroupIndex = model.index(2, 0, primIndex) self.assertGreater(model.rowCount(metadataGroupIndex), 0) self.assertEqual(model.rowCount(attributeGroupIndex), 2) self.assertEqual(model.rowCount(relationshipGroupIndex), 1) self.assertEqual(model.index(0, 0, attributeGroupIndex).data(), "x") self.assertEqual(model.index(0, 1, attributeGroupIndex).data(), "") self.assertEqual( model.index(0, 2, attributeGroupIndex).data(QtCore.Qt.DisplayRole), "") self.assertEqual( model.index(0, 2, attributeGroupIndex).data(QtCore.Qt.EditRole), None) self.assertEqual(model.index(1, 0, attributeGroupIndex).data(), "y") self.assertEqual(model.index(1, 1, attributeGroupIndex).data(), "int") self.assertEqual( model.index(1, 2, attributeGroupIndex).data(QtCore.Qt.DisplayRole), "2") self.assertEqual( model.index(1, 2, attributeGroupIndex).data(QtCore.Qt.EditRole), 2) self.assertEqual( model.index(0, 0, relationshipGroupIndex).data(), "rel1")
def __init__(self, parent=None): super(OpinionStackWidget, self).__init__(parent=parent) self.__toolBar = QtWidgets.QToolBar() self.__toolBar.addWidget(QtWidgets.QLabel('Opinion Stack')) self.__toolBar.addSeparator() self.__showAllAction = self.__toolBar.addAction("Show All") self.__showAllAction.setCheckable(True) self.__closeAction = self.__toolBar.addAction("Close") self.__showAllAction.toggled.connect(self.__OnShowAllToggled) self.__closeAction.triggered.connect(self.__OnClose) self.__opinionFilter = UsdQt.OpinionStackFilter() self.__view = QtWidgets.QTreeView() self.__view.setModel(self.__opinionFilter) self.__layout = QtWidgets.QVBoxLayout() self.__layout.addWidget(self.__toolBar) self.__layout.addWidget(self.__view) self.setLayout(self.__layout) policy = QtWidgets.QSizePolicy() policy.setHorizontalPolicy(QtWidgets.QSizePolicy.MinimumExpanding) policy.setVerticalPolicy(QtWidgets.QSizePolicy.MinimumExpanding) self.setSizePolicy(policy)
def testNestedUndoBlock(self): with UsdQt.UndoBlock(): prim = self.stage.DefinePrim('/World') self.assertTrue(bool(prim)) with UsdQt.UndoBlock(): prim.SetActive(False) with UsdQt.UndoBlock(): prim.SetActive(True) with UsdQt.UndoBlock(): prim.SetActive(False) self.assertFalse(prim.IsActive()) self.assertEqual(len(self.localUndoStack), 2) with UsdQt.UndoBlock(): prim.SetActive(False) with UsdQt.UndoBlock(): prim.SetActive(True) self.assertTrue(prim.IsActive()) self.assertEqual(len(self.localUndoStack), 3) self.localUndoStack[-1].Invert() # undo self.assertFalse(prim.IsActive()) self.localUndoStack[-1].Invert() # redo self.assertTrue(prim.IsActive()) self.localUndoStack[-1].Invert() # undo self.assertFalse(prim.IsActive()) self.localUndoStack[-2].Invert() # undo self.assertTrue(prim.IsActive()) self.localUndoStack[-3].Invert() # undo self.assertFalse(bool(prim)) self.localUndoStack[-3].Invert() # redo prim = self.stage.GetPrimAtPath('/World') self.assertTrue(bool(prim)) self.assertTrue(prim.IsActive()) self.assertEqual(len(self.localUndoStack), 3)
def Notice(self, notice, sender): inverse = UsdQt.UndoInverse() UsdQt.UndoRouter.TransferEdits(inverse) self.localUndoStack.append(inverse)
def LaunchOpinionViewer(self, prim, handler): self.__opinionViewer.Launch(UsdQt.OpinionStackModel(prim, handler))
objects = proxy.GetObjects() obj = objects[0] if type(obj) == Usd.Prim: self.editor.LaunchOpinionViewer( obj, _PrimMetadataHandler(proxy.GetName())) def ResetPrims(self, prims): self.model.ResetPrims(prims) self.editor.ResetColumnSpanned() # TODO: This is a hack that should be revisited self.editor.view.expandToDepth(1) if __name__ == '__main__': import sys app = QtWidgets.QApplication(sys.argv) stage = Usd.Stage.Open( '../usdQt/testenv/testUsdQtOpinionModel/simple.usda') prim = stage.GetPrimAtPath('/MyPrim1/Child1') model = UsdQt.OpinionStandardModel([prim]) # modelComposition = compositionModel.CompositionStandardModel(prim) editor = OpinionEditor() controller = OpinionController(model, editor) editor.SetSourceModel(model) editor.show() sys.exit(app.exec_())
def SetSourceModel(self, model): '''Replaces the current editor's current model with the new model. The model must be a subclass of HierarchyBaseModel.''' self.__filterModel.setSourceModel(model) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) with Usd.StageCacheContext(UsdUtils.StageCache.Get()): stage = Usd.Stage.Open( '../usdQt/testenv/testUsdQtHierarchyModel/simpleHierarchy.usda') model = UsdQt.HierarchyBaseModel(stage) class Listener(QtCore.QObject): def __init__(self, parent=None): super(Listener, self).__init__(parent=parent) @QtCore.Slot() def OnPrimSelectionChanged(self, selected=None, deselected=None): for index in self.sender().selectedIndexes(): prim = index.data(role=UsdQt.roles.HierarchyPrimRole) # print(prim) editor = HierarchyEditor() editor.SetSourceModel(model) editor.show()
def setUp(self): self.stage = Usd.Stage.Open(stageFilePath) assert (self.stage) self.model = UsdQt.LayerStandardModel(self.stage)
def setUp(self): stagePath = 'testenv/testUsdQtPrimFilterCache/simpleFilter.usda' stagePath = stagePath if os.path.isfile(stagePath) else stagePath.split('/')[-1] self.stage = Usd.Stage.Open(stagePath) self.cache = UsdQt.PrimFilterCache()