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

Reviewer's Guide

Refactors the Python node UI into a dedicated GtpyPythonNodeWidget class, exposes small helper APIs on GtpyPythonNode to support the widget, and slightly modernizes the CMake configuration and sources list.

File-Level Changes

Change Details Files
Extract Python node UI concerns into a dedicated widget class and wire it into the node factory.
  • Replace the inline widget factory lambda in the node constructor with a call to GtpyPythonNodeWidget::create.
  • Remove direct UI-related includes and helper methods (context menu and placeholder loading) from the node implementation and header.
src/nodes/gtpy_pythonnode.cpp
src/nodes/gtpy_pythonnode.h
Expose minimal APIs on GtpyPythonNode to support the external widget abstraction.
  • Add accessors for the plot active state and its underlying property.
  • Add a helper to prepare the script editor context by deserializing Python data.
  • Add a helper to synchronize plot-related node state (resizability, change notification).
src/nodes/gtpy_pythonnode.cpp
src/nodes/gtpy_pythonnode.h
Implement the new GtpyPythonNodeWidget responsible for plot rendering, script editor launching, and Assistant integration.
  • Create a QWidget subclass that owns the SVG plot, script editor button, and connects to node signals for plot updates and progress feedback.
  • Reimplement script editor opening logic, including persistence of editor size and Assistant integration via a custom context menu.
  • Encapsulate placeholder plot loading and Assistant context menu installation as private helper methods.
src/gui/gtpn_pythonnodewidget.cpp
src/gui/gtpn_pythonnodewidget.h
Update build configuration to include the new widget and modernize GTlab CMake usage.
  • Guard GTlab package discovery with a target check before calling gtlab_standard_setup and remove the unused GTlab.cmake include.
  • Register the new widget header and source in the src CMakeLists so it is compiled and installed.
CMakeLists.txt
src/CMakeLists.txt
cmake/GTlab.cmake
LICENSES/MPL-2.0.txt

Assessment against linked issues

Issue Objective Addressed Explanation
#26 Extract the Python node UI / widget code out of GtpyPythonNode into its own dedicated widget class and have the node delegate UI concerns to that class.
#26 Update the codebase to use the new IntelliGraph 0.15 API so that it is no longer compatible with IntelliGraph 0.13.

Possibly linked issues

  • #CHANGE: PR extracts Python node UI into its own widget class and updates IntelliGraph/CMake, matching the issue’s request.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

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

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.

Thanks, good catches. I’ll remove the unused includes. For create(), the factory is only registered for GtpyPythonNode, so a null return should only happen on misuse; I can add a debug assert there if we want the contract to be explicit.

@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