style combo

This commit is contained in:
Vinicius Moreira
2019-09-11 19:04:56 -03:00
parent 33708f054b
commit 4b8226146e
7 changed files with 52 additions and 7 deletions

View File

@@ -33,13 +33,18 @@ context = ApplicationContext(i18n=i18n,
cache_factory=cache_factory, cache_factory=cache_factory,
disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache), disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache),
logger=logger) logger=logger)
user_config = config.read()
app = QApplication(sys.argv) app = QApplication(sys.argv)
app.setApplicationName(__app_name__) app.setApplicationName(__app_name__)
app.setApplicationVersion(__version__) app.setApplicationVersion(__version__)
app.setWindowIcon(QIcon(resource.get_path('img/logo.svg'))) 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: if not user_config.gems:
managers = gems.load_managers(context=context, locale=args.locale) managers = gems.load_managers(context=context, locale=args.locale)

View File

@@ -7,13 +7,14 @@ from bauh import __app_name__
from bauh.api.constants import HOME_PATH from bauh.api.constants import HOME_PATH
CONFIG_PATH = '{}/.config/{}'.format(HOME_PATH, __app_name__) CONFIG_PATH = '{}/.config/{}'.format(HOME_PATH, __app_name__)
FILE_PATH = '{}/config.json'.format(CONFIG_PATH) FILE_PATH = '{}/config.json'.format(CONFIG_PATH)
class Configuration: class Configuration:
def __init__(self, gems: List[str]): def __init__(self, gems: List[str] = None, style: str = None):
self.gems = gems self.gems = gems
self.style = style
def read() -> Configuration: def read() -> Configuration:

View File

@@ -109,3 +109,4 @@ proceed=proceed
change=change change=change
exit=exit exit=exit
manage_window.settings.gems=Application types manage_window.settings.gems=Application types
style=style

View File

@@ -111,3 +111,4 @@ proceed=continuar
change=cambiar change=cambiar
exit=salir exit=salir
manage_window.settings.gems=Tipos de aplicativos manage_window.settings.gems=Tipos de aplicativos
style=estilo

View File

@@ -111,3 +111,4 @@ proceed=continuar
change=alterar change=alterar
exit=sair exit=sair
manage_window.settings.gems=Tipos de aplicativos manage_window.settings.gems=Tipos de aplicativos
style=estilo

28
bauh/view/qt/styles.py Normal file
View File

@@ -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)

View File

@@ -4,7 +4,7 @@ from typing import List, Type, Set
from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal
from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap, QCursor 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 QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QPushButton, QComboBox, QMenu, QAction
from bauh.api.abstract.cache import MemoryCache 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.history import HistoryDialog
from bauh.view.qt.info import InfoDialog from bauh.view.qt.info import InfoDialog
from bauh.view.qt.root import is_root, ask_root_password 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, \ from bauh.view.qt.thread import UpdateSelectedApps, RefreshApps, UninstallApp, DowngradeApp, GetAppInfo, \
GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \ GetAppHistory, SearchApps, InstallApp, AnimateProgress, VerifyModels, FindSuggestions, ListWarnings, \
AsyncAction, RunApp, ApplyFilters, CustomAction AsyncAction, RunApp, ApplyFilters, CustomAction
@@ -225,6 +226,7 @@ class ManageWindow(QWidget):
self.toolbar_bottom = QToolBar() self.toolbar_bottom = QToolBar()
self.toolbar_bottom.setIconSize(QSize(16, 16)) self.toolbar_bottom.setIconSize(QSize(16, 16))
self.toolbar_bottom.setStyleSheet('QToolBar { spacing: 3px }')
self.label_updates = QLabel() self.label_updates = QLabel()
self.ref_label_updates = self.toolbar_bottom.addWidget(self.label_updates) self.ref_label_updates = self.toolbar_bottom.addWidget(self.label_updates)
@@ -237,6 +239,10 @@ class ManageWindow(QWidget):
self.toolbar_bottom.addWidget(new_spacer()) 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') 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) 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.stop = False
self.thread_animate_progress.start() self.thread_animate_progress.start()
self.ref_progress_bar.setVisible(True) self.ref_progress_bar.setVisible(True)
self.ref_combo_styles.setVisible(False)
self.label_status.setText(action_label + "...") self.label_status.setText(action_label + "...")
self.ref_bt_upgrade.setVisible(False) self.ref_bt_upgrade.setVisible(False)
@@ -744,6 +751,7 @@ class ManageWindow(QWidget):
self.combo_filter_type.setEnabled(False) self.combo_filter_type.setEnabled(False)
def finish_action(self): def finish_action(self):
self.ref_combo_styles.setVisible(True)
self.thread_animate_progress.stop = True self.thread_animate_progress.stop = True
self.thread_animate_progress.wait() self.thread_animate_progress.wait()
self.ref_progress_bar.setVisible(False) self.ref_progress_bar.setVisible(False)