def get_settings(self) -> Optional[Generator[SettingsView, None, None]]: snap_config = self.configman.get_config() install_channel = new_select( label=self.i18n['snap.config.install_channel'], opts=[(self.i18n['yes'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None)], value=bool(snap_config['install_channel']), id_='snap_install_channel', 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=cat_exp_val, only_int=True, label=self.i18n['snap.config.categories_exp'], tooltip=self.i18n['snap.config.categories_exp.tip']) panel = PanelComponent([ FormComponent([install_channel, categories_exp], self.i18n['installation'].capitalize()) ]) yield SettingsView(self, panel)
def _gen_multithread_client_select( self, core_config: dict, default_width: int) -> SingleSelectComponent: available_mthread_clients = self.file_downloader.list_available_multithreaded_clients( ) available_mthread_clients.sort() default_i18n_key = 'default' if available_mthread_clients else 'core.config.download.multithreaded_client.none' mthread_client_opts = [(self.i18n[default_i18n_key].capitalize(), None, None)] for client in available_mthread_clients: mthread_client_opts.append((client, client, None)) current_mthread_client = core_config['download'][ 'multithreaded_client'] if current_mthread_client not in available_mthread_clients: current_mthread_client = None return new_select( label=self.i18n['core.config.download.multithreaded_client'], tip=self.i18n['core.config.download.multithreaded_client.tip'], id_="mthread_client", max_width=default_width, opts=mthread_client_opts, value=current_mthread_client)
def _gen_adv_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: default_width = floor(0.22 * 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'], value=str(core_config['memory_cache']['data_expiration']), only_int=True, max_width=default_width, id_="data_exp") input_icon_exp = TextInputComponent( label=self.i18n['core.config.mem_cache.icon_exp'], tooltip=self.i18n['core.config.mem_cache.icon_exp.tip'], value=str(core_config['memory_cache']['icon_expiration']), only_int=True, max_width=default_width, id_="icon_exp") select_trim_up = new_select( label=self.i18n['core.config.trim.after_upgrade'], tip=self.i18n['core.config.trim.after_upgrade.tip'], value=core_config['disk']['trim']['after_upgrade'], max_width=default_width, opts=[(self.i18n['yes'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None), (self.i18n['ask'].capitalize(), None, None)], id_='trim_after_upgrade') select_dep_check = self._gen_bool_component( label=self.i18n['core.config.system.dep_checking'], tooltip=self.i18n['core.config.system.dep_checking.tip'], value=core_config['system']['single_dependency_checking'], max_width=default_width, id_='dep_check') select_dmthread = self._gen_bool_component( label=self.i18n['core.config.download.multithreaded'], tooltip=self.i18n['core.config.download.multithreaded.tip'], id_="down_mthread", max_width=default_width, value=core_config['download']['multithreaded']) select_mthread_client = self._gen_multithread_client_select( core_config, default_width) sub_comps = [ FormComponent([ select_dmthread, select_mthread_client, select_trim_up, select_dep_check, input_data_exp, input_icon_exp ], spaces=False) ] return TabComponent(self.i18n['core.config.tab.advanced'].capitalize(), PanelComponent(sub_comps), None, 'core.adv')
def _gen_adv_settings(self, core_config: dict) -> TabComponent: input_data_exp = TextInputComponent( label=self.i18n['core.config.mem_cache.data_exp'], tooltip=self.i18n['core.config.mem_cache.data_exp.tip'], value=str(core_config['memory_cache']['data_expiration']), only_int=True, id_="data_exp") input_icon_exp = TextInputComponent( label=self.i18n['core.config.mem_cache.icon_exp'], tooltip=self.i18n['core.config.mem_cache.icon_exp.tip'], value=str(core_config['memory_cache']['icon_expiration']), only_int=True, id_="icon_exp") select_trim = new_select( label=self.i18n['core.config.trim.after_upgrade'], tip=self.i18n['core.config.trim.after_upgrade.tip'], value=core_config['disk']['trim']['after_upgrade'], opts=[(self.i18n['yes'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None), (self.i18n['ask'].capitalize(), None, None)], id_='trim_after_upgrade') select_dep_check = self._gen_bool_component( label=self.i18n['core.config.system.dep_checking'], tooltip=self.i18n['core.config.system.dep_checking.tip'], value=core_config['system']['single_dependency_checking'], id_='dep_check') select_check_ssl = self._gen_bool_component( label=self.i18n['core.config.download.check_ssl'], tooltip=self.i18n['core.config.download.check_ssl.tip'], value=core_config['download']['check_ssl'], id_='download.check_ssl') select_dmthread = self._gen_bool_component( label=self.i18n['core.config.download.multithreaded'], tooltip=self.i18n['core.config.download.multithreaded.tip'], id_="down_mthread", value=core_config['download']['multithreaded']) select_mthread_client = self._gen_multithread_client_select( core_config) inputs = [ select_dmthread, select_mthread_client, select_check_ssl, select_trim, select_dep_check, input_data_exp, input_icon_exp ] panel = PanelComponent([FormComponent(inputs, spaces=False)], id_='advanced') return TabComponent(self.i18n['core.config.tab.advanced'].capitalize(), panel, None, 'core.adv')
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent: snap_config = read_config() install_channel = new_select( label=self.i18n['snap.config.install_channel'], opts=[(self.i18n['yes'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None)], value=bool(snap_config['install_channel']), id_='install_channel', max_width=200, tip=self.i18n['snap.config.install_channel.tip']) return PanelComponent([ FormComponent([install_channel], self.i18n['installation'].capitalize()) ])
def _gen_backup_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: if timeshift.is_available(): default_width = floor(0.22 * screen_width) enabled_opt = self._gen_bool_component( label=self.i18n['core.config.backup'], tooltip=None, value=bool(core_config['backup']['enabled']), id_='enabled', max_width=default_width) ops_opts = [(self.i18n['yes'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None), (self.i18n['ask'].capitalize(), None, None)] install_mode = new_select( label=self.i18n['core.config.backup.install'], tip=None, value=core_config['backup']['install'], opts=ops_opts, max_width=default_width, id_='install') uninstall_mode = new_select( label=self.i18n['core.config.backup.uninstall'], tip=None, value=core_config['backup']['uninstall'], opts=ops_opts, max_width=default_width, id_='uninstall') upgrade_mode = new_select( label=self.i18n['core.config.backup.upgrade'], tip=None, value=core_config['backup']['upgrade'], opts=ops_opts, max_width=default_width, id_='upgrade') downgrade_mode = new_select( label=self.i18n['core.config.backup.downgrade'], tip=None, value=core_config['backup']['downgrade'], opts=ops_opts, max_width=default_width, id_='downgrade') mode = new_select( label=self.i18n['core.config.backup.mode'], tip=None, value=core_config['backup']['mode'], opts=[ (self.i18n['core.config.backup.mode.incremental'], 'incremental', self.i18n['core.config.backup.mode.incremental.tip']), (self.i18n['core.config.backup.mode.only_one'], 'only_one', self.i18n['core.config.backup.mode.only_one.tip']) ], max_width=default_width, id_='mode') type_ = new_select(label=self.i18n['type'].capitalize(), tip=None, value=core_config['backup']['type'], opts=[('rsync', 'rsync', None), ('btrfs', 'btrfs', None)], max_width=default_width, id_='type') sub_comps = [ FormComponent([ enabled_opt, mode, type_, install_mode, uninstall_mode, upgrade_mode, downgrade_mode ], spaces=False) ] return TabComponent( self.i18n['core.config.tab.backup'].capitalize(), PanelComponent(sub_comps), None, 'core.bkp')
def _gen_general_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: default_width = floor(0.15 * screen_width) locale_opts = [ InputOption(label=self.i18n['locale.{}'.format(k)].capitalize(), value=k) for k in translation.get_available_keys() ] current_locale = None if core_config['locale']: current_locale = [ l for l in locale_opts if l.value == core_config['locale'] ] if not current_locale: if self.i18n.current_key: current_locale = [ l for l in locale_opts if l.value == self.i18n.current_key ] if not current_locale: current_locale = [ l for l in locale_opts if l.value == self.i18n.default_key ] current_locale = current_locale[0] if current_locale else None select_locale = SingleSelectComponent( label=self.i18n['core.config.locale.label'], options=locale_opts, default_option=current_locale, type_=SelectViewType.COMBO, max_width=default_width, id_='locale') select_store_pwd = self._gen_bool_component( label=self.i18n['core.config.store_password'].capitalize(), tooltip=self.i18n['core.config.store_password.tip'].capitalize(), id_="store_pwd", max_width=default_width, value=bool(core_config['store_root_password'])) select_sysnotify = self._gen_bool_component( label=self.i18n['core.config.system.notifications'].capitalize(), tooltip=self.i18n['core.config.system.notifications.tip']. capitalize(), value=bool(core_config['system']['notifications']), max_width=default_width, id_="sys_notify") select_load_apps = self._gen_bool_component( label=self.i18n['core.config.boot.load_apps'], tooltip=self.i18n['core.config.boot.load_apps.tip'], value=bool(core_config['boot']['load_apps']), id_='boot.load_apps', max_width=default_width) select_sugs = self._gen_bool_component( label=self.i18n['core.config.suggestions.activated'].capitalize(), tooltip=self.i18n['core.config.suggestions.activated.tip']. capitalize(), id_="sugs_enabled", max_width=default_width, value=bool(core_config['suggestions']['enabled'])) inp_sugs = TextInputComponent( label=self.i18n['core.config.suggestions.by_type'], tooltip=self.i18n['core.config.suggestions.by_type.tip'], value=str(core_config['suggestions']['by_type']), only_int=True, max_width=default_width, id_="sugs_by_type") inp_reboot = new_select( label=self.i18n['core.config.updates.reboot'], tip=self.i18n['core.config.updates.reboot.tip'], id_='ask_for_reboot', max_width=default_width, value=bool(core_config['updates']['ask_for_reboot']), opts=[(self.i18n['ask'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None)]) sub_comps = [ FormComponent([ select_locale, select_store_pwd, select_sysnotify, select_load_apps, select_sugs, inp_sugs, inp_reboot ], spaces=False) ] return TabComponent(self.i18n['core.config.tab.general'].capitalize(), PanelComponent(sub_comps), None, 'core.gen')
def _gen_backup_settings(self, core_config: dict) -> Optional[TabComponent]: if timeshift.is_available(): enabled_opt = self._gen_bool_component( label=self.i18n['core.config.backup'], tooltip=None, value=bool(core_config['backup']['enabled']), id_='enabled') ops_opts = [(self.i18n['yes'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None), (self.i18n['ask'].capitalize(), None, None)] install_mode = new_select( label=self.i18n['core.config.backup.install'], tip=None, value=core_config['backup']['install'], opts=ops_opts, id_='install') uninstall_mode = new_select( label=self.i18n['core.config.backup.uninstall'], tip=None, value=core_config['backup']['uninstall'], opts=ops_opts, id_='uninstall') upgrade_mode = new_select( label=self.i18n['core.config.backup.upgrade'], tip=None, value=core_config['backup']['upgrade'], opts=ops_opts, id_='upgrade') downgrade_mode = new_select( label=self.i18n['core.config.backup.downgrade'], tip=None, value=core_config['backup']['downgrade'], opts=ops_opts, id_='downgrade') mode = new_select( label=self.i18n['core.config.backup.mode'], tip=None, value=core_config['backup']['mode'], opts=[ (self.i18n['core.config.backup.mode.incremental'], 'incremental', self.i18n['core.config.backup.mode.incremental.tip']), (self.i18n['core.config.backup.mode.only_one'], 'only_one', self.i18n['core.config.backup.mode.only_one.tip']) ], id_='mode') type_ = new_select(label=self.i18n['type'].capitalize(), tip=None, value=core_config['backup']['type'], opts=[('rsync', 'rsync', None), ('btrfs', 'btrfs', None)], id_='type') remove_method = core_config['backup']['remove_method'] if not remove_method or remove_method not in BACKUP_REMOVE_METHODS: remove_method = BACKUP_DEFAULT_REMOVE_METHOD remove_i18n = 'core.config.backup.remove_method' remove_opts = ((self.i18n[f'{remove_i18n}.{m}'], m, self.i18n[f'{remove_i18n}.{m}.tip']) for m in sorted(BACKUP_REMOVE_METHODS)) remove_label = f'{self.i18n[remove_i18n]} ({self.i18n["core.config.backup.mode"]} ' \ f'"{self.i18n["core.config.backup.mode.only_one"].capitalize()}")' sel_remove = new_select(label=remove_label, tip=None, value=remove_method, opts=remove_opts, capitalize_label=False, id_='remove_method') inputs = [ enabled_opt, type_, mode, sel_remove, install_mode, uninstall_mode, upgrade_mode, downgrade_mode ] panel = PanelComponent([FormComponent(inputs, spaces=False)], id_='backup') return TabComponent( self.i18n['core.config.tab.backup'].capitalize(), panel, None, 'core.bkp')
def _gen_general_settings(self, core_config: dict) -> TabComponent: locale_keys = translation.get_available_keys() locale_opts = [ InputOption(label=self.i18n[f'locale.{k}'].capitalize(), value=k) for k in locale_keys ] current_locale = None if core_config['locale']: current_locale = [ loc for loc in locale_opts if loc.value == core_config['locale'] ] if not current_locale: if self.i18n.current_key: current_locale = [ loc for loc in locale_opts if loc.value == self.i18n.current_key ] if not current_locale: current_locale = [ loc for loc in locale_opts if loc.value == self.i18n.default_key ] current_locale = current_locale[0] if current_locale else None sel_locale = SingleSelectComponent( label=self.i18n['core.config.locale.label'], options=locale_opts, default_option=current_locale, type_=SelectViewType.COMBO, alignment=ViewComponentAlignment.CENTER, id_='locale') sel_store_pwd = self._gen_bool_component( label=self.i18n['core.config.store_password'].capitalize(), tooltip=self.i18n['core.config.store_password.tip'].capitalize(), id_="store_pwd", value=bool(core_config['store_root_password'])) notify_tip = self.i18n[ 'core.config.system.notifications.tip'].capitalize() sel_sys_notify = self._gen_bool_component( label=self.i18n['core.config.system.notifications'].capitalize(), tooltip=notify_tip, value=bool(core_config['system']['notifications']), id_="sys_notify") sel_load_apps = self._gen_bool_component( label=self.i18n['core.config.boot.load_apps'], tooltip=self.i18n['core.config.boot.load_apps.tip'], value=bool(core_config['boot']['load_apps']), id_='boot.load_apps') sel_sugs = self._gen_bool_component( label=self.i18n['core.config.suggestions.activated'].capitalize(), tooltip=self.i18n['core.config.suggestions.activated.tip']. capitalize(), id_="sugs_enabled", value=bool(core_config['suggestions']['enabled'])) inp_sugs = TextInputComponent( label=self.i18n['core.config.suggestions.by_type'], tooltip=self.i18n['core.config.suggestions.by_type.tip'], value=str(core_config['suggestions']['by_type']), only_int=True, id_="sugs_by_type") inp_reboot = new_select( label=self.i18n['core.config.updates.reboot'], tip=self.i18n['core.config.updates.reboot.tip'], id_='ask_for_reboot', max_width=None, value=bool(core_config['updates']['ask_for_reboot']), opts=[(self.i18n['ask'].capitalize(), True, None), (self.i18n['no'].capitalize(), False, None)]) inputs = [ sel_locale, sel_store_pwd, sel_sys_notify, sel_load_apps, inp_reboot, sel_sugs, inp_sugs ] panel = PanelComponent([FormComponent(inputs, spaces=False)], id_='general') return TabComponent(self.i18n['core.config.tab.general'].capitalize(), panel, None, 'core.gen')