NodeLayout
1# NodeLayout.py 2 3from PySide6.QtWidgets import QGraphicsItem, QLineEdit, QGraphicsProxyWidget, QVBoxLayout, QWidget, QLabel, QComboBox, QTextEdit, QHBoxLayout 4from PySide6.QtCore import QRectF, Qt 5from PySide6.QtGui import QPainter, QBrush, QPen 6 7class Slot: 8 def __init__(self, data_attr, parent, layout, widget_class=QTextEdit): 9 self.data_attr = data_attr 10 self.parent = parent 11 self.layout = layout 12 self.widget_class = widget_class 13 14 self.create_widgets() 15 self.add_to_layout() 16 self.connect_signals() 17 18 def create_widgets(self): 19 self.label = QLabel(self.data_attr.capitalize()) 20 self.edit = self.widget_class(getattr(self.parent.data, self.data_attr)) 21 22 def add_to_layout(self): 23 self.layout.addWidget(self.label) 24 self.layout.addWidget(self.edit) 25 26 def connect_signals(self): 27 if isinstance(self.edit, QTextEdit): 28 self.edit.textChanged.connect(self.update_data) 29 elif isinstance(self.edit, QLineEdit): 30 self.edit.textChanged.connect(self.update_data) 31 32 def update_data(self): 33 if isinstance(self.edit, QTextEdit): 34 setattr(self.parent.data, self.data_attr, self.edit.toPlainText()) 35 elif isinstance(self.edit, QLineEdit): 36 setattr(self.parent.data, self.data_attr, self.edit.text()) 37 38 def show(self): 39 self.label.show() 40 self.edit.show() 41 42 def hide(self): 43 self.label.hide() 44 self.edit.hide() 45 46class NodeLayout(QGraphicsItem): 47 def __init__(self, parent): 48 super().__init__(parent) 49 self.parent = parent # Save the reference to the parent node 50 51 # Create a widget to hold the QLineEdit widgets 52 self.container_widget = QWidget() 53 self.layout = QVBoxLayout() 54 self.container_widget.setLayout(self.layout) 55 56 # Type Label and Combo Box 57 self.type_layout = QHBoxLayout() 58 self.type_label = QLabel("Type:") 59 self.type_combo = QComboBox() 60 self.type_combo.addItems(["None", "Start", "Agent", "Task", "Step", "Team"]) 61 self.type_combo.setCurrentText(self.parent.data.type) 62 self.type_layout.addWidget(self.type_label) 63 self.type_layout.addWidget(self.type_combo) 64 self.layout.addLayout(self.type_layout) 65 self.type_combo.currentTextChanged.connect(self.update_data_type) 66 67 # Initialize slots 68 self.slots = {} 69 self.add_slot("name", QLineEdit) 70 71 # Agent 72 self.add_slot("role", QTextEdit) 73 self.add_slot("goal", QTextEdit) 74 self.add_slot("backstory", QTextEdit) 75 76 # Task 77 self.add_slot("agent", QTextEdit) 78 self.add_slot("description", QTextEdit) 79 self.add_slot("expected_output", QTextEdit) 80 81 # Step 82 self.add_slot("tool", QTextEdit) 83 self.add_slot("arg", QTextEdit) 84 self.add_slot("output_var", QTextEdit) 85 86 self.proxy_widget = QGraphicsProxyWidget(self) 87 self.proxy_widget.setWidget(self.container_widget) 88 89 # Initialize visibility based on the current type 90 self.update_field_visibility() 91 92 # Call update_proxy_widget_geometry once to ensure layout is correct 93 self.update_proxy_widget_geometry() 94 95 def add_slot(self, data_attr, widget_class): 96 slot = Slot(data_attr, self.parent, self.layout, widget_class) 97 self.slots[data_attr] = slot 98 99 def boundingRect(self): 100 return self.parent.rect 101 102 def paint(self, painter, option, widget): 103 rect = self.boundingRect() 104 painter.setBrush(QBrush(Qt.white)) 105 painter.setPen(QPen(Qt.black)) 106 painter.drawRect(rect) 107 108 # Draw right-bottom square 109 painter.setBrush(QBrush(Qt.black)) 110 painter.drawRect(rect.right() - 10, rect.bottom() - 10, 10, 10) 111 112 def update_proxy_widget_geometry(self): 113 rect = self.boundingRect() 114 self.proxy_widget.setGeometry(rect.adjusted(5, 5, -5, -5)) 115 116 def update_data_type(self): 117 self.parent.data.type = self.type_combo.currentText() 118 self.update_field_visibility() # Update field visibility when type changes 119 120 def update_field_visibility(self): 121 node_type = self.parent.data.type 122 for slot in self.slots.values(): 123 slot.hide() 124 125 if node_type in ["Start", "None"]: 126 pass 127 elif node_type == "Team": 128 self.slots["name"].show() 129 elif node_type == "Agent": 130 self.slots["name"].show() 131 self.slots["role"].show() 132 self.slots["goal"].show() 133 self.slots["backstory"].show() 134 elif node_type == "Task": 135 self.slots["agent"].show() 136 self.slots["description"].show() 137 self.slots["expected_output"].show() 138 elif node_type == "Step": 139 self.slots["tool"].show() 140 self.slots["arg"].show() 141 self.slots["output_var"].show() 142 143 144 145 # Update geometry after setting visibility 146 self.update_proxy_widget_geometry()
class
Slot:
8class Slot: 9 def __init__(self, data_attr, parent, layout, widget_class=QTextEdit): 10 self.data_attr = data_attr 11 self.parent = parent 12 self.layout = layout 13 self.widget_class = widget_class 14 15 self.create_widgets() 16 self.add_to_layout() 17 self.connect_signals() 18 19 def create_widgets(self): 20 self.label = QLabel(self.data_attr.capitalize()) 21 self.edit = self.widget_class(getattr(self.parent.data, self.data_attr)) 22 23 def add_to_layout(self): 24 self.layout.addWidget(self.label) 25 self.layout.addWidget(self.edit) 26 27 def connect_signals(self): 28 if isinstance(self.edit, QTextEdit): 29 self.edit.textChanged.connect(self.update_data) 30 elif isinstance(self.edit, QLineEdit): 31 self.edit.textChanged.connect(self.update_data) 32 33 def update_data(self): 34 if isinstance(self.edit, QTextEdit): 35 setattr(self.parent.data, self.data_attr, self.edit.toPlainText()) 36 elif isinstance(self.edit, QLineEdit): 37 setattr(self.parent.data, self.data_attr, self.edit.text()) 38 39 def show(self): 40 self.label.show() 41 self.edit.show() 42 43 def hide(self): 44 self.label.hide() 45 self.edit.hide()
class
NodeLayout(PySide6.QtWidgets.QGraphicsItem):
47class NodeLayout(QGraphicsItem): 48 def __init__(self, parent): 49 super().__init__(parent) 50 self.parent = parent # Save the reference to the parent node 51 52 # Create a widget to hold the QLineEdit widgets 53 self.container_widget = QWidget() 54 self.layout = QVBoxLayout() 55 self.container_widget.setLayout(self.layout) 56 57 # Type Label and Combo Box 58 self.type_layout = QHBoxLayout() 59 self.type_label = QLabel("Type:") 60 self.type_combo = QComboBox() 61 self.type_combo.addItems(["None", "Start", "Agent", "Task", "Step", "Team"]) 62 self.type_combo.setCurrentText(self.parent.data.type) 63 self.type_layout.addWidget(self.type_label) 64 self.type_layout.addWidget(self.type_combo) 65 self.layout.addLayout(self.type_layout) 66 self.type_combo.currentTextChanged.connect(self.update_data_type) 67 68 # Initialize slots 69 self.slots = {} 70 self.add_slot("name", QLineEdit) 71 72 # Agent 73 self.add_slot("role", QTextEdit) 74 self.add_slot("goal", QTextEdit) 75 self.add_slot("backstory", QTextEdit) 76 77 # Task 78 self.add_slot("agent", QTextEdit) 79 self.add_slot("description", QTextEdit) 80 self.add_slot("expected_output", QTextEdit) 81 82 # Step 83 self.add_slot("tool", QTextEdit) 84 self.add_slot("arg", QTextEdit) 85 self.add_slot("output_var", QTextEdit) 86 87 self.proxy_widget = QGraphicsProxyWidget(self) 88 self.proxy_widget.setWidget(self.container_widget) 89 90 # Initialize visibility based on the current type 91 self.update_field_visibility() 92 93 # Call update_proxy_widget_geometry once to ensure layout is correct 94 self.update_proxy_widget_geometry() 95 96 def add_slot(self, data_attr, widget_class): 97 slot = Slot(data_attr, self.parent, self.layout, widget_class) 98 self.slots[data_attr] = slot 99 100 def boundingRect(self): 101 return self.parent.rect 102 103 def paint(self, painter, option, widget): 104 rect = self.boundingRect() 105 painter.setBrush(QBrush(Qt.white)) 106 painter.setPen(QPen(Qt.black)) 107 painter.drawRect(rect) 108 109 # Draw right-bottom square 110 painter.setBrush(QBrush(Qt.black)) 111 painter.drawRect(rect.right() - 10, rect.bottom() - 10, 10, 10) 112 113 def update_proxy_widget_geometry(self): 114 rect = self.boundingRect() 115 self.proxy_widget.setGeometry(rect.adjusted(5, 5, -5, -5)) 116 117 def update_data_type(self): 118 self.parent.data.type = self.type_combo.currentText() 119 self.update_field_visibility() # Update field visibility when type changes 120 121 def update_field_visibility(self): 122 node_type = self.parent.data.type 123 for slot in self.slots.values(): 124 slot.hide() 125 126 if node_type in ["Start", "None"]: 127 pass 128 elif node_type == "Team": 129 self.slots["name"].show() 130 elif node_type == "Agent": 131 self.slots["name"].show() 132 self.slots["role"].show() 133 self.slots["goal"].show() 134 self.slots["backstory"].show() 135 elif node_type == "Task": 136 self.slots["agent"].show() 137 self.slots["description"].show() 138 self.slots["expected_output"].show() 139 elif node_type == "Step": 140 self.slots["tool"].show() 141 self.slots["arg"].show() 142 self.slots["output_var"].show() 143 144 145 146 # Update geometry after setting visibility 147 self.update_proxy_widget_geometry()
QGraphicsItem(self, parent: Optional[PySide6.QtWidgets.QGraphicsItem] = None) -> None
NodeLayout(parent)
48 def __init__(self, parent): 49 super().__init__(parent) 50 self.parent = parent # Save the reference to the parent node 51 52 # Create a widget to hold the QLineEdit widgets 53 self.container_widget = QWidget() 54 self.layout = QVBoxLayout() 55 self.container_widget.setLayout(self.layout) 56 57 # Type Label and Combo Box 58 self.type_layout = QHBoxLayout() 59 self.type_label = QLabel("Type:") 60 self.type_combo = QComboBox() 61 self.type_combo.addItems(["None", "Start", "Agent", "Task", "Step", "Team"]) 62 self.type_combo.setCurrentText(self.parent.data.type) 63 self.type_layout.addWidget(self.type_label) 64 self.type_layout.addWidget(self.type_combo) 65 self.layout.addLayout(self.type_layout) 66 self.type_combo.currentTextChanged.connect(self.update_data_type) 67 68 # Initialize slots 69 self.slots = {} 70 self.add_slot("name", QLineEdit) 71 72 # Agent 73 self.add_slot("role", QTextEdit) 74 self.add_slot("goal", QTextEdit) 75 self.add_slot("backstory", QTextEdit) 76 77 # Task 78 self.add_slot("agent", QTextEdit) 79 self.add_slot("description", QTextEdit) 80 self.add_slot("expected_output", QTextEdit) 81 82 # Step 83 self.add_slot("tool", QTextEdit) 84 self.add_slot("arg", QTextEdit) 85 self.add_slot("output_var", QTextEdit) 86 87 self.proxy_widget = QGraphicsProxyWidget(self) 88 self.proxy_widget.setWidget(self.container_widget) 89 90 # Initialize visibility based on the current type 91 self.update_field_visibility() 92 93 # Call update_proxy_widget_geometry once to ensure layout is correct 94 self.update_proxy_widget_geometry()
def
paint(self, painter, option, widget):
103 def paint(self, painter, option, widget): 104 rect = self.boundingRect() 105 painter.setBrush(QBrush(Qt.white)) 106 painter.setPen(QPen(Qt.black)) 107 painter.drawRect(rect) 108 109 # Draw right-bottom square 110 painter.setBrush(QBrush(Qt.black)) 111 painter.drawRect(rect.right() - 10, rect.bottom() - 10, 10, 10)
def
update_field_visibility(self):
121 def update_field_visibility(self): 122 node_type = self.parent.data.type 123 for slot in self.slots.values(): 124 slot.hide() 125 126 if node_type in ["Start", "None"]: 127 pass 128 elif node_type == "Team": 129 self.slots["name"].show() 130 elif node_type == "Agent": 131 self.slots["name"].show() 132 self.slots["role"].show() 133 self.slots["goal"].show() 134 self.slots["backstory"].show() 135 elif node_type == "Task": 136 self.slots["agent"].show() 137 self.slots["description"].show() 138 self.slots["expected_output"].show() 139 elif node_type == "Step": 140 self.slots["tool"].show() 141 self.slots["arg"].show() 142 self.slots["output_var"].show() 143 144 145 146 # Update geometry after setting visibility 147 self.update_proxy_widget_geometry()
Inherited Members
- PySide6.QtWidgets.QGraphicsItem
- acceptDrops
- acceptHoverEvents
- acceptTouchEvents
- acceptedMouseButtons
- addToIndex
- advance
- boundingRegion
- boundingRegionGranularity
- cacheMode
- childItems
- childrenBoundingRect
- clearFocus
- clipPath
- collidesWithItem
- collidesWithPath
- collidingItems
- commonAncestorItem
- contains
- contextMenuEvent
- cursor
- data
- deviceTransform
- dragEnterEvent
- dragLeaveEvent
- dragMoveEvent
- dropEvent
- effectiveOpacity
- ensureVisible
- extension
- filtersChildEvents
- flags
- focusInEvent
- focusItem
- focusOutEvent
- focusProxy
- focusScopeItem
- grabKeyboard
- grabMouse
- graphicsEffect
- group
- handlesChildEvents
- hasCursor
- hasFocus
- hide
- hoverEnterEvent
- hoverLeaveEvent
- hoverMoveEvent
- inputMethodEvent
- inputMethodHints
- inputMethodQuery
- installSceneEventFilter
- isActive
- isAncestorOf
- isBlockedByModalPanel
- isClipped
- isEnabled
- isObscured
- isObscuredBy
- isPanel
- isSelected
- isUnderMouse
- isVisible
- isVisibleTo
- isWidget
- isWindow
- itemChange
- itemTransform
- keyPressEvent
- keyReleaseEvent
- mapFromItem
- mapFromParent
- mapFromScene
- mapRectFromItem
- mapRectFromParent
- mapRectFromScene
- mapRectToItem
- mapRectToParent
- mapRectToScene
- mapToItem
- mapToParent
- mapToScene
- mouseDoubleClickEvent
- mouseMoveEvent
- mousePressEvent
- mouseReleaseEvent
- moveBy
- opacity
- opaqueArea
- panel
- panelModality
- parentItem
- parentObject
- parentWidget
- pos
- prepareGeometryChange
- removeFromIndex
- removeSceneEventFilter
- resetTransform
- rotation
- scale
- scene
- sceneBoundingRect
- sceneEvent
- sceneEventFilter
- scenePos
- sceneTransform
- scroll
- setAcceptDrops
- setAcceptHoverEvents
- setAcceptTouchEvents
- setAcceptedMouseButtons
- setActive
- setBoundingRegionGranularity
- setCacheMode
- setCursor
- setData
- setEnabled
- setFiltersChildEvents
- setFlag
- setFlags
- setFocus
- setFocusProxy
- setGraphicsEffect
- setGroup
- setHandlesChildEvents
- setInputMethodHints
- setOpacity
- setPanelModality
- setParentItem
- setPos
- setRotation
- setScale
- setSelected
- setToolTip
- setTransform
- setTransformOriginPoint
- setTransformations
- setVisible
- setX
- setY
- setZValue
- shape
- show
- stackBefore
- toGraphicsObject
- toolTip
- topLevelItem
- topLevelWidget
- transform
- transformOriginPoint
- transformations
- type
- ungrabKeyboard
- ungrabMouse
- unsetCursor
- update
- updateMicroFocus
- wheelEvent
- window
- x
- y
- zValue
- GraphicsItemFlag
- GraphicsItemChange
- CacheMode
- PanelModality
- Extension
- UserType