From e70a09c93e3a7ad48551b4f04dbff77a6aee63d6 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 22 May 2014 15:40:05 +0200 Subject: [PATCH 1/5] Detect language folder in source directory --- openlp/core/common/applocation.py | 29 +++++++++++++++------------- openlp/core/utils/languagemanager.py | 3 +-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/openlp/core/common/applocation.py b/openlp/core/common/applocation.py index 2bc4027b6..f3abd5656 100644 --- a/openlp/core/common/applocation.py +++ b/openlp/core/common/applocation.py @@ -72,15 +72,15 @@ class AppLocation(object): :param dir_type: The directory type you want, for instance the data directory. Default *AppLocation.AppDir* """ if dir_type == AppLocation.AppDir: - return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0]) + return get_frozen_path(os.path.abspath(os.path.dirname(sys.argv[0])), os.path.dirname(openlp.__file__)) elif dir_type == AppLocation.PluginsDir: - app_path = os.path.abspath(os.path.split(sys.argv[0])[0]) + app_path = os.path.abspath(os.path.dirname(sys.argv[0])) return get_frozen_path(os.path.join(app_path, 'plugins'), - os.path.join(os.path.split(openlp.__file__)[0], 'plugins')) + os.path.join(os.path.dirname(openlp.__file__), 'plugins')) elif dir_type == AppLocation.VersionDir: - return get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), os.path.split(openlp.__file__)[0]) + return get_frozen_path(os.path.abspath(os.path.dirname(sys.argv[0])), os.path.dirname(openlp.__file__)) elif dir_type == AppLocation.LanguageDir: - app_path = get_frozen_path(os.path.abspath(os.path.split(sys.argv[0])[0]), _get_os_dir_path(dir_type)) + app_path = get_frozen_path(os.path.abspath(os.path.dirname(sys.argv[0])), _get_os_dir_path(dir_type)) return os.path.join(app_path, 'i18n') elif dir_type == AppLocation.DataDir and AppLocation.BaseDir: return os.path.join(AppLocation.BaseDir, 'data') @@ -140,25 +140,28 @@ def _get_os_dir_path(dir_type): """ Return a path based on which OS and environment we are running in. """ + # If running from source, return the language directory from the source directory + if dir_type == AppLocation.LanguageDir: + directory = os.path.abspath(os.path.join(os.path.dirname(openlp.__file__), '..', 'resources')) + if os.path.exists(directory): + return directory if sys.platform == 'win32': if dir_type == AppLocation.DataDir: return os.path.join(str(os.getenv('APPDATA')), 'openlp', 'data') elif dir_type == AppLocation.LanguageDir: - return os.path.split(openlp.__file__)[0] + return os.path.dirname(openlp.__file__) return os.path.join(str(os.getenv('APPDATA')), 'openlp') elif sys.platform == 'darwin': if dir_type == AppLocation.DataDir: - return os.path.join(str(os.getenv('HOME')), - 'Library', 'Application Support', 'openlp', 'Data') + return os.path.join(str(os.getenv('HOME')), 'Library', 'Application Support', 'openlp', 'Data') elif dir_type == AppLocation.LanguageDir: - return os.path.split(openlp.__file__)[0] + return os.path.dirname(openlp.__file__) return os.path.join(str(os.getenv('HOME')), 'Library', 'Application Support', 'openlp') else: if dir_type == AppLocation.LanguageDir: - for prefix in ['/usr/local', '/usr']: - directory = os.path.join(prefix, 'share', 'openlp') - if os.path.exists(directory): - return directory + directory = os.path.join('/usr', 'local', 'share', 'openlp') + if os.path.exists(directory): + return directory return os.path.join('/usr', 'share', 'openlp') if XDG_BASE_AVAILABLE: if dir_type == AppLocation.DataDir: diff --git a/openlp/core/utils/languagemanager.py b/openlp/core/utils/languagemanager.py index bb584f7bd..dd048e04c 100644 --- a/openlp/core/utils/languagemanager.py +++ b/openlp/core/utils/languagemanager.py @@ -71,8 +71,7 @@ class LanguageManager(object): """ Find all available language files in this OpenLP install """ - log.debug('Translation files: %s', AppLocation.get_directory( - AppLocation.LanguageDir)) + 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) # Remove qm files from the list which start with "qt_". From 873f18ad651e3b2ab4fc763a8c568009885252ea Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Thu, 22 May 2014 15:48:57 +0200 Subject: [PATCH 2/5] Add test --- tests/functional/openlp_core_lib/test_ui.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index f1b8ee17a..f6a27f020 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -154,6 +154,21 @@ class TestUi(TestCase): self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) + def test_create_action_2(self): + """ + Test creating an action + """ + # GIVEN: A dialog + dialog = QtGui.QDialog() + + # WHEN: We create an action with some properties + action = create_action(dialog, 'my_action', checked=True, enabled=False, visible=False) + + # THEN: These properties should be set + self.assertEqual(True, action.isChecked()) + self.assertEqual(False, action.isEnabled()) + self.assertEqual(False, action.isVisible()) + def test_create_valign_selection_widgets(self): """ Test creating a combo box for valign selection From 56ebf2de006d012000d95b8996491a4b36432d7f Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 28 May 2014 19:17:26 +0200 Subject: [PATCH 3/5] Revert change in check for language dir --- openlp/core/common/applocation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openlp/core/common/applocation.py b/openlp/core/common/applocation.py index f3abd5656..073d3c7f7 100644 --- a/openlp/core/common/applocation.py +++ b/openlp/core/common/applocation.py @@ -159,9 +159,10 @@ def _get_os_dir_path(dir_type): return os.path.join(str(os.getenv('HOME')), 'Library', 'Application Support', 'openlp') else: if dir_type == AppLocation.LanguageDir: - directory = os.path.join('/usr', 'local', 'share', 'openlp') - if os.path.exists(directory): - return directory + for prefix in ['/usr/local', '/usr']: + directory = os.path.join(prefix, 'share', 'openlp') + if os.path.exists(directory): + return directory return os.path.join('/usr', 'share', 'openlp') if XDG_BASE_AVAILABLE: if dir_type == AppLocation.DataDir: From 0441f0e71b3f4d2e4031c5ca5b8cbb5a98cca8fb Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 30 May 2014 19:59:11 +0200 Subject: [PATCH 4/5] Better description --- tests/functional/openlp_core_lib/test_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index f6a27f020..854edcf88 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -156,7 +156,7 @@ class TestUi(TestCase): def test_create_action_2(self): """ - Test creating an action + Test creating an action with the 'checked', 'enabled' and 'visible' properties. """ # GIVEN: A dialog dialog = QtGui.QDialog() From 08e41672cb713e31afa6e883959a692c544de8a5 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Sun, 8 Jun 2014 16:27:03 +0200 Subject: [PATCH 5/5] Better name for test --- tests/functional/openlp_core_lib/test_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_ui.py b/tests/functional/openlp_core_lib/test_ui.py index 7d1658968..591762947 100644 --- a/tests/functional/openlp_core_lib/test_ui.py +++ b/tests/functional/openlp_core_lib/test_ui.py @@ -154,7 +154,7 @@ class TestUi(TestCase): self.assertEqual('my tooltip', action.toolTip()) self.assertEqual('my statustip', action.statusTip()) - def test_create_action_2(self): + def test_create_checked_enabled_visible_action(self): """ Test creating an action with the 'checked', 'enabled' and 'visible' properties. """