From 16425b05a03016a1e29b16393df3cf55710844e0 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 24 Mar 2015 18:33:57 -0400 Subject: [PATCH 1/2] Fix bug 1247661 by restoring to main window when the dock icon is clicked --- openlp/core/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index a4a9d488e..fa6f59a4d 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -250,7 +250,7 @@ class OpenLP(OpenLPMixin, QtGui.QApplication): def event(self, event): """ - Enables direct file opening on OS X + Enables platform specific event handling i.e. direct file opening on OS X :param event: The event """ @@ -259,8 +259,19 @@ class OpenLP(OpenLPMixin, QtGui.QApplication): log.debug('Got open file event for %s!', file_name) self.args.insert(0, file_name) return True - else: - return QtGui.QApplication.event(self, event) + # Mac OS X should restore app window when user clicked on the OpenLP icon + # in the Dock bar. However, OpenLP consists of multiple windows and this + # does not work. This workaround fixes that. + # The main OpenLP window is restored when it was previously minimized. + elif event.type() == QtCore.QEvent.ApplicationActivate: + if is_macosx() and hasattr(self, 'main_window'): + if self.main_window.isMinimized(): + # Copied from QWidget.setWindowState() docs on how to restore and activate a minimized window + # while preserving its maximized and/or full-screen state. + self.main_window.setWindowState(self.main_window.windowState() & ~QtCore.Qt.WindowMinimized | + QtCore.Qt.WindowActive) + return True + return QtGui.QApplication.event(self, event) def parse_options(args): From 8e0fc05b82cd4c9468ea0b831f0285aca4b1c7ed Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Sat, 25 Apr 2015 10:06:32 -0400 Subject: [PATCH 2/2] Inital stab at test --- tests/functional/test_init.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/functional/test_init.py b/tests/functional/test_init.py index 151e3655b..8e3054433 100644 --- a/tests/functional/test_init.py +++ b/tests/functional/test_init.py @@ -66,6 +66,22 @@ class TestInit(TestCase, TestMixin): mocked_file_method.assert_called_once_with() self.assertEqual(self.openlp.args[0], file_path, "The path should be in args.") + def application_activate_event_test(self): + """ + Test that clicking on the dock icon on Mac OS X restores the main window if it is minimized + """ + # GIVEN: + with patch('openlp.core.is_macosx') as mocked_is_macosx: + mocked_is_macosx.return_value = True + event = QtCore.QEvent(QtCore.QEvent.ApplicationActivate) + + # WHEN: + result = self.openlp.event(event) + + # THEN: + self.assertTrue(result, "The method should have returned True.") + self.assertFalse(self.openlp.main_window.isMinimized()) + def backup_on_upgrade_first_install_test(self): """ Test that we don't try to backup on a new install