def buildNodeHeader(editor: PropertyEditorTree, node: logics.node2d.TreeNode2D): # icon | name # type nname = QtWidgets.QLineEdit(node.name) nname.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) def updateName(nval): node.name = nval editor.mwindow.updateTreeName() nname.textChanged.connect(updateName) editor.name = nname ntype = QtWidgets.QLabel(str(type(node))) ntype.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) nicon = QtWidgets.QLabel() nicon.setMinimumSize(32, 32) nicon.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) editor.icon = nicon # R side layout rlayout = QtWidgets.QVBoxLayout() rlayout.addWidget(nname) rlayout.addWidget(ntype) # Header layout hlayout = QtWidgets.QHBoxLayout() hlayout.addWidget(nicon) hlayout.addLayout(rlayout) return hlayout
def buildNodePropertyPage(mwindow, node: logics.node2d.TreeNode): if node is not None: host = mwindow.propertyWidget.layout() globals.propertyContainer.activeNode = node editorBase = PropertyEditorTree() host.addLayout(buildNodeHeader(editorBase, node)) line = QtWidgets.QFrame() line.setFrameShape(QtWidgets.QFrame.HLine) line.setFrameShadow(QtWidgets.QFrame.Sunken) host.addWidget(line) flayout = QtWidgets.QFormLayout() flayout.setHorizontalSpacing(12) editorBase.flayout = flayout editorBase.mwindow = mwindow for rows in buildNodeProperties(editorBase, node): if type(rows) == tuple: flayout.addRow(*rows) elif rows is not None: flayout.addRow(rows) host.addLayout(flayout) nsp = QtWidgets.QSpacerItem( QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Expanding)) host.addItem(nsp) return editorBase
def buildImageProperties(editor: PropertyEditorTree, node: logics.node2d.Image): rows = [] def repaintCallback(): if globals.repaintScreen is not None: globals.repaintScreen() editor.offPos = PropertyEditorTree() pl, pw = buildPos2DEditor(editor.offPos, node, 'offPos', "Position", repaintCallback) rows.append((pl, pw)) wl, ww = buildFloatEditor(node, 'widthScale', "Width Scale", repaintCallback) editor.widthScale = PropertyEditorTree(wl, ww) rows.append((wl, ww)) return rows
def buildShapeProperty(editor: PropertyEditorTree, obj: object, name: str, callback=None): lshape = getattr(obj, name) fwidget = QtWidgets.QWidget() flayout = QtWidgets.QFormLayout() flayout.setHorizontalSpacing(12) flayout.setContentsMargins(20, 0, 0, 0) if isinstance(lshape, logics.shape.Round): labelr, liner = properties.simple.buildFloatEditor( lshape, 'radius', "Radius", callback) editor.radius = PropertyEditorTree(labelr, liner) flayout.addRow(labelr, liner) elif isinstance(lshape, logics.shape.Rectangle): labelw, linew = properties.simple.buildFloatEditor( lshape, 'width', "Width", callback) editor.width = PropertyEditorTree(labelw, linew) flayout.addRow(labelw, linew) labelh, lineh = properties.simple.buildFloatEditor( lshape, 'height', "Height", callback) editor.width = PropertyEditorTree(labelh, lineh) flayout.addRow(labelh, lineh) fwidget.setLayout(flayout) return fwidget
def buildPos2DEditor(editor: PropertyEditorTree, obj: object, name: str, dispname: str, callback=None): base = QtWidgets.QHBoxLayout() base.setSpacing(8) fleft = QtWidgets.QFormLayout() fright = QtWidgets.QFormLayout() posObj = getattr(obj, name) lx, wx = buildFloatEditor(posObj, 'posX', "X", callback) editor.posX = PropertyEditorTree(lx, wx) ly, wy = buildFloatEditor(posObj, 'posY', "Y", callback) editor.posY = PropertyEditorTree(ly, wy) ls, ws = buildFloatEditor(posObj, 'scale', "Scale", callback) editor.scale = PropertyEditorTree(ls, ws) lr, wr = buildFloatEditor(posObj, 'rotRad', "Angle", callback) editor.rotRad = PropertyEditorTree(lr, wr) lr.mouseScale = 0.0001 wslock = QtWidgets.QCheckBox("Lock Scale") wslock.setChecked(posObj.lockScale) editor.lockScale = wslock wslock.stateChanged.connect( lambda nval=0, swid=ls: swid.setEnabled(nval <= 0)) wslock.stateChanged.connect( lambda nval=0, swid=ws: swid.setEnabled(nval <= 0)) wslock.stateChanged.connect( lambda nval=0, lobj=posObj: setattr(lobj, 'lockScale', nval > 0)) ws.setEnabled(not posObj.lockScale) ls.setEnabled(not posObj.lockScale) fleft.addRow(lx, wx) fright.addRow(ly, wy) fleft.addRow(ls, ws) fright.addRow(lr, wr) fleft.addRow(wslock) base.addLayout(fleft) base.addLayout(fright) return QtWidgets.QLabel(dispname), base
def buildTreeNode2DProperties(editor: PropertyEditorTree, node: logics.node2d.TreeNode2D): rows = [] def repaintCallback(): if globals.repaintScreen is not None: globals.repaintScreen() editor.offPos = PropertyEditorTree() pl, pw = buildPos2DEditor(editor.offPos, node, 'offPos', "Position", repaintCallback) rows.append((pl, pw)) if hasattr(node, "displayChain"): editor.displayChain = PropertyEditorTree() dl, dw = buildDisplayChainEditor(node, "displayChain", "Display Chain", repaintCallback) dp = buildDisplayChainProperty(editor.displayChain, node, "displayChain", repaintCallback) rows.append((dl, dw)) rows.append(dp) return rows
def buildSamplePointProperties(editor: PropertyEditorTree, node: logics.node2d.SamplePoint): rows = [] def repaintCallback(): if globals.repaintScreen is not None: globals.repaintScreen() editor.offPos = PropertyEditorTree() pl, pw = buildPos2DEditor(editor.offPos, node, 'offPos', "Position", repaintCallback) rows.append((pl, pw)) editor.sampleShape = PropertyEditorTree() sp = buildShapeProperty(editor.sampleShape, node, "sampleShape", repaintCallback) editor.sampleShape.Input = sp def changeShapeCallback(): repaintCallback() osp = editor.sampleShape.Input host = osp.parentWidget() nsp = buildShapeProperty(editor.sampleShape, node, "sampleShape", repaintCallback) osp = host.layout().replaceWidget(osp, nsp) osp.widget().deleteLater() editor.sampleShape.Input = nsp sl, sw = buildShapeEditor(node, "sampleShape", "Sampling Shape", changeShapeCallback) rows.append((sl, sw)) rows.append(sp) editor.encoder = PropertyEditorTree() el, ew = buildEncoderEditor(node, 'encoder', "Encoder", repaintCallback) ep = buildEncoderProperty(editor.encoder, node, 'encoder', repaintCallback) rows.append((el, ew)) rows.append(ep) return rows