Module: ui_app_state
Expand source code
# Copyright (C) 2023-present The Project Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from dataclasses import dataclass
from typing import List
from typing import Optional
from cl.runtime import Context
from cl.runtime.backend.core.app_theme import AppTheme
from cl.runtime.backend.core.tab_info import TabInfo
from cl.runtime.backend.core.ui_app_state_key import UiAppStateKey
from cl.runtime.backend.core.user_key import UserKey
from cl.runtime.records.dataclasses_extensions import field
from cl.runtime.records.dataclasses_extensions import missing
from cl.runtime.records.record_mixin import RecordMixin
@dataclass(slots=True, kw_only=True)
class UiAppState(UiAppStateKey, RecordMixin[UiAppStateKey]):
"""UiAppState."""
opened_tabs: List[TabInfo] | None = missing()
"""Information about opened tabs."""
active_tab_index: int | None = missing()
"""Index of active opened tab."""
backend_version: str | None = missing()
"""DEPRECATED. Use versions instead."""
application_name: str | None = missing()
"""Application name."""
read_only: bool | None = missing()
"""Flag indicating that UI is read-only."""
application_theme: str | None = missing() # TODO: Replace by AppTheme
"""Application theme (dark, light, etc.)."""
def get_key(self) -> UiAppStateKey:
return UiAppStateKey(user=self.user)
@classmethod
def get_current_user_app_theme(cls) -> AppTheme | None:
"""Get current user app theme."""
default_app_state_key = UiAppStateKey(user=UserKey(username="root")) # TODO: Review the use of root default
default_app_state = Context.current().load_one(UiAppStateKey, default_app_state_key)
if default_app_state is not None and default_app_state.application_theme is not None:
return default_app_state.application_theme
return "Light"
Classes
class UiAppState (*, user: UserKey = None, opened_tabs: Optional[List[TabInfo]] = None, active_tab_index: int | None = None, backend_version: str | None = None, application_name: str | None = None, read_only: bool | None = None, application_theme: str | None = None)
-
UiAppState.
Expand source code
@dataclass(slots=True, kw_only=True) class UiAppState(UiAppStateKey, RecordMixin[UiAppStateKey]): """UiAppState.""" opened_tabs: List[TabInfo] | None = missing() """Information about opened tabs.""" active_tab_index: int | None = missing() """Index of active opened tab.""" backend_version: str | None = missing() """DEPRECATED. Use versions instead.""" application_name: str | None = missing() """Application name.""" read_only: bool | None = missing() """Flag indicating that UI is read-only.""" application_theme: str | None = missing() # TODO: Replace by AppTheme """Application theme (dark, light, etc.).""" def get_key(self) -> UiAppStateKey: return UiAppStateKey(user=self.user) @classmethod def get_current_user_app_theme(cls) -> AppTheme | None: """Get current user app theme.""" default_app_state_key = UiAppStateKey(user=UserKey(username="root")) # TODO: Review the use of root default default_app_state = Context.current().load_one(UiAppStateKey, default_app_state_key) if default_app_state is not None and default_app_state.application_theme is not None: return default_app_state.application_theme return "Light"
Ancestors
- UiAppStateKey
- KeyMixin
- abc.ABC
- RecordMixin
- typing.Generic
Static methods
def get_current_user_app_theme() -> Optional[Literal['Dark', 'Light']]
-
Get current user app theme.
def get_key_type() -> Type
-
Inherited from:
UiAppStateKey
.get_key_type
Return key type even when called from a record.
Fields
var active_tab_index -> int | None
-
Index of active opened tab.
var application_name -> str | None
-
Application name.
var application_theme -> str | None
-
Application theme (dark, light, etc.).
var backend_version -> str | None
-
DEPRECATED. Use versions instead.
var opened_tabs -> Optional[List[TabInfo]]
-
Information about opened tabs.
var read_only -> bool | None
-
Flag indicating that UI is read-only.
var user -> UserKey
-
Inherited from:
UiAppStateKey
.user
A user the app state is applied for.
Methods
def get_key(self) -> UiAppStateKey
-
Inherited from:
RecordMixin
.get_key
Return a new key object whose fields populated from self, do not return self.
def init_all(self) -> None
-
Inherited from:
RecordMixin
.init_all
Invoke ‘init’ for each class in the order from base to derived, then validate against schema.