Ejemplo n.º 1
0
    def mayaSelectionChanged(self, *args):
        '''Callback to mirror maya selection changes in the Outliner'''
        if self._blockSelectionCallback:
            return
        self._blockSelectionCallback = True

        parentPath = self._proxyShape.getParent().fullPath()
        selected = pm.ls(type=pm.nt.AL_usdmaya_Transform, selection=1)
        qSelection = QtCore.QItemSelection()
        for dagNode in selected:
            dagPath = dagNode.fullPath()
            assert parentPath in dagPath, '%s not in %s' % (parentPath,
                                                            dagPath)
            primPath = dagPath[len(parentPath):].replace('|', '/')

            try:
                itemIndex = self.getIndexForPrimPath(primPath)
            except ItemLookupError:
                # create missing prim items as needed before selecting
                self.createParents(primPath)
                itemIndex = self.getIndexForPrimPath(primPath)
            qSelection.select(itemIndex, itemIndex)
        selModel = self.view.selectionModel()
        selModel.select(
            qSelection, QtCore.QItemSelectionModel.SelectCurrent
            | QtCore.QItemSelectionModel.Clear
            | QtCore.QItemSelectionModel.Rows)

        indexes = qSelection.indexes()
        if indexes:
            self.view.scrollTo(indexes[0], self.view.PositionAtTop)
        self._blockSelectionCallback = False
Ejemplo n.º 2
0
    def test_UnmodifiedFilterModel(self):
        filterModel = hierarchyModel.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))
Ejemplo n.º 3
0
    def test_RootStructure(self):

        self.assertEqual(self.model.rowCount(QtCore.QModelIndex()), 1)
        self.assertEqual(self.model._GetPrimForIndex(self.pseudoRootIndex),
                         self.stage.GetPseudoRoot())

        self.assertEqual(self.model.rowCount(self.pseudoRootIndex), 1)
        self.assertEqual(self.model._GetPrimForIndex(self.worldIndex),
                         self.world)
Ejemplo n.º 4
0
    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 = hierarchyModel.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')
Ejemplo n.º 5
0
    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")
Ejemplo n.º 6
0
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#

from __future__ import absolute_import

from treemodel.itemtree import ItemTree, TreeItem

from typing import (Any, Dict, Generic, Iterable, Iterator, List, Optional,
                    Tuple, Union, TYPE_CHECKING)

from pxr.UsdQt._Qt import QtCore, QtGui

NULL_INDEX = QtCore.QModelIndex()


class AbstractTreeModelMixin(object):
    '''
    Mixin class that implements the necessary methods for Qt model to reflect
    the structure of an ``ItemTree`` instance.
    '''
    def __init__(self, itemTree=None, parent=None):
        '''
        Parameters
        ----------
        itemTree : Optional[ItemTree]
        parent
        '''
        super(AbstractTreeModelMixin, self).__init__(parent=parent)