[wgem] custom icon selector

This commit is contained in:
Vinícius Moreira
2019-12-16 11:40:05 -03:00
parent 995dc23a72
commit f6434f9e30
13 changed files with 116 additions and 18 deletions

View File

@@ -18,7 +18,7 @@ from bauh.api.abstract.disk import DiskCacheLoader
from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.model import SoftwarePackage, PackageAction, PackageSuggestion, PackageUpdate, PackageHistory
from bauh.api.abstract.view import MessageType, MultipleSelectComponent, InputOption, SingleSelectComponent, \
SelectViewType, TextInputComponent, FormComponent
SelectViewType, TextInputComponent, FormComponent, FileChooserComponent
from bauh.api.constants import DESKTOP_ENTRIES_DIR
from bauh.commons.html import bold
from bauh.commons.system import ProcessHandler, get_dir_size, get_human_size_str
@@ -100,6 +100,9 @@ class WebApplicationManager(SoftwareManager):
def _strip_url_protocol(self, url: str) -> str:
return RE_PROTOCOL_STRIP.split(url)[1].strip().lower()
def serialize_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
super(WebApplicationManager, self).serialize_to_disk(pkg=pkg, icon_bytes=None, only_icon=False)
def search(self, words: str, disk_loader: DiskCacheLoader, limit: int = -1, is_url: bool = False) -> SearchResult:
res = SearchResult([], [], 0)
@@ -243,7 +246,9 @@ class WebApplicationManager(SoftwareManager):
options=[tray_op_off, tray_op_default, tray_op_min],
label=self.i18n['web.install.option.tray.label'])
form_1 = FormComponent(components=[inp_url, inp_name, inp_desc, inp_cat, inp_tray], label="Basic")
icon_chooser = FileChooserComponent(allowed_extensions={'png'}, label=self.i18n['web.install.option.icon.label'])
form_1 = FormComponent(components=[inp_url, inp_name, inp_desc, inp_cat, 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'])
@@ -254,7 +259,7 @@ class WebApplicationManager(SoftwareManager):
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'])
check_options = MultipleSelectComponent(options=[op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label='Advanced')
check_options = MultipleSelectComponent(options=[op_single, op_allow_urls, op_max, op_fs, op_nframe, op_ncache, op_insecure, op_igcert], default_options={op_single}, label=self.i18n['web.install.options.advanced'].capitalize())
res = watcher.request_confirmation(title=self.i18n['web.install.options_dialog.title'],
body=None,
@@ -287,6 +292,10 @@ class WebApplicationManager(SoftwareManager):
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))
return res, selected
return False, []

View File

@@ -1,4 +1,3 @@
import re
from pathlib import Path
from typing import List
@@ -11,13 +10,14 @@ class WebApplication(SoftwarePackage):
def __init__(self, id: str = None, url: str = None, name: str = None, description: str = None, icon_url: str = None,
installation_dir: str = None, desktop_entry: str = None, installed: bool = False, version: str = None,
categories: List[str] = None):
categories: List[str] = None, custom_icon: str = None):
super(WebApplication, self).__init__(id=id if id else url, name=name, description=description,
icon_url=icon_url, installed=installed, version=version,
categories=categories)
self.url = url
self.installation_dir = installation_dir
self.desktop_entry = desktop_entry
self.set_custom_icon(custom_icon)
def has_history(self):
return False
@@ -27,7 +27,7 @@ class WebApplication(SoftwarePackage):
@staticmethod
def _get_cached_attrs() -> tuple:
return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', 'desktop_entry', 'categories'
return 'id', 'name', 'version', 'url', 'description', 'icon_url', 'installation_dir', 'desktop_entry', 'categories', 'custom_icon'
def can_be_downgraded(self):
return False
@@ -45,9 +45,15 @@ class WebApplication(SoftwarePackage):
def get_default_icon_path(self) -> str:
return resource.get_path('img/web.png', ROOT_DIR)
def get_disk_data_path(self):
def get_disk_data_path(self) -> str:
return '{}/data.yml'.format(self.get_disk_cache_path())
def get_disk_icon_path(self) -> str:
if self.custom_icon:
return self.custom_icon
else:
super(WebApplication, self).get_disk_icon_path()
def is_application(self):
return True
@@ -76,6 +82,8 @@ class WebApplication(SoftwarePackage):
if val and hasattr(self, attr):
setattr(self, attr, val)
self.set_custom_icon(self.custom_icon)
def can_be_run(self) -> bool:
return self.installed and self.installation_dir
@@ -91,3 +99,10 @@ class WebApplication(SoftwarePackage):
def get_autostart_path(self) -> str:
if self.desktop_entry:
return '{}/.config/autostart/{}'.format(Path.home(), self.desktop_entry.split('/')[-1])
def set_custom_icon(self, custom_icon: str):
self.custom_icon = custom_icon
if custom_icon:
self.icon_url = custom_icon

View File

@@ -3,6 +3,8 @@ web.environment.install=Installing {}
web.waiting.env_updater=Updating environment
web.env.checking=Checking the Web installation environment
web.env.error=It seems there are issues with the Web installation environment. It wil not be possible to install {}.
web.install.options.basic=basic
web.install.options.advanced=advanced
web.install.options_dialog.title=Installation options
web.install.error=An error has happened during the {} installation
web.install.nativefier.error.unknown=Have a look at the {} to identify the reason
@@ -35,6 +37,7 @@ web.install.option.tray.default.tip=The app icon will be attached to the system
web.install.option.tray.min.label=Start minimized
web.install.option.tray.min.tip=The app will be started minimized as an icon in the system tray
web.install.option.category.none=none
web.install.option.icon.label=Custom icon
web.uninstall.error.install_dir.not_found=The installation directory {} was not found
web.uninstall.error.remove_dir=It was not possible to remove {}
web.info.1_url=URL

View File

@@ -3,6 +3,8 @@ web.environment.nativefier=Instalando {}
web.waiting.env_updater=Atualizando ambiente
web.env.checking=Verificando o ambiente de instalação Web
web.env.error=Parce que existem problemas com o ambiente de instalação Web. Não será possível instalar {}.
web.install.options.basic=básicas
web.install.options.advanced=avançadas
web.install.options_dialog.title=Opções de instalação
wen.install.error=Ocorreu um erro durante a instalação de {}
web.install.nativefier.error.unknown=Dê uma olhada em {} para identificar o motivo
@@ -35,6 +37,7 @@ web.install.option.tray.default.tip=O ícone do aplicativo será anexado a bande
web.install.option.tray.min.label=Iniciar minimizado
web.install.option.tray.min.tip=O aplicativo será iniciado minimizado como um ícone da bandeja do sistema
web.install.option.category.none=nenhuma
web.install.option.icon.label=Ícone alternativo
web.uninstall.error.install_dir.not_found=O diretório de instalação {} não foi encontrado
web.uninstall.error.remove=Não foi possível remover {}
web.info.1_url=URL
@@ -45,4 +48,4 @@ web.info.5_installation_dir=diretório de instalação
web.info.6_desktop_entry=atalho
web.info.7_exec_file=executável
web.info.8_icon_path=ícone
web.info.9_size=tamanho
web.info.9_size=tamanho