mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 11:44:15 +02:00
[api] improvement: abstraction for view containers
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from abc import ABC
|
||||
from enum import Enum
|
||||
from typing import List, Set, Optional, Dict, TypeVar, Type
|
||||
from typing import List, Set, Optional, Dict, TypeVar, Type, Union, Tuple
|
||||
|
||||
|
||||
class MessageType(Enum):
|
||||
@@ -30,6 +30,39 @@ class ViewComponent(ABC):
|
||||
V = TypeVar('V', bound=ViewComponent)
|
||||
|
||||
|
||||
class ViewContainer(ViewComponent, ABC):
|
||||
"""
|
||||
Represents a GUI component composed by other components
|
||||
"""
|
||||
|
||||
def __init__(self, components: Union[List[ViewComponent], Tuple[ViewComponent]],
|
||||
id_: Optional[str] = None,
|
||||
observers: Optional[List[ViewObserver]] = None):
|
||||
super(ViewContainer, self).__init__(id_=id_, observers=observers)
|
||||
self.components = components
|
||||
self.component_map = {c.id: c for c in components if c.id is not None} if components else None
|
||||
|
||||
def get_component(self, id_: str, type_: Type[V] = ViewComponent) -> Optional[V]:
|
||||
if self.component_map:
|
||||
instance = self.component_map.get(id_)
|
||||
|
||||
if instance:
|
||||
if isinstance(instance, type_):
|
||||
return instance
|
||||
|
||||
raise Exception(f"The {ViewComponent.__class__.__name__} (id={id_}) is not an "
|
||||
f"instance of '{type_.__name__}'")
|
||||
|
||||
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__}'")
|
||||
|
||||
|
||||
class SpacerComponent(ViewComponent):
|
||||
|
||||
def __init__(self):
|
||||
@@ -205,45 +238,15 @@ class TextInputComponent(ViewComponent):
|
||||
return self.label.capitalize() if self.capitalize_label else self.label
|
||||
|
||||
|
||||
class FormComponent(ViewComponent):
|
||||
class FormComponent(ViewContainer):
|
||||
|
||||
def __init__(self, components: List[ViewComponent], label: str = None, spaces: bool = True, id_: str = None,
|
||||
min_width: Optional[int] = None):
|
||||
super(FormComponent, self).__init__(id_=id_)
|
||||
super(FormComponent, self).__init__(id_=id_, components=components)
|
||||
self.label = label
|
||||
self.spaces = spaces
|
||||
self.components = components
|
||||
self.component_map = {c.id: c for c in components if c.id} if components else None
|
||||
self.min_width = min_width
|
||||
|
||||
def get_component(self, id_: str) -> Optional[ViewComponent]:
|
||||
if self.component_map:
|
||||
return self.component_map.get(id_)
|
||||
|
||||
def get_single_select_component(self, id_: str) -> Optional[SingleSelectComponent]:
|
||||
comp = self.get_component(id_)
|
||||
|
||||
if comp:
|
||||
if not isinstance(comp, SingleSelectComponent):
|
||||
raise Exception("'{}' is not a {}".format(id_, SingleSelectComponent.__class__.__name__))
|
||||
return comp
|
||||
|
||||
def get_form_component(self, id_: str) -> Optional["FormComponent"]:
|
||||
comp = self.get_component(id_)
|
||||
|
||||
if comp:
|
||||
if not isinstance(comp, FormComponent):
|
||||
raise Exception("'{}' is not a {}".format(id_, FormComponent.__class__.__name__))
|
||||
return comp
|
||||
|
||||
def get_text_input(self, id_) -> Optional[TextInputComponent]:
|
||||
comp = self.get_component(id_)
|
||||
|
||||
if comp:
|
||||
if not isinstance(comp, TextInputComponent):
|
||||
raise Exception("'{}' is not a {}".format(id_, TextInputComponent.__class__.__name__))
|
||||
return comp
|
||||
|
||||
|
||||
class FileChooserComponent(ViewComponent):
|
||||
|
||||
@@ -309,38 +312,7 @@ class RangeInputComponent(InputViewComponent):
|
||||
self.max_width = max_width
|
||||
|
||||
|
||||
class PanelComponent(ViewComponent):
|
||||
class PanelComponent(ViewContainer):
|
||||
|
||||
def __init__(self, components: List[ViewComponent], id_: str = None):
|
||||
super(PanelComponent, self).__init__(id_=id_)
|
||||
self.components = components
|
||||
self.component_map = {c.id: c for c in components if c.id is not None} if components else None
|
||||
|
||||
def get_component(self, id_: str) -> Optional[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_)
|
||||
|
||||
if comp:
|
||||
if not isinstance(comp, FormComponent):
|
||||
raise Exception("'{}' is not a {}".format(id_, FormComponent.__class__.__name__))
|
||||
return comp
|
||||
|
||||
def get_text_input(self, id_) -> Optional[TextInputComponent]:
|
||||
comp = self.get_component(id_)
|
||||
|
||||
if comp:
|
||||
if not isinstance(comp, TextInputComponent):
|
||||
raise Exception("'{}' is not a {}".format(id_, TextInputComponent.__class__.__name__))
|
||||
return comp
|
||||
super(PanelComponent, self).__init__(id_=id_, components=components)
|
||||
|
||||
@@ -851,20 +851,20 @@ class AppImageManager(SoftwareManager, SettingsController):
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]:
|
||||
appimage_config = self.configman.get_config()
|
||||
config_ = self.configman.get_config()
|
||||
max_width = floor(self.context.screen_width * 0.15)
|
||||
|
||||
comps = [
|
||||
TextInputComponent(label=self.i18n['appimage.config.database.expiration'],
|
||||
value=int(appimage_config['database']['expiration']) if isinstance(
|
||||
appimage_config['database']['expiration'], int) else '',
|
||||
value=int(config_['database']['expiration']) if isinstance(
|
||||
config_['database']['expiration'], int) else '',
|
||||
tooltip=self.i18n['appimage.config.database.expiration.tip'],
|
||||
only_int=True,
|
||||
max_width=max_width,
|
||||
id_='appim_db_exp'),
|
||||
TextInputComponent(label=self.i18n['appimage.config.suggestions.expiration'],
|
||||
value=int(appimage_config['suggestions']['expiration']) if isinstance(
|
||||
appimage_config['suggestions']['expiration'], int) else '',
|
||||
value=int(config_['suggestions']['expiration']) if isinstance(
|
||||
config_['suggestions']['expiration'], int) else '',
|
||||
tooltip=self.i18n['appimage.config.suggestions.expiration.tip'],
|
||||
only_int=True,
|
||||
max_width=max_width,
|
||||
@@ -874,14 +874,14 @@ class AppImageManager(SoftwareManager, SettingsController):
|
||||
yield SettingsView(self, PanelComponent([FormComponent(components=comps)]))
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
appimage_config = self.configman.get_config()
|
||||
config_ = self.configman.get_config()
|
||||
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
appimage_config['database']['expiration'] = form.get_text_input('appim_db_exp').get_int_value()
|
||||
appimage_config['suggestions']['expiration'] = form.get_text_input('appim_sugs_exp').get_int_value()
|
||||
config_['database']['expiration'] = form.get_component('appim_db_exp', TextInputComponent).get_int_value()
|
||||
config_['suggestions']['expiration'] = form.get_component('appim_sugs_exp', TextInputComponent).get_int_value()
|
||||
|
||||
try:
|
||||
self.configman.save_config(appimage_config)
|
||||
self.configman.save_config(config_)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -3026,47 +3026,59 @@ class ArchManager(SoftwareManager, SettingsController):
|
||||
yield self._get_general_settings(arch_config, max_width)
|
||||
yield self._get_aur_settings(arch_config, max_width)
|
||||
|
||||
def _fill_general_settings(self, arch_config: dict, form: FormComponent):
|
||||
arch_config['repositories'] = form.get_single_select_component('repos').get_selected()
|
||||
arch_config['sync_databases'] = form.get_single_select_component('sync_dbs').get_selected()
|
||||
arch_config['sync_databases_startup'] = form.get_single_select_component('sync_dbs_start').get_selected()
|
||||
arch_config['clean_cached'] = form.get_single_select_component('clean_cached').get_selected()
|
||||
arch_config['refresh_mirrors_startup'] = form.get_single_select_component('ref_mirs').get_selected()
|
||||
arch_config['mirrors_sort_limit'] = form.get_text_input('mirrors_sort_limit').get_int_value()
|
||||
arch_config['repositories_mthread_download'] = form.get_single_select_component('mthread_download').get_selected()
|
||||
arch_config['automatch_providers'] = form.get_single_select_component('autoprovs').get_selected()
|
||||
@staticmethod
|
||||
def fill_general_settings(arch_config: dict, form: FormComponent):
|
||||
arch_config['repositories'] = form.get_component('repos', SingleSelectComponent).get_selected()
|
||||
arch_config['sync_databases'] = form.get_component('sync_dbs', SingleSelectComponent).get_selected()
|
||||
arch_config['clean_cached'] = form.get_component('clean_cached', SingleSelectComponent).get_selected()
|
||||
arch_config['refresh_mirrors_startup'] = form.get_component('ref_mirs', SingleSelectComponent).get_selected()
|
||||
arch_config['mirrors_sort_limit'] = form.get_component('mirrors_sort_limit', TextInputComponent).get_int_value()
|
||||
arch_config['automatch_providers'] = form.get_component('autoprovs', SingleSelectComponent).get_selected()
|
||||
|
||||
prefer_repo_provider = form.get_single_select_component('prefer_repo_provider').get_selected()
|
||||
sync_dbs_startup = form.get_component('sync_dbs_start', SingleSelectComponent).get_selected()
|
||||
arch_config['sync_databases_startup'] = sync_dbs_startup
|
||||
|
||||
mthread_download = form.get_component('mthread_download', SingleSelectComponent).get_selected()
|
||||
arch_config['repositories_mthread_download'] = mthread_download
|
||||
|
||||
prefer_repo_provider = form.get_component('prefer_repo_provider', SingleSelectComponent).get_selected()
|
||||
arch_config['prefer_repository_provider'] = prefer_repo_provider
|
||||
|
||||
check_dep_break = form.get_single_select_component('check_dependency_breakage').get_selected()
|
||||
check_dep_break = form.get_component('check_dependency_breakage', SingleSelectComponent).get_selected()
|
||||
arch_config['check_dependency_breakage'] = check_dep_break
|
||||
|
||||
sug_opt_dep_uni = form.get_single_select_component('suggest_optdep_uninstall').get_selected()
|
||||
sug_opt_dep_uni = form.get_component('suggest_optdep_uninstall', SingleSelectComponent).get_selected()
|
||||
arch_config['suggest_optdep_uninstall'] = sug_opt_dep_uni
|
||||
|
||||
sug_unneeded_uni = form.get_single_select_component('suggest_unneeded_uninstall').get_selected()
|
||||
sug_unneeded_uni = form.get_component('suggest_unneeded_uninstall', SingleSelectComponent).get_selected()
|
||||
arch_config['suggest_unneeded_uninstall'] = sug_unneeded_uni
|
||||
|
||||
arch_config['categories_exp'] = form.get_text_input('arch_cats_exp').get_int_value()
|
||||
arch_config['categories_exp'] = form.get_component('arch_cats_exp', TextInputComponent).get_int_value()
|
||||
|
||||
def _fill_aur_settings(self, arch_config: dict, form: FormComponent):
|
||||
arch_config['optimize'] = form.get_single_select_component('opts').get_selected()
|
||||
arch_config['aur_rebuild_detector'] = form.get_single_select_component('rebuild_detector').get_selected()
|
||||
arch_config['optimize'] = form.get_component('opts', SingleSelectComponent).get_selected()
|
||||
|
||||
rebuild_no_bin = form.get_single_select_component('rebuild_detector_no_bin').get_selected()
|
||||
rebuild_detect = form.get_component('rebuild_detector', SingleSelectComponent).get_selected()
|
||||
arch_config['aur_rebuild_detector'] = rebuild_detect
|
||||
|
||||
rebuild_no_bin = form.get_component('rebuild_detector_no_bin', SingleSelectComponent).get_selected()
|
||||
arch_config['aur_rebuild_detector_no_bin'] = rebuild_no_bin
|
||||
|
||||
arch_config['edit_aur_pkgbuild'] = form.get_single_select_component('edit_aur_pkgbuild').get_selected()
|
||||
arch_config['aur_remove_build_dir'] = form.get_single_select_component('aur_remove_build_dir').get_selected()
|
||||
arch_config['aur_build_dir'] = form.get_component('aur_build_dir').file_path
|
||||
arch_config['aur_build_only_chosen'] = form.get_single_select_component('aur_build_only_chosen').get_selected()
|
||||
arch_config['aur_idx_exp'] = form.get_text_input('aur_idx_exp').get_int_value()
|
||||
arch_config['edit_aur_pkgbuild'] = form.get_component('edit_aur_pkgbuild', SingleSelectComponent).get_selected()
|
||||
|
||||
remove_build_dir = form.get_component('aur_remove_build_dir', SingleSelectComponent).get_selected()
|
||||
arch_config['aur_remove_build_dir'] = remove_build_dir
|
||||
|
||||
build_chosen = form.get_component('aur_build_only_chosen', SingleSelectComponent).get_selected()
|
||||
arch_config['aur_build_only_chosen'] = build_chosen
|
||||
|
||||
arch_config['aur_build_dir'] = form.get_component('aur_build_dir', FileChooserComponent).file_path
|
||||
arch_config['aur_idx_exp'] = form.get_component('aur_idx_exp', TextInputComponent).get_int_value()
|
||||
|
||||
if not arch_config['aur_build_dir']:
|
||||
arch_config['aur_build_dir'] = None
|
||||
|
||||
aur_enabled_select = form.get_single_select_component('aur')
|
||||
aur_enabled_select = form.get_component('aur', SingleSelectComponent)
|
||||
arch_config['aur'] = aur_enabled_select.get_selected()
|
||||
|
||||
if aur_enabled_select.changed() and arch_config['aur']:
|
||||
@@ -3078,7 +3090,7 @@ class ArchManager(SoftwareManager, SettingsController):
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
|
||||
if component.id == 'repo':
|
||||
self._fill_general_settings(arch_config, form)
|
||||
self.fill_general_settings(arch_config, form)
|
||||
elif component.id == 'aur':
|
||||
self._fill_aur_settings(arch_config, form)
|
||||
|
||||
|
||||
@@ -636,16 +636,26 @@ class DebianPackageManager(SoftwareManager, SettingsController):
|
||||
yield SettingsView(self, panel)
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
deb_config = self.configman.get_config()
|
||||
config_ = self.configman.get_config()
|
||||
|
||||
container = component.get_component_by_idx(0, FormComponent)
|
||||
deb_config['pkg_sources.app'] = container.get_single_select_component('pkg_sources.app').get_selected()
|
||||
deb_config['index_apps.exp'] = container.get_text_input('index_apps.exp').get_int_value()
|
||||
deb_config['sync_pkgs.time'] = container.get_text_input('sync_pkgs.time').get_int_value()
|
||||
deb_config['suggestions.exp'] = container.get_text_input('suggestions.exp').get_int_value()
|
||||
|
||||
for prop, type_ in {'pkg_sources.app': SingleSelectComponent,
|
||||
'index_apps.exp': TextInputComponent,
|
||||
'sync_pkgs.time': TextInputComponent,
|
||||
'suggestions.exp': TextInputComponent}.items():
|
||||
comp = container.get_component(prop, type_)
|
||||
|
||||
val = None
|
||||
if isinstance(comp, SingleSelectComponent):
|
||||
val = comp.get_selected()
|
||||
elif isinstance(comp, TextInputComponent):
|
||||
val = comp.get_int_value()
|
||||
|
||||
config_[prop] = val
|
||||
|
||||
try:
|
||||
self.configman.save_config(deb_config)
|
||||
self.configman.save_config(config_)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -631,7 +631,7 @@ class FlatpakManager(SoftwareManager, SettingsController):
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
flatpak_config = self.configman.get_config()
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
flatpak_config['installation_level'] = form.get_single_select_component('install').get_selected()
|
||||
flatpak_config['installation_level'] = form.get_component('install', SingleSelectComponent).get_selected()
|
||||
|
||||
try:
|
||||
self.configman.save_config(flatpak_config)
|
||||
|
||||
@@ -10,7 +10,7 @@ from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageHistory, PackageUpdate, PackageSuggestion, \
|
||||
SuggestionPriority, PackageStatus
|
||||
from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputOption, ViewComponent, PanelComponent, \
|
||||
from bauh.api.abstract.view import SingleSelectComponent, SelectViewType, InputOption, PanelComponent, \
|
||||
FormComponent, TextInputComponent
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
@@ -439,8 +439,9 @@ class SnapManager(SoftwareManager, SettingsController):
|
||||
max_width=max_width,
|
||||
tip=self.i18n['snap.config.install_channel.tip'])
|
||||
|
||||
cat_exp_val = snap_config['categories_exp'] if isinstance(snap_config['categories_exp'], int) else ''
|
||||
categories_exp = TextInputComponent(id_='snap_cat_exp',
|
||||
value=snap_config['categories_exp'] if isinstance(snap_config['categories_exp'], int) else '',
|
||||
value=cat_exp_val,
|
||||
max_width=max_width,
|
||||
only_int=True,
|
||||
label=self.i18n['snap.config.categories_exp'],
|
||||
@@ -450,14 +451,14 @@ class SnapManager(SoftwareManager, SettingsController):
|
||||
yield SettingsView(self, panel)
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
snap_config = self.configman.get_config()
|
||||
config_ = self.configman.get_config()
|
||||
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
snap_config['install_channel'] = form.get_single_select_component('snap_install_channel').get_selected()
|
||||
snap_config['categories_exp'] = form.get_text_input('snap_cat_exp').get_int_value()
|
||||
config_['install_channel'] = form.get_component('snap_install_channel', SingleSelectComponent).get_selected()
|
||||
config_['categories_exp'] = form.get_component('snap_cat_exp', TextInputComponent).get_int_value()
|
||||
|
||||
try:
|
||||
self.configman.save_config(snap_config)
|
||||
self.configman.save_config(config_)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -25,7 +25,7 @@ from bauh.api.abstract.model import SoftwarePackage, CustomSoftwareAction, Packa
|
||||
PackageHistory, \
|
||||
SuggestionPriority, PackageStatus
|
||||
from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \
|
||||
SelectViewType, TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, PanelComponent
|
||||
SelectViewType, TextInputComponent, FormComponent, FileChooserComponent, PanelComponent
|
||||
from bauh.api.paths import DESKTOP_ENTRIES_DIR
|
||||
from bauh.commons import resource
|
||||
from bauh.commons.boot import CreateConfigFile
|
||||
@@ -1152,27 +1152,27 @@ class WebApplicationManager(SoftwareManager, SettingsController):
|
||||
yield SettingsView(self, PanelComponent([form_env]))
|
||||
|
||||
def save_settings(self, component: PanelComponent) -> Tuple[bool, Optional[List[str]]]:
|
||||
web_config = self.configman.get_config()
|
||||
config_ = self.configman.get_config()
|
||||
|
||||
form_env = component.get_component_by_idx(0, FormComponent)
|
||||
form = component.get_component_by_idx(0, FormComponent)
|
||||
|
||||
electron_version = str(form_env.get_text_input('electron_branch').get_value()).strip()
|
||||
web_config['environment']['electron']['version'] = electron_version
|
||||
electron_version = str(form.get_component('electron_branch', TextInputComponent).get_value()).strip()
|
||||
config_['environment']['electron']['version'] = electron_version
|
||||
|
||||
if len(web_config['environment']['electron']['version']) == 0:
|
||||
web_config['environment']['electron']['version'] = None
|
||||
if len(config_['environment']['electron']['version']) == 0:
|
||||
config_['environment']['electron']['version'] = None
|
||||
|
||||
system_nativefier = form_env.get_single_select_component('nativefier').get_selected()
|
||||
system_nativefier = form.get_component('nativefier', SingleSelectComponent).get_selected()
|
||||
|
||||
if system_nativefier and not nativefier.is_available():
|
||||
return False, [self.i18n['web.settings.env.nativefier.system.not_installed'].format('Nativefier')]
|
||||
|
||||
web_config['environment']['system'] = system_nativefier
|
||||
web_config['environment']['cache_exp'] = form_env.get_text_input('web_cache_exp').get_int_value()
|
||||
web_config['suggestions']['cache_exp'] = form_env.get_text_input('web_sugs_exp').get_int_value()
|
||||
config_['environment']['system'] = system_nativefier
|
||||
config_['environment']['cache_exp'] = form.get_component('web_cache_exp', TextInputComponent).get_int_value()
|
||||
config_['suggestions']['cache_exp'] = form.get_component('web_sugs_exp', TextInputComponent).get_int_value()
|
||||
|
||||
try:
|
||||
self.configman.save_config(web_config)
|
||||
self.configman.save_config(config_)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
@@ -359,104 +359,131 @@ class GenericSettingsManager(SettingsController):
|
||||
# general
|
||||
gen_form = general.get_component_by_idx(0, FormComponent)
|
||||
|
||||
locale = gen_form.get_single_select_component('locale').get_selected()
|
||||
locale = gen_form.get_component('locale', SingleSelectComponent).get_selected()
|
||||
|
||||
if locale != self.i18n.current_key:
|
||||
core_config['locale'] = locale
|
||||
|
||||
core_config['system']['notifications'] = gen_form.get_single_select_component('sys_notify').get_selected()
|
||||
core_config['suggestions']['enabled'] = gen_form.get_single_select_component('sugs_enabled').get_selected()
|
||||
core_config['store_root_password'] = gen_form.get_single_select_component('store_pwd').get_selected()
|
||||
notifications = gen_form.get_component('sys_notify', SingleSelectComponent).get_selected()
|
||||
core_config['system']['notifications'] = notifications
|
||||
|
||||
sugs_by_type = gen_form.get_text_input('sugs_by_type').get_int_value()
|
||||
suggestions = gen_form.get_component('sugs_enabled', SingleSelectComponent).get_selected()
|
||||
core_config['suggestions']['enabled'] = suggestions
|
||||
|
||||
store_root_pwd = gen_form.get_component('store_pwd', SingleSelectComponent).get_selected()
|
||||
core_config['store_root_password'] = store_root_pwd
|
||||
|
||||
sugs_by_type = gen_form.get_component('sugs_by_type', TextInputComponent).get_int_value()
|
||||
core_config['suggestions']['by_type'] = sugs_by_type
|
||||
|
||||
core_config['updates']['ask_for_reboot'] = gen_form.get_single_select_component('ask_for_reboot').get_selected()
|
||||
core_config['boot']['load_apps'] = gen_form.get_single_select_component('boot.load_apps').get_selected()
|
||||
ask_reboot = gen_form.get_component('ask_for_reboot', SingleSelectComponent).get_selected()
|
||||
core_config['updates']['ask_for_reboot'] = ask_reboot
|
||||
|
||||
load_apps = gen_form.get_component('boot.load_apps', SingleSelectComponent).get_selected()
|
||||
core_config['boot']['load_apps'] = load_apps
|
||||
|
||||
# advanced
|
||||
adv_form = advanced.get_component_by_idx(0, FormComponent)
|
||||
|
||||
download_mthreaded = adv_form.get_single_select_component('down_mthread').get_selected()
|
||||
download_mthreaded = adv_form.get_component('down_mthread', SingleSelectComponent).get_selected()
|
||||
core_config['download']['multithreaded'] = download_mthreaded
|
||||
|
||||
mthread_client = adv_form.get_single_select_component('mthread_client').get_selected()
|
||||
mthread_client = adv_form.get_component('mthread_client', SingleSelectComponent).get_selected()
|
||||
core_config['download']['multithreaded_client'] = mthread_client
|
||||
|
||||
if isinstance(self.file_downloader, AdaptableFileDownloader):
|
||||
self.file_downloader.multithread_client = mthread_client
|
||||
self.file_downloader.multithread_enabled = download_mthreaded
|
||||
|
||||
single_dep_check = adv_form.get_single_select_component('dep_check').get_selected()
|
||||
single_dep_check = adv_form.get_component('dep_check', SingleSelectComponent).get_selected()
|
||||
core_config['system']['single_dependency_checking'] = single_dep_check
|
||||
|
||||
data_exp = adv_form.get_text_input('data_exp').get_int_value()
|
||||
data_exp = adv_form.get_component('data_exp', TextInputComponent).get_int_value()
|
||||
core_config['memory_cache']['data_expiration'] = data_exp
|
||||
|
||||
icon_exp = adv_form.get_text_input('icon_exp').get_int_value()
|
||||
icon_exp = adv_form.get_component('icon_exp', TextInputComponent).get_int_value()
|
||||
core_config['memory_cache']['icon_expiration'] = icon_exp
|
||||
|
||||
trim_after_upgrade = adv_form.get_single_select_component('trim_after_upgrade').get_selected()
|
||||
trim_after_upgrade = adv_form.get_component('trim_after_upgrade', SingleSelectComponent).get_selected()
|
||||
core_config['disk']['trim']['after_upgrade'] = trim_after_upgrade
|
||||
|
||||
# backup
|
||||
if backup:
|
||||
bkp_form = backup.get_component_by_idx(0, FormComponent)
|
||||
|
||||
core_config['backup']['enabled'] = bkp_form.get_single_select_component('enabled').get_selected()
|
||||
core_config['backup']['mode'] = bkp_form.get_single_select_component('mode').get_selected()
|
||||
core_config['backup']['type'] = bkp_form.get_single_select_component('type').get_selected()
|
||||
core_config['backup']['remove_method'] = bkp_form.get_single_select_component('remove_method').get_selected()
|
||||
core_config['backup']['install'] = bkp_form.get_single_select_component('install').get_selected()
|
||||
core_config['backup']['uninstall'] = bkp_form.get_single_select_component('uninstall').get_selected()
|
||||
core_config['backup']['upgrade'] = bkp_form.get_single_select_component('upgrade').get_selected()
|
||||
core_config['backup']['downgrade'] = bkp_form.get_single_select_component('downgrade').get_selected()
|
||||
core_config['backup']['enabled'] = bkp_form.get_component('enabled', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['mode'] = bkp_form.get_component('mode', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['type'] = bkp_form.get_component('type', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['install'] = bkp_form.get_component('install', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['upgrade'] = bkp_form.get_component('upgrade', SingleSelectComponent).get_selected()
|
||||
|
||||
bkp_remove_method = bkp_form.get_component('remove_method', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['remove_method'] = bkp_remove_method
|
||||
|
||||
bkp_uninstall = bkp_form.get_component('uninstall', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['uninstall'] = bkp_uninstall
|
||||
|
||||
bkp_downgrade = bkp_form.get_component('downgrade', SingleSelectComponent).get_selected()
|
||||
core_config['backup']['downgrade'] = bkp_downgrade
|
||||
|
||||
# tray
|
||||
tray_form = tray.get_component_by_idx(0, FormComponent)
|
||||
core_config['updates']['check_interval'] = tray_form.get_text_input('updates_interval').get_int_value()
|
||||
|
||||
def_icon_path = tray_form.get_component('def_icon').file_path
|
||||
updates_interval = tray_form.get_component('updates_interval', TextInputComponent).get_int_value()
|
||||
core_config['updates']['check_interval'] = updates_interval
|
||||
|
||||
def_icon_path = tray_form.get_component('def_icon', FileChooserComponent).file_path
|
||||
core_config['ui']['tray']['default_icon'] = def_icon_path if def_icon_path else None
|
||||
|
||||
up_icon_path = tray_form.get_component('up_icon').file_path
|
||||
up_icon_path = tray_form.get_component('up_icon', FileChooserComponent).file_path
|
||||
core_config['ui']['tray']['updates_icon'] = up_icon_path if up_icon_path else None
|
||||
|
||||
# ui
|
||||
ui_form = ui.get_component_by_idx(0, FormComponent)
|
||||
|
||||
core_config['download']['icons'] = ui_form.get_single_select_component('down_icons').get_selected()
|
||||
core_config['ui']['hdpi'] = ui_form.get_single_select_component('hdpi').get_selected()
|
||||
core_config['download']['icons'] = ui_form.get_component('down_icons', SingleSelectComponent).get_selected()
|
||||
core_config['ui']['hdpi'] = ui_form.get_component('hdpi', SingleSelectComponent).get_selected()
|
||||
|
||||
previous_autoscale = core_config['ui']['auto_scale']
|
||||
|
||||
core_config['ui']['auto_scale'] = ui_form.get_single_select_component('auto_scale').get_selected()
|
||||
core_config['ui']['auto_scale'] = ui_form.get_component('auto_scale', SingleSelectComponent).get_selected()
|
||||
|
||||
if previous_autoscale and not core_config['ui']['auto_scale']:
|
||||
self.logger.info("Deleting environment variable QT_AUTO_SCREEN_SCALE_FACTOR")
|
||||
del os.environ['QT_AUTO_SCREEN_SCALE_FACTOR']
|
||||
|
||||
core_config['ui']['scale_factor'] = ui_form.get_component('scalef').value / 100
|
||||
core_config['ui']['table']['max_displayed'] = ui_form.get_text_input('table_max').get_int_value()
|
||||
|
||||
style = ui_form.get_single_select_component('style').get_selected()
|
||||
table_max = ui_form.get_component('table_max', TextInputComponent).get_int_value()
|
||||
core_config['ui']['table']['max_displayed'] = table_max
|
||||
|
||||
style = ui_form.get_component('style', SingleSelectComponent).get_selected()
|
||||
|
||||
if core_config['ui']['qt_style']:
|
||||
cur_style = core_config['ui']['qt_style']
|
||||
else:
|
||||
cur_style = QApplication.instance().property('qt_style')
|
||||
|
||||
cur_style = core_config['ui']['qt_style'] if core_config['ui']['qt_style'] else QApplication.instance().property('qt_style')
|
||||
if style != cur_style:
|
||||
core_config['ui']['qt_style'] = style
|
||||
QApplication.instance().setProperty('qt_style', style)
|
||||
|
||||
core_config['ui']['system_theme'] = ui_form.get_single_select_component('system_theme').get_selected()
|
||||
core_config['ui']['system_theme'] = ui_form.get_component('system_theme', SingleSelectComponent).get_selected()
|
||||
|
||||
# gems
|
||||
checked_gems = gems_panel.components[1].get_component('gems').get_selected_values()
|
||||
checked_gems = gems_panel.components[1].get_component('gems', MultipleSelectComponent).get_selected_values()
|
||||
|
||||
for man in self.managers:
|
||||
modname = man.__module__.split('.')[-2]
|
||||
enabled = modname in checked_gems
|
||||
man.set_enabled(enabled)
|
||||
|
||||
core_config['gems'] = None if core_config['gems'] is None and len(checked_gems) == len(self.managers) else checked_gems
|
||||
if core_config['gems'] is None and len(checked_gems) == len(self.managers):
|
||||
sel_gems = None
|
||||
else:
|
||||
sel_gems = checked_gems
|
||||
|
||||
core_config['gems'] = sel_gems
|
||||
|
||||
try:
|
||||
self.configman.save_config(core_config)
|
||||
|
||||
Reference in New Issue
Block a user