[improvement][settings] new property 'ui.scale_factor' responsible for defining the interface scale factor

This commit is contained in:
Vinicius Moreira
2020-06-24 12:23:05 -03:00
parent cab309b023
commit 1088966991
16 changed files with 117 additions and 5 deletions

View File

@@ -22,6 +22,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- big refactoring regarding the components states (now it is easier to maintain the code)
- some components compatibility with the system's color scheme
- allowing "Oxygen" as a default style
- Settings
- new property **ui.scale_factor** responsible for defining the interface scale factor. Useful if bauh looks
small on the screen. It can be changed through the settings window (Interface tab):
<p align="center">
<img src="https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/releases/0.9.6/scale.png">
</p>
### Fixes
- AppImage

View File

@@ -282,6 +282,7 @@ ui:
updates_icon: null # defines a path to a custom icon indicating updates
hdpi: true # enables HDPI rendering improvements. Use 'false' to disable them if you think the interface looks strange
auto_scale: false # activates Qt auto screen scale factor (QT_AUTO_SCREEN_SCALE_FACTOR). It fixes scaling issues for some desktop environments ( like Gnome )
scale_factor: 1.0 # defines the interface display scaling factor (Qt). Raise the value to raise the interface size. The settings window display this value as a percentage (e.g: 1.0 -> 100%).
updates:
check_interval: 30 # the updates checking interval in SECONDS
ask_for_reboot: true # if a dialog asking for a system reboot should be displayed after a successful upgrade

View File

@@ -210,3 +210,17 @@ class TabGroupComponent(ViewComponent):
def get_tab(self, id_: str) -> TabComponent:
if self.tab_map:
return self.tab_map.get(id_)
class RangeInputComponent(InputViewComponent):
def __init__(self, id_: str, label: str, tooltip: str, min_value: float, max_value: float,
step_value: float, value: float = None, max_width: int = None):
super(RangeInputComponent, self).__init__(id_=id_)
self.label = label
self.tooltip = tooltip
self.min = min_value
self.max = max_value
self.step = step_value
self.value = value
self.max_width = max_width

View File

@@ -1,5 +1,6 @@
import os
import sys
import traceback
import urllib3
from PyQt5.QtCore import QCoreApplication, Qt
@@ -25,6 +26,13 @@ def main(tray: bool = False):
os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1'
logger.info("Auto screen scale factor activated")
try:
scale_factor = float(app_config['ui']['scale_factor'])
os.environ['QT_SCALE_FACTOR'] = str(scale_factor)
logger.info("Scale factor set to {}".format(scale_factor))
except:
traceback.print_exc()
if bool(app_config['ui']['hdpi']):
logger.info("HDPI settings activated")
QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

View File

@@ -39,7 +39,8 @@ def read_config(update_file: bool = False) -> dict:
},
'style': None,
'hdpi': True,
"auto_scale": False
"auto_scale": False,
"scale_factor": 1.0
},
'download': {

View File

@@ -11,7 +11,7 @@ from bauh.api.abstract.controller import SoftwareManager
from bauh.api.abstract.download import FileDownloader
from bauh.api.abstract.view import ViewComponent, TabComponent, InputOption, TextComponent, MultipleSelectComponent, \
PanelComponent, FormComponent, TabGroupComponent, SingleSelectComponent, SelectViewType, TextInputComponent, \
FileChooserComponent
FileChooserComponent, RangeInputComponent
from bauh.view.core import config, timeshift
from bauh.view.core.config import read_config
from bauh.view.core.downloader import AdaptableFileDownloader
@@ -191,6 +191,19 @@ class GenericSettingsManager:
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().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()])
@@ -226,7 +239,7 @@ class GenericSettingsManager:
max_width=default_width,
value=core_config['download']['icons'])
sub_comps = [FormComponent([select_hdpi, select_ascale, select_dicons, select_style, input_maxd], spaces=False)]
sub_comps = [FormComponent([select_hdpi, select_ascale, select_scale, select_dicons, select_style, input_maxd], spaces=False)]
return TabComponent(self.i18n['core.config.tab.ui'].capitalize(), PanelComponent(sub_comps), None, 'core.ui')
def _gen_general_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
@@ -388,6 +401,7 @@ class GenericSettingsManager:
self.logger.info("Deleting environment variable QT_AUTO_SCREEN_SCALE_FACTOR")
del os.environ['QT_AUTO_SCREEN_SCALE_FACTOR']
core_config['ui']['scale_factor'] = ui_form.get_component('scalef').value / 100
core_config['ui']['table']['max_displayed'] = ui_form.get_component('table_max').get_int_value()
style = ui_form.get_component('style').get_selected()

View File

