Skip to content

Commit

Permalink
Update to latest session/config object things
Browse files Browse the repository at this point in the history
  • Loading branch information
s0600204 committed Apr 15, 2019
1 parent 3821562 commit 8abc8e4
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions lisp/ui/settings/session_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

from lisp.core.dicttree import DictNode
from lisp.core.util import typename
from lisp.ui.settings.pages import ConfigurationPage, TreeMultiConfigurationWidget
from lisp.ui.settings.pages_tree_model import PagesTreeModel
from lisp.ui.settings.pages import SettingsPage, TreeMultiSettingsWidget
#from lisp.ui.settings.pages_tree_model import PagesTreeModel
from lisp.ui.widgets.pagestreewidget import PagesTreeModel
from lisp.ui.ui_utils import translate

logger = logging.getLogger(__name__)
Expand All @@ -47,11 +48,12 @@ def __init__(self, **kwargs):
self.resize(800, 510)
self.setLayout(QVBoxLayout())

self._confsMap = {}
self.model = PagesTreeModel()
for r_node in SessionConfigurationDialog.PagesRegistry.children:
self._populateModel(QModelIndex(), r_node)

self.mainPage = TreeMultiConfigurationWidget(self.model)
self.mainPage = TreeMultiSettingsWidget(self.model)
if len(self.PagesRegistry.children):
self.mainPage.selectFirst()
self.layout().addWidget(self.mainPage)
Expand All @@ -72,32 +74,42 @@ def __init__(self, **kwargs):
self.__onOk)

def applySettings(self):
self.mainPage.applySettings()
for plugin, config in self._confsMap.items():
settings = config['conf']
for page in config['pages']:
settings.update(page.getSettings())
plugin.WriteSessionConfig(settings)

def _populateModel(self, m_parent, r_parent):
if r_parent.value is not None:
page = r_parent.value.page
page_class = r_parent.value.page
config = r_parent.value.plugin.SessionConfig
else:
page = None
page_class = None
config = None

try:
if page is None:
if page_class is None:
# The current node have no page, use the parent model-index
# as parent for it's children
mod_index = m_parent
elif issubclass(page, ConfigurationPage):
mod_index = self.model.addPage(page(config), parent=m_parent)
else:
mod_index = self.model.addPage(page(), parent=m_parent)
page_instance = page_class()
page_instance.loadSettings(config)
mod_index = self.model.addPage(page_instance, parent=m_parent)

# Keep track of configurations and corresponding pages
self._confsMap.setdefault(r_parent.value.plugin,
{
"pages": [],
"conf": config
})
self._confsMap[r_parent.value.plugin]['pages'].append(page_instance)
except Exception:
if not isinstance(page, type):
page_name = 'NoPage'
elif issubclass(page, ConfigurationPage):
page_name = page.Name
if not isinstance(page_class, type):
page_name = 'InvalidPage'
else:
page_name = page.__name__
page_name = getattr(page_class, 'Name', page_class.__name__)

logger.warning(
'Cannot load configuration page: "{}" ({})'.format(
Expand All @@ -115,15 +127,15 @@ def registerSettingsPage(path, page, plugin):
"""
:param path: indicate the page "position": 'category.sub.key'
:type path: str
:type page: Type[lisp.ui.settings.settings_page.ConfigurationPage]
#:type config: lisp.core.configuration.Configuration
:type page: Type[lisp.ui.settings.settings_page.SettingsPage]
:type plugin_config: lisp.core.configuration.Configuration
"""
if issubclass(page, ConfigurationPage):
if issubclass(page, SettingsPage):
SessionConfigurationDialog.PagesRegistry.set(
path, PageEntry(page=page, plugin=plugin))
else:
raise TypeError(
'SessionConfiguration pages must be ConfigurationPage(s), not {}'
'SessionConfiguration pages must be SettingsPage(s), not {}'
.format(typename(page))
)

Expand Down

0 comments on commit 8abc8e4

Please sign in to comment.