mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[api.abstract.view] refactoring: TabGroupComponent as a ViewContainer
This commit is contained in:
@@ -35,7 +35,7 @@ class ViewContainer(ViewComponent, ABC):
|
|||||||
Represents a GUI component composed by other components
|
Represents a GUI component composed by other components
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, components: Union[List[ViewComponent], Tuple[ViewComponent]],
|
def __init__(self, components: Union[List[V], Tuple[V]],
|
||||||
id_: Optional[str] = None,
|
id_: Optional[str] = None,
|
||||||
observers: Optional[List[ViewObserver]] = None):
|
observers: Optional[List[ViewObserver]] = None):
|
||||||
super(ViewContainer, self).__init__(id_=id_, observers=observers)
|
super(ViewContainer, self).__init__(id_=id_, observers=observers)
|
||||||
@@ -282,20 +282,27 @@ class TabComponent(ViewComponent):
|
|||||||
def __init__(self, label: str, content: ViewComponent, icon_path: str = None, id_: str = None):
|
def __init__(self, label: str, content: ViewComponent, icon_path: str = None, id_: str = None):
|
||||||
super(TabComponent, self).__init__(id_=id_)
|
super(TabComponent, self).__init__(id_=id_)
|
||||||
self.label = label
|
self.label = label
|
||||||
self.content = content
|
self._content = content
|
||||||
self.icon_path = icon_path
|
self.icon_path = icon_path
|
||||||
|
|
||||||
|
def get_content(self, type_: Type[V] = ViewComponent) -> V:
|
||||||
|
if isinstance(self._content, type_):
|
||||||
|
return self._content
|
||||||
|
|
||||||
class TabGroupComponent(ViewComponent):
|
raise Exception(f"'content' is not an instance of '{type_.__name__}'")
|
||||||
|
|
||||||
|
|
||||||
|
class TabGroupComponent(ViewContainer):
|
||||||
|
|
||||||
def __init__(self, tabs: List[TabComponent], id_: str = None):
|
def __init__(self, tabs: List[TabComponent], id_: str = None):
|
||||||
super(TabGroupComponent, self).__init__(id_=id_)
|
super(TabGroupComponent, self).__init__(id_=id_, components=tabs)
|
||||||
self.tabs = tabs
|
|
||||||
self.tab_map = {c.id: c for c in tabs if c.id} if tabs else None
|
|
||||||
|
|
||||||
def get_tab(self, id_: str) -> TabComponent:
|
def get_tab(self, id_: str) -> Optional[TabComponent]:
|
||||||
if self.tab_map:
|
return self.get_component(id_, TabComponent)
|
||||||
return self.tab_map.get(id_)
|
|
||||||
|
@property
|
||||||
|
def tabs(self) -> List[TabComponent]:
|
||||||
|
return self.components
|
||||||
|
|
||||||
|
|
||||||
class RangeInputComponent(InputViewComponent):
|
class RangeInputComponent(InputViewComponent):
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import os
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from math import floor
|
from math import floor
|
||||||
@@ -510,17 +509,17 @@ class GenericSettingsManager(SettingsController):
|
|||||||
finally:
|
finally:
|
||||||
success_list.append(success)
|
success_list.append(success)
|
||||||
|
|
||||||
def _save_core_settings(self, root_component: TabGroupComponent, success_list: List[bool], warnings: List[str]):
|
def _save_core_settings(self, tabs: TabGroupComponent, success_list: List[bool], warnings: List[str]):
|
||||||
success = False
|
success = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bkp = root_component.get_tab('core.bkp')
|
bkp = tabs.get_tab('core.bkp')
|
||||||
success, errors = self._save_settings(general=root_component.get_tab('core.gen').content,
|
success, errors = self._save_settings(general=tabs.get_tab('core.gen').get_content(PanelComponent),
|
||||||
advanced=root_component.get_tab('core.adv').content,
|
advanced=tabs.get_tab('core.adv').get_content(PanelComponent),
|
||||||
tray=root_component.get_tab('core.tray').content,
|
tray=tabs.get_tab('core.tray').get_content(PanelComponent),
|
||||||
backup=bkp.content if bkp else None,
|
backup=bkp.get_content(PanelComponent) if bkp else None,
|
||||||
ui=root_component.get_tab('core.ui').content,
|
ui=tabs.get_tab('core.ui').get_content(PanelComponent),
|
||||||
gems_panel=root_component.get_tab('core.types').content)
|
gems_panel=tabs.get_tab('core.types').get_content(PanelComponent))
|
||||||
if errors:
|
if errors:
|
||||||
warnings.extend(errors)
|
warnings.extend(errors)
|
||||||
|
|
||||||
|
|||||||
@@ -951,7 +951,7 @@ class TabGroupQt(QTabWidget):
|
|||||||
scroll = QScrollArea()
|
scroll = QScrollArea()
|
||||||
scroll.setFrameShape(QFrame.NoFrame)
|
scroll.setFrameShape(QFrame.NoFrame)
|
||||||
scroll.setWidgetResizable(True)
|
scroll.setWidgetResizable(True)
|
||||||
scroll.setWidget(to_widget(c.content, i18n))
|
scroll.setWidget(to_widget(c.get_content(), i18n))
|
||||||
self.addTab(scroll, icon, c.label)
|
self.addTab(scroll, icon, c.label)
|
||||||
|
|
||||||
self.tabBar().setCursor(QCursor(Qt.PointingHandCursor))
|
self.tabBar().setCursor(QCursor(Qt.PointingHandCursor))
|
||||||
|
|||||||
Reference in New Issue
Block a user