fix: showing a previous not working gem as selected after installation in the gem selector panel

This commit is contained in:
Vinicius Moreira
2019-09-18 18:32:08 -03:00
parent 6c3e0e00bf
commit 65f313cbd8
4 changed files with 29 additions and 18 deletions

View File

@@ -47,7 +47,7 @@ def main():
if app.style().objectName().lower() not in {'fusion', 'breeze'}:
app.setStyle('Fusion')
managers = gems.load_managers(context=context, locale=args.locale, enabled_gems=user_config.enabled_gems if user_config.enabled_gems else None)
managers = gems.load_managers(context=context, locale=args.locale, config=user_config)
manager = GenericSoftwareManager(managers, context=context, app_args=args)
manager.prepare()

View File

@@ -17,16 +17,18 @@ class GenericSoftwareManager(SoftwareManager):
super(GenericSoftwareManager, self).__init__(context=context)
self.managers = managers
self.map = {t: m for m in self.managers for t in m.get_managed_types()}
self._available_map = {} if app_args.check_packaging_once else None
self._available_cache = {} if app_args.check_packaging_once else None
self.thread_prepare = None
self.i18n = context.i18n
self.disk_loader_factory = context.disk_loader_factory
self.logger = context.logger
self._already_prepared = []
self.working_managers = []
def reset_cache(self):
if self._available_map is not None:
self._available_map = {}
if self._available_cache is not None:
self._available_cache = {}
self.working_managers.clear()
def _sort(self, apps: List[SoftwarePackage], word: str) -> List[SoftwarePackage]:
@@ -51,16 +53,24 @@ class GenericSoftwareManager(SoftwareManager):
def _can_work(self, man: SoftwareManager):
if self._available_map is not None:
enabled = self._available_map.get(man.get_managed_types())
if self._available_cache is not None:
available = self._available_cache.get(man.get_managed_types())
if enabled is None:
enabled = man.is_enabled() and man.can_work()
self._available_map[man.get_managed_types()] = enabled
if available is None:
available = man.is_enabled() and man.can_work()
self._available_cache[man.get_managed_types()] = available
return enabled
else:
return man.is_enabled() and man.can_work()
available = man.is_enabled() and man.can_work()
if available:
if man not in self.working_managers:
self.working_managers.append(man)
else:
if man in self.working_managers:
self.working_managers.remove(man)
return available
def _search(self, word: str, man: SoftwareManager, disk_loader, res: SearchResult):
if self._can_work(man):

View File

@@ -5,6 +5,7 @@ from typing import List
from bauh import ROOT_DIR
from bauh.api.abstract.controller import SoftwareManager, ApplicationContext
from bauh.view.core.config import Configuration
from bauh.view.util import util
@@ -19,7 +20,7 @@ def find_manager(member):
return manager_found
def load_managers(locale: str, context: ApplicationContext, enabled_gems: List[str] = None) -> List[SoftwareManager]:
def load_managers(locale: str, context: ApplicationContext, config: Configuration) -> List[SoftwareManager]:
managers = []
for f in os.scandir(ROOT_DIR + '/gems'):
@@ -37,10 +38,10 @@ def load_managers(locale: str, context: ApplicationContext, enabled_gems: List[s
man = manager_class(context=context)
if enabled_gems is None:
if config.enabled_gems is None:
man.set_enabled(man.is_default_enabled())
else:
man.set_enabled(f.name in enabled_gems)
man.set_enabled(f.name in config.enabled_gems)
managers.append(man)

View File

@@ -37,7 +37,7 @@ class GemSelectorPanel(QWidget):
self.gem_map = {}
gem_options = []
current_enabled = set()
default = set()
for m in manager.managers:
if m.can_work():
@@ -50,13 +50,13 @@ class GemSelectorPanel(QWidget):
gem_options.append(op)
self.gem_map[modname] = m
if m.is_enabled():
current_enabled.add(op)
if m.is_enabled() and m in manager.working_managers:
default.add(op)
if self.config.enabled_gems:
default_ops = {o for o in gem_options if o.value in self.config.enabled_gems}
else:
default_ops = current_enabled
default_ops = default
self.bt_proceed.setEnabled(bool(default_ops))