Move menu management from C++ to Python#752
Conversation
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.
| QMenu * m_canvasMenu = nullptr; | ||
| QMenu * m_profilingMenu = nullptr; | ||
| QMenu * m_windowMenu = nullptr; | ||
| std::unordered_map<std::string, RMenu *> m_menus; |
There was a problem hiding this comment.
Use a container (std::unordered_map) for all menus.
| public: | ||
|
|
||
| using QMenu::addAction; // Keep all QMenu overloads visible | ||
| using QMenu::QMenu; // Inherit constructors |
There was a problem hiding this comment.
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(); }; |
There was a problem hiding this comment.
Formatter forces to add a line here.
| namespace py = pybind11; | ||
|
|
||
| (*this) | ||
| .def( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
@c1ydehhx @tigercosmos Please take a look |
Work includes:
RMenu(new class) for Python accessRMenuextends Qt'sQMenuand accepts Python callables directly. It eliminate the need for Python code to create QAction objects via PySide6.RManageris changed to returnRMenu *instead ofQMenu *.On the Python side,
_gui_common._add_menu_item()callsRMenu.add_action(), and no longer importsQtGui. Associated helpers are rewritten. All of the 7 menus are changed to be managed in Python: File, View, One, Mesh, Canvas, Profiling, Window.