Skip to content

Commit

Permalink
Improve changes applied on restart dialog
Browse files Browse the repository at this point in the history
- display all changes as a list (it fixes an issue where if you changed both theme and language only warning about theme was displayed)
- reformat using richtext
- use an actual warning dialog
- modifies the API so we can pass multiples warnings and notes
- make title and last sentence fixed
- since we detect changes in options not need to write to them if unchanged
  • Loading branch information
zas committed Apr 12, 2024
1 parent fb91b92 commit 86e4378
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
30 changes: 12 additions & 18 deletions picard/ui/options/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
UiTheme,
)
from picard.ui.ui_options_interface import Ui_InterfaceOptionsPage
from picard.ui.util import changes_require_restart_warning


_default_starting_dir = QStandardPaths.writableLocation(QStandardPaths.StandardLocation.HomeLocation)
Expand Down Expand Up @@ -184,28 +185,21 @@ def save(self):
self.tagger.window.update_toolbar_style()
new_theme_setting = str(self.ui.ui_theme.itemData(self.ui.ui_theme.currentIndex()))
new_language = self.ui.ui_language.itemData(self.ui.ui_language.currentIndex())
restart_warning = None
warnings = []
notes = []
if new_theme_setting != config.setting['ui_theme']:
restart_warning_title = _("Theme changed")
restart_warning = _("You have changed the application theme. You have to restart Picard in order for the change to take effect.")
warnings.append(_("You have changed the application theme."))
if new_theme_setting == str(UiTheme.SYSTEM):
restart_warning += '\n\n' + _(
notes.append(_(
'Please note that using the system theme might cause the user interface to be not shown correctly. '
'If this is the case select the "Default" theme option to use Picard\'s default theme again.'
)
elif new_language != config.setting['ui_language']:
restart_warning_title = _("Language changed")
restart_warning = _("You have changed the interface language. You have to restart Picard in order for the change to take effect.")
if restart_warning:
dialog = QtWidgets.QMessageBox(
QtWidgets.QMessageBox.Icon.Information,
restart_warning_title,
restart_warning,
QtWidgets.QMessageBox.StandardButton.Ok,
self)
dialog.exec()
config.setting['ui_theme'] = new_theme_setting
config.setting['ui_language'] = self.ui.ui_language.itemData(self.ui.ui_language.currentIndex())
))
config.setting['ui_theme'] = new_theme_setting
if new_language != config.setting['ui_language']:
config.setting['ui_language'] = new_language
warnings.append(_("You have changed the interface language."))
changes_require_restart_warning(self, warnings=warnings, notes=notes)

config.setting['filebrowser_horizontal_autoscroll'] = self.ui.filebrowser_horizontal_autoscroll.isChecked()
config.setting['starting_directory'] = self.ui.starting_directory.isChecked()
config.setting['starting_directory_path'] = os.path.normpath(self.ui.starting_directory_path.text())
Expand Down
21 changes: 21 additions & 0 deletions picard/ui/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from html import escape as html_escape

from PyQt6 import (
QtCore,
QtGui,
Expand Down Expand Up @@ -115,3 +117,22 @@ def qlistwidget_items(qlistwidget):
"""Yield all items from a QListWidget"""
for i in range(qlistwidget.count()):
yield qlistwidget.item(i)


def changes_require_restart_warning(parent, warnings=None, notes=None):
"""Display a warning dialog about modified options requiring a restart"""
if not warnings:
return
text = '<p><ul>'
for warning in warnings:
text += '<li>' + html_escape(warning) + '</li>'
text += "</ul></p>"
if notes:
for note in notes:
text += "<p><em>" + html_escape(note) + "</em></p>"
text += "<p><strong>" + _("You have to restart Picard for the changes to take effect.") + "</strong></p>"
QtWidgets.QMessageBox.warning(
parent,
_("Changes only applied on restart"),
text
)

0 comments on commit 86e4378

Please sign in to comment.