def update_file(self, pkg: AppImage, root_password: Optional[str], watcher: ProcessWatcher): max_width = 350 file_chooser = FileChooserComponent(label=self.i18n['file'].capitalize(), allowed_extensions={'AppImage', '*'}, search_path=get_default_manual_installation_file_dir(), max_width=max_width) input_version = TextInputComponent(label=self.i18n['version'].capitalize(), max_width=max_width) file_chooser.observers.append(ManualInstallationFileObserver(None, input_version)) while True: if watcher.request_confirmation(title=self.i18n['appimage.custom_action.manual_update.details'], body=None, components=[FormComponent(label='', components=[file_chooser, input_version], spaces=False)], confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize(), min_height=100, max_width=max_width + 150): if not file_chooser.file_path or not os.path.isfile(file_chooser.file_path) or not file_chooser.file_path.lower().strip().endswith('.appimage'): watcher.request_confirmation(title=self.i18n['error'].capitalize(), body=self.i18n['appimage.custom_action.install_file.invalid_file'], deny_button=False) else: break else: return False pkg.local_file_path = file_chooser.file_path pkg.version = input_version.get_value() reqs = UpgradeRequirements(to_install=None, to_remove=None, to_upgrade=[UpgradeRequirement(pkg=pkg)], cannot_upgrade=None) return self.upgrade(reqs, root_password=root_password, watcher=watcher)
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent: appimage_config = self.configman.get_config() max_width = floor(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 '', 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 '', tooltip=self. i18n['appimage.config.suggestions.expiration.tip'], only_int=True, max_width=max_width, id_='appim_sugs_exp') ] return PanelComponent([FormComponent(components=comps, id_='form')])
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) -> 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_general_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: default_width = floor(0.11 * 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_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 = self._gen_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_sugs, inp_sugs, inp_reboot], spaces=False)] return TabComponent(self.i18n['core.config.tab.general'].capitalize(), PanelComponent(sub_comps), None, 'core.gen')
def _gen_tray_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: default_width = floor(0.22 * screen_width) input_update_interval = TextInputComponent(label=self.i18n['core.config.updates.interval'].capitalize(), tooltip=self.i18n['core.config.updates.interval.tip'], only_int=True, value=str(core_config['updates']['check_interval']), max_width=default_width, id_="updates_interval") allowed_exts = {'png', 'svg', 'jpg', 'jpeg', 'ico', 'xpm'} select_def_icon = FileChooserComponent(id_='def_icon', label=self.i18n["core.config.ui.tray.default_icon"].capitalize(), tooltip=self.i18n["core.config.ui.tray.default_icon.tip"].capitalize(), file_path=str(core_config['ui']['tray']['default_icon']) if core_config['ui']['tray']['default_icon'] else None, max_width=default_width, allowed_extensions=allowed_exts) select_up_icon = FileChooserComponent(id_='up_icon', label=self.i18n["core.config.ui.tray.updates_icon"].capitalize(), tooltip=self.i18n["core.config.ui.tray.updates_icon.tip"].capitalize(), file_path=str(core_config['ui']['tray']['updates_icon']) if core_config['ui']['tray']['updates_icon'] else None, max_width=default_width, allowed_extensions=allowed_exts) 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 get_settings(self) -> Optional[Generator[SettingsView, None, None]]: config_ = self.configman.get_config() comps = [ TextInputComponent(label=self.i18n['appimage.config.database.expiration'], value=int(config_['database']['expiration']) if isinstance( config_['database']['expiration'], int) else '', tooltip=self.i18n['appimage.config.database.expiration.tip'], only_int=True, id_='appim_db_exp'), TextInputComponent(label=self.i18n['appimage.config.suggestions.expiration'], value=int(config_['suggestions']['expiration']) if isinstance( config_['suggestions']['expiration'], int) else '', tooltip=self.i18n['appimage.config.suggestions.expiration.tip'], only_int=True, id_='appim_sugs_exp') ] yield SettingsView(self, PanelComponent([FormComponent(components=comps)]))
def update_file(self, pkg: AppImage, root_password: str, watcher: ProcessWatcher): file_chooser = FileChooserComponent( label=self.i18n['file'].capitalize(), allowed_extensions={'AppImage'}) input_version = TextInputComponent( label=self.i18n['version'].capitalize()) while True: if watcher.request_confirmation( title=self. i18n['appimage.custom_action.manual_update.details'], body=None, components=[ FormComponent(label='', components=[file_chooser, input_version], spaces=False) ], confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize()): if not file_chooser.file_path or not os.path.isfile( file_chooser.file_path): watcher.request_confirmation( title=self.i18n['error'].capitalize(), body=self.i18n[ 'appimage.custom_action.install_file.invalid_file'], deny_button=False) else: break else: return False pkg.local_file_path = file_chooser.file_path pkg.version = input_version.get_value() reqs = UpgradeRequirements(to_install=None, to_remove=None, to_upgrade=[UpgradeRequirement(pkg=pkg)], cannot_upgrade=None) return self.upgrade(reqs, root_password=root_password, watcher=watcher)
def _gen_ui_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: default_width = floor(0.11 * screen_width) select_hdpi = self._gen_bool_component(label=self.i18n['core.config.ui.hdpi'], tooltip=self.i18n['core.config.ui.hdpi.tip'], value=bool(core_config['ui']['hdpi']), max_width=default_width, id_='hdpi') select_ascale = self._gen_bool_component(label=self.i18n['core.config.ui.auto_scale'], tooltip=self.i18n['core.config.ui.auto_scale.tip'].format('QT_AUTO_SCREEN_SCALE_FACTOR'), value=bool(core_config['ui']['auto_scale']), max_width=default_width, id_='auto_scale') cur_style = QApplication.instance().style().objectName().lower() if not core_config['ui']['style'] else core_config['ui']['style'] style_opts = [InputOption(label=self.i18n['core.config.ui.style.default'].capitalize(), value=None)] style_opts.extend([InputOption(label=s.capitalize(), value=s.lower()) for s in QStyleFactory.keys()]) default_style = [o for o in style_opts if o.value == cur_style] if not default_style: if cur_style: default_style = InputOption(label=cur_style, value=cur_style) style_opts.append(default_style) else: default_style = style_opts[0] else: default_style = default_style[0] select_style = SingleSelectComponent(label=self.i18n['style'].capitalize(), options=style_opts, default_option=default_style, type_=SelectViewType.COMBO, max_width=default_width, id_="style") input_maxd = TextInputComponent(label=self.i18n['core.config.ui.max_displayed'].capitalize(), tooltip=self.i18n['core.config.ui.max_displayed.tip'].capitalize(), only_int=True, id_="table_max", max_width=default_width, value=str(core_config['ui']['table']['max_displayed'])) select_dicons = self._gen_bool_component(label=self.i18n['core.config.download.icons'], tooltip=self.i18n['core.config.download.icons.tip'], id_="down_icons", max_width=default_width, value=core_config['download']['icons']) sub_comps = [FormComponent([select_hdpi, select_ascale, select_dicons, select_style, input_maxd], spaces=False)] return TabComponent(self.i18n['core.config.tab.ui'].capitalize(), PanelComponent(sub_comps), None, 'core.ui')
def _new_text_input(self, c: TextInputComponent) -> Tuple[QLabel, QLineEdit]: view = QLineEditObserver( ) if c.type == TextInputType.SINGLE_LINE else QPlainTextEditObserver() view.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) if c.id: view.setObjectName(c.id) if c.min_width >= 0: view.setMinimumWidth(int(c.min_width)) if c.min_height >= 0: view.setMinimumHeight(int(c.min_height)) if c.only_int: view.setValidator(QIntValidator()) if c.tooltip: view.setToolTip(c.tooltip) if c.placeholder: view.setPlaceholderText(c.placeholder) if c.value is not None: view.setText(str(c.value)) view.setCursorPosition(0) if c.read_only: view.setEnabled(False) def update_model(text: str): c.set_value(val=text, caller=view) view.textChanged.connect(update_model) c.observers.append(view) label = QWidget() label.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) label.setLayout(QHBoxLayout()) label_component = QLabel() label.layout().addWidget(label_component) if label: label_component.setText(c.get_label()) if c.tooltip: label.layout().addWidget(self.gen_tip_icon(c.tooltip)) return label, self._wrap(view, c)
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent: config = read_config() max_width = floor(screen_width * 0.15) input_electron = TextInputComponent( label=self.i18n['web.settings.electron.version.label'], value=config['environment']['electron']['version'], tooltip=self.i18n['web.settings.electron.version.tooltip'], placeholder='{}: 7.1.0'.format(self.i18n['example.short']), max_width=max_width, id_='electron_version') native_opts = [ InputOption( label=self.i18n['web.settings.nativefier.env'].capitalize(), value=False, tooltip=self.i18n['web.settings.nativefier.env.tooltip']. format(app=self.context.app_name)), InputOption( label=self.i18n['web.settings.nativefier.system'].capitalize(), value=True, tooltip=self.i18n['web.settings.nativefier.system.tooltip']) ] select_nativefier = SingleSelectComponent( label="Nativefier", options=native_opts, default_option=[ o for o in native_opts if o.value == config['environment']['system'] ][0], type_=SelectViewType.COMBO, tooltip=self.i18n['web.settings.nativefier.tip'], max_width=max_width, id_='nativefier') form_env = FormComponent( label=self.i18n['web.settings.nativefier.env'].capitalize(), components=[input_electron, select_nativefier]) return PanelComponent([form_env])
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent: config = read_config() max_width = floor(screen_width * 0.15) enabled_opts = [ InputOption(label=self.i18n['yes'].capitalize(), value=True), InputOption(label=self.i18n['no'].capitalize(), value=False) ] updater_opts = [ SingleSelectComponent( label=self.i18n['appimage.config.db_updates.activated'], options=enabled_opts, default_option=[ o for o in enabled_opts if o.value == config['db_updater']['enabled'] ][0], max_per_line=len(enabled_opts), type_=SelectViewType.RADIO, tooltip=self.i18n['appimage.config.db_updates.activated.tip'], max_width=max_width, id_='up_enabled'), TextInputComponent( label=self.i18n['interval'], value=str(config['db_updater']['interval']), tooltip=self.i18n['appimage.config.db_updates.interval.tip'], only_int=True, max_width=max_width, id_='up_int') ] return PanelComponent([ FormComponent(updater_opts, self.i18n['appimage.config.db_updates']) ])
def __init__(self, model: TextInputComponent): super(TextInputQt, self).__init__() self.model = model self.setLayout(QGridLayout()) self.setStyleSheet('QGridLayout {margin-left: 0} QLabel { font-weight: bold}') self.layout().addWidget(QLabel(model.get_label()), 0, 0) if self.model.max_width > 0: self.setMaximumWidth(self.model.max_width) self.text_input = QLineEditObserver() if model.type == TextInputType.SINGLE_LINE else QPlainTextEditObserver() if model.only_int: self.text_input.setValidator(QIntValidator()) if model.placeholder: self.text_input.setPlaceholderText(model.placeholder) if model.min_width >= 0: self.text_input.setMinimumWidth(model.min_width) if model.min_height >= 0: self.text_input.setMinimumHeight(model.min_height) if model.tooltip: self.text_input.setToolTip(model.tooltip) if model.value: self.text_input.setText(model.value) self.text_input.setCursorPosition(0) self.text_input.textChanged.connect(self._update_model) self.model.observers.append(self.text_input) self.layout().addWidget(self.text_input, 0, 1)
def install_file(self, root_password: str, watcher: ProcessWatcher) -> bool: file_chooser = FileChooserComponent( label=self.i18n['file'].capitalize(), allowed_extensions={'AppImage'}) input_name = TextInputComponent(label=self.i18n['name'].capitalize()) input_version = TextInputComponent( label=self.i18n['version'].capitalize()) input_description = TextInputComponent( label=self.i18n['description'].capitalize()) cat_ops = [ InputOption(label=self.i18n['category.none'].capitalize(), value=0) ] cat_ops.extend([ InputOption(label=self.i18n[c.lower()].capitalize(), value=c) for c in self.context.default_categories ]) inp_cat = SingleSelectComponent(label=self.i18n['category'], type_=SelectViewType.COMBO, options=cat_ops, default_option=cat_ops[0]) form = FormComponent(label='', components=[ file_chooser, input_name, input_version, input_description, inp_cat ], spaces=False) while True: if watcher.request_confirmation( title=self. i18n['appimage.custom_action.install_file.details'], body=None, components=[form], confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize()): if not file_chooser.file_path or not os.path.isfile( file_chooser.file_path): watcher.request_confirmation( title=self.i18n['error'].capitalize(), body=self.i18n[ 'appimage.custom_action.install_file.invalid_file'], deny_button=False) elif not input_name.get_value() or not input_name.get_value( ).strip(): watcher.request_confirmation( title=self.i18n['error'].capitalize(), body=self.i18n[ 'appimage.custom_action.install_file.invalid_name'], deny_button=False) else: break else: return False appim = AppImage(i18n=self.i18n, imported=True, custom_actions=self.custom_app_actions) appim.name = input_name.get_value().strip() appim.local_file_path = file_chooser.file_path appim.version = input_version.get_value() appim.latest_version = input_version.get_value() appim.description = input_description.get_value() appim.categories = ['Imported'] if inp_cat.get_selected() != cat_ops[0].value: appim.categories.append(inp_cat.get_selected()) installed = self.install(root_password=root_password, pkg=appim, watcher=watcher) if installed: appim.installed = True self.cache_to_disk(appim, None, False) return installed
def _ask_install_options( self, app: WebApplication, watcher: ProcessWatcher) -> Tuple[bool, List[str]]: watcher.change_substatus(self.i18n['web.install.substatus.options']) inp_url = TextInputComponent(label=self.i18n['address'], value=app.url, read_only=True) inp_name = TextInputComponent(label=self.i18n['name'], value=app.name) inp_desc = TextInputComponent(label=self.i18n['description'], value=app.description) cat_ops = [ InputOption(label=self.i18n['web.install.option.category.none']. capitalize(), value=0) ] cat_ops.extend([ InputOption(label=self.i18n[c.lower()].capitalize(), value=c) for c in self.context.default_categories ]) def_cat = cat_ops[0] if app.categories: for opt in cat_ops: if opt.value == app.categories[0]: def_cat = opt break inp_cat = SingleSelectComponent(label=self.i18n['category'], type_=SelectViewType.COMBO, options=cat_ops, default_option=def_cat) tray_op_off = InputOption( id_='tray_off', label=self.i18n['web.install.option.tray.off.label'], value=0, tooltip=self.i18n['web.install.option.tray.off.tip']) tray_op_default = InputOption( id_='tray_def', label=self.i18n['web.install.option.tray.default.label'], value='--tray', tooltip=self.i18n['web.install.option.tray.default.tip']) tray_op_min = InputOption( id_='tray_min', label=self.i18n['web.install.option.tray.min.label'], value='--tray=start-in-tray', tooltip=self.i18n['web.install.option.tray.min.tip']) tray_opts = [tray_op_off, tray_op_default, tray_op_min] def_tray_opt = None if app.preset_options: for opt in tray_opts: if opt.id in app.preset_options: def_tray_opt = opt break inp_tray = SingleSelectComponent( type_=SelectViewType.COMBO, options=tray_opts, default_option=def_tray_opt, label=self.i18n['web.install.option.tray.label']) icon_op_ded = InputOption( id_='icon_ded', label=self.i18n['web.install.option.wicon.deducted.label'], value=0, tooltip=self.i18n['web.install.option.wicon.deducted.tip'].format( 'Nativefier')) icon_op_disp = InputOption( id_='icon_disp', label=self.i18n['web.install.option.wicon.displayed.label'], value=1, tooltip=self.i18n['web.install.option.wicon.displayed.tip']) inp_icon = SingleSelectComponent( type_=SelectViewType.COMBO, options=[icon_op_disp, icon_op_ded], default_option=icon_op_disp if app.icon_url and app.save_icon else icon_op_ded, label=self.i18n['web.install.option.wicon.label']) icon_chooser = FileChooserComponent( allowed_extensions={'png', 'svg', 'ico', 'jpg', 'jpeg'}, label=self.i18n['web.install.option.icon.label']) form_1 = FormComponent( components=[ inp_url, inp_name, inp_desc, inp_cat, inp_icon, icon_chooser, inp_tray ], label=self.i18n['web.install.options.basic'].capitalize()) op_single = InputOption( id_='single', label=self.i18n['web.install.option.single.label'], value="--single-instance", tooltip=self.i18n['web.install.option.single.tip']) op_max = InputOption(id_='max', label=self.i18n['web.install.option.max.label'], value="--maximize", tooltip=self.i18n['web.install.option.max.tip']) op_fs = InputOption( id_='fullscreen', label=self.i18n['web.install.option.fullscreen.label'], value="--full-screen", tooltip=self.i18n['web.install.option.fullscreen.tip']) op_nframe = InputOption( id_='no_frame', label=self.i18n['web.install.option.noframe.label'], value="--hide-window-frame", tooltip=self.i18n['web.install.option.noframe.tip']) op_allow_urls = InputOption( id_='allow_urls', label=self.i18n['web.install.option.allow_urls.label'], value='--internal-urls=.*', tooltip=self.i18n['web.install.option.allow_urls.tip']) op_ncache = InputOption( id_='no_cache', label=self.i18n['web.install.option.nocache.label'], value="--clear-cache", tooltip=self.i18n['web.install.option.nocache.tip']) op_insecure = InputOption( id_='insecure', label=self.i18n['web.install.option.insecure.label'], value="--insecure", tooltip=self.i18n['web.install.option.insecure.tip']) op_igcert = InputOption( id_='ignore_certs', label=self.i18n['web.install.option.ignore_certificate.label'], value="--ignore-certificate", tooltip=self.i18n['web.install.option.ignore_certificate.tip']) adv_opts = [ op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert ] def_adv_opts = {op_single, op_allow_urls} if app.preset_options: for opt in adv_opts: if opt.id in app.preset_options: def_adv_opts.add(opt) check_options = MultipleSelectComponent( options=adv_opts, default_options=def_adv_opts, label=self.i18n['web.install.options.advanced'].capitalize()) res = watcher.request_confirmation( title=self.i18n['web.install.options_dialog.title'], body=None, components=[form_1, check_options], confirmation_label=self.i18n['continue'].capitalize(), deny_label=self.i18n['cancel'].capitalize()) if res: selected = [] if check_options.values: selected.extend(check_options.get_selected_values()) tray_mode = inp_tray.get_selected() if tray_mode is not None and tray_mode != 0: selected.append(tray_mode) custom_name = inp_name.get_value() if custom_name: app.name = custom_name custom_desc = inp_desc.get_value() if custom_desc: app.description = inp_desc.get_value() cat = inp_cat.get_selected() if cat != 0: app.categories = [cat] if icon_chooser.file_path: app.set_custom_icon(icon_chooser.file_path) selected.append('--icon={}'.format(icon_chooser.file_path)) app.save_icon = inp_icon.value == icon_op_disp return res, selected return False, []
def get_settings(self) -> Optional[Generator[SettingsView, None, None]]: config_ = self.configman.get_config() purge_opts = [InputOption(label=self._i18n['yes'].capitalize(), value=True), InputOption(label=self._i18n['no'].capitalize(), value=False)] purge_current = tuple(o for o in purge_opts if o.value == bool(config_['remove.purge']))[0] sel_purge = SingleSelectComponent(id_='remove.purge', label=self._i18n['debian.config.remove.purge'], tooltip=self._i18n['debian.config.remove.purge.tip'], options=purge_opts, default_option=purge_current, type_=SelectViewType.RADIO, max_per_line=2) sources_app = config_.get('pkg_sources.app') if isinstance(sources_app, str) and sources_app not in self.known_sources_apps: self._log.warning(f"'pkg_sources.app' ({sources_app}) is not supported. A 'None' value will be considered") sources_app = None lb_source_auto = self._i18n['debian.config.pkg_sources.app.auto'] source_opts = [InputOption(id_='auto', value=None, label=lb_source_auto)] source_opts.extend((InputOption(id_=a, value=a, label=a) for a in self.known_sources_apps if which(a))) source_auto_tip = self._i18n['debian.config.pkg_sources.app.tip'].format(auto=f'"{lb_source_auto}"') input_sources = SingleSelectComponent(id_='pkg_sources.app', label=self._i18n['debian.config.pkg_sources.app'], tooltip=source_auto_tip, options=source_opts, default_option=next(o for o in source_opts if o.value == sources_app), alignment=ViewComponentAlignment.CENTER, type_=SelectViewType.COMBO) try: app_cache_exp = int(config_.get('index_apps.exp', 0)) except ValueError: self._log.error(f"Unexpected value form Debian configuration property 'index_apps.exp': " f"{config_['index_apps.exp']}. Zero (0) will be considered instead.") app_cache_exp = 0 ti_index_apps_exp = TextInputComponent(id_='index_apps.exp', label=self._i18n['debian.config.index_apps.exp'], tooltip=self._i18n['debian.config.index_apps.exp.tip'], value=str(app_cache_exp), only_int=True) try: sync_pkgs_time = int(config_.get('sync_pkgs.time', 0)) except ValueError: self._log.error(f"Unexpected value form Debian configuration property 'sync_pkgs.time': {config_['sync_pkgs.time']}. " f"Zero (0) will be considered instead.") sync_pkgs_time = 0 ti_sync_pkgs = TextInputComponent(id_='sync_pkgs.time', label=self._i18n['debian.config.sync_pkgs.time'], tooltip=self._i18n['debian.config.sync_pkgs.time.tip'], value=str(sync_pkgs_time), only_int=True) try: suggestions_exp = int(config_.get('suggestions.exp', 0)) except ValueError: self._log.error(f"Unexpected value form Debian configuration property 'suggestions.exp': {config_['suggestions.exp']}. " f"Zero (0) will be considered instead.") suggestions_exp = 0 ti_suggestions_exp = TextInputComponent(id_='suggestions.exp', label=self._i18n['debian.config.suggestions.exp'], tooltip=self._i18n['debian.config.suggestions.exp.tip'], value=str(suggestions_exp), only_int=True) panel = PanelComponent([FormComponent([input_sources, sel_purge, ti_sync_pkgs, ti_index_apps_exp, ti_suggestions_exp])]) yield SettingsView(self, panel)
def _gen_ui_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: default_width = floor(0.15 * screen_width) select_hdpi = self._gen_bool_component( label=self.i18n['core.config.ui.hdpi'], tooltip=self.i18n['core.config.ui.hdpi.tip'], value=bool(core_config['ui']['hdpi']), max_width=default_width, id_='hdpi') select_ascale = self._gen_bool_component( label=self.i18n['core.config.ui.auto_scale'], tooltip=self.i18n['core.config.ui.auto_scale.tip'].format( 'QT_AUTO_SCREEN_SCALE_FACTOR'), value=bool(core_config['ui']['auto_scale']), max_width=default_width, id_='auto_scale') try: scale = float(core_config['ui']['scale_factor']) if scale < 1.0: scale = 1.0 except: scale = 1.0 select_scale = RangeInputComponent( id_="scalef", label=self.i18n['core.config.ui.scale_factor'] + ' (%)', tooltip=self.i18n['core.config.ui.scale_factor.tip'], min_value=100, max_value=400, step_value=5, value=scale * 100, max_width=default_width) cur_style = QApplication.instance().property( 'qt_style') if not core_config['ui']['qt_style'] else core_config[ 'ui']['qt_style'] style_opts = [ InputOption(label=s.capitalize(), value=s.lower()) for s in QStyleFactory.keys() ] default_style = [o for o in style_opts if o.value == cur_style] if not default_style: if cur_style: default_style = InputOption(label=cur_style, value=cur_style) style_opts.append(default_style) else: default_style = style_opts[0] else: default_style = default_style[0] select_style = SingleSelectComponent( label=self.i18n['style'].capitalize(), tooltip=self.i18n['core.config.ui.qt_style.tooltip'], options=style_opts, default_option=default_style, type_=SelectViewType.COMBO, max_width=default_width, id_="style") select_system_theme = self._gen_bool_component( label=self.i18n['core.config.ui.system_theme'], tooltip=self.i18n['core.config.ui.system_theme.tip'].format( app=__app_name__), value=bool(core_config['ui']['system_theme']), max_width=default_width, id_='system_theme') input_maxd = TextInputComponent( label=self.i18n['core.config.ui.max_displayed'], tooltip=self.i18n['core.config.ui.max_displayed.tip'], only_int=True, id_="table_max", max_width=default_width, value=str(core_config['ui']['table']['max_displayed'])) select_dicons = self._gen_bool_component( label=self.i18n['core.config.download.icons'], tooltip=self.i18n['core.config.download.icons.tip'], id_="down_icons", max_width=default_width, value=core_config['download']['icons']) sub_comps = [ FormComponent([ select_hdpi, select_ascale, select_scale, select_dicons, select_system_theme, select_style, input_maxd ], spaces=False) ] return TabComponent(self.i18n['core.config.tab.ui'].capitalize(), PanelComponent(sub_comps), None, 'core.ui')
def install_file(self, root_password: Optional[str], watcher: ProcessWatcher) -> bool: max_width = 350 file_chooser = FileChooserComponent(label=self.i18n['file'].capitalize(), allowed_extensions={'AppImage', '*'}, search_path=get_default_manual_installation_file_dir(), max_width=max_width) input_name = TextInputComponent(label=self.i18n['name'].capitalize(), max_width=max_width) input_version = TextInputComponent(label=self.i18n['version'].capitalize(), max_width=max_width) file_chooser.observers.append(ManualInstallationFileObserver(input_name, input_version)) input_description = TextInputComponent(label=self.i18n['description'].capitalize(), max_width=max_width) cat_ops = [InputOption(label=self.i18n['category.none'].capitalize(), value=0)] cat_ops.extend([InputOption(label=self.i18n.get(f'category.{c.lower()}', c.lower()).capitalize(), value=c) for c in self.context.default_categories]) inp_cat = SingleSelectComponent(label=self.i18n['category'], type_=SelectViewType.COMBO, options=cat_ops, default_option=cat_ops[0], max_width=max_width) form = FormComponent(label='', components=[file_chooser, input_name, input_version, input_description, inp_cat], spaces=False) while True: if watcher.request_confirmation(title=self.i18n['appimage.custom_action.install_file.details'], body=None, components=[form], confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize(), min_height=100, max_width=max_width + 150): if not file_chooser.file_path or not os.path.isfile(file_chooser.file_path) or not file_chooser.file_path.lower().strip().endswith('.appimage'): watcher.request_confirmation(title=self.i18n['error'].capitalize(), body=self.i18n['appimage.custom_action.install_file.invalid_file'], deny_button=False) elif not input_name.get_value() or not input_name.get_value().strip(): watcher.request_confirmation(title=self.i18n['error'].capitalize(), body=self.i18n['appimage.custom_action.install_file.invalid_name'], deny_button=False) else: break else: return False appim = AppImage(i18n=self.i18n, imported=True) appim.name = input_name.get_value().strip() appim.local_file_path = file_chooser.file_path appim.version = input_version.get_value() appim.latest_version = input_version.get_value() appim.description = input_description.get_value() appim.categories = ['Imported'] if inp_cat.get_selected() != cat_ops[0].value: appim.categories.append(inp_cat.get_selected()) res = self.install(root_password=root_password, pkg=appim, disk_loader=None, watcher=watcher).success if res: appim.installed = True self.cache_to_disk(appim, None, False) return res
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')