def __selectionChangedCallback(self): """ Is called when a pass is selected. This will create the UI for altering the shadowBranch and adding new light passes to another tree list. """ # Don't respond to changes while we update if self.__updating: return selectedItems = self.__treeWidget.selectedItems() # If more than one item is selected, don't display settings if len(selectedItems) != 1: self.__clearEditor() return if not selectedItems: selectedItem = None selectedKey = None else: selectedItem = selectedItems[0] selectedKey = hash(selectedItem.getItemData().getShadowBranchNode()) if self.__editorKey == selectedKey: return self.__editorKey = selectedKey if self.__editorKey is None: return self.__clearEditor() renderPass = selectedItem.getItemData() # Shadow Branch shadowBranchNode = renderPass.getShadowBranchNode() policy = UI4.FormMaster.CreateParameterPolicy(None, shadowBranchNode.getParameters()) # Hints can be used to specify additional options. Setting 'hideTitle' # to true will display the contents of the parameter group directly # rather than showing them as group with a title. policy.getWidgetHints()['hideTitle'] = False self.__editorWidget.layout().addWidget( UI4.FormMaster.ParameterWidgetFactory.buildWidget( self.__editorWidget, policy)) ####################################################################### # Set up Add button and define click action addLightButton = LightPickerButton(self) addLightButton.setDisplayMode(DISPLAY_LIGHTS) addLightButton.setText('Add light') addLightButton.setIcon(UI4.Util.IconManager.GetIcon( 'Icons/plus16.png')) @connectsignal(addLightButton, 'itemChosen') def addButtonClick(value, meta): lightPath = meta[0] type = meta[1] self.addLightPass(lightPath) self.__editorWidget.layout().addWidget(addLightButton) self.__addLightButton = addLightButton # Light list stretch box self.__lightListStretchBox = UI4.Widgets.StretchBox(self, allowHorizontal=False, allowVertical=True) self.__editorWidget.layout().addWidget(self.__lightListStretchBox) ####################################################################### # Set up the lightListWidget which represents the light passes lightListWidget = QT4Widgets.SortableTreeWidget(self.__lightListStretchBox) lightListWidget.setHeaderLabels(['Name']) lightListWidget.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection) lightListWidget.setAllColumnsShowFocus(True) lightListWidget.setRootIsDecorated(False) lightListWidget.setDraggable(True) lightListWidget.setMinimumHeight(100) self.__lightListStretchBox.layout().addWidget(lightListWidget) self.__lightListStretchBox.setMinHeight(100) self.__lightListStretchBox.setFixedHeight(100) ####################################################################### # lightListWidget events # Configure treeWidget that holds passes self.__lightWidget = lightListWidget self.__handleLightListEvents(self.__lightWidget) self.connect(lightListWidget, QtCore.SIGNAL('itemSelectionChanged()'), self.__lightSelectionChangedCallback) self.__editorWidget.layout().addWidget(self.__lightSettingsWidget) self.updateLightList()
def __init__(self, parent, node): node.upgrade() self.__node = node QtGui.QWidget.__init__(self, parent) QtGui.QVBoxLayout(self) self.__frozen = True self.__updateTreeOnIdle = False self.__selectedPonyPolicy = None self.__preselectName = None # location FormWidget locationPolicy = UI4.FormMaster.CreateParameterPolicy( None, self.__node.getParameter('location')) factory = UI4.FormMaster.KatanaFactory.ParameterWidgetFactory w = factory.buildWidget(self, locationPolicy) self.layout().addWidget(w) # toolbar self.__toolbarLayout = QtGui.QHBoxLayout() self.layout().addItem(self.__toolbarLayout) self.__addButton = UI4.Widgets.ToolbarButton( 'Add Pony', self, UI4.Util.IconManager.GetPixmap('Icons/plus16.png'), rolloverPixmap=UI4.Util.IconManager.GetPixmap( 'Icons/plusHilite16.png')) self.connect(self.__addButton, QtCore.SIGNAL('clicked()'), self.__addButtonClicked) self.__toolbarLayout.addWidget(self.__addButton) self.__toolbarLayout.addStretch() # tree widget self.__treeStretchBox = UI4.Widgets.StretchBox(self, allowHorizontal=False, allowVertical=True) self.layout().addWidget(self.__treeStretchBox) self.__treeWidget = QT4Widgets.SortableTreeWidget( self.__treeStretchBox) self.__treeWidget.setHeaderLabels(['Name']) self.__treeWidget.setSelectionMode(QtGui.QTreeWidget.SingleSelection) self.__treeWidget.setAllColumnsShowFocus(True) self.__treeWidget.setRootIsDecorated(False) self.__treeWidget.header().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.__treeWidget.header().setClickable(False) self.connect(self.__treeWidget, QtCore.SIGNAL('itemSelectionChanged()'), self.__treeWidgetSelectionChanged) self.connect(self.__treeWidget, QtCore.SIGNAL('keyPressEvent'), self.__treeWidgetKeyPressCallback) self.__treeStretchBox.layout().addWidget(self.__treeWidget) self.__treeStretchBox.setFixedHeight(120) self.__formItemTree = QT4FormWidgets.FormItemTree(self) self.layout().addWidget(self.__formItemTree) self.__updateTreeContents() self.layout().addStretch()
def __init__(self, parent, node): """ Initialize the editor and set up UI """ self.__node = node self.__preselectionKey = None self.__lightselectionKey = None self.__editorKey = None self.__updating = False QtGui.QWidget.__init__(self, parent) QtGui.QHBoxLayout(self) self.__treeLayout = QtGui.QVBoxLayout() self.layout().addLayout(self.__treeLayout) # toolbar { self.__treeToolbarLayout = QtGui.QHBoxLayout() self.__treeLayout.addLayout(self.__treeToolbarLayout) self.__addButton = UI4.Widgets.ToolbarButton( 'Add Render Pass', self, UI4.Util.IconManager.GetPixmap('Icons/plus16.png'), rolloverPixmap = UI4.Util.IconManager.GetPixmap( 'Icons/plusHilite16.png')) @connectsignal(self.__addButton, 'clicked()') def addButtonClick(): renderPass = self.__node.addRenderPass('pass1') self.__preselectionKey = hash(renderPass.getShadowBranchNode()) self.__treeToolbarLayout.addWidget(self.__addButton) self.__treeToolbarLayout.addStretch() # } self.__treeStretchBox = UI4.Widgets.StretchBox(self, allowHorizontal=True, allowVertical=True) self.__treeLayout.addWidget(self.__treeStretchBox) ####################################################################### # Set up the treeWidget which represents the passes treeWidget = QT4Widgets.SortableTreeWidget(self.__treeStretchBox) treeWidget.setHeaderLabels(['Name']) treeWidget.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection) treeWidget.setAllColumnsShowFocus(True) treeWidget.setRootIsDecorated(False) treeWidget.header().setResizeMode(QtGui.QHeaderView.ResizeToContents) treeWidget.header().setClickable(False) treeWidget.header().hide() treeWidget.setDraggable(True) ####################################################################### # treeWidget events @connectsignal(treeWidget, 'mousePressEvent') def treeWidgetMousePressEvent(event): """ Handle mouse events """ # Set up context menu (right-click) if event.button() == QtCore.Qt.RightButton: item = treeWidget.itemAt(event.pos()) if not item: return scriptItem = item.getItemData() item.setHiliteColor(QtGui.QColor(32,32,32)) treeWidget.update(treeWidget.indexFromItem(item)) menu = QtGui.QMenu(None) # Add 'Delete' action menu.addAction('Delete', scriptItem.delete) menu.addSeparator() # Add 'View From ShadowBranch Node' action def viewNode(): NodegraphAPI.SetNodeViewed( scriptItem.getShadowBranchNode(), True, exclusive=True) action = menu.addAction('View From ShadowBranch Node',viewNode) action.setIcon(UI4.Util.IconManager.GetIcon( 'Icons/AttributeEditor/blue_snapback.png')) # Show menu pos = event.pos() pos = treeWidget.mapToGlobal(QtCore.QPoint( pos.x(), pos.y())) try: menu.exec_(pos) finally: item.setHiliteColor(None) treeWidget.update(treeWidget.indexFromItem(item)) event.accept() @connectsignal(treeWidget, 'keyPressEvent') def keyPressEvent(event): """ Handle key events """ selectedItems = treeWidget.selectedItems() if not selectedItems: return # Single selection for now scriptItem = selectedItems[0].getItemData() # Delete key: Remove selected items if event.key() == QtCore.Qt.Key_Delete: for item in selectedItems: item.getItemData().delete() # Configure treeWidget callbacks and delegates self.__treeWidget = treeWidget self.__treeWidget.setItemDelegate( self.RenderPassItemDelegate(self.__treeWidget)) self.__handleDragEvents(self.__treeWidget) self.connect(treeWidget, QtCore.SIGNAL('itemSelectionChanged()'), self.__selectionChangedCallback) # Add treeWidget to layout self.__treeStretchBox.layout().addWidget(treeWidget) self.__treeStretchBox.setFixedHeight(160) self.__treeStretchBox.setFixedWidth(120) self.__treeLayout.addStretch() # Layout settings self.__editorMainLayout = QtGui.QVBoxLayout() self.layout().addLayout(self.__editorMainLayout, 10) self.__editorMainLayout.addSpacing(4) self.__editorWidget = QtGui.QWidget(self) self.__editorMainLayout.addWidget(self.__editorWidget) QtGui.QVBoxLayout(self.__editorWidget) self.__editorMainLayout.addStretch() # Create lightSettings widget containing the UI for a light self.__lightSettingsWidget = QtGui.QWidget(self) self.__editorWidget.layout().addWidget(self.__lightSettingsWidget) QtGui.QVBoxLayout(self.__lightSettingsWidget)