Beispiel #1
0
    def save_settings(self,
                      component: TabGroupComponent) -> Tuple[bool, List[str]]:
        ti = time.time()
        save_threads, warnings, success_map = [], [], {}

        save_core = Thread(target=self._save_core_settings,
                           args=(component, success_map, warnings),
                           daemon=True)
        save_core.start()
        save_threads.append(save_core)

        for man in self.managers:
            if man:
                modname = man.__module__.split('.')[-2]
                tab = component.get_tab(modname)

                if not tab:
                    self.logger.warning("Tab for {} was not found".format(
                        man.__class__.__name__))
                else:
                    save_man = Thread(target=self._save_manager_settings(
                        man, tab.content, success_map, warnings),
                                      daemon=True)
                    save_man.start()
                    save_threads.append(save_man)

        for t in save_threads:
            t.join()

        success = all(success_map.values())

        tf = time.time()
        self.logger.info("Saving all settings took {0:.8f} seconds".format(tf -
                                                                           ti))
        return success, warnings
Beispiel #2
0
    def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
        tabs = list()

        gem_opts, def_gem_opts, gem_tabs = [], set(), []

        for man in self.managers:
            if man.can_work():
                man_comp = man.get_settings(screen_width, screen_height)
                modname = man.__module__.split('.')[-2]
                icon_path = "{r}/gems/{n}/resources/img/{n}.svg".format(r=ROOT_DIR, n=modname)

                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))

                opt = InputOption(label=self.i18n.get('gem.{}.label'.format(modname), modname.capitalize()),
                                  tooltip=self.i18n.get('gem.{}.info'.format(modname)),
                                  value=modname,
                                  icon_path='{r}/gems/{n}/resources/img/{n}.svg'.format(r=ROOT_DIR, n=modname))
                gem_opts.append(opt)

                if man.is_enabled() and man in self.working_managers:
                    def_gem_opts.add(opt)

        core_config = read_config()

        if gem_opts:
            type_help = TextComponent(html=self.i18n['core.config.types.tip'])
            gem_opts.sort(key=lambda o: o.value)
            gem_selector = MultipleSelectComponent(label=None,
                                                   tooltip=None,
                                                   options=gem_opts,
                                                   max_width=floor(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))

        bkp_settings = self._gen_backup_settings(core_config, screen_width, screen_height)

        if bkp_settings:
            tabs.append(bkp_settings)

        for tab in gem_tabs:
            tabs.append(tab)

        return TabGroupComponent(tabs)
Beispiel #3
0
    def save_settings(self,
                      component: TabGroupComponent) -> Tuple[bool, List[str]]:

        saved, warnings = True, []

        bkp = component.get_tab('core.bkp')
        success, errors = self._save_settings(
            general=component.get_tab('core.gen').content,
            advanced=component.get_tab('core.adv').content,
            tray=component.get_tab('core.tray').content,
            backup=bkp.content if bkp else None,
            ui=component.get_tab('core.ui').content,
            gems_panel=component.get_tab('core.types').content)

        if not success:
            saved = False

        if errors:
            warnings.extend(errors)

        for man in self.managers:
            if man:
                modname = man.__module__.split('.')[-2]
                tab = component.get_tab(modname)

                if not tab:
                    self.logger.warning("Tab for {} was not found".format(
                        man.__class__.__name__))
                else:
                    res = man.save_settings(tab.content)

                    if res:
                        success, errors = res[0], res[1]

                        if not success:
                            saved = False

                        if errors:
                            warnings.extend(errors)

        return saved, warnings
Beispiel #4
0
    def _save_core_settings(self, root_component: TabGroupComponent,
                            success_map: Dict[str, bool], warnings: List[str]):
        success = False

        try:
            bkp = root_component.get_tab('core.bkp')
            success, errors = self._save_settings(
                general=root_component.get_tab('core.gen').content,
                advanced=root_component.get_tab('core.adv').content,
                tray=root_component.get_tab('core.tray').content,
                backup=bkp.content if bkp else None,
                ui=root_component.get_tab('core.ui').content,
                gems_panel=root_component.get_tab('core.types').content)
            if errors:
                warnings.extend(errors)

        except:
            self.logger.error(
                "An exception happened while saving the core settings")
            traceback.print_exc()
        finally:
            success_map[self.__class__.__name__] = success
Beispiel #5
0
    def _save_core_settings(self, tabs: TabGroupComponent,
                            success_list: List[bool], warnings: List[str]):
        success = False

        try:
            bkp = tabs.get_tab('core.bkp')
            success, errors = self._save_settings(
                general=tabs.get_tab('core.gen').get_content(PanelComponent),
                advanced=tabs.get_tab('core.adv').get_content(PanelComponent),
                tray=tabs.get_tab('core.tray').get_content(PanelComponent),
                backup=bkp.get_content(PanelComponent) if bkp else None,
                ui=tabs.get_tab('core.ui').get_content(PanelComponent),
                gems_panel=tabs.get_tab('core.types').get_content(
                    PanelComponent))
            if errors:
                warnings.extend(errors)

        except Exception:
            self.logger.error(
                "An exception happened while saving the core settings")
            traceback.print_exc()
        finally:
            success_list.append(success)
Beispiel #6
0
    def get_settings(self) -> TabGroupComponent:
        tabs = list()

        gem_opts, def_gem_opts, gem_tabs = [], set(), []

        self._settings_views = dict()

        for man in self.managers:
            can_work, reason_not_work = man.can_work()
            modname = man.__module__.split('.')[-2]

            man_settings = man.get_settings() if can_work else None
            if man_settings:
                for view in man_settings:
                    icon_path = view.icon_path

                    if not icon_path:
                        icon_path = f"{ROOT_DIR}/gems/{modname}/resources/img/{modname}.svg"

                    tab_name = view.label if view.label else self.i18n.get(
                        f'gem.{modname}.label', modname.capitalize())
                    gem_tabs.append(
                        TabComponent(label=tab_name,
                                     content=view.component,
                                     icon_path=icon_path))

                    views = self._settings_views.get(man.__class__, list())
                    self._settings_views[man.__class__] = views
                    views.append(view)

            help_tip = reason_not_work if not can_work and reason_not_work else self.i18n.get(
                f'gem.{modname}.info')
            opt = InputOption(
                label=self.i18n.get(f'gem.{modname}.label',
                                    modname.capitalize()),
                tooltip=help_tip,
                value=modname,
                icon_path=
                f'{ROOT_DIR}/gems/{modname}/resources/img/{modname}.svg',
                read_only=not can_work,
                extra_properties={'warning': 'true'} if not can_work else None)
            gem_opts.append(opt)

            if man.is_enabled() and man in self.working_managers:
                def_gem_opts.add(opt)

        core_config = self.configman.get_config()

        if gem_opts:
            type_help = TextComponent(html=self.i18n['core.config.types.tip'])
            gem_opts.sort(key=lambda o: o.value)
            gem_selector = MultipleSelectComponent(
                label=None,
                tooltip=None,
                options=gem_opts,
                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))
        tabs.append(self._gen_interface_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)

        if bkp_settings:
            tabs.append(bkp_settings)

        for tab in gem_tabs:
            tabs.append(tab)

        return TabGroupComponent(tabs)