Skip to content

Commit

Permalink
Set application style to 'windowsvista' on Windows (#2905)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsavol authored Jul 30, 2024
1 parent ee3bc45 commit 1b51b6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
10 changes: 10 additions & 0 deletions spinetoolbox/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
QMenu,
QMessageBox,
QScrollArea,
QStyleFactory,
QToolButton,
QVBoxLayout,
QWidget,
Expand Down Expand Up @@ -128,6 +129,7 @@ def __init__(self):
from .ui.mainwindow import Ui_MainWindow # pylint: disable=import-outside-toplevel

super().__init__(flags=Qt.Window)
self.set_app_style()
self.set_error_mode()
self._qsettings = QSettings("SpineProject", "Spine Toolbox", self)
self._update_qsettings()
Expand Down Expand Up @@ -315,6 +317,14 @@ def connect_signals(self):
self.kernel_shutdown.connect(self._handle_kernel_shutdown)
self.persistent_console_requested.connect(self._setup_persistent_console, Qt.BlockingQueuedConnection)

@staticmethod
def set_app_style():
"""Sets app style on Windows to 'windowsvista' or to a default if not available."""
if sys.platform == "win32":
if "windowsvista" not in QStyleFactory.keys():
return
QApplication.setStyle("windowsvista")

@staticmethod
def set_error_mode():
"""Sets Windows error mode to show all error dialog boxes from subprocesses.
Expand Down
26 changes: 14 additions & 12 deletions tests/mock_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@

def create_toolboxui():
"""Returns ToolboxUI, where QSettings among others has been mocked."""
with mock.patch("spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"), mock.patch(
"spinetoolbox.ui_main.QSettings.value"
) as mock_qsettings_value:
with mock.patch(
"spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value, mock.patch(
"spinetoolbox.ui_main.ToolboxUI.set_app_style") as mock_set_app_style, mock.patch(
"spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"
):
mock_qsettings_value.side_effect = qsettings_value_side_effect
mock_set_app_style.return_value = True
toolbox = ToolboxUI()
return toolbox

Expand All @@ -41,16 +44,15 @@ def create_project(toolbox, project_dir):
def create_toolboxui_with_project(project_dir):
"""Returns ToolboxUI with a project instance where
QSettings among others has been mocked."""
with mock.patch("spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
"spinetoolbox.ui_main.QSettings.value"
) as mock_qsettings_value, mock.patch("spinetoolbox.ui_main.QSettings.setValue"), mock.patch(
"spinetoolbox.ui_main.QSettings.sync"
), mock.patch(
"spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"
), mock.patch(
"spinetoolbox.ui_main.QScrollArea.setWidget"
):
with mock.patch("spinetoolbox.ui_main.QSettings.value") as mock_qsettings_value, mock.patch(
"spinetoolbox.ui_main.ToolboxUI.set_app_style") as mock_set_app_style, mock.patch(
"spinetoolbox.ui_main.ToolboxUI.save_project"), mock.patch(
"spinetoolbox.ui_main.QSettings.setValue"), mock.patch(
"spinetoolbox.ui_main.QSettings.sync"), mock.patch(
"spinetoolbox.plugin_manager.PluginManager.load_installed_plugins"), mock.patch(
"spinetoolbox.ui_main.QScrollArea.setWidget"):
mock_qsettings_value.side_effect = qsettings_value_side_effect
mock_set_app_style.return_value = True
toolbox = ToolboxUI()
toolbox.create_project(project_dir)
return toolbox
Expand Down

0 comments on commit 1b51b6a

Please sign in to comment.