-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store): add
DispatchItem
and NotificationDispatchItem
as con…
…venience `ActionItem` subclasses to dispatch actions and events
- Loading branch information
Showing
9 changed files
with
87 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Implement a menu item that dispatches an action or an event.""" | ||
|
||
from __future__ import annotations | ||
|
||
import sys | ||
from dataclasses import field | ||
from typing import TYPE_CHECKING | ||
|
||
from ubo_gui.menu.types import ActionItem | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Callable | ||
|
||
from ubo_app.store.main import ActionType, EventType | ||
|
||
|
||
def _default_action() -> Callable[[], None]: | ||
# WARNING: Dirty hack ahead | ||
# This is to set the default value of `icon` based on the provided/default value of | ||
# `importance` | ||
from ubo_app.store.main import store | ||
|
||
parent_frame = sys._getframe().f_back # noqa: SLF001 | ||
if not parent_frame or not (operation := parent_frame.f_locals.get('operation')): | ||
msg = 'No operation provided for `DispatchItem`' | ||
raise ValueError(msg) | ||
return lambda: store.dispatch(operation) | ||
|
||
|
||
class DispatchItem(ActionItem): | ||
"""Menu item that dispatches an action or an event.""" | ||
|
||
operation: ActionType | EventType | ||
action: Callable[[], None] = field(default_factory=_default_action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters