forked from openlp/openlp
Move some changes out of annother branch
This commit is contained in:
parent
15f3b0fcca
commit
7aa7e5c635
@ -463,8 +463,8 @@ def get_file_encoding(file_path):
|
|||||||
Utility function to incrementally detect the file encoding.
|
Utility function to incrementally detect the file encoding.
|
||||||
|
|
||||||
:param openlp.core.common.path.Path file_path: Filename for the file to determine the encoding for.
|
:param openlp.core.common.path.Path file_path: Filename for the file to determine the encoding for.
|
||||||
:return: A dict with the keys 'encoding' and 'confidence'
|
:return: The name of the encoding detected
|
||||||
:rtype: dict[str, float]
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
detector = UniversalDetector()
|
detector = UniversalDetector()
|
||||||
try:
|
try:
|
||||||
@ -477,7 +477,7 @@ def get_file_encoding(file_path):
|
|||||||
except OSError:
|
except OSError:
|
||||||
log.exception('Error detecting file encoding')
|
log.exception('Error detecting file encoding')
|
||||||
finally:
|
finally:
|
||||||
return detector.close()
|
return detector.close()['encoding']
|
||||||
|
|
||||||
|
|
||||||
def normalize_str(irregular_string):
|
def normalize_str(irregular_string):
|
||||||
|
@ -333,7 +333,7 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
|
|||||||
self.validate_and_load(file_paths)
|
self.validate_and_load(file_paths)
|
||||||
self.application.set_normal_cursor()
|
self.application.set_normal_cursor()
|
||||||
|
|
||||||
def load_file(self, data):
|
def handle_mime_data(self, data):
|
||||||
"""
|
"""
|
||||||
Turn file from Drag and Drop into an array so the Validate code can run it.
|
Turn file from Drag and Drop into an array so the Validate code can run it.
|
||||||
|
|
||||||
@ -379,11 +379,11 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
|
|||||||
duplicates_found = False
|
duplicates_found = False
|
||||||
files_added = False
|
files_added = False
|
||||||
for file_path in file_paths:
|
for file_path in file_paths:
|
||||||
if path_to_str(file_path) in full_list:
|
if file_path in full_list:
|
||||||
duplicates_found = True
|
duplicates_found = True
|
||||||
else:
|
else:
|
||||||
files_added = True
|
files_added = True
|
||||||
full_list.append(path_to_str(file_path))
|
full_list.append(file_path)
|
||||||
if full_list and files_added:
|
if full_list and files_added:
|
||||||
if target_group is None:
|
if target_group is None:
|
||||||
self.list_view.clear()
|
self.list_view.clear()
|
||||||
@ -416,8 +416,8 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
|
|||||||
file_paths = []
|
file_paths = []
|
||||||
for index in range(self.list_view.count()):
|
for index in range(self.list_view.count()):
|
||||||
list_item = self.list_view.item(index)
|
list_item = self.list_view.item(index)
|
||||||
filename = list_item.data(QtCore.Qt.UserRole)
|
file_path = list_item.data(QtCore.Qt.UserRole)
|
||||||
file_paths.append(str_to_path(filename))
|
file_paths.append(file_path)
|
||||||
return file_paths
|
return file_paths
|
||||||
|
|
||||||
def load_list(self, load_list, target_group):
|
def load_list(self, load_list, target_group):
|
||||||
|
@ -24,7 +24,7 @@ import logging
|
|||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
|
from openlp.core.common.i18n import UiStrings, get_natural_key, translate
|
||||||
from openlp.core.common.path import path_to_str, str_to_path
|
from openlp.core.common.path import path_to_str
|
||||||
from openlp.core.common.registry import Registry
|
from openlp.core.common.registry import Registry
|
||||||
from openlp.core.common.settings import Settings
|
from openlp.core.common.settings import Settings
|
||||||
from openlp.core.lib import ServiceItemContext, build_icon, check_item_selected, create_thumb, validate_thumb
|
from openlp.core.lib import ServiceItemContext, build_icon, check_item_selected, create_thumb, validate_thumb
|
||||||
@ -127,7 +127,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
"""
|
"""
|
||||||
self.list_view.setIconSize(QtCore.QSize(88, 50))
|
self.list_view.setIconSize(QtCore.QSize(88, 50))
|
||||||
file_paths = Settings().value(self.settings_section + '/presentations files')
|
file_paths = Settings().value(self.settings_section + '/presentations files')
|
||||||
self.load_list([path_to_str(path) for path in file_paths], initial_load=True)
|
self.load_list(file_paths, initial_load=True)
|
||||||
self.populate_display_types()
|
self.populate_display_types()
|
||||||
|
|
||||||
def populate_display_types(self):
|
def populate_display_types(self):
|
||||||
@ -158,7 +158,6 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
|
|
||||||
:param list[openlp.core.common.path.Path] file_paths: List of file paths to add to the media manager.
|
:param list[openlp.core.common.path.Path] file_paths: List of file paths to add to the media manager.
|
||||||
"""
|
"""
|
||||||
file_paths = [str_to_path(filename) for filename in file_paths]
|
|
||||||
current_paths = self.get_file_list()
|
current_paths = self.get_file_list()
|
||||||
titles = [file_path.name for file_path in current_paths]
|
titles = [file_path.name for file_path in current_paths]
|
||||||
self.application.set_busy_cursor()
|
self.application.set_busy_cursor()
|
||||||
@ -175,7 +174,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
if not file_path.exists():
|
if not file_path.exists():
|
||||||
item_name = QtWidgets.QListWidgetItem(file_name)
|
item_name = QtWidgets.QListWidgetItem(file_name)
|
||||||
item_name.setIcon(UiIcons().delete)
|
item_name.setIcon(UiIcons().delete)
|
||||||
item_name.setData(QtCore.Qt.UserRole, path_to_str(file_path))
|
item_name.setData(QtCore.Qt.UserRole, file_path)
|
||||||
item_name.setToolTip(str(file_path))
|
item_name.setToolTip(str(file_path))
|
||||||
self.list_view.addItem(item_name)
|
self.list_view.addItem(item_name)
|
||||||
else:
|
else:
|
||||||
@ -211,7 +210,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
'This type of presentation is not supported.'))
|
'This type of presentation is not supported.'))
|
||||||
continue
|
continue
|
||||||
item_name = QtWidgets.QListWidgetItem(file_name)
|
item_name = QtWidgets.QListWidgetItem(file_name)
|
||||||
item_name.setData(QtCore.Qt.UserRole, path_to_str(file_path))
|
item_name.setData(QtCore.Qt.UserRole, file_path)
|
||||||
item_name.setIcon(icon)
|
item_name.setIcon(icon)
|
||||||
item_name.setToolTip(str(file_path))
|
item_name.setToolTip(str(file_path))
|
||||||
self.list_view.addItem(item_name)
|
self.list_view.addItem(item_name)
|
||||||
@ -230,8 +229,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
self.application.set_busy_cursor()
|
self.application.set_busy_cursor()
|
||||||
self.main_window.display_progress_bar(len(row_list))
|
self.main_window.display_progress_bar(len(row_list))
|
||||||
for item in items:
|
for item in items:
|
||||||
file_path = str_to_path(item.data(QtCore.Qt.UserRole))
|
self.clean_up_thumbnails(item.data(QtCore.Qt.UserRole))
|
||||||
self.clean_up_thumbnails(file_path)
|
|
||||||
self.main_window.increment_progress_bar()
|
self.main_window.increment_progress_bar()
|
||||||
self.main_window.finished_progress_bar()
|
self.main_window.finished_progress_bar()
|
||||||
for row in row_list:
|
for row in row_list:
|
||||||
@ -278,7 +276,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
if len(items) > 1:
|
if len(items) > 1:
|
||||||
return False
|
return False
|
||||||
if file_path is None:
|
if file_path is None:
|
||||||
file_path = str_to_path(items[0].data(QtCore.Qt.UserRole))
|
file_path = items[0].data(QtCore.Qt.UserRole)
|
||||||
file_type = file_path.suffix.lower()[1:]
|
file_type = file_path.suffix.lower()[1:]
|
||||||
if not self.display_type_combo_box.currentText():
|
if not self.display_type_combo_box.currentText():
|
||||||
return False
|
return False
|
||||||
@ -293,7 +291,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
service_item.theme = -1
|
service_item.theme = -1
|
||||||
for bitem in items:
|
for bitem in items:
|
||||||
if file_path is None:
|
if file_path is None:
|
||||||
file_path = str_to_path(bitem.data(QtCore.Qt.UserRole))
|
file_path = bitem.data(QtCore.Qt.UserRole)
|
||||||
path, file_name = file_path.parent, file_path.name
|
path, file_name = file_path.parent, file_path.name
|
||||||
service_item.title = file_name
|
service_item.title = file_name
|
||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
@ -329,7 +327,7 @@ class PresentationMediaItem(MediaManagerItem):
|
|||||||
service_item.processor = self.display_type_combo_box.currentText()
|
service_item.processor = self.display_type_combo_box.currentText()
|
||||||
service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
|
service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
|
||||||
for bitem in items:
|
for bitem in items:
|
||||||
file_path = str_to_path(bitem.data(QtCore.Qt.UserRole))
|
file_path = bitem.data(QtCore.Qt.UserRole)
|
||||||
path, file_name = file_path.parent, file_path.name
|
path, file_name = file_path.parent, file_path.name
|
||||||
service_item.title = file_name
|
service_item.title = file_name
|
||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
|
@ -143,7 +143,7 @@ class TestThemeManager(TestCase):
|
|||||||
mocked_theme.export_theme.return_value = "{}"
|
mocked_theme.export_theme.return_value = "{}"
|
||||||
|
|
||||||
# WHEN: Calling _write_theme with a theme with a name with special characters in it
|
# WHEN: Calling _write_theme with a theme with a name with special characters in it
|
||||||
theme_manager._write_theme(mocked_theme, None, None)
|
theme_manager._write_theme(mocked_theme)
|
||||||
|
|
||||||
# THEN: It should have been created
|
# THEN: It should have been created
|
||||||
assert os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.json')) is True, \
|
assert os.path.exists(os.path.join(self.temp_folder, 'theme 愛 name', 'theme 愛 name.json')) is True, \
|
||||||
@ -224,7 +224,7 @@ class TestThemeManager(TestCase):
|
|||||||
theme_manager = ThemeManager(None)
|
theme_manager = ThemeManager(None)
|
||||||
|
|
||||||
# WHEN: unzip_theme is called
|
# WHEN: unzip_theme is called
|
||||||
theme_manager.unzip_theme('theme.file', 'folder')
|
theme_manager.unzip_theme(Path('theme.file'), Path('folder'))
|
||||||
|
|
||||||
# THEN: The critical_error_message_box should have been called
|
# THEN: The critical_error_message_box should have been called
|
||||||
assert mocked_critical_error_message_box.call_count == 1, 'Should have been called once'
|
assert mocked_critical_error_message_box.call_count == 1, 'Should have been called once'
|
||||||
|
Loading…
Reference in New Issue
Block a user