Skip to content

Commit 7b8262b

Browse files
authored
Merge pull request #7 from bhowiebkr/feature/node_improvements
Adding custom GUI code embedded into the node graph
2 parents 9a82992 + fcb22a5 commit 7b8262b

11 files changed

+1440
-401
lines changed

code_editor_dialog.py

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,72 @@
11
# code_editor_dialog.py
2-
# A dedicated dialog window that now uses the advanced PythonCodeEditor widget.
2+
# A dedicated dialog window that now uses a QTabWidget to host
3+
# separate editors for execution code, GUI layout, and GUI logic.
34

4-
from PySide6.QtWidgets import QDialog, QVBoxLayout, QDialogButtonBox
5+
from PySide6.QtWidgets import QDialog, QVBoxLayout, QDialogButtonBox, QTabWidget
56
from PySide6.QtGui import QFont
67
from python_code_editor import PythonCodeEditor
78

9+
810
class CodeEditorDialog(QDialog):
911
"""
10-
A dialog that hosts the advanced PythonCodeEditor widget.
12+
A dialog that hosts a tabbed interface for editing all of a node's code.
1113
"""
12-
def __init__(self, code, parent=None):
14+
15+
def __init__(self, code, gui_code, gui_logic_code, parent=None):
1316
super().__init__(parent)
14-
self.setWindowTitle("Node Code Editor")
15-
self.setMinimumSize(700, 500)
17+
self.setWindowTitle("Unified Code Editor")
18+
self.setMinimumSize(750, 600)
1619

1720
layout = QVBoxLayout(self)
21+
tab_widget = QTabWidget()
22+
layout.addWidget(tab_widget)
1823

19-
# --- Use the new advanced code editor ---
24+
# --- Execution Code Editor ---
2025
self.code_editor = PythonCodeEditor()
2126
self.code_editor.setFont(QFont("Monospace", 11))
22-
23-
# Set placeholder text if the initial code is empty
24-
if not code:
25-
code = ("from typing import Tuple\n\n"
26-
"def process_data(input_1: str) -> Tuple[str, int]:\n"
27-
" # Your code here\n"
28-
" # Use parameters for inputs and return for outputs.\n"
29-
" # Type hints define the pins.\n"
30-
" return 'processed', len(input_1)")
31-
32-
self.code_editor.setPlainText(code)
33-
34-
layout.addWidget(self.code_editor)
35-
36-
# --- OK and Cancel Buttons ---
27+
exec_placeholder = "from typing import Tuple\n\n" "@node_entry\n" "def node_function(input_1: str) -> Tuple[str, int]:\n" " return 'hello', len(input_1)"
28+
# Only add placeholder if the code is None (new node)
29+
self.code_editor.setPlainText(code if code is not None else exec_placeholder)
30+
tab_widget.addTab(self.code_editor, "Execution Code")
31+
32+
# --- GUI Layout Code Editor ---
33+
self.gui_editor = PythonCodeEditor()
34+
self.gui_editor.setFont(QFont("Monospace", 11))
35+
gui_placeholder = (
36+
"# This script builds the node's custom GUI.\n"
37+
"# Use 'parent', 'layout', 'widgets', and 'QtWidgets' variables.\n\n"
38+
"label = QtWidgets.QLabel('Multiplier:', parent)\n"
39+
"spinbox = QtWidgets.QSpinBox(parent)\n"
40+
"spinbox.setValue(2)\n"
41+
"layout.addWidget(label)\n"
42+
"layout.addWidget(spinbox)\n"
43+
"widgets['multiplier'] = spinbox\n"
44+
)
45+
self.gui_editor.setPlainText(gui_code if gui_code is not None else gui_placeholder)
46+
tab_widget.addTab(self.gui_editor, "GUI Layout")
47+
48+
# --- GUI Logic Code Editor ---
49+
self.gui_logic_editor = PythonCodeEditor()
50+
self.gui_logic_editor.setFont(QFont("Monospace", 11))
51+
gui_logic_placeholder = (
52+
"# This script defines how the GUI interacts with the execution code.\n\n"
53+
"def get_values(widgets):\n"
54+
" return {'multiplier': widgets['multiplier'].value()}\n\n"
55+
"def set_values(widgets, outputs):\n"
56+
" # result = outputs.get('output_1', 'N/A')\n"
57+
" # widgets['result_label'].setText(f'Result: {result}')\n\n"
58+
"def set_initial_state(widgets, state):\n"
59+
" if 'multiplier' in state:\n"
60+
" widgets['multiplier'].setValue(state['multiplier'])\n"
61+
)
62+
self.gui_logic_editor.setPlainText(gui_logic_code if gui_logic_code is not None else gui_logic_placeholder)
63+
tab_widget.addTab(self.gui_logic_editor, "GUI Logic")
64+
3765
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
3866
button_box.accepted.connect(self.accept)
3967
button_box.rejected.connect(self.reject)
4068
layout.addWidget(button_box)
4169

42-
def get_code(self):
43-
"""Returns the code currently in the editor."""
44-
return self.code_editor.toPlainText()
70+
def get_results(self):
71+
"""Returns the code from all three editors in a dictionary."""
72+
return {"code": self.code_editor.toPlainText(), "gui_code": self.gui_editor.toPlainText(), "gui_logic_code": self.gui_logic_editor.toPlainText()}

default_graphs.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)