Example |
This example demonstrates specifically how to enable dragging items from other parts in Houdini and dropping them into the Python Panel interface.
<?xml version="1.0" encoding="UTF-8"?> <pythonPanelDocument> <!-- This file contains definitions of Python interfaces and the interfaces menu. It should not be hand-edited when it is being used by the application. Note, that two definitions of the same interface or of the interfaces menu are not allowed in a single file. --> <interface name="DragDropExample" label="Drag and Drop Example" icon="SOP_torus"> <script><![CDATA[from hutil.Qt import QtCore, QtGui, QtWidgets class DDTest(QtWidgets.QFrame): def __init__(self, parent=None): super(DDTest, self).__init__(parent) self.myList = QtWidgets.QListView(self) self.myModel = QtGui.QStandardItemModel(self.myList) self.myList.setModel(self.myModel) self.mySlider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self) self.mySlider.setRange(1, 100) self.mySlider.setSliderPosition(20) self.mySlider.valueChanged.connect(self.sliderChange) list_label = QtWidgets.QLabel("Selected nodes (drag and drop to add):") slider_label = QtWidgets.QLabel("Uniform scale:") horiz_layout = QtWidgets.QHBoxLayout() horiz_layout.addWidget(slider_label) horiz_layout.addWidget(self.mySlider) layout = QtWidgets.QVBoxLayout() layout.addWidget(list_label) layout.addWidget(self.myList) layout.addLayout(horiz_layout) self.setLayout(layout) self.setAcceptDrops(True) def dragEnterEvent(self, event): event.acceptProposedAction() def dropEvent(self, event): str = event.mimeData().text() index = str.find(",") while index > 0: item = QtGui.QStandardItem() item.setText(str[0:index]) item.setCheckable(True) item.setCheckState(QtCore.Qt.Checked) self.myModel.appendRow(item) str = str[index+1:] index = str.find(",") item = QtGui.QStandardItem() item.setText(str) item.setCheckable(True) item.setCheckState(QtCore.Qt.Checked) self.myModel.appendRow(item) event.acceptProposedAction() def sliderChange(self, value): scale = float(value) / 20 for i in range(0, self.myModel.rowCount()): item = self.myModel.item(i) if item.checkState() is QtCore.Qt.Checked: node = hou.node(item.text()) if node is not None: node.setParms({"scale": scale}) def onCreateInterface(): return DDTest() ]]></script> </interface> </pythonPanelDocument>