Skip to content

Commit

Permalink
EMSUSD-1519 Collections: remove all includes and excludes
Browse files Browse the repository at this point in the history
- Add to the data classes a function to remove all includes and excludes.
- Add to the UI a menu item to remove all includes and excludes.
- Make the UI call the data when triggered.
- Make menu item separators show up even as first item.
- Fix place hodler text in list view.
- Fix non-light collections.
  • Loading branch information
pierrebai-adsk committed Dec 20, 2024
1 parent 0dea815 commit b74a980
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@

from pxr import Usd

# TODO: support I8N
EXPAND_PRIMS_MENU_OPTION = "Expand Prims"
EXPAND_PRIMS_PROPERTIES_MENU_OPTION = "Expand Prims and Properties"
EXPLICIT_ONLY_MENU_OPTION = "Explicit Only"
kIncludeExcludeLabel = "Include/Exclude"
kRemoveAllLabel = "Remove All"

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

# Note: this is necessary to avoid the separator not show up.
self.setSeparatorsCollapsible(False)

self._incExSeparator = self.addSection(kIncludeExcludeLabel)
self._removeAllAction = QAction(kRemoveAllLabel, self)
self.addActions([self._incExSeparator, self._removeAllAction])

self._removeAllAction.triggered.connect(self._onRemoveAll)

self._collData.dataChanged.connect(self._onDataChanged)
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)
Expand All @@ -28,11 +41,10 @@ def __init__(self, data: CollectionData, parent: QWidget):
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)

actionGroup.triggered.connect(self.onExpressionSelected)

self._onDataChanged()

def _onDataChanged(self):
Expand All @@ -44,6 +56,9 @@ def _onDataChanged(self):
elif usdExpansionRule == Usd.Tokens.explicitOnly:
self.explicitOnlyAction.setChecked(True)

def _onRemoveAll(self):
self._collData.removeAllIncludeExclude()

def onExpressionSelected(self, menuOption):
if menuOption == self.expandPrimsAction:
self._collData.setExpansionRule(Usd.Tokens.expandPrims)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from PySide6.QtGui import QPainter, QPaintEvent, QFont # type: ignore
from PySide6.QtWidgets import ( # type: ignore
QLabel,
QListView,
QStyledItemDelegate,
QStyleOptionViewItem
Expand All @@ -33,7 +34,7 @@
Signal,
)
from PySide2.QtGui import QPainter, QPaintEvent, QFont # type: ignore
from PySide2.QtWidgets import QListView, QStyledItemDelegate, QStyleOptionViewItem # type: ignore
from PySide2.QtWidgets import QLabel, QListView, QStyledItemDelegate, QStyleOptionViewItem # type: ignore


NO_OBJECTS_FOUND_LABEL = "No objects found"
Expand Down Expand Up @@ -81,6 +82,16 @@ def __init__(self, data: StringListData, headerTitle: str = "", parent=None):
self.setSelectionMode(QListView.SelectionMode.ExtendedSelection)
self.setContentsMargins(1, 0, 1, 1)

self.placeholder_label = QLabel(self)
self.placeholder_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
palette = self.placeholder_label.palette()
palette.setColor(
self.placeholder_label.foregroundRole(),
Theme.instance().palette.colorPlaceHolderText,
)
self.placeholder_label.setPalette(palette)
self.placeholder_label.hide()

self.setCursor(Qt.ArrowCursor)

DragAndDropEventFilter(self, data)
Expand All @@ -107,19 +118,22 @@ def paintEvent(self, event: QPaintEvent):
self._paintPlaceHolder(DRAG_OBJECTS_HERE_LABEL)
elif Host.instance().canPick:
self._paintPlaceHolder(PICK_OBJECTS_LABEL)
else:
self.placeholder_label.hide()
else:
self.placeholder_label.hide()

def _paintPlaceHolder(self, placeHolderText):
self.placeholder_label.setText(placeHolderText)
self.placeholder_label.setGeometry(self.viewport().geometry())
self.placeholder_label.show()

def selectedItems(self) -> Sequence[str]:
return [str(index.data(Qt.DisplayRole)) for index in self.selectedIndexes()]

def hasSelectedItems(self) -> bool:
return bool(self.selectionModel().hasSelection())

def _paintPlaceHolder(self, placeHolderText):
painter = QPainter(self.viewport())
theme = Theme.instance()
painter.setPen(theme.palette.colorPlaceHolderText)
painter.drawText(self.rect(), Qt.AlignCenter, placeHolderText)

class DragAndDropEventFilter(QObject):
def __init__(self, widget, data: StringListData):
super().__init__(widget)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class Palette(object):
def __init__(self):
super(Theme.Palette, self)
self.colorResizeBorderActive: QColor = QColor(0x5285a6)
self.colorPlaceHolderText = QColor(128, 128, 128)

pal = QPallette = QPalette()
pal = QPalette()

self.colorPlaceHolderText = pal.color(QPalette.ColorRole.WindowText)
self.colorPlaceHolderText.setAlphaF(0.7)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def getExcludeData(self) -> StringListData:
Returns the excluded items string list.
'''
return None

def removeAllIncludeExclude(self):
'''
Remove all included and excluded items.
'''
pass

# Expression

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def includesAll(self) -> bool:
if not self._collection:
return False
includeRootAttribute = self._collection.GetIncludeRootAttr()
return includeRootAttribute.Get()
return bool(includeRootAttribute.Get())

def setIncludeAll(self, state: bool):
'''
Expand All @@ -99,6 +99,13 @@ def getExcludeData(self) -> CollectionStringListData:
'''
return self._excludes

def removeAllIncludeExclude(self):
'''
Remove all included and excluded items.
By design, we author a block collection opinion.
'''
self._collection.BlockCollection()

# Expression

def getExpansionRule(self):
Expand Down Expand Up @@ -143,14 +150,10 @@ def setMembershipExpression(self, textExpression: AnyStr):
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()

0 comments on commit b74a980

Please sign in to comment.