Extracted widget code into own class by rainman110 · Pull Request #27 · dlr-gtlab/python-node-module · GitHub
Skip to content

Extracted widget code into own class#27

Open
rainman110 wants to merge 4 commits into
mainfrom
26-change---extract-widget-code-into-own-class
Open

Extracted widget code into own class#27
rainman110 wants to merge 4 commits into
mainfrom
26-change---extract-widget-code-into-own-class

Conversation

@rainman110

@rainman110 rainman110 commented May 28, 2026

Copy link
Copy Markdown
Contributor

Description

Extract the Python node UI into a dedicated widget class and adjust the Python node to delegate UI concerns to it.

Enhancements:

  • Introduce a dedicated GtpyPythonNodeWidget class to encapsulate the Python node's plotting and script editor UI logic.
  • Expose helper methods on GtpyPythonNode for plot state, script editor context preparation, and plot syncing to support the new widget abstraction.
  • Modernized cmake usage

Closes #26

How Has This Been Tested?

Checklist:

  • A test for the new functionality was added (if applicable).
  • All tests run without failure.
  • The changelog has been extended, if this MR contains important changes from the users's point of view.
  • The new code complies with the GTlab's style guide.
  • New interface methods / functions are exported via EXPORT. Non-interface functions are NOT exported.
  • The number of code quality warnings is not increasing.

Summary by Sourcery

Extract the Python node UI into a dedicated widget class and delegate UI responsibilities from the node to this widget.

Enhancements:

  • Introduce a GtpyPythonNodeWidget class encapsulating the Python node's plot display, script editor handling, and Assistant integration.
  • Expose helper methods on GtpyPythonNode to manage plot state, script editor context, and plot synchronization for use by the widget.
  • Refine the GTlab CMake configuration to only call find_package(GTlab) when the GTlab::Core target is not already available.

Build:

  • Modernize the top-level CMake configuration by reordering and guarding GTlab discovery to better support consumer projects.

@rainman110 rainman110 linked an issue May 28, 2026 that may be closed by this pull request
@sourcery-ai

sourcery-ai Bot commented May 28, 2026

Copy link
Copy Markdown

The license is not used anymore, since we deleted GTlab.cmake
@rainman110 rainman110 marked this pull request as ready for review May 28, 2026 09:48
@rainman110 rainman110 changed the title 26 change extract widget code into own class Extracted widget code into own class May 28, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In GtpyPythonNodeWidget::create, returning an empty unique_ptr when the node is not a GtpyPythonNode may violate registerWidgetFactory expectations; consider asserting the type or providing a minimal fallback widget instead of returning null.
  • In gtpn_pythonnodewidget.cpp headers like gtpy_contextmanager.h, gtpy_gilscope.h, and gtpy_tempdir.h are included but not used in this file; they can likely be removed to reduce compile-time dependencies.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `GtpyPythonNodeWidget::create`, returning an empty `unique_ptr` when the node is not a `GtpyPythonNode` may violate `registerWidgetFactory` expectations; consider asserting the type or providing a minimal fallback widget instead of returning null.
- In `gtpn_pythonnodewidget.cpp` headers like `gtpy_contextmanager.h`, `gtpy_gilscope.h`, and `gtpy_tempdir.h` are included but not used in this file; they can likely be removed to reduce compile-time dependencies.

## Individual Comments

### Comment 1
<location path="src/gui/gtpn_pythonnodewidget.cpp" line_range="74-83" />
<code_context>
+    }
+}
+
+void
+GtpyPythonNodeWidget::updateTimePassed(int progress)
+{
+    if (progress != 100)
+    {
+        m_button->setIcon(gt::gui::icon::processRunningIcon(progress));
+    }
+    else
+    {
+        m_button->setIcon(gt::gui::icon::python());
+    }
+}
+
+void
+GtpyPythonNodeWidget::showCustomContextMenu(const QPoint& pos)
+{
+    if (!m_textEdit)
+    {
+        return;
+    }
+
+    QMenu* menu = m_textEdit->createStandardContextMenu();
+    QAction* customAction = new QAction(QStringLiteral("Assistant"), menu);
+
+    connect(customAction, &QAction::triggered,
+            this, &GtpyPythonNodeWidget::insertAssistantPrompt);
+
+    menu->addSeparator();
+    menu->addAction(customAction);
+    menu->exec(m_textEdit->mapToGlobal(pos));
+    delete menu;
+}
+
+void
+GtpyPythonNodeWidget::insertAssistantPrompt()
+{
+    if (!m_textEdit)
</code_context>
<issue_to_address>
**issue (bug_risk):** The Assistant menu installation is guarded by a different capability than the prompt invocation, which may lead to a no-op action.

`openScriptEditor()` installs the context menu based on `getSharedFunction("Assistant", "prompt")`, but `insertAssistantPrompt()` calls `getSharedFunction("Assistant", "open_prompt_python")`. If only one of these is available, the "Assistant" menu will appear but do nothing when clicked. Consider basing the menu installation on the availability of `open_prompt_python`, or using a single consistent capability key for both the check and the call.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/gui/gtpn_pythonnodewidget.cpp
@rainman110

Copy link
Copy Markdown
Contributor Author

@rainman110 rainman110 requested a review from jensschmeink May 28, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CHANGE] - Extract Widget Code into own class

1 participant