Add custom step names and fix F key shortcut
- Add name field to PromptStep, CodeStep, and ToolStep dataclasses - Update step dialogs to allow editing step names - Display custom step names in both list and flow views - Fix F key shortcut by installing event filter on graph widget - Steps without custom names show default "Prompt N" / "Code N" Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
|
||||
from typing import Optional, List
|
||||
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout
|
||||
from PySide6.QtCore import Signal, Qt, QTimer
|
||||
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QHBoxLayout, QPushButton
|
||||
from PySide6.QtCore import Signal, Qt, QTimer, QEvent
|
||||
from PySide6.QtGui import QKeyEvent
|
||||
|
||||
from NodeGraphQt import NodeGraph, BaseNode
|
||||
|
||||
@@ -163,9 +164,23 @@ class FlowGraphWidget(QWidget):
|
||||
help_layout.addStretch()
|
||||
|
||||
# Fit view button
|
||||
fit_label = QLabel("Press F to fit all")
|
||||
fit_label.setStyleSheet("color: #667eea; font-weight: 500;")
|
||||
help_layout.addWidget(fit_label)
|
||||
self.btn_fit = QPushButton("Fit All (F)")
|
||||
self.btn_fit.setStyleSheet("""
|
||||
QPushButton {
|
||||
background-color: #667eea;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
padding: 4px 12px;
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #5a67d8;
|
||||
}
|
||||
""")
|
||||
self.btn_fit.clicked.connect(self.fit_all_nodes)
|
||||
help_layout.addWidget(self.btn_fit)
|
||||
|
||||
layout.addWidget(help_bar)
|
||||
|
||||
@@ -184,6 +199,9 @@ class FlowGraphWidget(QWidget):
|
||||
# Add graph widget
|
||||
layout.addWidget(self._graph.widget, 1)
|
||||
|
||||
# Install event filter to catch F key on the graph widget
|
||||
self._graph.widget.installEventFilter(self)
|
||||
|
||||
def set_tool(self, tool: Optional[Tool]):
|
||||
"""Set the tool to visualize."""
|
||||
self._tool = tool
|
||||
@@ -218,16 +236,20 @@ class FlowGraphWidget(QWidget):
|
||||
|
||||
for i, step in enumerate(self._tool.steps or []):
|
||||
if isinstance(step, PromptStep):
|
||||
# Use custom name if set, otherwise default to "Prompt N"
|
||||
node_name = step.name if step.name else f'Prompt {i+1}'
|
||||
node = self._graph.create_node(
|
||||
'cmdforge.PromptNode',
|
||||
name=f'Prompt {i+1}',
|
||||
name=node_name,
|
||||
pos=[x_pos, 0]
|
||||
)
|
||||
node.set_step(step, i)
|
||||
elif isinstance(step, CodeStep):
|
||||
# Use custom name if set, otherwise default to "Code N"
|
||||
node_name = step.name if step.name else f'Code {i+1}'
|
||||
node = self._graph.create_node(
|
||||
'cmdforge.CodeNode',
|
||||
name=f'Code {i+1}',
|
||||
name=node_name,
|
||||
pos=[x_pos, 0]
|
||||
)
|
||||
node.set_step(step, i)
|
||||
@@ -272,6 +294,36 @@ class FlowGraphWidget(QWidget):
|
||||
# Clear selection
|
||||
self._graph.clear_selection()
|
||||
|
||||
def fit_all_nodes(self):
|
||||
"""Fit view to show all nodes."""
|
||||
if not self._graph:
|
||||
return
|
||||
|
||||
all_nodes = self._graph.all_nodes()
|
||||
if not all_nodes:
|
||||
return
|
||||
|
||||
# Select all, fit, then clear selection
|
||||
for node in all_nodes:
|
||||
node.set_selected(True)
|
||||
self._graph.fit_to_selection()
|
||||
self._graph.clear_selection()
|
||||
|
||||
def keyPressEvent(self, event: QKeyEvent):
|
||||
"""Handle keyboard shortcuts."""
|
||||
if event.key() == Qt.Key_F:
|
||||
self.fit_all_nodes()
|
||||
event.accept()
|
||||
else:
|
||||
super().keyPressEvent(event)
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
"""Filter events from the graph widget to catch F key."""
|
||||
if event.type() == QEvent.KeyPress and event.key() == Qt.Key_F:
|
||||
self.fit_all_nodes()
|
||||
return True # Event handled
|
||||
return super().eventFilter(obj, event)
|
||||
|
||||
def _on_node_double_clicked(self, node):
|
||||
"""Handle node double-click."""
|
||||
if hasattr(node, '_step_index') and node._step_index >= 0:
|
||||
|
||||
Reference in New Issue
Block a user