From 374b7ce03f23e8b10a127501b1bb977a22f9db6e Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Fri, 8 Apr 2022 17:41:29 -0300 Subject: [PATCH] [api] refactoring: removing screen measures as parameters of SoftwareManager.get_settings --- bauh/api/abstract/controller.py | 4 +-- bauh/gems/appimage/controller.py | 4 +-- bauh/gems/arch/controller.py | 4 +-- bauh/gems/debian/controller.py | 4 +-- bauh/gems/flatpak/controller.py | 4 +-- bauh/gems/snap/controller.py | 2 +- bauh/gems/web/controller.py | 4 +-- bauh/manage.py | 2 +- bauh/view/core/controller.py | 15 ++++------ bauh/view/core/settings.py | 48 +++++++++++++++++--------------- bauh/view/qt/settings.py | 4 +-- bauh/view/qt/window.py | 2 +- 12 files changed, 47 insertions(+), 50 deletions(-) diff --git a/bauh/api/abstract/controller.py b/bauh/api/abstract/controller.py index 2c9223b0..ee810179 100644 --- a/bauh/api/abstract/controller.py +++ b/bauh/api/abstract/controller.py @@ -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 diff --git a/bauh/gems/appimage/controller.py b/bauh/gems/appimage/controller.py index 7fe48172..ed0b140d 100644 --- a/bauh/gems/appimage/controller.py +++ b/bauh/gems/appimage/controller.py @@ -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'], diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index fbf511cb..748d7e5d 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -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', diff --git a/bauh/gems/debian/controller.py b/bauh/gems/debian/controller.py index 5c6df34d..c5e8d213 100644 --- a/bauh/gems/debian/controller.py +++ b/bauh/gems/debian/controller.py @@ -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') diff --git a/bauh/gems/flatpak/controller.py b/bauh/gems/flatpak/controller.py index eae5c8d5..9bdd557d 100644 --- a/bauh/gems/flatpak/controller.py +++ b/bauh/gems/flatpak/controller.py @@ -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())]) diff --git a/bauh/gems/snap/controller.py b/bauh/gems/snap/controller.py index 2408dbca..43b9cbe8 100644 --- a/bauh/gems/snap/controller.py +++ b/bauh/gems/snap/controller.py @@ -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 diff --git a/bauh/gems/web/controller.py b/bauh/gems/web/controller.py index 629b9916..6f041314 100644 --- a/bauh/gems/web/controller.py +++ b/bauh/gems/web/controller.py @@ -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'], diff --git a/bauh/manage.py b/bauh/manage.py index c116ccba..0f8bf736 100644 --- a/bauh/manage.py +++ b/bauh/manage.py @@ -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, diff --git a/bauh/view/core/controller.py b/bauh/view/core/controller.py index 4e6be7d2..d78e2ade 100755 --- a/bauh/view/core/controller.py +++ b/bauh/view/core/controller.py @@ -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) diff --git a/bauh/view/core/settings.py b/bauh/view/core/settings.py index 561bf12c..b324860d 100644 --- a/bauh/view/core/settings.py +++ b/bauh/view/core/settings.py @@ -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, diff --git a/bauh/view/qt/settings.py b/bauh/view/qt/settings.py index f3d89ce6..7d82bfae 100644 --- a/bauh/view/qt/settings.py +++ b/bauh/view/qt/settings.py @@ -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') diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index f04e1179..2cb6b538 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -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()