def load_themes(self): """ Loads the theme lists and triggers updates across the whole system using direct calls or core functions and events for the plugins. The plugins will call back in to get the real list if they want it. """ self.theme_list = [] self.theme_list_widget.clear() files = AppLocation.get_files(self.settings_section, '.png') # Sort the themes by its name considering language specific files.sort(key=lambda file_name: get_locale_key(str(file_name))) # now process the file list of png files for name in files: # check to see file is in theme root directory theme = os.path.join(self.path, name) if os.path.exists(theme): text_name = os.path.splitext(name)[0] if text_name == self.global_theme: name = translate('OpenLP.ThemeManager', '{name} (default)').format(name=text_name) else: name = text_name thumb = os.path.join(self.thumb_path, '{name}.png'.format(name=text_name)) item_name = QtWidgets.QListWidgetItem(name) if validate_thumb(theme, thumb): icon = build_icon(thumb) else: icon = create_thumb(theme, thumb) item_name.setIcon(icon) item_name.setData(QtCore.Qt.UserRole, text_name) self.theme_list_widget.addItem(item_name) self.theme_list.append(text_name) self._push_themes()
def load_themes(self): """ Loads the theme lists and triggers updates across the whole system using direct calls or core functions and events for the plugins. The plugins will call back in to get the real list if they want it. """ self.theme_list = [] self.theme_list_widget.clear() files = AppLocation.get_files(self.settings_section, '.png') # Sort the themes by its name considering language specific files.sort(key=lambda file_name: get_locale_key(str(file_name))) # now process the file list of png files for name in files: # check to see file is in theme root directory theme = os.path.join(self.path, name) if os.path.exists(theme): text_name = os.path.splitext(name)[0] if text_name == self.global_theme: name = translate('OpenLP.ThemeManager', '%s (default)') % text_name else: name = text_name thumb = os.path.join(self.thumb_path, '%s.png' % text_name) item_name = QtWidgets.QListWidgetItem(name) if validate_thumb(theme, thumb): icon = build_icon(thumb) else: icon = create_thumb(theme, thumb) item_name.setIcon(icon) item_name.setData(QtCore.Qt.UserRole, text_name) self.theme_list_widget.addItem(item_name) self.theme_list.append(text_name) self._push_themes()
def load_first_time_themes(self): """ Imports any themes on start up and makes sure there is at least one theme """ self.application.set_busy_cursor() files = AppLocation.get_files(self.settings_section, '.otz') for theme_file in files: theme_file = os.path.join(self.path, theme_file) self.unzip_theme(theme_file, self.path) delete_file(theme_file) files = AppLocation.get_files(self.settings_section, '.png') # No themes have been found so create one if not files: theme = ThemeXML() theme.theme_name = UiStrings().Default self._write_theme(theme, None, None) Settings().setValue(self.settings_section + '/global theme', theme.theme_name) self.application.set_normal_cursor()
def get_files_no_section_no_extension_test(self): """ Test the AppLocation.get_files() method with no parameters passed. """ with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = 'test/dir' mocked_listdir.return_value = copy.deepcopy(FILE_LIST) # When: Get the list of files. result = AppLocation.get_files() # Then: check if the file lists are identical. self.assertListEqual(FILE_LIST, result, 'The file lists should be identical.')
def test_get_files_no_section_no_extension(self): """ Test the AppLocation.get_files() method with no parameters passed. """ with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = 'test/dir' mocked_listdir.return_value = copy.deepcopy(FILE_LIST) # When: Get the list of files. result = AppLocation.get_files() # Then: check if the file lists are identical. self.assertListEqual(FILE_LIST, result, 'The file lists should be identical.')
def reload_bibles(self): """ Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance of HTTPBible is loaded instead of the BibleDB class. """ log.debug('Reload bibles') files = AppLocation.get_files(self.settings_section, self.suffix) if 'alternative_book_names.sqlite' in files: files.remove('alternative_book_names.sqlite') log.debug('Bible Files %s', files) self.db_cache = {} self.old_bible_databases = [] for filename in files: bible = BibleDB(self.parent, path=self.path, file=filename) if not bible.session: continue name = bible.get_name() # Remove corrupted files. if name is None: bible.session.close() delete_file(os.path.join(self.path, filename)) continue # Find old database versions. if bible.is_old_database(): self.old_bible_databases.append([filename, name]) bible.session.close() continue log.debug('Bible Name: "%s"', name) self.db_cache[name] = bible # Look to see if lazy load bible exists and get create getter. source = self.db_cache[name].get_object(BibleMeta, 'download_source') if source: download_name = self.db_cache[name].get_object( BibleMeta, 'download_name').value meta_proxy = self.db_cache[name].get_object( BibleMeta, 'proxy_server') web_bible = HTTPBible(self.parent, path=self.path, file=filename, download_source=source.value, download_name=download_name) if meta_proxy: web_bible.proxy_server = meta_proxy.value self.db_cache[name] = web_bible log.debug('Bibles reloaded')
def get_files_test(self): """ Test the AppLocation.get_files() method with all parameters passed. """ with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = os.path.join('test', 'dir') mocked_listdir.return_value = copy.deepcopy(FILE_LIST) # When: Get the list of files. result = AppLocation.get_files('section', '.mp3') # Then: Check if the section parameter was used correctly. mocked_listdir.assert_called_with(os.path.join('test', 'dir', 'section')) # Then: check if the file lists are identical. self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.')
def test_get_files(self): """ Test the AppLocation.get_files() method with all parameters passed. """ with patch('openlp.core.common.AppLocation.get_data_path') as mocked_get_data_path, \ patch('openlp.core.common.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = os.path.join('test', 'dir') mocked_listdir.return_value = copy.deepcopy(FILE_LIST) # When: Get the list of files. result = AppLocation.get_files('section', '.mp3') # Then: Check if the section parameter was used correctly. mocked_listdir.assert_called_with( os.path.join('test', 'dir', 'section')) # Then: check if the file lists are identical. self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.')
def reload_bibles(self): """ Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance of HTTPBible is loaded instead of the BibleDB class. """ log.debug('Reload bibles') files = AppLocation.get_files(self.settings_section, self.suffix) if 'alternative_book_names.sqlite' in files: files.remove('alternative_book_names.sqlite') log.debug('Bible Files %s', files) self.db_cache = {} self.old_bible_databases = [] for filename in files: bible = BibleDB(self.parent, path=self.path, file=filename) if not bible.session: continue name = bible.get_name() # Remove corrupted files. if name is None: bible.session.close() delete_file(os.path.join(self.path, filename)) continue # Find old database versions. if bible.is_old_database(): self.old_bible_databases.append([filename, name]) bible.session.close() continue log.debug('Bible Name: "%s"', name) self.db_cache[name] = bible # Look to see if lazy load bible exists and get create getter. source = self.db_cache[name].get_object(BibleMeta, 'download_source') if source: download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server') web_bible = HTTPBible(self.parent, path=self.path, file=filename, download_source=source.value, download_name=download_name) if meta_proxy: web_bible.proxy_server = meta_proxy.value self.db_cache[name] = web_bible log.debug('Bibles reloaded')
def load_loops(self): """ Loads all loops into the plugin """ self.loop_list = [] self.loop_list_widget.clear() files = AppLocation.get_files(self.settings_section) # Sort the loops by name, language specific files.sort(key=lambda file_name: get_locale_key(str(file_name))) # now process the file list of loop for name in files: if os.path.isfile(os.path.join(self.path, name)): # check to see loop has corresponding thumbnail loop_thumb = os.path.join(self.thumb_path, os.path.splitext(name)[0] + '.jpg') if os.path.exists(loop_thumb) == False: self.create_loop_thumbnail(name) loop_name = os.path.splitext(name)[0] item_name = QtGui.QListWidgetItem(loop_name) icon = build_icon(loop_thumb) item_name.setIcon(icon) item_name.setData(QtCore.Qt.UserRole, name) self.loop_list_widget.addItem(item_name) self.loop_list.append(loop_name)