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 Collections: remove all includes and excludes #4058

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I know this is maya convention, but we probably would want to keep it capitalized for consistency in this case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right I wrote these a few days ago, before the other review. We can change them afterward

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 @@ -132,14 +132,14 @@ def onAddToIncludePrimClicked(self):
stage = self._collData.getStage()
if not stage:
return
items = Host.instance().pick(stage, ADD_INCLUDE_OBJECTS_TITLE)
items = Host.instance().pick(stage, dialogTitle=ADD_INCLUDE_OBJECTS_TITLE)
self._collData.getIncludeData().addStrings(items)

def onAddToExcludePrimClicked(self):
stage = self._collData.getStage()
if not stage:
return
items = Host.instance().pick(stage, ADD_EXCLUDE_OBJECTS_TITLE)
items = Host.instance().pick(stage, dialogTitle=ADD_EXCLUDE_OBJECTS_TITLE)
self._collData.getExcludeData().addStrings(items)

def onRemoveSelectionFromInclude(self):
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()

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MayaHost(Host):
def __init__(self):
pass

def pick(self, stage: Usd.Stage) -> Sequence[Usd.Prim]:
def pick(self, stage: Usd.Stage, *, dialogTitle: str = "") -> Sequence[Usd.Prim]:
return [] # nothing to do yet


Expand Down