mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[api] refactoring: removing screen measures as parameters of SoftwareManager.get_settings
This commit is contained in:
@@ -379,10 +379,8 @@ class SoftwareManager(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
"""
|
||||
:param screen_width
|
||||
:param screen_height
|
||||
:return: a form abstraction with all available settings
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -850,9 +850,9 @@ class AppImageManager(SoftwareManager):
|
||||
print(f'{Fore.RED}[bauh][appimage] An exception has happened when deleting {f}{Fore.RESET}')
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
appimage_config = self.configman.get_config()
|
||||
max_width = floor(screen_width * 0.15)
|
||||
max_width = floor(self.context.screen_width * 0.15)
|
||||
|
||||
comps = [
|
||||
TextInputComponent(label=self.i18n['appimage.config.database.expiration'],
|
||||
|
||||
@@ -2860,9 +2860,9 @@ class ArchManager(SoftwareManager):
|
||||
id_=id_,
|
||||
capitalize_label=capitalize_label)
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
arch_config = self.configman.get_config()
|
||||
max_width = floor(screen_width * 0.25)
|
||||
max_width = floor(self.context.screen_width * 0.25)
|
||||
|
||||
db_sync_start = self._gen_bool_selector(id_='sync_dbs_start',
|
||||
label_key='arch.config.sync_dbs',
|
||||
|
||||
@@ -568,10 +568,10 @@ class DebianPackageManager(SoftwareManager):
|
||||
final_cmd = pkg.app.exe_path.replace('%U', '')
|
||||
Popen(final_cmd, shell=True)
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
deb_config = self.configman.get_config()
|
||||
|
||||
comps_width = int(screen_width * 0.105)
|
||||
comps_width = int(self.context.screen_width * 0.105)
|
||||
|
||||
sources_app = deb_config.get('pkg_sources.app')
|
||||
|
||||
|
||||
@@ -603,7 +603,7 @@ class FlatpakManager(SoftwareManager):
|
||||
else:
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
if not self.context.root_user:
|
||||
fields = []
|
||||
|
||||
@@ -622,7 +622,7 @@ class FlatpakManager(SoftwareManager):
|
||||
options=install_opts,
|
||||
default_option=[o for o in install_opts if o.value == flatpak_config['installation_level']][0],
|
||||
max_per_line=len(install_opts),
|
||||
max_width=floor(screen_width * 0.22),
|
||||
max_width=floor(self.context.screen_width * 0.22),
|
||||
type_=SelectViewType.RADIO))
|
||||
|
||||
return PanelComponent([FormComponent(fields, self.i18n['installation'].capitalize())])
|
||||
|
||||
@@ -427,7 +427,7 @@ class SnapManager(SoftwareManager):
|
||||
if pkg.screenshots:
|
||||
yield from pkg.screenshots
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
snap_config = self.configman.get_config()
|
||||
max_width = 200
|
||||
|
||||
|
||||
@@ -1105,9 +1105,9 @@ class WebApplicationManager(SoftwareManager):
|
||||
print('{}[bauh][web] An exception has happened when deleting {}{}'.format(Fore.RED, ENV_PATH, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> Optional[ViewComponent]:
|
||||
def get_settings(self) -> Optional[ViewComponent]:
|
||||
web_config = self.configman.get_config()
|
||||
max_width = floor(screen_width * 0.15)
|
||||
max_width = floor(self.context.screen_width * 0.15)
|
||||
|
||||
input_electron = TextInputComponent(label=self.i18n['web.settings.electron.version.label'],
|
||||
value=web_config['environment']['electron']['version'],
|
||||
|
||||
@@ -62,7 +62,7 @@ def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logg
|
||||
|
||||
if app_args.settings: # only settings window
|
||||
manager.cache_available_managers()
|
||||
return app, SettingsWindow(manager=manager, i18n=i18n, screen_size=screen_size, window=None)
|
||||
return app, SettingsWindow(manager=manager, i18n=i18n, window=None)
|
||||
else:
|
||||
manage_window = ManageWindow(i18n=i18n,
|
||||
manager=manager,
|
||||
|
||||
@@ -38,8 +38,7 @@ class GenericUpgradeRequirements(UpgradeRequirements):
|
||||
|
||||
class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, config: dict,
|
||||
settings_manager: GenericSettingsManager = None):
|
||||
def __init__(self, managers: List[SoftwareManager], context: ApplicationContext, config: dict):
|
||||
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()}
|
||||
@@ -51,7 +50,7 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
self._already_prepared = []
|
||||
self.working_managers = []
|
||||
self.config = config
|
||||
self.settings_manager = settings_manager
|
||||
self.settings_manager: Optional[GenericSettingsManager] = None
|
||||
self.http_client = context.http_client
|
||||
self.configman = CoreConfigManager()
|
||||
self._action_reset: Optional[CustomSoftwareAction] = None
|
||||
@@ -533,19 +532,17 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
def get_working_managers(self):
|
||||
return [m for m in self.managers if self._can_work(m)]
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
def get_settings(self) -> ViewComponent:
|
||||
if self.settings_manager is None:
|
||||
self.settings_manager = GenericSettingsManager(managers=self.managers,
|
||||
working_managers=self.working_managers,
|
||||
logger=self.logger,
|
||||
i18n=self.i18n,
|
||||
file_downloader=self.context.file_downloader,
|
||||
configman=self.configman)
|
||||
configman=self.configman,
|
||||
context=self.context)
|
||||
else:
|
||||
self.settings_manager.managers = self.managers
|
||||
self.settings_manager.working_managers = self.working_managers
|
||||
|
||||
return self.settings_manager.get_settings(screen_width=screen_width, screen_height=screen_height)
|
||||
return self.settings_manager.get_settings()
|
||||
|
||||
def save_settings(self, component: TabGroupComponent) -> Tuple[bool, List[str]]:
|
||||
return self.settings_manager.save_settings(component)
|
||||
|
||||
@@ -9,6 +9,7 @@ from typing import List, Tuple, Optional, Dict
|
||||
from PyQt5.QtWidgets import QApplication, QStyleFactory
|
||||
|
||||
from bauh import ROOT_DIR, __app_name__
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
from bauh.api.abstract.download import FileDownloader
|
||||
from bauh.api.abstract.view import ViewComponent, TabComponent, InputOption, TextComponent, MultipleSelectComponent, \
|
||||
@@ -24,16 +25,17 @@ from bauh.view.util.translation import I18n
|
||||
|
||||
class GenericSettingsManager:
|
||||
|
||||
def __init__(self, managers: List[SoftwareManager], working_managers: List[SoftwareManager],
|
||||
logger: logging.Logger, i18n: I18n, file_downloader: FileDownloader, configman: CoreConfigManager):
|
||||
self.i18n = i18n
|
||||
def __init__(self, context: ApplicationContext, managers: List[SoftwareManager],
|
||||
working_managers: List[SoftwareManager], configman: CoreConfigManager):
|
||||
self.context = context
|
||||
self.i18n = context.i18n
|
||||
self.managers = managers
|
||||
self.working_managers = working_managers
|
||||
self.logger = logger
|
||||
self.file_downloader = file_downloader
|
||||
self.logger = context.logger
|
||||
self.file_downloader = self.context.file_downloader
|
||||
self.configman = configman
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
def get_settings(self) -> ViewComponent:
|
||||
tabs = list()
|
||||
|
||||
gem_opts, def_gem_opts, gem_tabs = [], set(), []
|
||||
@@ -43,7 +45,7 @@ class GenericSettingsManager:
|
||||
modname = man.__module__.split('.')[-2]
|
||||
icon_path = "{r}/gems/{n}/resources/img/{n}.svg".format(r=ROOT_DIR, n=modname)
|
||||
|
||||
man_comp = man.get_settings(screen_width, screen_height) if can_work else None
|
||||
man_comp = man.get_settings() if can_work else None
|
||||
if man_comp:
|
||||
tab_name = self.i18n.get('gem.{}.label'.format(modname), modname.capitalize())
|
||||
gem_tabs.append(TabComponent(label=tab_name, content=man_comp, icon_path=icon_path, id_=modname))
|
||||
@@ -68,19 +70,19 @@ class GenericSettingsManager:
|
||||
gem_selector = MultipleSelectComponent(label=None,
|
||||
tooltip=None,
|
||||
options=gem_opts,
|
||||
max_width=floor(screen_width * 0.22),
|
||||
max_width=floor(self.context.screen_width * 0.22),
|
||||
default_options=def_gem_opts,
|
||||
id_="gems")
|
||||
tabs.append(TabComponent(label=self.i18n['core.config.tab.types'],
|
||||
content=PanelComponent([type_help, FormComponent([gem_selector], spaces=False)]),
|
||||
id_='core.types'))
|
||||
|
||||
tabs.append(self._gen_general_settings(core_config, screen_width, screen_height))
|
||||
tabs.append(self._gen_ui_settings(core_config, screen_width, screen_height))
|
||||
tabs.append(self._gen_tray_settings(core_config, screen_width, screen_height))
|
||||
tabs.append(self._gen_adv_settings(core_config, screen_width, screen_height))
|
||||
tabs.append(self._gen_general_settings(core_config))
|
||||
tabs.append(self._gen_ui_settings(core_config))
|
||||
tabs.append(self._gen_tray_settings(core_config))
|
||||
tabs.append(self._gen_adv_settings(core_config))
|
||||
|
||||
bkp_settings = self._gen_backup_settings(core_config, screen_width, screen_height)
|
||||
bkp_settings = self._gen_backup_settings(core_config)
|
||||
|
||||
if bkp_settings:
|
||||
tabs.append(bkp_settings)
|
||||
@@ -90,8 +92,8 @@ class GenericSettingsManager:
|
||||
|
||||
return TabGroupComponent(tabs)
|
||||
|
||||
def _gen_adv_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
|
||||
default_width = floor(0.22 * screen_width)
|
||||
def _gen_adv_settings(self, core_config: dict) -> TabComponent:
|
||||
default_width = floor(0.22 * self.context.screen_width)
|
||||
|
||||
input_data_exp = TextInputComponent(label=self.i18n['core.config.mem_cache.data_exp'],
|
||||
tooltip=self.i18n['core.config.mem_cache.data_exp.tip'],
|
||||
@@ -155,8 +157,8 @@ class GenericSettingsManager:
|
||||
opts=mthread_client_opts,
|
||||
value=current_mthread_client)
|
||||
|
||||
def _gen_tray_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
|
||||
default_width = floor(0.22 * screen_width)
|
||||
def _gen_tray_settings(self, core_config: dict) -> TabComponent:
|
||||
default_width = floor(0.22 * self.context.screen_width)
|
||||
|
||||
input_update_interval = TextInputComponent(label=self.i18n['core.config.updates.interval'].capitalize(),
|
||||
tooltip=self.i18n['core.config.updates.interval.tip'],
|
||||
@@ -183,8 +185,8 @@ class GenericSettingsManager:
|
||||
sub_comps = [FormComponent([input_update_interval, select_def_icon, select_up_icon], spaces=False)]
|
||||
return TabComponent(self.i18n['core.config.tab.tray'].capitalize(), PanelComponent(sub_comps), None, 'core.tray')
|
||||
|
||||
def _gen_ui_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
|
||||
default_width = floor(0.15 * screen_width)
|
||||
def _gen_ui_settings(self, core_config: dict) -> TabComponent:
|
||||
default_width = floor(0.15 * self.context.screen_width)
|
||||
|
||||
select_hdpi = self._gen_bool_component(label=self.i18n['core.config.ui.hdpi'],
|
||||
tooltip=self.i18n['core.config.ui.hdpi.tip'],
|
||||
@@ -259,8 +261,8 @@ class GenericSettingsManager:
|
||||
|
||||
return TabComponent(self.i18n['core.config.tab.ui'].capitalize(), PanelComponent(sub_comps), None, 'core.ui')
|
||||
|
||||
def _gen_general_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
|
||||
default_width = floor(0.15 * screen_width)
|
||||
def _gen_general_settings(self, core_config: dict) -> TabComponent:
|
||||
default_width = floor(0.15 * self.context.screen_width)
|
||||
|
||||
locale_opts = [InputOption(label=self.i18n['locale.{}'.format(k)].capitalize(), value=k) for k in translation.get_available_keys()]
|
||||
|
||||
@@ -521,9 +523,9 @@ class GenericSettingsManager:
|
||||
self.logger.info("Saving all settings took {0:.8f} seconds".format(tf - ti))
|
||||
return success, warnings
|
||||
|
||||
def _gen_backup_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
|
||||
def _gen_backup_settings(self, core_config: dict) -> TabComponent:
|
||||
if timeshift.is_available():
|
||||
default_width = floor(0.22 * screen_width)
|
||||
default_width = floor(0.22 * self.context.screen_width)
|
||||
|
||||
enabled_opt = self._gen_bool_component(label=self.i18n['core.config.backup'],
|
||||
tooltip=None,
|
||||
|
||||
@@ -36,7 +36,7 @@ class ReloadManagePanel(QThread):
|
||||
|
||||
class SettingsWindow(QWidget):
|
||||
|
||||
def __init__(self, manager: SoftwareManager, i18n: I18n, screen_size: QSize, window: QWidget, parent: Optional[QWidget] = None):
|
||||
def __init__(self, manager: SoftwareManager, i18n: I18n, window: QWidget, parent: Optional[QWidget] = None):
|
||||
super(SettingsWindow, self).__init__(parent=parent, flags=Qt.CustomizeWindowHint | Qt.WindowTitleHint)
|
||||
self.setWindowTitle(f"{i18n['settings'].capitalize()} ({__app_name__})")
|
||||
self.setLayout(QVBoxLayout())
|
||||
@@ -45,7 +45,7 @@ class SettingsWindow(QWidget):
|
||||
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
|
||||
self.window = window
|
||||
|
||||
self.settings_model = self.manager.get_settings(screen_size.width(), screen_size.height())
|
||||
self.settings_model = self.manager.get_settings()
|
||||
|
||||
self.tab_group = to_widget(self.settings_model, i18n)
|
||||
self.tab_group.setObjectName('settings')
|
||||
|
||||
@@ -1549,7 +1549,7 @@ class ManageWindow(QWidget):
|
||||
if self.settings_window:
|
||||
self.settings_window.handle_display()
|
||||
else:
|
||||
self.settings_window = SettingsWindow(self.manager, self.i18n, self.screen_size, self)
|
||||
self.settings_window = SettingsWindow(manager=self.manager, i18n=self.i18n, window=self)
|
||||
self.settings_window.setMinimumWidth(int(self.screen_size.width() / 4))
|
||||
self.settings_window.resize(self.size())
|
||||
self.settings_window.adjustSize()
|
||||
|
||||
Reference in New Issue
Block a user