mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 00:04:15 +02:00
[api] improvement: allowing several settings views to be returned (SoftwareManager.get_settings)
This commit is contained in:
@@ -119,6 +119,29 @@ class SoftwareAction(Enum):
|
||||
DOWNGRADE = 5
|
||||
|
||||
|
||||
class SettingsController(ABC):
|
||||
|
||||
def save_settings(self, component: ViewComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
"""
|
||||
:return: a tuple with a bool informing if the settings were saved and a list of error messages
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class SettingsView:
|
||||
|
||||
def __init__(self, controller: SettingsController, component: ViewComponent, label: Optional[str] = None,
|
||||
icon_path: Optional[str] = None):
|
||||
|
||||
self.controller = controller
|
||||
self.component = component
|
||||
self.label = label
|
||||
self.icon_path = icon_path
|
||||
|
||||
def save(self) -> Tuple[bool, Optional[List[str]]]:
|
||||
return self.controller.save_settings(self.component)
|
||||
|
||||
|
||||
class SoftwareManager(ABC):
|
||||
|
||||
"""
|
||||
@@ -379,15 +402,9 @@ class SoftwareManager(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
"""
|
||||
:return: a form abstraction with all available settings
|
||||
"""
|
||||
pass
|
||||
|
||||
def save_settings(self, component: ViewComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
"""
|
||||
:return: a tuple with a bool informing if the settings were saved and a list of error messages
|
||||
:return: panel abstractions with optional icon paths associated with
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from abc import ABC
|
||||
from enum import Enum
|
||||
from typing import List, Set, Optional, Dict
|
||||
from typing import List, Set, Optional, Dict, TypeVar, Type
|
||||
|
||||
|
||||
class MessageType(Enum):
|
||||
@@ -27,6 +27,9 @@ class ViewComponent(ABC):
|
||||
self.observers.append(obs)
|
||||
|
||||
|
||||
V = TypeVar('V', bound=ViewComponent)
|
||||
|
||||
|
||||
class SpacerComponent(ViewComponent):
|
||||
|
||||
def __init__(self):
|
||||
@@ -35,7 +38,7 @@ class SpacerComponent(ViewComponent):
|
||||
|
||||
class InputViewComponent(ViewComponent):
|
||||
"""
|
||||
Represents an component which needs a user interaction to provide its value
|
||||
Represents a component which needs a user interaction to provide its value
|
||||
"""
|
||||
|
||||
|
||||
@@ -317,6 +320,15 @@ class PanelComponent(ViewComponent):
|
||||
if self.component_map:
|
||||
return self.component_map.get(id_)
|
||||
|
||||
def get_component_by_idx(self, idx: int, type_: Type[V]) -> Optional[V]:
|
||||
if self.components and idx < len(self.components):
|
||||
c = self.components[idx]
|
||||
if isinstance(c, type_):
|
||||
return c
|
||||
|
||||
raise Exception(f"The {ViewComponent.__class__.__name__} at index {idx} is not an "
|
||||
f"instance of '{type_.__name__}'")
|
||||
|
||||
def get_form_component(self, id_: str) -> Optional[FormComponent]:
|
||||
comp = self.get_component(id_)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user