mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[ui][settings] supported types working
This commit is contained in:
@@ -10,10 +10,13 @@ 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
|
||||
InputOption, PanelComponent, SelectViewType
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import internet
|
||||
from bauh.commons.config import save_config
|
||||
from bauh.view.core import config
|
||||
from bauh.view.core.config import read_config
|
||||
from bauh.view.util import translation
|
||||
|
||||
RE_IS_URL = re.compile(r'^https?://.+')
|
||||
|
||||
@@ -403,8 +406,38 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
def get_working_managers(self):
|
||||
return [m for m in self.managers if self._can_work(m)]
|
||||
|
||||
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],
|
||||
type_=SelectViewType.COMBO,
|
||||
id_='locale')
|
||||
|
||||
return TabComponent(self.i18n['core.config.tab_label'].capitalize(), PanelComponent([FormComponent([select_locale])]), 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()
|
||||
|
||||
if locale != self.i18n.current_key:
|
||||
core_config['locale'] = locale
|
||||
|
||||
try:
|
||||
config.save(core_config)
|
||||
return True, None
|
||||
except:
|
||||
return False, [traceback.format_exc()]
|
||||
|
||||
def get_settings(self) -> ViewComponent:
|
||||
settings_forms = []
|
||||
tabs = []
|
||||
|
||||
tabs.append(self._gen_settings_panel())
|
||||
|
||||
for man in self.managers:
|
||||
if self._can_work(man):
|
||||
@@ -413,14 +446,22 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
if man_comp:
|
||||
modname = man.__module__.split('.')[-2]
|
||||
icon_path = "{r}/gems/{n}/resources/img/{n}.svg".format(r=ROOT_DIR, n=modname)
|
||||
settings_forms.append(TabComponent(None, man_comp, icon_path, modname))
|
||||
tabs.append(TabComponent(None, man_comp, icon_path, modname))
|
||||
|
||||
return TabGroupComponent(settings_forms)
|
||||
return TabGroupComponent(tabs)
|
||||
|
||||
def save_settings(self, component: TabGroupComponent) -> Tuple[bool, List[str]]:
|
||||
|
||||
saved, warnings = True, []
|
||||
|
||||
success, errors = self._save_settings(component.get_tab('core').content)
|
||||
|
||||
if not success:
|
||||
saved = False
|
||||
|
||||
if errors:
|
||||
warnings.extend(errors)
|
||||
|
||||
for man in self.managers:
|
||||
if man:
|
||||
modname = man.__module__.split('.')[-2]
|
||||
@@ -429,12 +470,15 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
if not tab:
|
||||
self.logger.warning("Tab for {} was not found".format(man.__class__.__name__))
|
||||
else:
|
||||
success, errors = man.save_settings(tab.content)
|
||||
res = man.save_settings(tab.content)
|
||||
|
||||
if not success:
|
||||
saved = False
|
||||
if res:
|
||||
success, errors = res[0], res[1]
|
||||
|
||||
if errors:
|
||||
warnings.extend(errors)
|
||||
if not success:
|
||||
saved = False
|
||||
|
||||
if errors:
|
||||
warnings.extend(errors)
|
||||
|
||||
return saved, warnings
|
||||
|
||||
@@ -88,6 +88,7 @@ class RadioBoxQt(QWidget):
|
||||
def __init__(self, model: SingleSelectComponent, parent: QWidget = None):
|
||||
super(RadioBoxQt, self).__init__(parent=parent)
|
||||
self.model = model
|
||||
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||
|
||||
grid = QGridLayout()
|
||||
self.setLayout(grid)
|
||||
@@ -95,6 +96,7 @@ class RadioBoxQt(QWidget):
|
||||
line, col = 0, 0
|
||||
for op in model.options:
|
||||
comp = RadioButtonQt(op, model)
|
||||
comp.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||
comp.setText(op.label)
|
||||
comp.setToolTip(op.tooltip)
|
||||
|
||||
@@ -411,7 +413,7 @@ class TabGroupQt(QTabWidget):
|
||||
self.setTabPosition(QTabWidget.North)
|
||||
|
||||
for c in model.tabs:
|
||||
icon = QIcon(c.icon_path) if c.icon_path else None
|
||||
icon = QIcon(c.icon_path) if c.icon_path else QIcon()
|
||||
self.addTab(to_widget(c.content, i18n), icon, c.label)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QToolBar, QSizePolicy, QToolBu
|
||||
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
from bauh.api.abstract.view import MessageType
|
||||
from bauh.view.qt import dialog
|
||||
from bauh.view.qt import dialog, css
|
||||
from bauh.view.qt.components import to_widget, new_spacer
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
@@ -13,7 +13,7 @@ class SettingsWindow(QWidget):
|
||||
|
||||
def __init__(self, manager: SoftwareManager, i18n: I18n, parent: QWidget = None):
|
||||
super(SettingsWindow, self).__init__(parent=parent)
|
||||
self.setWindowTitle('Settings')
|
||||
self.setWindowTitle(i18n['settings'].capitalize())
|
||||
self.setLayout(QVBoxLayout())
|
||||
self.manager = manager
|
||||
self.i18n = i18n
|
||||
@@ -33,10 +33,11 @@ class SettingsWindow(QWidget):
|
||||
|
||||
action_bar.addWidget(new_spacer())
|
||||
|
||||
bt_save = QPushButton()
|
||||
bt_save.setText(self.i18n['save'].capitalize())
|
||||
bt_save.clicked.connect(self._save_settings)
|
||||
action_bar.addWidget(bt_save)
|
||||
bt_change = QPushButton()
|
||||
bt_change.setStyleSheet(css.OK_BUTTON)
|
||||
bt_change.setText(self.i18n['change'].capitalize())
|
||||
bt_change.clicked.connect(self._save_settings)
|
||||
action_bar.addWidget(bt_change)
|
||||
|
||||
self.layout().addWidget(action_bar)
|
||||
|
||||
@@ -47,10 +48,10 @@ class SettingsWindow(QWidget):
|
||||
self.close()
|
||||
else:
|
||||
msg = StringIO()
|
||||
msg.write("It was not possible to properly the settings\n")
|
||||
msg.write("<p>It was not possible to properly save the settings</p>")
|
||||
|
||||
for w in warnings:
|
||||
msg.write(w + '\n')
|
||||
msg.write('<p style="font-weight: bold">* ' + w + '</p><br/>')
|
||||
|
||||
msg.seek(0)
|
||||
|
||||
|
||||
@@ -1183,7 +1183,7 @@ class ManageWindow(QWidget):
|
||||
action_gems.triggered.connect(self.show_gems_selector)
|
||||
menu_row.addAction(action_gems)
|
||||
|
||||
action_settings = QAction('Settings') # TODO
|
||||
action_settings = QAction(self.i18n['settings'].capitalize())
|
||||
action_settings.triggered.connect(self.show_settings_window)
|
||||
menu_row.addAction(action_settings)
|
||||
|
||||
|
||||
@@ -219,4 +219,15 @@ file_chooser.title=Selector de fitxers
|
||||
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
|
||||
user=usuari
|
||||
example.short=ex
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=idioma
|
||||
locale.en=anglès
|
||||
locale.es=castellà
|
||||
locale.pt=portuguès
|
||||
locale.ca=català
|
||||
locale.de=alemany
|
||||
locale.it=italià
|
||||
interval=interval
|
||||
installation=instal·lació
|
||||
@@ -174,4 +174,15 @@ message.file.not_exist=Datei existiert nicht
|
||||
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
|
||||
user=Benutzer
|
||||
example.short=z.B
|
||||
core.config.tab_label=Allgemeines
|
||||
core.config.locale.label=Sprache
|
||||
locale.en=englisch
|
||||
locale.es=spanisch
|
||||
locale.pt=portugiesisch
|
||||
locale.ca=Katalanisch
|
||||
locale.de=deutsch
|
||||
locale.it=italienisch
|
||||
interval=intervall
|
||||
installation=Installation
|
||||
@@ -178,4 +178,15 @@ message.file.not_exist=File does not exist
|
||||
message.file.not_exist.body=The file {} seems not to exist
|
||||
development=development
|
||||
icon_button.tooltip.disabled=This action is unavailable
|
||||
user=user
|
||||
user=user
|
||||
example.short=e.g
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=language
|
||||
locale.en=english
|
||||
locale.es=spanish
|
||||
locale.pt=portuguese
|
||||
locale.ca=catalan
|
||||
locale.de=german
|
||||
locale.it=italian
|
||||
interval=interval
|
||||
installation=installation
|
||||
@@ -218,4 +218,15 @@ file_chooser.title=Selector de archivos
|
||||
message.file.not_exist=Archivo no existe
|
||||
message.file.not_exist.body=El archivo {} parece no existir
|
||||
icon_button.tooltip.disabled=This action is unavailable
|
||||
user=usuario
|
||||
user=usuario
|
||||
example.short=p.ej
|
||||
core.config.tab_label=general
|
||||
core.config.locale.label=idioma
|
||||
locale.es=inglés
|
||||
locale.es=español
|
||||
locale.pt=portugués
|
||||
locale.ca=catalán
|
||||
locale.de=alemán
|
||||
locale.it=italiano
|
||||
interval=intervalo
|
||||
installation=instalación
|
||||
@@ -175,4 +175,15 @@ message.file.not_exist=File non esiste
|
||||
message.file.not_exist.body=Il file {} sembra non esistere
|
||||
development=sviluppo
|
||||
icon_button.tooltip.disabled=Questa azione non è disponibile
|
||||
user=utente
|
||||
user=utente
|
||||
core.config.tab_label=generale
|
||||
core.config.locale.label=idioma
|
||||
example.short=es
|
||||
locale.en=inglese
|
||||
locale.es=spagnolo
|
||||
locale.pt=portoghese
|
||||
locale.ca=catalan
|
||||
locale.de=tedesco
|
||||
locale.it=italiano
|
||||
interval=intervallo
|
||||
installation=installazione
|
||||
@@ -221,4 +221,15 @@ file_chooser.title=Seletor arquivos
|
||||
message.file.not_exist=Arquivo não existe
|
||||
message.file.not_exist.body=O arquivo {} parece não existir
|
||||
icon_button.tooltip.disabled=Esta ação está indisponível
|
||||
user=usuário
|
||||
user=usuário
|
||||
example.short=ex
|
||||
core.config.tab_label=geral
|
||||
core.config.locale.label=idioma
|
||||
locale.en=inglês
|
||||
locale.es=espanhol
|
||||
locale.pt=português
|
||||
locale.ca=catalão
|
||||
locale.de=alemão
|
||||
locale.it=italiano
|
||||
interval=intervalo
|
||||
installation=instalação
|
||||
@@ -1,6 +1,9 @@
|
||||
import glob
|
||||
import locale
|
||||
from typing import Tuple
|
||||
import traceback
|
||||
from typing import Tuple, Set
|
||||
|
||||
from colorama import Fore
|
||||
|
||||
from bauh.view.util import resource
|
||||
|
||||
@@ -38,6 +41,11 @@ class I18n(dict):
|
||||
return res
|
||||
|
||||
|
||||
def get_available_keys() -> Set[str]:
|
||||
locale_dir = resource.get_path('locale')
|
||||
return {file.split('/')[-1] for file in glob.glob(locale_dir + '/*')}
|
||||
|
||||
|
||||
def get_locale_keys(key: str = None, locale_dir: str = resource.get_path('locale')) -> Tuple[str, dict]:
|
||||
|
||||
locale_path = None
|
||||
@@ -65,8 +73,9 @@ def get_locale_keys(key: str = None, locale_dir: str = resource.get_path('locale
|
||||
|
||||
locale_obj = {}
|
||||
for line in locale_keys:
|
||||
if line:
|
||||
keyval = line.strip().split('=')
|
||||
line_strip = line.strip()
|
||||
if line_strip:
|
||||
keyval = line_strip.split('=')
|
||||
locale_obj[keyval[0].strip()] = keyval[1].strip()
|
||||
|
||||
return locale_path.split('/')[-1], locale_obj
|
||||
|
||||
Reference in New Issue
Block a user