[api.abstract.view] refactoring: TabGroupComponent as a ViewContainer

This commit is contained in:
Vinicius Moreira
2022-04-11 17:25:33 -03:00
parent 9ac0d015b7
commit 924a3ede46
3 changed files with 25 additions and 19 deletions

View File

@@ -35,7 +35,7 @@ class ViewContainer(ViewComponent, ABC):
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,
observers: Optional[List[ViewObserver]] = None):
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):
super(TabComponent, self).__init__(id_=id_)
self.label = label
self.content = content
self._content = content
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):
super(TabGroupComponent, self).__init__(id_=id_)
self.tabs = tabs
self.tab_map = {c.id: c for c in tabs if c.id} if tabs else None
super(TabGroupComponent, self).__init__(id_=id_, components=tabs)
def get_tab(self, id_: str) -> TabComponent:
if self.tab_map:
return self.tab_map.get(id_)
def get_tab(self, id_: str) -> Optional[TabComponent]:
return self.get_component(id_, TabComponent)
@property
def tabs(self) -> List[TabComponent]:
return self.components
class RangeInputComponent(InputViewComponent):

View File

@@ -1,5 +1,4 @@
import os
import os
import time
import traceback
from math import floor
@@ -510,17 +509,17 @@ class GenericSettingsManager(SettingsController):
finally:
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
try:
bkp = root_component.get_tab('core.bkp')
success, errors = self._save_settings(general=root_component.get_tab('core.gen').content,
advanced=root_component.get_tab('core.adv').content,
tray=root_component.get_tab('core.tray').content,
backup=bkp.content if bkp else None,
ui=root_component.get_tab('core.ui').content,
gems_panel=root_component.get_tab('core.types').content)
bkp = tabs.get_tab('core.bkp')
success, errors = self._save_settings(general=tabs.get_tab('core.gen').get_content(PanelComponent),
advanced=tabs.get_tab('core.adv').get_content(PanelComponent),
tray=tabs.get_tab('core.tray').get_content(PanelComponent),
backup=bkp.get_content(PanelComponent) if bkp else None,
ui=tabs.get_tab('core.ui').get_content(PanelComponent),
gems_panel=tabs.get_tab('core.types').get_content(PanelComponent))
if errors:
warnings.extend(errors)

View File

@@ -951,7 +951,7 @@ class TabGroupQt(QTabWidget):
scroll = QScrollArea()
scroll.setFrameShape(QFrame.NoFrame)
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.tabBar().setCursor(QCursor(Qt.PointingHandCursor))