mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-10 07:44:17 +02:00
restarting the app when changing the style to avoid GUI bugs
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user