mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 02:24:16 +02:00
[ui][settings] sketch
This commit is contained in:
@@ -8,8 +8,11 @@ from bauh.api.abstract.controller import SoftwareManager, SearchResult, Applicat
|
||||
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
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import internet
|
||||
from bauh.view.core import config
|
||||
|
||||
RE_IS_URL = re.compile(r'^https?://.+')
|
||||
|
||||
@@ -398,3 +401,15 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
def get_working_managers(self):
|
||||
return [m for m in self.managers if self._can_work(m)]
|
||||
|
||||
def get_settings(self) -> ViewComponent:
|
||||
settings_forms = []
|
||||
|
||||
for man in self.managers:
|
||||
if self._can_work(man):
|
||||
man_comp = man.get_settings()
|
||||
|
||||
if man_comp:
|
||||
settings_forms.append(TabComponent(man.__class__.__name__, man_comp))
|
||||
|
||||
return TabGroupComponent(settings_forms)
|
||||
|
||||
@@ -4,11 +4,11 @@ from typing import Tuple
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QIcon, QPixmap
|
||||
from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \
|
||||
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout, QFileDialog
|
||||
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout, QFileDialog, QTabWidget
|
||||
|
||||
from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \
|
||||
TextInputComponent, FormComponent, FileChooserComponent
|
||||
from bauh.view.qt import css, view_utils
|
||||
TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, TabGroupComponent
|
||||
from bauh.view.qt import css
|
||||
from bauh.view.util import resource
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
@@ -83,6 +83,34 @@ class ComboBoxQt(QComboBox):
|
||||
self.setToolTip(self.model.value.tooltip)
|
||||
|
||||
|
||||
class RadioBoxQt(QWidget):
|
||||
|
||||
def __init__(self, model: SingleSelectComponent, parent: QWidget = None):
|
||||
super(RadioBoxQt, self).__init__(parent=parent)
|
||||
self.model = model
|
||||
|
||||
grid = QGridLayout()
|
||||
self.setLayout(grid)
|
||||
|
||||
line, col = 0, 0
|
||||
for op in model.options:
|
||||
comp = RadioButtonQt(op, model)
|
||||
comp.setText(op.label)
|
||||
comp.setToolTip(op.tooltip)
|
||||
|
||||
if model.value and model.value == op:
|
||||
self.value = comp
|
||||
comp.setChecked(True)
|
||||
|
||||
grid.addWidget(comp, line, col)
|
||||
|
||||
if col + 1 == self.model.max_per_line:
|
||||
line += 1
|
||||
col = 0
|
||||
else:
|
||||
col += 1
|
||||
|
||||
|
||||
class RadioSelectQt(QGroupBox):
|
||||
|
||||
def __init__(self, model: SingleSelectComponent):
|
||||
@@ -291,11 +319,13 @@ class FormQt(QGroupBox):
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, SingleSelectComponent):
|
||||
label = QLabel(c.label.capitalize() if c.label else '')
|
||||
field = ComboBoxQt(c)
|
||||
field = ComboBoxQt(c) if c.type == SelectViewType.COMBO else RadioBoxQt(c)
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, FileChooserComponent):
|
||||
label, field = self._new_file_chooser(c)
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, FormComponent):
|
||||
self.layout().addRow(FormQt(c, self.i18n))
|
||||
else:
|
||||
raise Exception('Unsupported component type {}'.format(c.__class__.__name__))
|
||||
|
||||
@@ -353,7 +383,18 @@ class FormQt(QGroupBox):
|
||||
return QLabel(c.label if c.label else ''), chooser
|
||||
|
||||
|
||||
def new_single_select(model: SingleSelectComponent):
|
||||
class TabGroupQt(QTabWidget):
|
||||
|
||||
def __init__(self, model: TabGroupComponent, i18n: I18n, parent: QWidget = None):
|
||||
super(TabGroupQt, self).__init__(parent=parent)
|
||||
self.model = model
|
||||
self.setTabPosition(QTabWidget.West)
|
||||
|
||||
for c in model.components:
|
||||
self.addTab(to_widget(c.content, i18n), c.label)
|
||||
|
||||
|
||||
def new_single_select(model: SingleSelectComponent) -> QWidget:
|
||||
if model.type == SelectViewType.RADIO:
|
||||
return RadioSelectQt(model)
|
||||
elif model.type == SelectViewType.COMBO:
|
||||
@@ -370,3 +411,18 @@ def new_spacer(min_width: int = None) -> QWidget:
|
||||
|
||||
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
||||
return spacer
|
||||
|
||||
|
||||
def to_widget(comp: ViewComponent, i18n: I18n, parent: QWidget = None) -> QWidget:
|
||||
if isinstance(comp, SingleSelectComponent):
|
||||
return new_single_select(comp)
|
||||
elif isinstance(comp, MultipleSelectComponent):
|
||||
return MultipleSelectQt(comp, None)
|
||||
elif isinstance(comp, TextInputComponent):
|
||||
return TextInputQt(comp)
|
||||
elif isinstance(comp, FormComponent):
|
||||
return FormQt(comp, i18n)
|
||||
elif isinstance(comp, TabGroupComponent):
|
||||
return TabGroupQt(comp, i18n, parent)
|
||||
else:
|
||||
raise Exception("Cannot render instances of " + comp.__class__.__name__)
|
||||
|
||||
@@ -3,10 +3,9 @@ from typing import List
|
||||
from PyQt5.QtCore import QSize
|
||||
from PyQt5.QtWidgets import QMessageBox, QVBoxLayout, QLabel, QWidget, QScrollArea, QFrame
|
||||
|
||||
from bauh.api.abstract.view import ViewComponent, SingleSelectComponent, MultipleSelectComponent, TextInputComponent, \
|
||||
FormComponent
|
||||
from bauh.api.abstract.view import ViewComponent
|
||||
from bauh.view.qt import css
|
||||
from bauh.view.qt.components import MultipleSelectQt, new_single_select, TextInputQt, FormQt
|
||||
from bauh.view.qt.components import to_widget
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
|
||||
@@ -43,17 +42,7 @@ class ConfirmationDialog(QMessageBox):
|
||||
height = 0
|
||||
|
||||
for idx, comp in enumerate(components):
|
||||
if isinstance(comp, SingleSelectComponent):
|
||||
inst = new_single_select(comp)
|
||||
elif isinstance(comp, MultipleSelectComponent):
|
||||
inst = MultipleSelectQt(comp, None)
|
||||
elif isinstance(comp, TextInputComponent):
|
||||
inst = TextInputQt(comp)
|
||||
elif isinstance(comp, FormComponent):
|
||||
inst = FormQt(comp, i18n)
|
||||
else:
|
||||
raise Exception("Cannot render instances of " + comp.__class__.__name__)
|
||||
|
||||
inst = to_widget(comp, i18n)
|
||||
height += inst.sizeHint().height()
|
||||
|
||||
if inst.sizeHint().width() > width:
|
||||
|
||||
29
bauh/view/qt/settings.py
Normal file
29
bauh/view/qt/settings.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QToolBar, QSizePolicy, QToolButton
|
||||
|
||||
from bauh.api.abstract.controller import SoftwareManager
|
||||
from bauh.view.qt.components import to_widget
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
|
||||
class SettingsWindow(QWidget):
|
||||
|
||||
def __init__(self, manager: SoftwareManager, i18n: I18n, parent: QWidget = None):
|
||||
super(SettingsWindow, self).__init__(parent=parent)
|
||||
self.setWindowTitle('Settings')
|
||||
self.setLayout(QVBoxLayout())
|
||||
self.manager = manager
|
||||
self.i18n = i18n
|
||||
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||
|
||||
settings_model = self.manager.get_settings()
|
||||
|
||||
self.layout().addWidget(to_widget(settings_model, i18n))
|
||||
|
||||
action_bar = QToolBar()
|
||||
action_bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
|
||||
|
||||
bt_save = QToolButton()
|
||||
bt_save.setText('Save')
|
||||
action_bar.addWidget(bt_save)
|
||||
|
||||
self.layout().addWidget(action_bar)
|
||||
@@ -17,16 +17,17 @@ from bauh.api.http import HttpClient
|
||||
from bauh.commons import user
|
||||
from bauh.commons.html import bold
|
||||
from bauh.view.core.controller import GenericSoftwareManager
|
||||
from bauh.view.qt import dialog, commons, qt_utils, root
|
||||
from bauh.view.qt import dialog, commons, qt_utils, root, view_utils
|
||||
from bauh.view.qt.about import AboutDialog
|
||||
from bauh.view.qt.apps_table import AppsTable, UpdateToggleButton
|
||||
from bauh.view.qt.components import new_spacer, InputFilter, IconButton
|
||||
from bauh.view.qt.components import new_spacer, InputFilter, IconButton, to_widget
|
||||
from bauh.view.qt.confirmation import ConfirmationDialog
|
||||
from bauh.view.qt.gem_selector import GemSelectorPanel
|
||||
from bauh.view.qt.history import HistoryDialog
|
||||
from bauh.view.qt.info import InfoDialog
|
||||
from bauh.view.qt.root import ask_root_password
|
||||
from bauh.view.qt.screenshots import ScreenshotsDialog
|
||||
from bauh.view.qt.settings import SettingsWindow
|
||||
from bauh.view.qt.styles import StylesComboBox
|
||||
from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \
|
||||
GetAppHistory, SearchPackages, InstallPackage, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \
|
||||
@@ -345,6 +346,7 @@ class ManageWindow(QWidget):
|
||||
|
||||
self.thread_warnings = ListWarnings(man=manager, i18n=i18n)
|
||||
self.thread_warnings.signal_warnings.connect(self._show_warnings)
|
||||
self.settings_window = None
|
||||
|
||||
def set_tray_icon(self, tray_icon):
|
||||
self.tray_icon = tray_icon
|
||||
@@ -1163,6 +1165,14 @@ class ManageWindow(QWidget):
|
||||
show_panel_after_restart=bool(self.tray_icon))
|
||||
gem_panel.show()
|
||||
|
||||
def show_settings_window(self):
|
||||
self.settings_window = SettingsWindow(self.manager, self.i18n)
|
||||
self.settings_window.setMinimumWidth(int(self.screen_size.width() / 4))
|
||||
self.settings_window.resize(self.size())
|
||||
self.settings_window.adjustSize()
|
||||
qt_utils.centralize(self.settings_window)
|
||||
self.settings_window.show()
|
||||
|
||||
def _show_settings_menu(self):
|
||||
menu_row = QMenu()
|
||||
|
||||
@@ -1173,6 +1183,10 @@ class ManageWindow(QWidget):
|
||||
action_gems.triggered.connect(self.show_gems_selector)
|
||||
menu_row.addAction(action_gems)
|
||||
|
||||
action_settings = QAction('Settings') # TODO
|
||||
action_settings.triggered.connect(self.show_settings_window)
|
||||
menu_row.addAction(action_settings)
|
||||
|
||||
action_about = QAction(self.i18n['manage_window.settings.about'])
|
||||
action_about.setIcon(QIcon(resource.get_path('img/about.svg')))
|
||||
action_about.triggered.connect(self._show_about)
|
||||
|
||||
Reference in New Issue
Block a user