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

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

View File

@@ -109,4 +109,6 @@ proceed=proceed
change=change
exit=exit
manage_window.settings.gems=Application types
style=style
style=style
style.change.title=Style change
style.change.question=To change the current style is necessary to restart {}. Proceed ?

View File

@@ -111,4 +111,6 @@ proceed=continuar
change=cambiar
exit=salir
manage_window.settings.gems=Tipos de aplicativos
style=estilo
style=estilo
style.change.title=Cambio de estilo
style.change.question=Para cambiar el estilo actual es necesario reiniciar {}. ¿Proceder?

View File

@@ -111,4 +111,6 @@ proceed=continuar
change=alterar
exit=sair
manage_window.settings.gems=Tipos de aplicativos
style=estilo
style=estilo
style.change.title=Mudança de estilo
style.change.question=Para alterar o estilo atual é necessário reiniciar o {}. Continuar ?

View File

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

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)