Skip to content

Commit

Permalink
EMSUSD-1519 refactor collection UI
Browse files Browse the repository at this point in the history
- Rename list.py to stringListPanel.py
- Add data and usdData modules.
- Add collectionData and stringData to the data module as abstract interface to read and modify collection data.
- Add usdCollectionData and usdCollectionStringListData to usdData, for USD implementation.
- Allow setting the collection on the usdCollectionData.
- Still need to derive a Maya implementation to host picking and undo/redo.
- Make all UI use the collectionData and stringListData clases to hold and modify data instead of having business logic in UI.
- This also avoids business logic referring to UI labels and such.
- This also automatically updates the data source for teh Ui since the model is the data source.
- Removed all update and updateUI functions and flags and listen to dataChanged signals instead.
- Moved drag-and-drop event filter to string list view.
- Don't stop adding dropped item just because one is invalid.
- Move dropped item conversion and validation to the data class.

Small UI fixes:
- Fix selection mode of list views.
- Fixed issues with the check box callback getting the wrong state.
- Add include-all checkbox tooltip.
- Made the color and font size for the filtered list view come from the Theme.
- Removed place holder label and use paint event instead to both paint "no object found" and "drop stuff here".
  • Loading branch information
pierrebai-adsk committed Dec 17, 2024
1 parent d0139af commit 510aee3
Show file tree
Hide file tree
Showing 15 changed files with 525 additions and 298 deletions.
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/menu
${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,5 +1,6 @@
from .expressionRulesMenu import ExpressionMenu
from ..common.menuButton import MenuButton
from ..data.collectionData import CollectionData

try:
from PySide6.QtCore import QEvent, Qt # type: ignore
Expand All @@ -11,9 +12,9 @@
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

self._expressionText = QTextEdit(self)
Expand All @@ -22,7 +23,7 @@ def __init__(self, collection: Usd.CollectionAPI, parent: QWidget, expressionCha
self._expressionText.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self._expressionText.setPlaceholderText("Type an expression here...")

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

menuWidget = QWidget(self)
Expand All @@ -37,31 +38,19 @@ def __init__(self, collection: Usd.CollectionAPI, parent: QWidget, expressionCha

self._expressionText.installEventFilter(self)
self.setLayout(mainLayout)
self.update()

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

0 comments on commit 510aee3

Please sign in to comment.