Example |
このサンプルでは、主にHoudini内の他の箇所からアイテムをドラッグしてPython Panelインターフェースにドロップする方法を説明しています。
<?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>