Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMSUSD-1519 refactor collection UI #4053

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/mayaUsd/resources/ae/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,28 @@ if(MAYA_APP_VERSION VERSION_GREATER_EQUAL 2023)
${MAYAUSD_SHARED_COMPONENTS}/common/filteredStringListModel.py
${MAYAUSD_SHARED_COMPONENTS}/common/filteredStringListView.py
${MAYAUSD_SHARED_COMPONENTS}/common/host.py
${MAYAUSD_SHARED_COMPONENTS}/common/list.py
${MAYAUSD_SHARED_COMPONENTS}/common/stringListPanel.py
${MAYAUSD_SHARED_COMPONENTS}/common/persistentStorage.py
${MAYAUSD_SHARED_COMPONENTS}/common/resizable.py
${MAYAUSD_SHARED_COMPONENTS}/common/theme.py
${MAYAUSD_SHARED_COMPONENTS}/common/menuButton.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python/usd_shared_components/common/
)

install(FILES
${MAYAUSD_SHARED_COMPONENTS}/data/__init__.py
${MAYAUSD_SHARED_COMPONENTS}/data/collectionData.py
${MAYAUSD_SHARED_COMPONENTS}/data/stringListData.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python/usd_shared_components/data/
)

install(FILES
${MAYAUSD_SHARED_COMPONENTS}/usdData/__init__.py
${MAYAUSD_SHARED_COMPONENTS}/usdData/usdCollectionData.py
${MAYAUSD_SHARED_COMPONENTS}/usdData/usdCollectionStringListData.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python/usd_shared_components/usdData/
)

set(LIB_ICONS
${MAYAUSD_SHARED_COMPONENTS}/icons/dark/add
${MAYAUSD_SHARED_COMPONENTS}/icons/dark/delete
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ..data.collectionData import CollectionData

try:
from PySide6.QtWidgets import QMenu, QWidget # type: ignore
Expand All @@ -13,28 +14,29 @@
EXPLICIT_ONLY_MENU_OPTION = "Explicit Only"

class ExpressionMenu(QMenu):
def __init__(self, collection, parent: QWidget):
def __init__(self, data: CollectionData, parent: QWidget):
super(ExpressionMenu, self).__init__(parent)
self._collection = collection
self._collData = data

expansionRulesMenu = QMenu("Expansion Rules", self)
self.expandPrimsAction = QAction(EXPAND_PRIMS_MENU_OPTION, expansionRulesMenu, checkable=True)
self.expandPrimsPropertiesAction = QAction(EXPAND_PRIMS_PROPERTIES_MENU_OPTION, expansionRulesMenu, checkable=True)
self.explicitOnlyAction = QAction(EXPLICIT_ONLY_MENU_OPTION, expansionRulesMenu, checkable=True)
expansionRulesMenu.addActions([self.expandPrimsAction, self.expandPrimsPropertiesAction, self.explicitOnlyAction])

self.update()

actionGroup = QActionGroup(self)
actionGroup.setExclusive(True)
for action in expansionRulesMenu.actions():
actionGroup.addAction(action)

self.triggered.connect(self.onExpressionSelected)
self._collData.dataChanged.connect(self._onDataChanged)
self.addMenu(expansionRulesMenu)

def update(self):
usdExpansionRule = self._collection.GetExpansionRuleAttr().Get()
self._onDataChanged()

def _onDataChanged(self):
usdExpansionRule = self._collData.getExpansionRule()
if usdExpansionRule == Usd.Tokens.expandPrims:
self.expandPrimsAction.setChecked(True)
elif usdExpansionRule == Usd.Tokens.expandPrimsAndProperties:
Expand All @@ -43,13 +45,9 @@ def update(self):
self.explicitOnlyAction.setChecked(True)

def onExpressionSelected(self, menuOption):
usdExpansionRule = self._collection.GetExpansionRuleAttr().Get()
if menuOption == self.expandPrimsAction:
if usdExpansionRule != Usd.Tokens.expandPrims:
self._collection.CreateExpansionRuleAttr(Usd.Tokens.expandPrims)
self._collData.setExpansionRule(Usd.Tokens.expandPrims)
elif menuOption == self.expandPrimsPropertiesAction:
if usdExpansionRule != Usd.Tokens.expandPrimsAndProperties:
self._collection.CreateExpansionRuleAttr(Usd.Tokens.expandPrimsAndProperties)
self._collData.setExpansionRule(Usd.Tokens.expandPrimsAndProperties)
elif menuOption == self.explicitOnlyAction:
if usdExpansionRule != Usd.Tokens.explicitOnly:
self._collection.CreateExpansionRuleAttr(Usd.Tokens.explicitOnly)
self._collData.setExpansionRule(Usd.Tokens.explicitOnly)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .expressionRulesMenu import ExpressionMenu
from ..common.menuButton import MenuButton
from ..common.theme import Theme
from ..data.collectionData import CollectionData

try:
from PySide6.QtCore import QEvent, Qt # type: ignore
Expand All @@ -12,16 +13,16 @@
from pxr import Usd, Sdf

class ExpressionWidget(QWidget):
def __init__(self, collection: Usd.CollectionAPI, parent: QWidget, expressionChangedCallback):
def __init__(self, data: CollectionData, parent: QWidget, expressionChangedCallback):
super(ExpressionWidget, self).__init__(parent)
self._collection = collection
self._collData = data
self._expressionCallback = expressionChangedCallback

mainLayout = QVBoxLayout(self)
margin: int = Theme.instance().uiScaled(2)
mainLayout.setSpacing(margin)

self._expressionMenu = ExpressionMenu(collection, self)
self._expressionMenu = ExpressionMenu(data, self)
menuButton = MenuButton(self._expressionMenu, self)

menuWidget = QWidget(self)
Expand All @@ -45,31 +46,20 @@ def __init__(self, collection: Usd.CollectionAPI, parent: QWidget, expressionCha
mainLayout.addWidget(self._expressionText, 1)

self._expressionText.installEventFilter(self)
self.update()
self.setLayout(mainLayout)
pierrebai-adsk marked this conversation as resolved.
Show resolved Hide resolved

def update(self):
usdExpressionAttr = self._collection.GetMembershipExpressionAttr().Get()
self._collData.dataChanged.connect(self._onDataChanged)
self._onDataChanged()

def _onDataChanged(self):
usdExpressionAttr = self._collData.getMembershipExpression()
if usdExpressionAttr != None:
self._expressionText.setPlainText(usdExpressionAttr.GetText())

self._expressionMenu.update()

def submitExpression(self):
usdExpressionAttr = self._collection.GetMembershipExpressionAttr().Get()
usdExpression = ""
if usdExpressionAttr != None:
usdExpression = usdExpressionAttr.GetText()

textExpression = self._expressionText.toPlainText()
if usdExpression != textExpression:
# assign default value if text is empty
if textExpression == "":
self._collection.CreateMembershipExpressionAttr()
else:
self._collection.CreateMembershipExpressionAttr(Sdf.PathExpression(textExpression))

if self._expressionCallback != None:
self._expressionCallback()
self._collData.setMembershipExpression(self._expressionText.toPlainText())
if self._expressionCallback != None:
self._expressionCallback()

def eventFilter(self, obj, event):
if event.type() == QEvent.KeyPress and obj is self._expressionText:
Expand Down
Loading