From 6ca37531a057e32870b6bf9dc0759d523a9f4312 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 1 Apr 2014 13:07:25 -0400 Subject: [PATCH 1/6] Remove unnecessary platform specific code, remove orphaned and unused registry execute, and fix two functions to register to the registry instead of executing. --- openlp/core/ui/mainwindow.py | 16 ++++++---------- openlp/core/ui/slidecontroller.py | 1 - openlp/plugins/bibles/forms/bibleupgradeform.py | 2 +- openlp/plugins/bibles/lib/db.py | 2 +- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 703307e18..6c56bee37 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -322,14 +322,8 @@ class Ui_MainWindow(object): # i18n add Language Actions add_actions(self.settings_language_menu, (self.auto_language_item, None)) add_actions(self.settings_language_menu, self.language_group.actions()) - # Order things differently in OS X so that Preferences menu item in the - # app menu is correct (this gets picked up automatically by Qt). - if sys.platform == 'darwin': - add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), - None, self.settings_configure_item, self.settings_shortcuts_item, self.formatting_tag_item)) - else: - add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), - None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item)) + add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), + None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item)) add_actions(self.tools_menu, (self.tools_add_tool_item, None)) add_actions(self.tools_menu, (self.tools_open_data_folder, None)) add_actions(self.tools_menu, (self.tools_first_time_wizard, None)) @@ -393,8 +387,10 @@ class Ui_MainWindow(object): self.import_language_item.setText(translate('OpenLP.MainWindow', '&Language')) self.export_theme_item.setText(translate('OpenLP.MainWindow', '&Theme')) self.export_language_item.setText(translate('OpenLP.MainWindow', '&Language')) - self.settings_shortcuts_item.setText(translate('OpenLP.MainWindow', 'Configure &Shortcuts...')) - self.formatting_tag_item.setText(translate('OpenLP.MainWindow', 'Configure &Formatting Tags...')) + # Do not use config, options, setup, settings or preferences in menu item name unless it is OpenLP's preferences. + # Qt automatically detects the Preferences entry for the Mac OS X menu based on the name of the menu item. + self.settings_shortcuts_item.setText(translate('OpenLP.MainWindow', '&Shortcuts...')) + self.formatting_tag_item.setText(translate('OpenLP.MainWindow', '&Formatting Tags...')) self.settings_configure_item.setText(translate('OpenLP.MainWindow', '&Configure OpenLP...')) self.settings_export_item.setStatusTip(translate('OpenLP.MainWindow', 'Export OpenLP settings to a specified *.config file')) diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 7faf10ca2..ed3ddaeda 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -1039,7 +1039,6 @@ class SlideController(DisplayController, RegistryProperties): """ self.preview_widget.change_slide(row) self.update_preview() - Registry().execute('slidecontroller_%s_changed' % self.type_prefix, row) def update_preview(self): """ diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 9925b1ebc..d9936dfe6 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -78,7 +78,7 @@ class BibleUpgradeForm(OpenLPWizard): Set up the UI for the bible wizard. """ super(BibleUpgradeForm, self).setupUi(image) - Registry().execute('openlp_stop_wizard', self.stop_import) + Registry().register_function('openlp_stop_wizard', self.stop_import) def stop_import(self): """ diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 743bb01c6..48c11fa5e 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -154,7 +154,7 @@ class BibleDB(QtCore.QObject, Manager, RegistryProperties): if 'path' in kwargs: self.path = kwargs['path'] self.wizard = None - Registry().execute('openlp_stop_wizard', self.stop_import) + Registry().register_function('openlp_stop_wizard', self.stop_import) def stop_import(self): """ From d26b34aee0837267c68df61c685cd8de9c9c3700 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 1 Apr 2014 14:58:22 -0400 Subject: [PATCH 2/6] Modify loading file from the command line to only load files ending with osz, oszl, or otz. --- openlp/core/ui/mainwindow.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 6c56bee37..b14694ccc 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -597,10 +597,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): args = [] for a in self.arguments: args.extend([a]) - filename = args[0] - if not isinstance(filename, str): - filename = str(filename, sys.getfilesystemencoding()) - self.service_manager_contents.load_file(filename) + for arg in args: + filename = arg + if not isinstance(filename, str): + filename = str(filename, sys.getfilesystemencoding()) + if filename.endswith(('.osz', '.oszl', '.otz')): + self.service_manager_contents.load_file(filename) elif Settings().value(self.general_settings_section + '/auto open'): self.service_manager_contents.load_Last_file() self.timer_version_id = self.startTimer(1000) From bc55bcd7fa7719cf212c001ad5256986bab0935f Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Thu, 3 Apr 2014 08:38:39 -0400 Subject: [PATCH 3/6] Fix argurment to pass correct type. --- openlp/core/utils/languagemanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index cd5ce7add..bb584f7bd 100644 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -74,7 +74,7 @@ class LanguageManager(object): log.debug('Translation files: %s', AppLocation.get_directory( AppLocation.LanguageDir)) trans_dir = QtCore.QDir(AppLocation.get_directory(AppLocation.LanguageDir)) - file_names = trans_dir.entryList('*.qm', QtCore.QDir.Files, QtCore.QDir.Name) + file_names = trans_dir.entryList(['*.qm'], QtCore.QDir.Files, QtCore.QDir.Name) # Remove qm files from the list which start with "qt_". file_names = [file_ for file_ in file_names if not file_.startswith('qt_')] return list(map(trans_dir.filePath, file_names)) From e5d5af38c2f45b279f43a698b6c99ca22ba0609c Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Sun, 6 Apr 2014 22:03:05 -0400 Subject: [PATCH 4/6] Move opening of files passed in via command line to function. --- openlp/core/ui/mainwindow.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index b14694ccc..b70192039 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -594,15 +594,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): self.live_controller.display.setFocus() self.activateWindow() if self.arguments: - args = [] - for a in self.arguments: - args.extend([a]) - for arg in args: - filename = arg - if not isinstance(filename, str): - filename = str(filename, sys.getfilesystemencoding()) - if filename.endswith(('.osz', '.oszl', '.otz')): - self.service_manager_contents.load_file(filename) + self.open_cmd_line_files() elif Settings().value(self.general_settings_section + '/auto open'): self.service_manager_contents.load_Last_file() self.timer_version_id = self.startTimer(1000) @@ -1362,3 +1354,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): if self.new_data_path == AppLocation.get_directory(AppLocation.DataDir): settings.remove('advanced/data path') self.application.set_normal_cursor() + + def open_cmd_line_files(self): + """ + Open files passed in through command line arguments + """ + args = [] + for a in self.arguments: + args.extend([a]) + for arg in args: + filename = arg + if not isinstance(filename, str): + filename = str(filename, sys.getfilesystemencoding()) + if filename.endswith(('.osz', '.oszl')): + self.service_manager_contents.load_file(filename) From 1945b4c380001d4b774986584b815c40ad14bd44 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Sun, 6 Apr 2014 22:07:19 -0400 Subject: [PATCH 5/6] Remove changes to platform specific code. --- openlp/core/ui/mainwindow.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index b70192039..d11fae767 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -322,8 +322,14 @@ class Ui_MainWindow(object): # i18n add Language Actions add_actions(self.settings_language_menu, (self.auto_language_item, None)) add_actions(self.settings_language_menu, self.language_group.actions()) - add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), - None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item)) + # Order things differently in OS X so that Preferences menu item in the + # app menu is correct (this gets picked up automatically by Qt). + if sys.platform == 'darwin': + add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), + None, self.settings_configure_item, self.settings_shortcuts_item, self.formatting_tag_item)) + else: + add_actions(self.settings_menu, (self.settings_plugin_list_item, self.settings_language_menu.menuAction(), + None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item)) add_actions(self.tools_menu, (self.tools_add_tool_item, None)) add_actions(self.tools_menu, (self.tools_open_data_folder, None)) add_actions(self.tools_menu, (self.tools_first_time_wizard, None)) @@ -387,10 +393,8 @@ class Ui_MainWindow(object): self.import_language_item.setText(translate('OpenLP.MainWindow', '&Language')) self.export_theme_item.setText(translate('OpenLP.MainWindow', '&Theme')) self.export_language_item.setText(translate('OpenLP.MainWindow', '&Language')) - # Do not use config, options, setup, settings or preferences in menu item name unless it is OpenLP's preferences. - # Qt automatically detects the Preferences entry for the Mac OS X menu based on the name of the menu item. - self.settings_shortcuts_item.setText(translate('OpenLP.MainWindow', '&Shortcuts...')) - self.formatting_tag_item.setText(translate('OpenLP.MainWindow', '&Formatting Tags...')) + self.settings_shortcuts_item.setText(translate('OpenLP.MainWindow', 'Configure &Shortcuts...')) + self.formatting_tag_item.setText(translate('OpenLP.MainWindow', 'Configure &Formatting Tags...')) self.settings_configure_item.setText(translate('OpenLP.MainWindow', '&Configure OpenLP...')) self.settings_export_item.setStatusTip(translate('OpenLP.MainWindow', 'Export OpenLP settings to a specified *.config file')) From 25c3503397ab3cdb3bc7c778405717e910fef462 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Tue, 8 Apr 2014 16:45:40 -0400 Subject: [PATCH 6/6] Add test to check for proper handling of service files passed in through the command line. --- .../openlp_core_ui/test_mainwindow.py | 97 ++++++++++++++++++ tests/resources/service/test.osz | Bin 0 -> 8082 bytes 2 files changed, 97 insertions(+) create mode 100644 tests/functional/openlp_core_ui/test_mainwindow.py create mode 100644 tests/resources/service/test.osz diff --git a/tests/functional/openlp_core_ui/test_mainwindow.py b/tests/functional/openlp_core_ui/test_mainwindow.py new file mode 100644 index 000000000..0b17828b9 --- /dev/null +++ b/tests/functional/openlp_core_ui/test_mainwindow.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Package to test openlp.core.ui.mainwindow package. +""" +import os + +from unittest import TestCase + +from openlp.core.ui.mainwindow import MainWindow +from openlp.core.common.registry import Registry +from tests.utils.constants import TEST_RESOURCES_PATH +from tests.helpers.testmixin import TestMixin +from tests.functional import MagicMock, patch + + +class TestMainWindow(TestCase, TestMixin): + + def setUp(self): + Registry.create() + self.registry = Registry() + self.get_application() + # Mock cursor busy/normal methods. + self.app.set_busy_cursor = MagicMock() + self.app.set_normal_cursor = MagicMock() + self.app.args = [] + Registry().register('application', self.app) + # Mock classes and methods used by mainwindow. + with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \ + patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \ + patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \ + patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \ + patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \ + patch('openlp.core.ui.mainwindow.QtGui.QToolBox') as mocked_q_tool_box_class, \ + patch('openlp.core.ui.mainwindow.QtGui.QMainWindow.addDockWidget') as mocked_add_dock_method, \ + patch('openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \ + patch('openlp.core.ui.mainwindow.Renderer') as mocked_renderer: + self.main_window = MainWindow() + + def tearDown(self): + del self.main_window + + def cmd_line_file_test(self): + """ + Test that passing a service file from the command line loads the service. + """ + # GIVEN a service as an argument to openlp + service = os.path.join(TEST_RESOURCES_PATH, 'service', 'test.osz') + self.main_window.arguments = [service] + with patch('openlp.core.ui.servicemanager.ServiceManager.load_file') as mocked_load_path: + + # WHEN the argument is processed + self.main_window.open_cmd_line_files() + + # THEN the service from the arguments is loaded + mocked_load_path.assert_called_with(service), 'load_path should have been called with the service\'s path' + + def cmd_line_arg_test(self): + """ + Test that passing a non service file does nothing. + """ + # GIVEN a non service file as an argument to openlp + service = os.path.join('openlp.py') + self.main_window.arguments = [service] + with patch('openlp.core.ui.servicemanager.ServiceManager.load_file') as mocked_load_path: + + # WHEN the argument is processed + self.main_window.open_cmd_line_files() + + # THEN the file should not be opened + assert not mocked_load_path.called, 'load_path should not have been called' diff --git a/tests/resources/service/test.osz b/tests/resources/service/test.osz new file mode 100644 index 0000000000000000000000000000000000000000..a289c07750289ed1daf256935486aee320d09fc9 GIT binary patch literal 8082 zcmeHMVQ(9`5l!yeqCeoim(_>n3dol2-Ba+Fx7db{FN&ntJS6SWaCRnU{(%e+$JW#xS6^+hk& zL2cAFXr0L1tE;R2O-HmB>?oB%;uj3zpt zm7__E)XvO?(`l**@RwB}7lh$NPqW||;L;&_oOsVJK4yTPHt|RoUgbcLup6@npnTvj z#9ZwPn9-UU3oi@xVrX7vKsbnRl!tq?5f%nbm>2EMv3039m1Bt+$G!97v<`zlqiw7} z8)jk+bvn%`0upO}sPK$|S7Iy!AYBEw9hp1e?%V_J0f!|Z;|0yEqfo`@sk+p;zX>)> zi%n%n81`VvgyO#PX#1!{F6TlA4hA%46dl+R{BsH$@CU>QmN=*V5*B;T5r)nLE#{Cb zZeI#uj{ak7FT~Vo911V$Ljz2J>MR~JL}F?J3ed`*Xt#9eIK~0y z2ctw`3p&rVN`^E?tSg5`L~>vF5@~92%JG#KlF3Wt41{)qZSe$p9QLeUct8>u&*MpD zZ#DD*M|zsY-JzVq*(}!+3dJ|proN9uZ{V{pu=jcDl<8w)-2P{58{Eg0;5bbX0lvWE zb~*NuY50^PE%FpErO`g40K@Fgu#1UChD7F}bLSNDkU_3l-GMdWyR!{XdRN~ewIB#n zM}&(RzC?@IcfLo`LLITQ0@)}OoMZ$6Thj=#11I`_);cn zu(P%G^?vL(G&P* z)?NRy{~kMm)Od`?%IyteGwiSJ2Fv5;49)%?p$qN+IGFe4Hcb;J3o~4g*7wG4fY~=P zJGZY*?rhz~@3m1A#m5obSe`A~i9R}M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