Skip to content

Move menu management from C++ to Python#752

Open
yungyuc wants to merge 2 commits intosolvcon:masterfrom
yungyuc:feature/menu-in-py
Open

Move menu management from C++ to Python#752
yungyuc wants to merge 2 commits intosolvcon:masterfrom
yungyuc:feature/menu-in-py

Conversation

@yungyuc
Copy link
Copy Markdown
Member

@yungyuc yungyuc commented May 4, 2026

Work includes:

  • Wrap Qt menu management in RMenu (new class) for Python access
  • Populate the menu in Python instead.

RMenu extends Qt's QMenu and accepts Python callables directly. It eliminate the need for Python code to create QAction objects via PySide6.

RManager is changed to return RMenu * instead of QMenu *.

On the Python side, _gui_common._add_menu_item() calls RMenu.add_action(), and no longer imports QtGui. Associated helpers are rewritten. All of the 7 menus are changed to be managed in Python: File, View, One, Mesh, Canvas, Profiling, Window.

Work includes:
* Wrap Qt menu management in `RMenu` (new class) for Python access
* Populate the menu in Python instead.

`RMenu` extends Qt's `QMenu` and accepts Python callables directly. It
eliminate the need for Python code to create QAction objects via PySide6.

`RManager` is changed to return `RMenu *` instead of `QMenu *`.

On the Python side, `_gui_common._add_menu_item()` calls `RMenu.add_action()`,
and no longer imports `QtGui`. Associated helpers are rewritten.
All of the 7 menus are changed to be managed in Python: File, View, One, Mesh,
Canvas, Profiling, Window.
@yungyuc yungyuc self-assigned this May 4, 2026
@yungyuc yungyuc added the pilot GUI and visualization label May 4, 2026
@yungyuc yungyuc moved this from Todo to In Progress in pilot general GUI May 4, 2026
QMenu * m_canvasMenu = nullptr;
QMenu * m_profilingMenu = nullptr;
QMenu * m_windowMenu = nullptr;
std::unordered_map<std::string, RMenu *> m_menus;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Use a container (std::unordered_map) for all menus.

public:

using QMenu::addAction; // Keep all QMenu overloads visible
using QMenu::QMenu; // Inherit constructors
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

clang-format ask using QMenu:QMenu to be after using QMenu::addAction but I don't know why. It does not hurt to follow the tool though.

bool checked)
{
auto func_ = [func]()
{ func(); };
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Formatter forces to add a line here.

namespace py = pybind11;

(*this)
.def(
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The function wrap_mainWindow() becomes too long and the menu wrappers should use a standalone wrap_menu().

At the same time, these long functions should be moved outside the class declaration. Many lines of code need to be moved and should use a distinct PR, not this one.


from . import _pilot_core as _pcore
from PySide6 import QtCore, QtGui
from PySide6 import QtCore
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This should be before the above line and use a blank line to separate. But to keep the patch clean (this line of diff simply dropped QtGui), the reformatting should use another PR.

@yungyuc yungyuc marked this pull request as ready for review May 4, 2026 13:04
@yungyuc
Copy link
Copy Markdown
Member Author

yungyuc commented May 4, 2026

@c1ydehhx @tigercosmos Please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pilot GUI and visualization

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant