Skip to content

Add user-defined Menus#3137

Open
Alxiice wants to merge 12 commits into
developfrom
feature/add_menu_manager
Open

Add user-defined Menus#3137
Alxiice wants to merge 12 commits into
developfrom
feature/add_menu_manager

Conversation

@Alxiice

@Alxiice Alxiice commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Description

New feature to add user-defined menus.
image

Features

  • Create Menu
  • Add different items inside :
    • A sub-menu
    • A button
    • A checkbox
    • A radio button (choose option in a list of checkbox)
  • Attach callbacks on clickable items
  • Callbacks are either callable object or a function with specific params
  • Callbacks have access to the MeshroomApp instance so that we can access the node graph
  • Callbacks have access to the menu object : for radio buttons, it enables having access to menu items, ...
  • We also pass kwargs which change depending on the context (checked status for checkbox, selected item for radio button, etc)
  • Each menu entry can have these properties :
    • name : name
    • label : display label (name by default)
    • icon : for menu entry and buttons
    • tooltip : display detailed message about the entry
    • shortcut : shortcut to call the entry
    • index : insert index (by default last one)
  • Meshroom looks for a menu.py script in the meshroom folder of plugins to load menus.

How the API looks

import logging
from meshroom.api import register_menu, Menu, MenuItem, MenuCallback

# === Callbacks ===

def say_hello(menu, app, **kwargs):
    logging.info("[MenuTest] Hello from the 'Say Hello' button!")
    app.showMessage("Hello from the Menu Test plugin!", duration=3000)


class ToggleVerboseLogging(MenuCallback):
    def __call__(self, menu, app, **kwargs):
        enabled = kwargs.get("enabled", False)
        level = "debug" if enabled else "info"
        logging.getLogger().setLevel(level.upper())
        logging.info(f"[MenuTest] Verbose logging {'enabled' if enabled else 'disabled'}.")


# === Create the Menu ===

user_menu = Menu("Settings")

user_menu.addButton(
    "sayHello",
    label="Say Hello",
    callback=say_hello,
    tooltip="Show a status bar message",
    icon="testMenu/meshroom/agitant-la-main.png", 
    shortcut="Ctrl+Alt+H",
)

user_menu.addSeparator()

user_menu.addCheckbox(
    "verboseLogging",
    label="Verbose Logging",
    callback=ToggleVerboseLogging(),
    tooltip="Toggle debug-level logging",
    checked=False,
)


# === Register the Menu ===

register_menu(user_menu)

Another example with a radio button :

from meshroom.api import register_menu, Menu, MenuItem


def radioButtonCallback(menu, app, **kwargs):
    selected: MenuItem = kwargs["selected"]
    print(f"[MenuTest] Radiobutton selected: {selected.label}")
    app.showMessage(f"Radiobutton selected: {selected.label}", duration=2000)


menu_test = Menu("Test")

menu_test.addRadioButton(
    "testRadioButton",
    items=[
        MenuItem("a", label="A"),
        MenuItem("b", label="B"),
        MenuItem("c", label="C"),
    ],
    callback=radioButtonCallback,
)

register_menu(menu_test)

Details

Here's how the code is organized. I ordered every file by logical order so you can review from the first to last file here :

  • core/
    • core/menu.py : Define the Menu, MenuItem, MeshroomMenuManager, etc. All the objects used in the rest of the code, specific to a menu. Also build the list model for the QML part.
    • core.__init__.py : Add a loadPluginMenu function to find menus on plugins when launching Meshroom.
  • api/
    • api/menu.py gives a top-level access to a register function. This is what should be used in plugins
    • api/__init__.py creates redirections to every useful class/function to create menus in plugins. That way every import should be :
    from meshroom.api import Menu, register_menu, ...
  • ui/
    • ui/app.py : set the menu manager as a context property to access it in QML
    • ui/qml/Controls/userMenu.qml : define the menu and components for every instanciable widget
      • ui/qml/Application.qml : Add Instantiator using the menu model.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dynamic menu registration system allowing plugins to register custom menus and callbacks. It adds a Python-side registry (MeshroomMenuManager) and dynamically instantiates these menus in the QML UI using a new UserMenu component. The review feedback highlights several critical and medium-severity issues: a missing import of importlib.util that will cause a runtime error, a potential IndexError in exception handling, shadowing of the built-in type function, potential duplicate initialization side-effects, test pollution risks due to mutable class-level registries, an incorrect callback instantiation in the docstring example, and a lack of defensive checks for dynamic QML object creation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread meshroom/core/__init__.py Outdated
Comment thread meshroom/ui/menu.py
Comment thread meshroom/core/__init__.py
Comment thread meshroom/core/menu.py Outdated
Comment thread meshroom/core/menu.py Outdated
Comment thread meshroom/ui/menu.py
Comment thread meshroom/ui/qml/Controls/UserMenu.qml
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.84211% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.00%. Comparing base (1d89d80) to head (b2d5c8d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
meshroom/core/__init__.py 29.41% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3137      +/-   ##
===========================================
- Coverage    86.07%   86.00%   -0.08%     
===========================================
  Files           78       78              
  Lines        12111    12130      +19     
===========================================
+ Hits         10425    10432       +7     
- Misses        1686     1698      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Alxiice Alxiice self-assigned this Jun 15, 2026
@Alxiice Alxiice added the feature new feature (proposed as PR or issue planned by dev) label Jun 15, 2026
@Alxiice Alxiice added this to the Meshroom 2026.1.0 milestone Jun 15, 2026
@Alxiice
Alxiice force-pushed the feature/add_menu_manager branch from a2743d0 to c7ddb0b Compare June 16, 2026 20:41
Comment thread meshroom/core/menu.py Fixed
@Alxiice
Alxiice force-pushed the feature/add_menu_manager branch 4 times, most recently from 3fe422e to c522c09 Compare June 26, 2026 15:47
@Alxiice
Alxiice force-pushed the feature/add_menu_manager branch from c522c09 to 8dd869f Compare July 1, 2026 08:15
Comment thread meshroom/api/qml.py Outdated
Comment thread meshroom/core/menu.py Outdated

@fabiencastan fabiencastan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do not create an API module.

Comment thread meshroom/core/menu.py Fixed
@Alxiice
Alxiice requested review from fabiencastan and nicolas-lambert-tc and removed request for fabiencastan July 3, 2026 09:53
@Alxiice
Alxiice force-pushed the feature/add_menu_manager branch 2 times, most recently from 87da141 to 9cccdba Compare July 7, 2026 10:28
@Alxiice
Alxiice force-pushed the feature/add_menu_manager branch from 9cccdba to fe4eee5 Compare July 15, 2026 16:12
@Alxiice
Alxiice force-pushed the feature/add_menu_manager branch from fe4eee5 to b2d5c8d Compare July 16, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature new feature (proposed as PR or issue planned by dev)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants