app_model.backends.qt
#
Qt objects for app_model.
Classes:
-
QCommandAction–Base QAction for a command id. Can execute the command.
-
QCommandRuleAction–QAction for a CommandRule.
-
QKeyBindingSequence–A QKeySequence based on a KeyBinding instance.
-
QMenuItemAction–QAction for a MenuItem.
-
QModelKeyBindingEdit–Editor for a KeyBinding instance.
-
QModelMainWindow–QMainWindow with app-model support.
-
QModelMenu–QMenu for a menu_id in an
app_modelMenusRegistry. -
QModelMenuBar–QMenuBar that is built from a list of model menu ids.
-
QModelSubmenu–QMenu for a menu_id in an
app_modelMenusRegistry. -
QModelToolBar–QToolBar that is built from a list of model menu ids.
Functions:
-
qkey2modelkey–Return KeyCode from Qt.Key.
-
qkeycombo2modelkey–Return KeyCode or KeyCombo from QKeyCombination.
-
qkeysequence2modelkeybinding–Return KeyBinding from QKeySequence.
-
qmods2modelmods–Return KeyMod from Qt.KeyboardModifier.
-
to_qicon–Create QIcon from Icon.
QCommandAction
#
QCommandAction(
command_id: str,
app: Application | str,
parent: QObject | None = None,
)
Bases: QAction
Base QAction for a command id. Can execute the command.
Parameters:
-
command_id(str) –Command ID.
-
app(Application | str) –Application instance or name of application instance.
-
parent(QObject | None, default:None) –Optional parent widget, by default None
Source code in src/app_model/backends/qt/_qaction.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
QCommandRuleAction
#
QCommandRuleAction(
command_rule: CommandRule,
app: Application | str,
parent: QObject | None = None,
*,
use_short_title: bool = False,
)
Bases: QCommandAction
QAction for a CommandRule.
Parameters:
-
command_rule(CommandRule) –CommandRuleinstance to create an action for. -
app(Application | str) –Application instance or name of application instance.
-
parent(QObject | None, default:None) –Optional parent widget, by default None
-
use_short_title(bool, default:False) –If True, use the
short_titleof the command rule, if it exists.
Methods:
-
update_from_context–Update the enabled state of this menu item from
ctx.
Source code in src/app_model/backends/qt/_qaction.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
update_from_context
#
update_from_context(ctx: Mapping[str, object]) -> None
Update the enabled state of this menu item from ctx.
Source code in src/app_model/backends/qt/_qaction.py
123 124 125 126 127 128 129 130 | |
QKeyBindingSequence
#
QKeyBindingSequence(kb: KeyBinding)
Bases: QKeySequence
A QKeySequence based on a KeyBinding instance.
Source code in src/app_model/backends/qt/_qkeymap.py
71 72 73 | |
QMenuItemAction
#
QMenuItemAction(
menu_item: MenuItem,
app: Application | str,
parent: QObject | None = None,
)
Bases: QCommandRuleAction
QAction for a MenuItem.
Mostly the same as a CommandRuleAction, but aware of the menu_item.when clause
to toggle visibility.
Parameters:
-
menu_item(MenuItem) –MenuIteminstance to create an action for. -
app(Application | str) –Application instance or name of application instance.
-
parent(QObject | None, default:None) –Optional parent widget, by default None
Methods:
-
create–Create a new QMenuItemAction for the given menu item.
-
update_from_context–Update the enabled/visible state of this menu item from
ctx.
Source code in src/app_model/backends/qt/_qaction.py
159 160 161 162 163 164 165 166 167 168 | |
create
classmethod
#
create(
menu_item: MenuItem,
app: Application | str,
parent: QObject | None = None,
) -> Self
Create a new QMenuItemAction for the given menu item.
Prefer this method over __init__ to ensure that the cache is used,
so that:
a1 = QMenuItemAction.create(action, full_app)
a2 = QMenuItemAction.create(action, full_app)
a1 is a2 # True
Source code in src/app_model/backends/qt/_qaction.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
update_from_context
#
update_from_context(ctx: Mapping[str, object]) -> None
Update the enabled/visible state of this menu item from ctx.
Source code in src/app_model/backends/qt/_qaction.py
203 204 205 206 | |
QModelKeyBindingEdit
#
Bases: QKeySequenceEdit
Editor for a KeyBinding instance.
This is a QKeySequenceEdit with a method that converts the current keySequence to an app_model KeyBinding instance.
Methods:
-
keyBinding–Return app_model KeyBinding instance for the current keySequence.
keyBinding
#
keyBinding() -> Optional[KeyBinding]
Return app_model KeyBinding instance for the current keySequence.
Source code in src/app_model/backends/qt/_qkeybindingedit.py
18 19 20 21 22 | |
QModelMainWindow
#
QModelMainWindow(
app: Application | str, parent: QWidget | None = None
)
Bases: QMainWindow
QMainWindow with app-model support.
Methods:
-
addModelToolBar–Add a tool bar to the main window.
-
setModelMenuBar–Set the menu bar to a list of menu ids.
Source code in src/app_model/backends/qt/_qmainwindow.py
19 20 21 | |
addModelToolBar
#
addModelToolBar(
menu_id: str,
*,
exclude: Collection[str] | None = None,
area: ToolBarArea | None = None,
toolbutton_style: ToolButtonStyle = Qt.ToolButtonStyle.ToolButtonIconOnly,
) -> QModelToolBar
Add a tool bar to the main window.
Source code in src/app_model/backends/qt/_qmainwindow.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
setModelMenuBar
#
setModelMenuBar(
menu_ids: Mapping[str, str]
| Sequence[str | tuple[str, str]],
) -> QModelMenuBar
Set the menu bar to a list of menu ids.
Parameters:
-
menu_ids(Mapping[str, str] | Sequence[str | tuple[str, str]]) –A mapping of menu ids to menu titles or a sequence of menu ids.
Source code in src/app_model/backends/qt/_qmainwindow.py
23 24 25 26 27 28 29 30 31 32 33 34 35 | |
QModelMenu
#
QModelMenu(
menu_id: str,
app: Application | str,
title: str | None = None,
parent: QWidget | None = None,
)
Bases: QMenu
QMenu for a menu_id in an app_model MenusRegistry.
Parameters:
-
menu_id(str) –Menu ID to look up in the registry.
-
app(Application | str) –Application instance or name of application instance.
-
title(str | None, default:None) –Optional title for the menu, by default None
-
parent(QWidget | None, default:None) –Optional parent widget, by default None
Methods:
-
findAction–Find an action by its ObjectName.
-
rebuild–Rebuild menu by looking up self._menu_id in menu_registry.
-
update_from_context–Update the enabled/visible state of each menu item with
ctx.
Source code in src/app_model/backends/qt/_qmenu.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | |
findAction
#
findAction(object_name: str) -> QAction | QModelMenu | None
Find an action by its ObjectName.
Parameters:
-
object_name(str) –Action ID to find. Note that
QCommandActionhaveObjectNameset to theircommand.id
Source code in src/app_model/backends/qt/_qmenu.py
58 59 60 61 62 63 64 65 66 67 | |
rebuild
#
rebuild(
include_submenus: bool = True,
exclude: Collection[str] | None = None,
) -> None
Rebuild menu by looking up self._menu_id in menu_registry.
Source code in src/app_model/backends/qt/_qmenu.py
84 85 86 87 88 89 90 91 92 93 94 | |
update_from_context
#
update_from_context(ctx: Mapping[str, object]) -> None
Update the enabled/visible state of each menu item with ctx.
See app_model.expressions for details on expressions.
Parameters:
-
ctx(Mapping) –A namespace that will be used to
eval()the'enablement'and'when'expressions provided for each action in the menu. ALL variables used in these expressions must either be present in thectxdict, or be builtins.
Source code in src/app_model/backends/qt/_qmenu.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
QModelMenuBar
#
QModelMenuBar(
menus: Mapping[str, str]
| Sequence[str | tuple[str, str]],
app: Application | str,
parent: QWidget | None = None,
)
Bases: QMenuBar
QMenuBar that is built from a list of model menu ids.
Parameters:
-
menus(Mapping[str, str] | Sequence[str | tuple[str, str]]) –A mapping of menu ids to menu titles or a sequence of menu ids.
-
app(Application | str) –Application instance or name of application instance.
-
parent(QWidget | None, default:None) –Optional parent widget, by default None
Methods:
-
update_from_context–Update the enabled/visible state of each menu item with
ctx.
Source code in src/app_model/backends/qt/_qmenu.py
253 254 255 256 257 258 259 260 261 262 263 264 | |
update_from_context
#
update_from_context(ctx: Mapping[str, object]) -> None
Update the enabled/visible state of each menu item with ctx.
See app_model.expressions for details on expressions.
Parameters:
-
ctx(Mapping) –A namespace that will be used to
eval()the'enablement'and'when'expressions provided for each action in the menu. ALL variables used in these expressions must either be present in thectxdict, or be builtins.
Source code in src/app_model/backends/qt/_qmenu.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
QModelSubmenu
#
QModelSubmenu(
submenu: SubmenuItem,
app: Application | str,
parent: QWidget | None = None,
)
Bases: QModelMenu
QMenu for a menu_id in an app_model MenusRegistry.
Parameters:
-
submenu(SubmenuItem) –SubmenuItem for which to create a QMenu.
-
app(Application | str) –Application instance or name of application instance.
-
parent(QWidget | None, default:None) –Optional parent widget, by default None
Methods:
-
findAction–Find an action by its ObjectName.
-
rebuild–Rebuild menu by looking up self._menu_id in menu_registry.
-
update_from_context–Update the enabled state of this menu item from
ctx.
Source code in src/app_model/backends/qt/_qmenu.py
125 126 127 128 129 130 131 132 133 134 135 136 137 | |
findAction
#
findAction(object_name: str) -> QAction | QModelMenu | None
Find an action by its ObjectName.
Parameters:
-
object_name(str) –Action ID to find. Note that
QCommandActionhaveObjectNameset to theircommand.id
Source code in src/app_model/backends/qt/_qmenu.py
58 59 60 61 62 63 64 65 66 67 | |
rebuild
#
rebuild(
include_submenus: bool = True,
exclude: Collection[str] | None = None,
) -> None
Rebuild menu by looking up self._menu_id in menu_registry.
Source code in src/app_model/backends/qt/_qmenu.py
84 85 86 87 88 89 90 91 92 93 94 | |
update_from_context
#
update_from_context(ctx: Mapping[str, object]) -> None
Update the enabled state of this menu item from ctx.
Source code in src/app_model/backends/qt/_qmenu.py
139 140 141 142 | |
QModelToolBar
#
QModelToolBar(
menu_id: str,
app: Application | str,
*,
exclude: Collection[str] | None = None,
title: str | None = None,
parent: QWidget | None = None,
)
Bases: QToolBar
QToolBar that is built from a list of model menu ids.
Parameters:
-
menu_id(str) –Menu ID to look up in the registry.
-
app(Application | str) –Application instance or name of application instance.
-
exclude(Collection[str] | None, default:None) –Optional list of menu ids to exclude from the toolbar, by default None
-
title(str | None, default:None) –Optional title for the menu, by default None
-
parent(QWidget | None, default:None) –Optional parent widget, by default None
Methods:
-
addMenu–No-op for toolbar.
-
findAction–Find an action by its ObjectName.
-
rebuild–Rebuild toolbar by looking up self._menu_id in menu_registry.
-
update_from_context–Update the enabled/visible state of each menu item with
ctx.
Source code in src/app_model/backends/qt/_qmenu.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
addMenu
#
addMenu(menu: QMenu) -> None
No-op for toolbar.
Source code in src/app_model/backends/qt/_qmenu.py
191 192 | |
findAction
#
findAction(object_name: str) -> QAction | QModelMenu | None
Find an action by its ObjectName.
Parameters:
-
object_name(str) –Action ID to find. Note that
QCommandActionhaveObjectNameset to theircommand.id
Source code in src/app_model/backends/qt/_qmenu.py
194 195 196 197 198 199 200 201 202 203 | |
rebuild
#
rebuild(
include_submenus: bool = True,
exclude: Collection[str] | None = None,
) -> None
Rebuild toolbar by looking up self._menu_id in menu_registry.
Source code in src/app_model/backends/qt/_qmenu.py
220 221 222 223 224 225 226 227 228 229 230 | |
update_from_context
#
update_from_context(ctx: Mapping[str, object]) -> None
Update the enabled/visible state of each menu item with ctx.
See app_model.expressions for details on expressions.
Parameters:
-
ctx(Mapping) –A namespace that will be used to
eval()the'enablement'and'when'expressions provided for each action in the menu. ALL variables used in these expressions must either be present in thectxdict, or be builtins.
Source code in src/app_model/backends/qt/_qmenu.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
qkey2modelkey
#
qkey2modelkey(key: Key) -> KeyCode | KeyCombo
Return KeyCode from Qt.Key.
Source code in src/app_model/backends/qt/_qkeymap.py
258 259 260 261 262 263 264 265 | |
qkeycombo2modelkey
#
qkeycombo2modelkey(
key: QKeyCombination,
) -> KeyCode | KeyCombo
Return KeyCode or KeyCombo from QKeyCombination.
Source code in src/app_model/backends/qt/_qkeymap.py
268 269 270 271 272 273 274 275 | |
qkeysequence2modelkeybinding
#
qkeysequence2modelkeybinding(
key: QKeySequence,
) -> KeyBinding
Return KeyBinding from QKeySequence.
Source code in src/app_model/backends/qt/_qkeymap.py
278 279 280 281 282 | |
qmods2modelmods
#
qmods2modelmods(modifiers: KeyboardModifier) -> KeyMod
Return KeyMod from Qt.KeyboardModifier.
Source code in src/app_model/backends/qt/_qkeymap.py
236 237 238 239 240 241 242 243 244 245 | |
to_qicon
#
to_qicon(
icon: Icon, theme: Literal["dark", "light"] = "dark"
) -> QIcon
Create QIcon from Icon.
Source code in src/app_model/backends/qt/_util.py
14 15 16 17 18 19 20 21 22 23 24 25 | |