mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 08:34:17 +02:00
[ui][settings] more improvements and settings
This commit is contained in:
@@ -10,7 +10,7 @@ from bauh.api.abstract.disk import DiskCacheLoader
|
||||
from bauh.api.abstract.handler import ProcessWatcher
|
||||
from bauh.api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory, PackageSuggestion, PackageAction
|
||||
from bauh.api.abstract.view import FormComponent, ViewComponent, TabGroupComponent, TabComponent, SingleSelectComponent, \
|
||||
InputOption, PanelComponent, SelectViewType
|
||||
InputOption, PanelComponent, SelectViewType, TextInputComponent, TwoStateButtonComponent
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import internet
|
||||
from bauh.commons.config import save_config
|
||||
@@ -406,42 +406,74 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
def get_working_managers(self):
|
||||
return [m for m in self.managers if self._can_work(m)]
|
||||
|
||||
def _gen_bool_component(self, label: str, tooltip: str, value: bool, id_: str) -> SingleSelectComponent:
|
||||
opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True),
|
||||
InputOption(label=self.i18n['no'].capitalize(), value=False)]
|
||||
|
||||
return SingleSelectComponent(label=label,
|
||||
options=opts,
|
||||
default_option=[o for o in opts if o.value == value][0],
|
||||
type_=SelectViewType.RADIO,
|
||||
tooltip=tooltip,
|
||||
max_per_line=len(opts),
|
||||
id_=id_)
|
||||
|
||||
def _gen_settings_panel(self) -> TabComponent:
|
||||
core_config = read_config()
|
||||
|
||||
current_locale = self.i18n.current_key
|
||||
locale_opts = [InputOption(label=self.i18n['locale.{}'.format(k)].capitalize(), value=k) for k in translation.get_available_keys()]
|
||||
select_locale = SingleSelectComponent(label=self.i18n['core.config.locale.label'],
|
||||
options=locale_opts,
|
||||
default_option=[l for l in locale_opts if l.value == current_locale][0],
|
||||
default_option=[l for l in locale_opts if l.value == core_config['locale']][0],
|
||||
type_=SelectViewType.COMBO,
|
||||
id_='locale')
|
||||
|
||||
disk_cache = core_config['disk_cache']['enabled']
|
||||
dcache_opts = [InputOption(label=self.i18n['yes'].capitalize(), value=True),
|
||||
InputOption(label=self.i18n['no'].capitalize(), value=False)]
|
||||
select_dcache = self._gen_bool_component(label=self.i18n['core.config.disk_cache'],
|
||||
tooltip=self.i18n['core.config.disk_cache.tip'].format(app=self.context.app_name),
|
||||
value=core_config['disk_cache']['enabled'],
|
||||
id_='dcache')
|
||||
|
||||
select_dcache = SingleSelectComponent(label=self.i18n['core.config.disk_cache'],
|
||||
options=dcache_opts,
|
||||
default_option=[o for o in dcache_opts if o.value == disk_cache][0],
|
||||
type_=SelectViewType.RADIO,
|
||||
tooltip=self.i18n['core.config.disk_cache.tip'].format(app=self.context.app_name),
|
||||
max_per_line=len(dcache_opts),
|
||||
id_='dcache')
|
||||
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']),
|
||||
id_="updates_interval")
|
||||
|
||||
sub_comps = [select_locale, select_dcache]
|
||||
form_general = FormComponent(label=self.i18n['core.config.tab_label'].capitalize(),
|
||||
components=[select_locale, input_update_interval, select_dcache],
|
||||
id_="form_general")
|
||||
|
||||
select_dicons = self._gen_bool_component(label=self.i18n['core.config.download.icons'],
|
||||
tooltip=self.i18n['core.config.download.icons.tip'],
|
||||
id_="down_icons",
|
||||
value=core_config['download']['icons'])
|
||||
|
||||
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'])
|
||||
|
||||
form_download = FormComponent(label=self.i18n['download'].capitalize(), components=[select_dicons, select_dmthread], id_='form_download')
|
||||
|
||||
sub_comps = [form_general, form_download]
|
||||
return TabComponent(self.i18n['core.config.tab_label'].capitalize(), PanelComponent([FormComponent(sub_comps)]), None, 'core')
|
||||
|
||||
def _save_settings(self, panel: PanelComponent) -> Tuple[bool, List[str]]:
|
||||
core_config = config.read_config()
|
||||
|
||||
main_form = panel.components[0]
|
||||
locale = main_form.get_component('locale').get_selected()
|
||||
locale = main_form.get_component('form_general').get_component('locale').get_selected()
|
||||
|
||||
if locale != self.i18n.current_key:
|
||||
core_config['locale'] = locale
|
||||
|
||||
core_config['disk_cache']['enabled'] = main_form.get_component('dcache').get_selected()
|
||||
core_config['disk_cache']['enabled'] = main_form.get_component('form_general').get_component('dcache').get_selected()
|
||||
core_config['updates']['check_interval'] = main_form.get_component('form_general').get_component('updates_interval').get_int_value()
|
||||
|
||||
download_icons = main_form.get_component('form_download').get_component('down_icons').get_selected()
|
||||
core_config['download']['icons'] = download_icons
|
||||
|
||||
download_mthreaded = main_form.get_component('form_download').get_component('down_mthread').get_selected()
|
||||
core_config['download']['multithreaded'] = download_mthreaded
|
||||
|
||||
try:
|
||||
config.save(core_config)
|
||||
|
||||
@@ -4,10 +4,11 @@ from typing import Tuple
|
||||
from PyQt5.QtCore import Qt, QSize
|
||||
from PyQt5.QtGui import QIcon, QPixmap, QIntValidator
|
||||
from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \
|
||||
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout, QFileDialog, QTabWidget, QVBoxLayout
|
||||
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout, QFileDialog, QTabWidget, QVBoxLayout, QSlider
|
||||
|
||||
from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \
|
||||
TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, TabGroupComponent, PanelComponent
|
||||
TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, TabGroupComponent, PanelComponent, \
|
||||
TwoStateButtonComponent
|
||||
from bauh.view.qt import css
|
||||
from bauh.view.util import resource
|
||||
from bauh.view.util.translation import I18n
|
||||
@@ -61,6 +62,21 @@ class CheckboxQt(QCheckBox):
|
||||
self.callback(self.model, checked)
|
||||
|
||||
|
||||
class TwoStateButtonQt(QSlider):
|
||||
|
||||
def __init__(self, model: TwoStateButtonComponent):
|
||||
super(TwoStateButtonQt, self).__init__(Qt.Horizontal)
|
||||
self.model = model
|
||||
self.setMaximum(1)
|
||||
self.valueChanged.connect(self._change_state)
|
||||
|
||||
def mousePressEvent(self, QMouseEvent):
|
||||
self.setValue(1 if self.value() == 0 else 0)
|
||||
|
||||
def _change_state(self, state: int):
|
||||
self.model.state = bool(state)
|
||||
|
||||
|
||||
class ComboBoxQt(QComboBox):
|
||||
|
||||
def __init__(self, model: SingleSelectComponent):
|
||||
@@ -337,19 +353,7 @@ class FormQt(QGroupBox):
|
||||
label, field = self._new_text_input(c)
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, SingleSelectComponent):
|
||||
|
||||
label = QWidget()
|
||||
label.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||
label.setLayout(QHBoxLayout())
|
||||
label_comp = QLabel()
|
||||
label.layout().addWidget(label_comp)
|
||||
|
||||
if c.label:
|
||||
label_comp.setText(c.label.capitalize())
|
||||
|
||||
if c.tooltip:
|
||||
label.layout().addWidget(self.gen_tip_icon(c.tooltip))
|
||||
|
||||
label = self._new_label(c)
|
||||
field = ComboBoxQt(c) if c.type == SelectViewType.COMBO else RadioBoxQt(c)
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, FileChooserComponent):
|
||||
@@ -357,11 +361,29 @@ class FormQt(QGroupBox):
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, FormComponent):
|
||||
self.layout().addRow(FormQt(c, self.i18n))
|
||||
elif isinstance(c, TwoStateButtonComponent):
|
||||
label = self._new_label(c)
|
||||
self.layout().addRow(label, TwoStateButtonQt(c))
|
||||
else:
|
||||
raise Exception('Unsupported component type {}'.format(c.__class__.__name__))
|
||||
|
||||
self.layout().addRow(QLabel(), QLabel())
|
||||
|
||||
def _new_label(self, comp) -> QWidget:
|
||||
label = QWidget()
|
||||
label.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||
label.setLayout(QHBoxLayout())
|
||||
label_comp = QLabel()
|
||||
label.layout().addWidget(label_comp)
|
||||
|
||||
if comp.label:
|
||||
label_comp.setText(comp.label.capitalize())
|
||||
|
||||
if comp.tooltip:
|
||||
label.layout().addWidget(self.gen_tip_icon(comp.tooltip))
|
||||
|
||||
return label
|
||||
|
||||
def gen_tip_icon(self, tip: str) -> QLabel:
|
||||
tip_icon = QLabel()
|
||||
tip_icon.setToolTip(tip.strip())
|
||||
@@ -481,5 +503,7 @@ def to_widget(comp: ViewComponent, i18n: I18n, parent: QWidget = None) -> QWidge
|
||||
return TabGroupQt(comp, i18n, parent)
|
||||
elif isinstance(comp, PanelComponent):
|
||||
return PanelQt(comp, i18n, parent)
|
||||
elif isinstance(comp, TwoStateButtonComponent):
|
||||
return TwoStateButtonQt(comp)
|
||||
else:
|
||||
raise Exception("Cannot render instances of " + comp.__class__.__name__)
|
||||
|
||||
@@ -220,10 +220,18 @@ message.file.not_exist=Fitxer no existeix
|
||||
message.file.not_exist.body=El fitxer {} sembla no existir
|
||||
icon_button.tooltip.disabled=Aquesta acció no està disponible
|
||||
user=usuari
|
||||
example.short=ex
|
||||
example.short=e.g
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=idioma
|
||||
core.config.disk_cache=Cau em disco
|
||||
core.config.locale.label=language
|
||||
core.config.disk_cache=Disk cache
|
||||
core.config.disk_cache.tip={app} will save some data about your installed applications into the disk to load them faster in the next initializations
|
||||
core.config.updates.interval=Updates interval
|
||||
core.config.updates.interval.tip=Defines the time interval in which the update-checking for the installed applications will happen ( in SECONDS )
|
||||
core.config.downloads=downloads
|
||||
core.config.download.icons=Icons
|
||||
core.config.download.icons.tip=If the application icons should be downloaded and displayed on the table
|
||||
core.config.download.multithreaded=Parallelism
|
||||
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with parallelism / multi-thread (faster). At the moment only the aria2 application is supported
|
||||
locale.en=anglès
|
||||
locale.es=castellà
|
||||
locale.pt=portuguès
|
||||
@@ -231,4 +239,5 @@ locale.ca=català
|
||||
locale.de=alemany
|
||||
locale.it=italià
|
||||
interval=interval
|
||||
installation=instal·lació
|
||||
installation=instal·lació
|
||||
download=download
|
||||
@@ -175,11 +175,18 @@ message.file.not_exist.body=Die Datei {} scheint nicht zu existieren
|
||||
development=Entwicklung
|
||||
icon_button.tooltip.disabled=Diese Aktion ist nicht verfügbar
|
||||
user=Benutzer
|
||||
example.short=z.B
|
||||
core.config.tab_label=Allgemeines
|
||||
core.config.locale.label=Sprache
|
||||
core.config.disk_cache=Festplattencache
|
||||
core.config.disk_cache.tip={app} speichert einige Daten zu Ihren installierten Anwendungen auf der Festplatte, um sie bei den nächsten Initialisierungen schneller zu laden
|
||||
example.short=e.g
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=language
|
||||
core.config.disk_cache=Disk cache
|
||||
core.config.disk_cache.tip={app} will save some data about your installed applications into the disk to load them faster in the next initializations
|
||||
core.config.updates.interval=Updates interval
|
||||
core.config.updates.interval.tip=Defines the time interval in which the update-checking for the installed applications will happen ( in SECONDS )
|
||||
core.config.downloads=downloads
|
||||
core.config.download.icons=Icons
|
||||
core.config.download.icons.tip=If the application icons should be downloaded and displayed on the table
|
||||
core.config.download.multithreaded=Parallelism
|
||||
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with parallelism / multi-thread (faster). At the moment only the aria2 application is supported
|
||||
locale.en=englisch
|
||||
locale.es=spanisch
|
||||
locale.pt=portugiesisch
|
||||
@@ -187,4 +194,5 @@ locale.ca=Katalanisch
|
||||
locale.de=deutsch
|
||||
locale.it=italienisch
|
||||
interval=intervall
|
||||
installation=Installation
|
||||
installation=Installation
|
||||
download=download
|
||||
@@ -183,7 +183,13 @@ example.short=e.g
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=language
|
||||
core.config.disk_cache=Disk cache
|
||||
core.config.disk_cache.tip={app} will save some data about your installed applications on the disk to load them faster in the next initializations
|
||||
core.config.disk_cache.tip={app} will save some data about your installed applications into the disk to load them faster in the next initializations
|
||||
core.config.updates.interval=Updates interval
|
||||
core.config.updates.interval.tip=Defines the time interval in which the update-checking for the installed applications will happen ( in SECONDS )
|
||||
core.config.download.icons=Icons
|
||||
core.config.download.icons.tip=If the application icons should be downloaded and displayed on the table
|
||||
core.config.download.multithreaded=Parallelism
|
||||
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with parallelism / multi-thread ( faster ). At the moment only the aria2 application is supported
|
||||
locale.en=english
|
||||
locale.es=spanish
|
||||
locale.pt=portuguese
|
||||
@@ -191,4 +197,5 @@ locale.ca=catalan
|
||||
locale.de=german
|
||||
locale.it=italian
|
||||
interval=interval
|
||||
installation=installation
|
||||
installation=installation
|
||||
download=download
|
||||
@@ -224,6 +224,13 @@ core.config.tab_label=general
|
||||
core.config.locale.label=idioma
|
||||
core.config.disk_cache=Cache em disco
|
||||
core.config.disk_cache.tip={app} guardará algunos datos sobre sus aplicaciones instaladas en el disco para cargarlas más rápido en las próximas inicializaciones
|
||||
core.config.updates.interval=Intervalo de actualizaciones
|
||||
core.config.updates.interval.tip=Define el intervalo de tiempo en el que se realizará la verificación de actualizaciones para las aplicaciones instaladas ( en SEGUNDOS )
|
||||
core.config.downloads=downloads
|
||||
core.config.download.icons=Iconos
|
||||
core.config.download.icons.tip=Si los íconos de las aplicaciones se deben descargar y mostrar en la tabla
|
||||
core.config.download.multithreaded=Paralelismo
|
||||
core.config.download.multithreaded.tip=Si las aplicaciones, paquetes y archivos deben descargarse con una herramienta que funcione con paralelismo / multi-thread ( más rápido ). Por el momento solo se admite la aplicación aria2
|
||||
locale.es=inglés
|
||||
locale.es=español
|
||||
locale.pt=portugués
|
||||
@@ -231,4 +238,5 @@ locale.ca=catalán
|
||||
locale.de=alemán
|
||||
locale.it=italiano
|
||||
interval=intervalo
|
||||
installation=instalación
|
||||
installation=instalación
|
||||
download=descarga
|
||||
@@ -176,11 +176,18 @@ message.file.not_exist.body=Il file {} sembra non esistere
|
||||
development=sviluppo
|
||||
icon_button.tooltip.disabled=Questa azione non è disponibile
|
||||
user=utente
|
||||
core.config.tab_label=generale
|
||||
core.config.locale.label=idioma
|
||||
core.config.disk_cache=cache nel disco
|
||||
core.config.disk_cache.tip={app} salverà alcuni dati sulle applicazioni installate sul disco per caricarle più velocemente nelle successive inizializzazioni
|
||||
example.short=es
|
||||
example.short=e.g
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=language
|
||||
core.config.disk_cache=Disk cache
|
||||
core.config.disk_cache.tip={app} will save some data about your installed applications into the disk to load them faster in the next initializations
|
||||
core.config.updates.interval=Updates interval
|
||||
core.config.updates.interval.tip=Defines the time interval in which the update-checking for the installed applications will happen ( in SECONDS )
|
||||
core.config.downloads=downloads
|
||||
core.config.download.icons=Icons
|
||||
core.config.download.icons.tip=If the application icons should be downloaded and displayed on the table
|
||||
core.config.download.multithreaded=Parallelism
|
||||
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with parallelism / multi-thread (faster). At the moment only the aria2 application is supported
|
||||
locale.en=inglese
|
||||
locale.es=spagnolo
|
||||
locale.pt=portoghese
|
||||
@@ -188,4 +195,5 @@ locale.ca=catalan
|
||||
locale.de=tedesco
|
||||
locale.it=italiano
|
||||
interval=intervallo
|
||||
installation=installazione
|
||||
installation=installazione
|
||||
download=download
|
||||
@@ -227,6 +227,13 @@ core.config.tab_label=geral
|
||||
core.config.locale.label=idioma
|
||||
core.config.disk_cache=Cache em disco
|
||||
core.config.disk_cache.tip={app} gravará alguns dados sobre seus aplicativos instalados no disco para que eles sejam carregados rapidamente nas próximas inicializações
|
||||
core.config.updates.interval=Intervalo de atualizações
|
||||
core.config.updates.interval.tip=Define o intervalo de tempo em que ocorrerá a verificação de atualizações para os aplicativos instalados ( em SEGUNDOS )
|
||||
core.config.downloads=downloads
|
||||
core.config.download.icons=Ícones
|
||||
core.config.download.icons.tip=Se os ícones dos aplicativos devem ser baixados e exibidos na tabela
|
||||
core.config.download.multithreaded=Paralelismo
|
||||
core.config.download.multithreaded.tip=Se os aplicativos, pacotes e arquivos devem ser baixados através de uma ferramenta que trabalha com paralelismo / multi-thread ( mais rápido ). No momento somente o aplicativo aria2 é suportado.
|
||||
locale.en=inglês
|
||||
locale.es=espanhol
|
||||
locale.pt=português
|
||||
@@ -234,4 +241,5 @@ locale.ca=catalão
|
||||
locale.de=alemão
|
||||
locale.it=italiano
|
||||
interval=intervalo
|
||||
installation=instalação
|
||||
installation=instalação
|
||||
download=download
|
||||
Reference in New Issue
Block a user