Skip to content

fontlabapp.qt.menus.OwnedMenus · declarations 001

Back to fontlabapp.qt.menus.OwnedMenus

__init__

__init__(qt: Any, fontlab: Any, *, error_sink: Callable[[Exception, object], object], owned_title: str = OWNED_MENU_TITLE, main_window: Any = None) -> None

Store the modules and the policy; create no Qt object yet.

qt: the PythonQt module. fontlab: the FontLab module. error_sink(error, owner): receives every callback and teardown failure; it must not raise. owned_title: title of the fallback menu. main_window: an already known main window; None makes main_window() look it up on first use.

action

action(token: int) -> Any

Return the live QAction of token, or None once removed.

add_action

add_action(menu_title: Any, text: str, callback: Callable[[], object], *, index: int | None = None, checkable: bool = False) -> int

Add an action to the menu titled menu_title; return its token.

menu_title may also be a QMenu, such as one from menu(token). & in menu titles is ignored when matching. If no menu matches, the action goes to the owned menu. index inserts before that action position; an index outside the menu appends. callback() runs when the action triggers, inside the dispatch guard.

add_menu

add_menu(menu_title: str, text: str) -> int

Append a submenu titled text to menu_title; return its token.

menu(token) returns the QMenu; pass it to add_action. Removing the submenu removes its owned actions before deleting their Qt parent.

close

close() -> None

Remove every item newest first, run queued teardown, drop the menu.

Every item is tried. The first failure is re-raised at the end. Inside one of our slots the whole call is queued instead.

dispatching property

dispatching: bool

Return True while a slot connected by this owner runs.

has_items property

has_items: bool

Return True if this owner has an action or tool window to remove.

main_window

main_window() -> Any

Return FontLab's main window (cached); see qtsafe.main_window.

Raises qtsafe.MainWindowNotFound (a RuntimeError) if the window does not exist. Nothing is cached then; the next call retries.

menu

menu(token: int) -> Any

Return the live QMenu of an add_menu token, or None once removed.

own_menu

own_menu() -> Any

Return this owner's own menu, creating it on first use.

The lookup never consults other menus, so a FontLab or another host's menu with the same title as owned_title is not shared. Pass the result to add_action.

remove

remove(token: int) -> None

Undo one item; unknown or repeated tokens do nothing.

Inside one of our slots the removal is queued and runs once later.

tool_window

tool_window(widget: Any, title: str, *, on_close: Callable[[], object] | None = None) -> tuple[int, Any]

Show widget in a tool window; return (token, window).

on_close() runs once when the title-bar close or remove(token) ends the window. Widget and window teardown wait for the event loop. The widget is detached first, so the caller keeps it. The caller may resize window after this call.