From 4b8226146e73d807bc988e12bd9db19b671cd0bb Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Wed, 11 Sep 2019 19:04:56 -0300 Subject: [PATCH] style combo --- bauh/app.py | 7 ++++++- bauh/core/config.py | 5 +++-- bauh/resources/locale/en | 3 ++- bauh/resources/locale/es | 3 ++- bauh/resources/locale/pt | 3 ++- bauh/view/qt/styles.py | 28 ++++++++++++++++++++++++++++ bauh/view/qt/window.py | 10 +++++++++- 7 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 bauh/view/qt/styles.py diff --git a/bauh/app.py b/bauh/app.py index 27210f9e..b4dcc9c9 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -33,13 +33,18 @@ context = ApplicationContext(i18n=i18n, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache), logger=logger) +user_config = config.read() app = QApplication(sys.argv) app.setApplicationName(__app_name__) app.setApplicationVersion(__version__) app.setWindowIcon(QIcon(resource.get_path('img/logo.svg'))) -user_config = config.read() +if user_config.style: + app.setStyle(user_config.style) +else: + if app.style().objectName().lower() not in {'fusion', 'breeze'}: + app.setStyle('fusion') if not user_config.gems: managers = gems.load_managers(context=context, locale=args.locale) diff --git a/bauh/core/config.py b/bauh/core/config.py index c101cd78..d252009b 100644 --- a/bauh/core/config.py +++ b/bauh/core/config.py @@ -7,13 +7,14 @@ from bauh import __app_name__ from bauh.api.constants import HOME_PATH CONFIG_PATH = '{}/.config/{}'.format(HOME_PATH, __app_name__) -FILE_PATH = '{}/config.json'.format(CONFIG_PATH) +FILE_PATH = '{}/config.json'.format(CONFIG_PATH) class Configuration: - def __init__(self, gems: List[str]): + def __init__(self, gems: List[str] = None, style: str = None): self.gems = gems + self.style = style def read() -> Configuration: diff --git a/bauh/resources/locale/en b/bauh/resources/locale/en index c74f9f82..390ebd81 100644 --- a/bauh/resources/locale/en +++ b/bauh/resources/locale/en @@ -108,4 +108,5 @@ gem_selector.question=What types of applications do you want to find here ? proceed=proceed change=change exit=exit -manage_window.settings.gems=Application types \ No newline at end of file +manage_window.settings.gems=Application types +style=style \ No newline at end of file diff --git a/bauh/resources/locale/es b/bauh/resources/locale/es index 877f4496..5b68bfbc 100644 --- a/bauh/resources/locale/es +++ b/bauh/resources/locale/es @@ -110,4 +110,5 @@ gem_selector.question=¿Qué tipos de aplicativos quieres encontrar aquí? proceed=continuar change=cambiar exit=salir -manage_window.settings.gems=Tipos de aplicativos \ No newline at end of file +manage_window.settings.gems=Tipos de aplicativos +style=estilo \ No newline at end of file diff --git a/bauh/resources/locale/pt b/bauh/resources/locale/pt index d83fcd4c..69a6820a 100644 --- a/bauh/resources/locale/pt +++ b/bauh/resources/locale/pt @@ -110,4 +110,5 @@ gem_selector.question=Quais tipos de aplicativos você quer encontrar por aqui ? proceed=continuar change=alterar exit=sair -manage_window.settings.gems=Tipos de aplicativos \ No newline at end of file +manage_window.settings.gems=Tipos de aplicativos +style=estilo \ No newline at end of file diff --git a/bauh/view/qt/styles.py b/bauh/view/qt/styles.py new file mode 100644 index 00000000..f2097b61 --- /dev/null +++ b/bauh/view/qt/styles.py @@ -0,0 +1,28 @@ +from PyQt5.QtWidgets import QComboBox, QApplication, QStyleFactory, QWidget + +from bauh.core import config + + +class StylesComboBox(QComboBox): + + def __init__(self, parent: QWidget, i18n: dict): + super(StylesComboBox, self).__init__(parent=parent) + self.app = QApplication.instance() + self.styles = [] + + for idx, style in enumerate(QStyleFactory.keys()): + self.styles.append(style) + self.addItem('{}: {}'.format(i18n['style'].capitalize(), style), style) + + if style.lower() == self.app.style().objectName(): + self.setCurrentIndex(idx) + + self.currentIndexChanged.connect(self.change_style) + + def change_style(self, idx: int): + style = self.styles[idx] + self.app.setStyle(style) + + user_config = config.read() + user_config.style = style + config.save(user_config) diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 139c7965..39b1e313 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -4,7 +4,7 @@ from typing import List, Type, Set from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap, QCursor -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \ +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolBar, \ QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QPushButton, QComboBox, QMenu, QAction from bauh.api.abstract.cache import MemoryCache @@ -24,6 +24,7 @@ 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 is_root, ask_root_password +from bauh.view.qt.styles import StylesComboBox from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \ GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \ AsyncAction, RunApp, ApplyFilters, CustomAction @@ -225,6 +226,7 @@ class ManageWindow(QWidget): self.toolbar_bottom = QToolBar() self.toolbar_bottom.setIconSize(QSize(16, 16)) + self.toolbar_bottom.setStyleSheet('QToolBar { spacing: 3px }') self.label_updates = QLabel() self.ref_label_updates = self.toolbar_bottom.addWidget(self.label_updates) @@ -237,6 +239,10 @@ class ManageWindow(QWidget): self.toolbar_bottom.addWidget(new_spacer()) + combo_styles = StylesComboBox(self, i18n) + combo_styles.setStyleSheet('QComboBox {font-size: 12px;}') + self.ref_combo_styles = self.toolbar_bottom.addWidget(combo_styles) + bt_settings = IconButton(icon_path=resource.get_path('img/app_settings.svg'), action=self._show_settings_menu, background='#12ABAB') self.ref_bt_settings = self.toolbar_bottom.addWidget(bt_settings) @@ -720,6 +726,7 @@ class ManageWindow(QWidget): self.thread_animate_progress.stop = False self.thread_animate_progress.start() self.ref_progress_bar.setVisible(True) + self.ref_combo_styles.setVisible(False) self.label_status.setText(action_label + "...") self.ref_bt_upgrade.setVisible(False) @@ -744,6 +751,7 @@ class ManageWindow(QWidget): self.combo_filter_type.setEnabled(False) def finish_action(self): + self.ref_combo_styles.setVisible(True) self.thread_animate_progress.stop = True self.thread_animate_progress.wait() self.ref_progress_bar.setVisible(False)