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

@@ -13,7 +13,10 @@ class ConfirmationDialog(QMessageBox):
self.setWindowTitle(title)
self.setStyleSheet('QLabel { margin-right: 25px; }')
self.bt_yes = self.addButton(locale_keys['popup.button.yes'] if not confirmation_label else confirmation_label.capitalize(), QMessageBox.YesRole)
self.addButton(locale_keys['popup.button.no'] if not deny_label else deny_label.capitalize(), QMessageBox.NoRole)
self.bt_yes.setStyleSheet('background: green; color: white; font-weight: bold')
bt_no = self.addButton(locale_keys['popup.button.no'] if not deny_label else deny_label.capitalize(), QMessageBox.NoRole)
bt_no.setStyleSheet('background: red; color: white; font-weight: bold')
if body:
if not components:

View File

@@ -26,10 +26,10 @@ def show_message(title: str, body: str, type_: MessageType, icon: QIcon = QIcon(
def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIcon(resource.get_path('img/logo.svg')), widgets: List[QWidget] = None):
dialog_confirmation = QMessageBox()
dialog_confirmation.setIcon(QMessageBox.Question)
dialog_confirmation.setWindowTitle(title)
dialog_confirmation.setStyleSheet('QLabel { margin-right: 25px; }')
diag = QMessageBox()
diag.setIcon(QMessageBox.Question)
diag.setWindowTitle(title)
diag.setStyleSheet('QLabel { margin-right: 25px; }')
wbody = QWidget()
wbody.setLayout(QHBoxLayout())
@@ -39,14 +39,17 @@ def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIc
for w in widgets:
wbody.layout().addWidget(w)
dialog_confirmation.layout().addWidget(wbody, 0, 1)
diag.layout().addWidget(wbody, 0, 1)
bt_yes = dialog_confirmation.addButton(locale_keys['popup.button.yes'], QMessageBox.YesRole)
dialog_confirmation.addButton(locale_keys['popup.button.no'], QMessageBox.NoRole)
bt_yes = diag.addButton(locale_keys['popup.button.yes'], QMessageBox.YesRole)
bt_yes.setStyleSheet('background: green; color: white; font-weight: bold')
bt_no = diag.addButton(locale_keys['popup.button.no'], QMessageBox.NoRole)
bt_no.setStyleSheet('background: red; color: white; font-weight: bold')
if icon:
dialog_confirmation.setWindowIcon(icon)
diag.setWindowIcon(icon)
dialog_confirmation.exec_()
diag.exec_()
return dialog_confirmation.clickedButton() == bt_yes
return diag.clickedButton() == bt_yes

View File

@@ -9,8 +9,9 @@ from PyQt5.QtWidgets import QWidget, QLabel, QGridLayout, QPushButton
from bauh import ROOT_DIR
from bauh.api.abstract.controller import SoftwareManager
from bauh.api.abstract.view import MultipleSelectComponent, InputOption
from bauh.commons import resource
from bauh.commons import resource, system
from bauh.core.config import Configuration, save
from bauh.util import util
from bauh.view.qt.components import MultipleSelectQt, CheckboxQt, new_spacer
@@ -76,13 +77,7 @@ class GemSelectorPanel(QWidget):
config = Configuration(gems=[o.value for o in self.gem_select_model.values])
save(config)
restart_cmd = [sys.executable, *sys.argv]
if self.show_panel_after_restart:
restart_cmd.append('--show-panel')
subprocess.Popen(restart_cmd)
QCoreApplication.exit()
util.restart_app(self.show_panel_after_restart)
def exit(self):
if self.exit_on_close:

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)

View File

@@ -239,9 +239,9 @@ 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)
self.combo_styles = StylesComboBox(parent=self, i18n=i18n, show_panel_after_restart=bool(tray_icon))
self.combo_styles.setStyleSheet('QComboBox {font-size: 12px;}')
self.ref_combo_styles = self.toolbar_bottom.addWidget(self.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)
@@ -261,6 +261,10 @@ class ManageWindow(QWidget):
self.thread_warnings = ListWarnings(man=manager, locale_keys=i18n)
self.thread_warnings.signal_warnings.connect(self._show_warnings)
def set_tray_icon(self, tray_icon):
self.tray_icon = tray_icon
self.combo_styles.show_panel_after_restart = bool(tray_icon)
def _update_process_progress(self, val: int):
self.progress_bar.setTextVisible(True)
self.thread_animate_progress.set_progress(val)