@@ -9,11 +9,11 @@ from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon, QPixmap, QIntValidator, QCursor
from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout, QFileDialog, QTabWidget, QVBoxLayout, \
QSlider, QScrollArea, QFrame, QAction
QSlider, QScrollArea, QFrame, QAction, QSpinBox
from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \
TextInputComponent, FormComponent, FileChooserComponent, ViewComponent, TabGroupComponent, PanelComponent, \
TwoStateButtonComponent, TextComponent, SpacerComponent
TwoStateButtonComponent, TextComponent, SpacerComponent, RangeInputComponent
from bauh.view.qt import css
from bauh.view.qt.colors import RED
from bauh.view.util import resource
@@ -699,6 +699,9 @@ class FormQt(QGroupBox):
label = self._new_label(c)
field = FormComboBoxQt(c) if c.type == SelectViewType.COMBO else FormRadioSelectQt(c)
self.layout().addRow(label, self._wrap(field, c))
elif isinstance(c, RangeInputComponent):
label = self._new_label(c)
self.layout().addRow(label, self._wrap(self._new_range_input(c), c))
elif isinstance(c, FileChooserComponent):
label, field = self._new_file_chooser(c)
self.layout().addRow(label, field)
@@ -712,6 +715,8 @@ class FormQt(QGroupBox):
self.layout().addRow(label, FormMultipleSelectQt(c))
elif isinstance(c, TextComponent):
self.layout().addRow(self._new_label(c), QWidget())
elif isinstance(c, RangeInputComponent):
self.layout()
else:
raise Exception('Unsupported component type {}'.format(c.__class__.__name__))
@@ -792,6 +797,22 @@ class FormQt(QGroupBox):
return label, self._wrap(line_edit, c)
def _new_range_input(self, model: RangeInputComponent) -> QSpinBox:
spinner = QSpinBox()
spinner.setMinimum(model.min)
spinner.setMaximum(model.max)
spinner.setSingleStep(model.step)
spinner.setValue(model.value if model.value is not None else model.min)
if model.tooltip:
spinner.setToolTip(model.tooltip)
def _update_value():
model.value = spinner.value()
spinner.valueChanged.connect(_update_value)
return spinner
def _wrap(self, comp: QWidget, model: ViewComponent) -> QWidget:
field_container = QWidget()
field_container.setLayout(QHBoxLayout())
@@ -904,6 +925,8 @@ def to_widget(comp: ViewComponent, i18n: I18n, parent: QWidget = None) -> QWidge
return MultipleSelectQt(comp, None)
elif isinstance(comp, TextInputComponent):
return TextInputQt(comp)
elif isinstance(comp, RangeInputComponent):
return RangeInputQt(comp)
elif isinstance(comp, FormComponent):
return FormQt(comp, i18n)
elif isinstance(comp, TabGroupComponent):
@@ -924,3 +947,32 @@ def to_widget(comp: ViewComponent, i18n: I18n, parent: QWidget = None) -> QWidge
return new_spacer()
else:
raise Exception("Cannot render instances of " + comp.__class__.__name__)
class RangeInputQt(QGroupBox):
def __init__(self, model: RangeInputComponent):
super(RangeInputQt, self).__init__()
self.model = model
self.setLayout(QGridLayout())
self.setStyleSheet('QGridLayout {margin-left: 0} QLabel { font-weight: bold}')
self.layout().addWidget(QLabel(model.label.capitalize() + ' :' if model.label else ''), 0, 0)
if self.model.max_width > 0:
self.setMaximumWidth(self.model.max_width)
self.spinner = QSpinBox()
self.spinner.setMinimum(model.min)
self.spinner.setMaximum(model.max)
self.spinner.setSingleStep(model.step)
self.spinner.setValue(model.value if model.value is not None else model.min)
if model.tooltip:
self.spinner.setToolTip(model.tooltip)
self.layout().addWidget(self.spinner, 0, 1)
self.spinner.valueChanged.connect(self._update_value)
def _update_value(self):
self.model.value = self.spinner.value()

View File

@@ -231,6 +231,8 @@ core.config.ui.hdpi=HDPI
core.config.ui.hdpi.tip=If improvements related to HDPI resolutions should be activated
core.config.ui.max_displayed=Applications displayed
core.config.ui.max_displayed.tip=Maximum number of applications displayed on the table
core.config.ui.scale_factor=Scale
core.config.ui.scale_factor.tip=It defines the interface display scaling factor (Qt). Raise the value to raise the interface size. Restart required.
core.config.ui.style.default=Default
core.config.ui.tray.default_icon=Default icon
core.config.ui.tray.default_icon.tip=The default icon for {app} displayed on the tray

View File

