def __init__(self, link: Link, parent=None): super().__init__(link, parent) print("creating test link") self.name = "Outcome" self._widget_proxy = QGraphicsProxyWidget(self) self._widget = QTestLinkProxy() print("proxy widget created") self.name_edit = QLabelEdit(self._widget) self.name_edit.setCallback(self.set_name) self.name_edit.setText(self.name) self.name_edit.setFixedWidth(80) self.name_edit.setAlignment(Qt.AlignCenter) self.name_edit.setFont(QFont("Arial", 10)) print("name edit initialized") _start = self.get_start() _end = self.get_end() _center = [(_start[0] + _end[0]) * 0.5, (_start[1] + _end[1]) * 0.5] _size = [80, 25] print("center position found") self._widget.setGeometry(_center[0] - _size[0] * 0.5, _center[1] - _size[1] * 0.5, _size[0], _size[1]) print("name edit geometry set") self._widget_proxy.setWidget(self._widget) print("widget set to proxy")
def init_content(self): for socket in self.node.sockets: self.addSocket(socket) self.name_edit = QLabelEdit() if type(self.node) is NodeEvent: self.name_edit.setCallback(self.node.set_name) self.name_edit.setText("Name") self.name_edit.setFixedWidth(200 - 20) self.name_edit.setAlignment(Qt.AlignCenter) self.name_edit.setFont(QFont("Arial", 10)) self.layout.addWidget(self.name_edit)
class _NodeEventContent(QDMContentWidget): def __init__(self, parent): self.name_edit = None super().__init__(parent) self.setFixedWidth(200 - 20) self.setFixedHeight(50 - 20) def init_content(self): for socket in self.node.sockets: self.addSocket(socket) self.name_edit = QLabelEdit() if type(self.node) is NodeEvent: self.name_edit.setCallback(self.node.set_name) self.name_edit.setText("Name") self.name_edit.setFixedWidth(200 - 20) self.name_edit.setAlignment(Qt.AlignCenter) self.name_edit.setFont(QFont("Arial", 10)) self.layout.addWidget(self.name_edit) def refresh(self): self.name_edit.setText(self.node.name)
class TestLinkGraphics(QDMGraphicsLinkDirect): def __init__(self, link: Link, parent=None): super().__init__(link, parent) print("creating test link") self.name = "Outcome" self._widget_proxy = QGraphicsProxyWidget(self) self._widget = QTestLinkProxy() print("proxy widget created") self.name_edit = QLabelEdit(self._widget) self.name_edit.setCallback(self.set_name) self.name_edit.setText(self.name) self.name_edit.setFixedWidth(80) self.name_edit.setAlignment(Qt.AlignCenter) self.name_edit.setFont(QFont("Arial", 10)) print("name edit initialized") _start = self.get_start() _end = self.get_end() _center = [(_start[0] + _end[0]) * 0.5, (_start[1] + _end[1]) * 0.5] _size = [80, 25] print("center position found") self._widget.setGeometry(_center[0] - _size[0] * 0.5, _center[1] - _size[1] * 0.5, _size[0], _size[1]) print("name edit geometry set") self._widget_proxy.setWidget(self._widget) print("widget set to proxy") def updatePath(self): _start = self.get_start() _end = self.get_end() _center = [(_start[0] + _end[0]) * 0.5, (_start[1] + _end[1]) * 0.5] _size = [80, 20] self._widget.setGeometry(_center[0] - _size[0] * 0.5, _center[1] - _size[1] * 0.5, _size[0], _size[1]) path = QPainterPath(QPointF(_start[0], _start[1])) _out_id = self.link.socketOut.identifier if "up" in _out_id or "down" in _out_id: path.lineTo(QPointF(_start[0], _center[1])) else: path.lineTo(QPointF(_center[0], _start[1])) path.lineTo(QPointF(_center[0], _center[1])) _in_id = self.link.socketIn.identifier if "up" in _in_id or "down" in _in_id: path.lineTo(QPointF(_end[0], _center[1])) else: path.lineTo(QPointF(_center[0], _end[1])) path.lineTo(QPointF(_end[0], _end[1])) self.setPath(path) @classmethod def get_type_name(cls): return "Test" def get_color(self): return "#d52a56" def set_name(self, text): self.name = text def get_save_text(self): data = super().get_save_text() data += "name:{0} ".format(self.name) return data def load_save_text(self, properties: dict): super().load_save_text(properties) if "name" in properties.keys(): self.name = properties["name"] self.name_edit.setText(self.name)