Skip to content
Snippets Groups Projects

Display a data waiting message only if any tracked account is present

Merged Jakub Ziebinski requested to merge jziebinski/fix-no-account-message into develop
All threads resolved!
@@ -48,59 +48,36 @@ class CliveScreen(Screen[ScreenResultType], CliveWidget):
"""Provides the ability to control the binding order in the footer."""
return self._sort_bindings(super().active_bindings)
@staticmethod
def _common_decorator_prevent_decorator(
availability_check_func: Callable[[Clive], bool],
logger_message: str,
notify_message: str,
) -> Callable[[Callable[P, None]], Callable[P, None]]:
def decorator(func: Callable[P, None]) -> Callable[P, None]:
@wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
app_ = get_clive().app_instance()
if not availability_check_func(app_):
logger.debug(f"action {func.__name__} {logger_message}")
app_.notify(notify_message, severity="warning")
return
func(*args, **kwargs)
return wrapper
return decorator
@staticmethod
def prevent_action_when_no_accounts_node_data(func: Callable[P, None]) -> Callable[P, None]:
def check_data_available(app_: Clive) -> bool:
@classmethod
def prevent_action_when_no_accounts_node_data(cls, func: Callable[P, None]) -> Callable[P, None]:
def check_data_available(app: Clive) -> bool:
return (
app_.world.profile.accounts.is_tracked_accounts_node_data_available
or app_.world.profile.accounts.is_tracked_accounts_alarms_data_available
app.world.profile.accounts.is_tracked_accounts_node_data_available
and app.world.profile.accounts.is_tracked_accounts_alarms_data_available
)
return CliveScreen._common_decorator_prevent_decorator(
return cls._common_prevent_decorator(
check_data_available,
"prevented because no data is available",
"Waiting for data...",
)(func)
@staticmethod
def prevent_action_when_no_working_account(func: Callable[P, None]) -> Callable[P, None]:
def check_data_available(app_: Clive) -> bool:
return app_.world.profile.accounts.has_working_account
@classmethod
def prevent_action_when_no_working_account(cls, func: Callable[P, None]) -> Callable[P, None]:
def check_data_available(app: Clive) -> bool:
return app.world.profile.accounts.has_working_account
return CliveScreen._common_decorator_prevent_decorator(
return cls._common_prevent_decorator(
check_data_available,
"prevented because no working account is set",
"Cannot perform this action without working account",
)(func)
@staticmethod
def prevent_action_when_no_tracked_accounts(func: Callable[P, None]) -> Callable[P, None]:
def check_data_available(app_: Clive) -> bool:
return app_.world.profile.accounts.has_tracked_accounts
@classmethod
def prevent_action_when_no_tracked_accounts(cls, func: Callable[P, None]) -> Callable[P, None]:
def check_data_available(app: Clive) -> bool:
return app.world.profile.accounts.has_tracked_accounts
return CliveScreen._common_decorator_prevent_decorator(
return cls._common_prevent_decorator(
check_data_available,
"prevented because no tracked accounts are present",
"Cannot perform this action without any tracked accounts",
)(func)
@@ -108,7 +85,7 @@ class CliveScreen(Screen[ScreenResultType], CliveWidget):
def try_again_after_unlock(func: Callable[P, Awaitable[None]]) -> Callable[P, Awaitable[None]]:
@wraps(func)
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
app_ = get_clive().app_instance()
app = get_clive().app_instance()
try:
await func(*args, **kwargs)
@@ -117,16 +94,36 @@ class CliveScreen(Screen[ScreenResultType], CliveWidget):
async def _on_unlock_result(*, unlocked: bool) -> None:
if not unlocked:
app_.notify("Aborted. UNLOCKED mode was required for this action.", severity="warning")
app.notify("Aborted. UNLOCKED mode was required for this action.", severity="warning")
return
await func(*args, **kwargs)
app_.notify("This action requires Clive to be in UNLOCKED mode. Please unlock...")
await app_.push_screen(Unlock(unlock_result_callback=_on_unlock_result))
app.notify("This action requires Clive to be in UNLOCKED mode. Please unlock...")
await app.push_screen(Unlock(unlock_result_callback=_on_unlock_result))
return wrapper
@classmethod
def _common_prevent_decorator(
cls,
availability_check_func: Callable[[Clive], bool],
notify_message: str,
) -> Callable[[Callable[P, None]], Callable[P, None]]:
def decorator(func: Callable[P, None]) -> Callable[P, None]:
@wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
app = get_clive().app_instance()
if not availability_check_func(app):
logger.debug(f"action {func.__name__} {notify_message}")
app.notify(notify_message, severity="warning")
return
func(*args, **kwargs)
return wrapper
return decorator
@on(ScreenSuspend)
def _post_suspended(self) -> None:
"""
Loading