@@ -230,6 +230,8 @@ core.config.ui.hdpi=HiDPI
core.config.ui.hdpi.tip=Falls aktiviert werden Optimierungen für hochauflösende Displays vorgenommen
core.config.ui.max_displayed=Anzahl der Anwendungen
core.config.ui.max_displayed.tip=Maximale Anzahl von Anwendungen, die in der Tabelle angezeigt werden
core.config.ui.scale_factor=Scale
core.config.ui.scale_factor.tip=It defines the interface display scaling factor (Qt). Raise the value to raise the interface size. Restart required.
core.config.ui.style.default=Default
core.config.ui.tray.default_icon=Anwendungs-Icon
core.config.ui.tray.default_icon.tip=The default icon for {app} displayed on the tray

View File

@@ -230,6 +230,8 @@ core.config.ui.hdpi.tip=If improvements related to HDPI resolutions should be ac
core.config.ui.hdpi=HDPI
core.config.ui.max_displayed.tip=Maximum number of applications displayed on the table
core.config.ui.max_displayed=Applications displayed
core.config.ui.scale_factor=Scale
core.config.ui.scale_factor.tip=It defines the interface display scaling factor (Qt). Raise the value to raise the interface size. Restart required.
core.config.ui.style.default=Default
core.config.ui.tray.default_icon.tip=The default icon for {app} displayed on the tray
core.config.ui.tray.default_icon=Default icon

View File

@@ -231,6 +231,8 @@ core.config.ui.hdpi=HDPI
core.config.ui.hdpi.tip=Si se deben activar las mejoras relacionadas con las resoluciones HDPI
core.config.ui.max_displayed=Aplicaciones mostradas
core.config.ui.max_displayed.tip=Número máximo de aplicaciones que se muestran en la tabla
core.config.ui.scale_factor=Escala
core.config.ui.scale_factor.tip=Define el factor de escala de visualización de la interfaz (Qt). Aumente el valor para aumentar el tamaño de la interfaz. Reinicio requerido.
core.config.ui.style.default=Predeterminado
core.config.ui.tray.default_icon=Ícono predeterminado
core.config.ui.tray.default_icon.tip=El icono predeterminado que se muestra en la bandeja

View File

@@ -231,6 +231,8 @@ core.config.ui.hdpi=HDPI
core.config.ui.hdpi.tip=If improvements related to HDPI resolutions should be activated
core.config.ui.max_displayed=Applications displayed
core.config.ui.max_displayed.tip=Maximum number of applications displayed on the table
core.config.ui.scale_factor=Scale
core.config.ui.scale_factor.tip=It defines the interface display scaling factor (Qt). Raise the value to raise the interface size. Restart required.
core.config.ui.style.default=Default
core.config.ui.tray.default_icon=Default icon
core.config.ui.tray.default_icon.tip=The default icon for {app} displayed on the tray

View File

@@ -230,6 +230,8 @@ core.config.ui.hdpi.tip=Se melhorias para resoluções HDPI devem ser ativadas
core.config.ui.hdpi=HDPI
core.config.ui.max_displayed.tip=Número máximo de aplicativos exibidos na tabela
core.config.ui.max_displayed=Aplicativos exibidos
core.config.ui.scale_factor=Escala
core.config.ui.scale_factor.tip=Define o fator de escala de exibição da interface (Qt). Aumente o valor para aumentar o tamanho da interface. Reinicialização necessária.
core.config.ui.style.default=Padrão
core.config.ui.tray.default_icon.tip=O ícone padrão exibido na bandeja
core.config.ui.tray.default_icon=Ícone padrão

View File

@@ -230,6 +230,8 @@ core.config.ui.hdpi=HDPI
core.config.ui.hdpi.tip=Если улучшения, связанные с разрешением HDPI должны быть активированы
core.config.ui.max_displayed=Отображаемые приложения
core.config.ui.max_displayed.tip=Максимальное количество приложений, отображаемых в таблице
core.config.ui.scale_factor=Scale
core.config.ui.scale_factor.tip=It defines the interface display scaling factor (Qt). Raise the value to raise the interface size. Restart required.
core.config.ui.style.default=Default
core.config.ui.tray.default_icon=Значок по умолчанию
core.config.ui.tray.default_icon.tip=Значок по умолчанию для {app}, отображаемый в трее

View File

@@ -230,6 +230,8 @@ core.config.ui.hdpi.tip=HDPI çözünürlükleri ile ilgili iyileştirmeler etki
core.config.ui.hdpi=HDPI
core.config.ui.max_displayed.tip=Tabloda görüntülenen azami uygulama sayısı
core.config.ui.max_displayed=Görüntülenen uygulamalar
core.config.ui.scale_factor=Scale
core.config.ui.scale_factor.tip=It defines the interface display scaling factor (Qt). Raise the value to raise the interface size. Restart required.
core.config.ui.style.default=Default
core.config.ui.tray.default_icon.tip=Tepside görüntülenen {app} için varsayılan simge
core.config.ui.tray.default_icon=Varsayılan simge

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB