Skip to content

fontlabapp.qt.menus

menus

Menu actions and tool windows that are safe to remove under signal dispatch.

What it does: OwnedMenus adds QActions to FontLab menus (or to one menu it owns) and shows widgets in tool windows. Each item gets an integer token. remove(token) and close() undo the items in a safe way.

Why: A menu callback or a window button often removes its own item. If the host disconnects or deletes the QAction or QWidget while its signal still dispatches, PythonQt deletes the signal receiver twice and FontLab crashes (AGENTS.md: disconnect before deleteLater; never tear down in a slot). Every slot that this class connects counts a dispatch depth. While the depth is above zero, remove and close queue their work. One shared zero-delay DeferredBatch timer runs the queue after the outermost slot returns. Each queued item runs once.

How to use: menus = OwnedMenus(qt, fontlab, error_sink=sink) token = menus.add_action("Edit", "My action", callback) menus.remove(token) or menus.close() at unload. token, window = menus.tool_window(widget, "Title", on_close=done).

Rules: GUI thread only. qt is the PythonQt module and fontlab is the FontLab module; the caller passes both in. Callbacks take no arguments. Their errors go to error_sink(error, owner) and never reach Qt. QAction.text is a property in PythonQt, not a method.

Guard scope: The dispatch guard covers only the slots that this class connects: menu triggered and the tool-window close. A signal that the caller connects itself (for example a button in the tool window) does not raise the depth. If such a slot calls remove or close, the teardown runs at once, inside that dispatch. Such a slot must queue its own call, for example with QTimer.singleShot(0, ...). Subclasses wrap their own slots with _slot (Glyport's plugin host does this for Apply/Cancel).

Cold import: stdlib plus fontlabapp.core.signals.deferred and fontlabapp.qt.safe.

Classes

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
OWNED_MENU_TITLE attribute