From 40a8d1958472c76975cb3110a491591ba6934a71 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Thu, 12 Sep 2019 12:12:25 -0300 Subject: [PATCH] restarting the app when changing the style to avoid GUI bugs --- bauh/app.py | 2 +- bauh/resources/locale/en | 4 +++- bauh/resources/locale/es | 4 +++- bauh/resources/locale/pt | 4 +++- bauh/util/util.py | 19 +++++++++++++++++++ bauh/view/qt/confirmation.py | 5 ++++- bauh/view/qt/dialog.py | 23 +++++++++++++---------- bauh/view/qt/gem_selector.py | 11 +++-------- bauh/view/qt/styles.py | 30 +++++++++++++++++++++++------- bauh/view/qt/window.py | 10 +++++++--- 10 files changed, 79 insertions(+), 33 deletions(-) diff --git a/bauh/app.py b/bauh/app.py index de4fdbd8..ce0aac96 100755 --- a/bauh/app.py +++ b/bauh/app.py @@ -78,7 +78,7 @@ else: check_interval=args.check_interval, update_notification=bool(args.update_notification), config=user_config) - manage_window.tray_icon = tray_icon + manage_window.set_tray_icon(tray_icon) tray_icon.show() if args.show_panel: diff --git a/bauh/resources/locale/en b/bauh/resources/locale/en index 390ebd81..76410530 100644 --- a/bauh/resources/locale/en +++ b/bauh/resources/locale/en @@ -109,4 +109,6 @@ proceed=proceed change=change exit=exit manage_window.settings.gems=Application types -style=style \ No newline at end of file +style=style +style.change.title=Style change +style.change.question=To change the current style is necessary to restart {}. Proceed ? \ No newline at end of file diff --git a/bauh/resources/locale/es b/bauh/resources/locale/es index 5b68bfbc..b98d253f 100644 --- a/bauh/resources/locale/es +++ b/bauh/resources/locale/es @@ -111,4 +111,6 @@ proceed=continuar change=cambiar exit=salir manage_window.settings.gems=Tipos de aplicativos -style=estilo \ No newline at end of file +style=estilo +style.change.title=Cambio de estilo +style.change.question=Para cambiar el estilo actual es necesario reiniciar {}. ¿Proceder? \ No newline at end of file diff --git a/bauh/resources/locale/pt b/bauh/resources/locale/pt index 69a6820a..fa80244d 100644 --- a/bauh/resources/locale/pt +++ b/bauh/resources/locale/pt @@ -111,4 +111,6 @@ proceed=continuar change=alterar exit=sair manage_window.settings.gems=Tipos de aplicativos -style=estilo \ No newline at end of file +style=estilo +style.change.title=Mudança de estilo +style.change.question=Para alterar o estilo atual é necessário reiniciar o {}. Continuar ? \ No newline at end of file diff --git a/bauh/util/util.py b/bauh/util/util.py index aaa4072f..f6cc4b39 100644 --- a/bauh/util/util.py +++ b/bauh/util/util.py @@ -1,6 +1,10 @@ import glob import locale import os +import subprocess +import sys + +from PyQt5.QtCore import QCoreApplication from bauh import __app_name__ from bauh.util import resource @@ -42,3 +46,18 @@ def get_locale_keys(key: str = None, locale_dir: str = resource.get_path('locale def notify_user(msg: str, icon_path: str = resource.get_path('img/logo.svg')): os.system("notify-send -a {} {} '{}'".format(__app_name__, "-i {}".format(icon_path) if icon_path else '', msg)) + + +def restart_app(show_panel: bool): + """ + :param show_panel: if the panel should be displayed after the app restart + :return: + """ + restart_cmd = [sys.executable, *sys.argv] + + if show_panel: + restart_cmd.append('--show-panel') + + subprocess.Popen(restart_cmd) + QCoreApplication.exit() + diff --git a/bauh/view/qt/confirmation.py b/bauh/view/qt/confirmation.py index 91c9f036..8d00fa43 100644 --- a/bauh/view/qt/confirmation.py +++ b/bauh/view/qt/confirmation.py @@ -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: diff --git a/bauh/view/qt/dialog.py b/bauh/view/qt/dialog.py index 00326ccc..cd7725a9 100644 --- a/bauh/view/qt/dialog.py +++ b/bauh/view/qt/dialog.py @@ -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 diff --git a/bauh/view/qt/gem_selector.py b/bauh/view/qt/gem_selector.py index c535edc9..98357a24 100644 --- a/bauh/view/qt/gem_selector.py +++ b/bauh/view/qt/gem_selector.py @@ -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: diff --git a/bauh/view/qt/styles.py b/bauh/view/qt/styles.py index f2097b61..224bd2c0 100644 --- a/bauh/view/qt/styles.py +++ b/bauh/view/qt/styles.py @@ -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) diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index ffa36258..e3a03fe0 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -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)