restarting the app when changing the style to avoid GUI bugs

This commit is contained in:
Vinicius Moreira
2019-09-12 12:12:25 -03:00
parent 2485d064e0
commit 40a8d19584
10 changed files with 79 additions and 33 deletions

View File

@@ -1,14 +1,21 @@
from PyQt5.QtWidgets import QComboBox, QApplication, QStyleFactory, QWidget
from PyQt5.QtWidgets import QComboBox, QStyleFactory, QWidget, QApplication
from bauh import __app_name__
from bauh.commons.html import bold
from bauh.core import config
from bauh.util import util
from bauh.view.qt import dialog
class StylesComboBox(QComboBox):
def __init__(self, parent: QWidget, i18n: dict):
def __init__(self, parent: QWidget, i18n: dict, show_panel_after_restart: bool):
super(StylesComboBox, self).__init__(parent=parent)
self.app = QApplication.instance()
self.styles = []
self.i18n = i18n
self.last_index = 0
self.show_panel_after_restart = show_panel_after_restart
for idx, style in enumerate(QStyleFactory.keys()):
self.styles.append(style)
@@ -16,13 +23,22 @@ class StylesComboBox(QComboBox):
if style.lower() == self.app.style().objectName():
self.setCurrentIndex(idx)
self.last_index = 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)
if dialog.ask_confirmation(self.i18n['style.change.title'], self.i18n['style.change.question'].format(bold(__app_name__)), self.i18n):
self.last_index = idx
style = self.styles[idx]
user_config = config.read()
user_config.style = style
config.save(user_config)
util.restart_app(self.show_panel_after_restart)
else:
self.blockSignals(True)
self.setCurrentIndex(self.last_index)
self.blockSignals(False)