Remove an unnecessary exception; Notify the user if one of the plugins fails to initialise; Try to make image slides work properly.

This commit is contained in:
Raoul Snyman 2018-06-30 21:36:32 -07:00
parent af446d31b9
commit 0d0ec8f818
3 changed files with 36 additions and 39 deletions

View File

@ -113,7 +113,6 @@ class CategoryActionList(object):
if item[1] == action: if item[1] == action:
self.actions.remove(item) self.actions.remove(item)
return return
raise ValueError('Action "{action}" does not exist.'.format(action=action))
class CategoryList(object): class CategoryList(object):

View File

@ -24,8 +24,11 @@ Provide plugin management
""" """
import os import os
from PyQt5 import QtWidgets
from openlp.core.common import extension_loader from openlp.core.common import extension_loader
from openlp.core.common.applocation import AppLocation from openlp.core.common.applocation import AppLocation
from openlp.core.common.i18n import UiStrings
from openlp.core.common.mixins import LogMixin, RegistryProperties from openlp.core.common.mixins import LogMixin, RegistryProperties
from openlp.core.common.registry import RegistryBase from openlp.core.common.registry import RegistryBase
from openlp.core.lib import Plugin, PluginStatus from openlp.core.lib import Plugin, PluginStatus
@ -152,12 +155,21 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
Loop through all the plugins and give them an opportunity to initialise themselves. Loop through all the plugins and give them an opportunity to initialise themselves.
""" """
uninitialised_plugins = []
for plugin in self.plugins: for plugin in self.plugins:
self.log_info('initialising plugins {plugin} in a {state} state'.format(plugin=plugin.name, self.log_info('initialising plugins {plugin} in a {state} state'.format(plugin=plugin.name,
state=plugin.is_active())) state=plugin.is_active()))
if plugin.is_active(): if plugin.is_active():
plugin.initialise() try:
self.log_info('Initialisation Complete for {plugin}'.format(plugin=plugin.name)) plugin.initialise()
self.log_info('Initialisation Complete for {plugin}'.format(plugin=plugin.name))
except Exception:
uninitialised_plugins.append(plugin.name.title())
self.log_exception('Unable to initialise plugin {plugin}'.format(plugin=plugin.name))
if uninitialised_plugins:
QtWidgets.QMessageBox.critical(None, UiStrings().Error, 'Unable to initialise the following plugins:\n' +
'\n'.join(uninitialised_plugins) + '\n\nSee the log file for more details',
QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
def finalise_plugins(self): def finalise_plugins(self):
""" """

View File

@ -31,7 +31,7 @@ from openlp.core.common.mixins import RegistryProperties
from openlp.core.common.path import Path from openlp.core.common.path import Path
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 ImageSource, ItemCapabilities, ServiceItem from openlp.core.lib import ItemCapabilities, ServiceItem
from openlp.core.widgets.layouts import AspectRatioLayout from openlp.core.widgets.layouts import AspectRatioLayout
@ -54,6 +54,16 @@ def handle_mime_data_urls(mime_data):
return file_paths return file_paths
def remove_url_prefix(filename):
"""
Remove the "file://" URL prefix
:param str filename: The filename that may have a file URL prefix
:returns str: The file name without the file URL prefix
"""
return filename.replace('file://', '')
class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties): class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
""" """
A special type of QTableWidget which lists the slides in the slide controller A special type of QTableWidget which lists the slides in the slide controller
@ -187,52 +197,28 @@ class ListPreviewWidget(QtWidgets.QTableWidget, RegistryProperties):
else: else:
label = QtWidgets.QLabel() label = QtWidgets.QLabel()
label.setContentsMargins(4, 4, 4, 4) label.setContentsMargins(4, 4, 4, 4)
if self.service_item.is_media(): label.setAlignment(QtCore.Qt.AlignCenter)
label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter) if not self.service_item.is_media():
else:
label.setScaledContents(True) label.setScaledContents(True)
if self.service_item.is_command(): if self.service_item.is_command():
if self.service_item.is_capable(ItemCapabilities.HasThumbnails): if self.service_item.is_capable(ItemCapabilities.HasThumbnails):
image = self.image_manager.get_image(slide['image'], ImageSource.CommandPlugins) pixmap = QtGui.QPixmap(remove_url_prefix(slide['thumbnail']))
pixmap = QtGui.QPixmap.fromImage(image)
else: else:
pixmap = QtGui.QPixmap(slide['image']) pixmap = QtGui.QPixmap(remove_url_prefix(slide['image']))
else: else:
# image = self.image_manager.get_image(slide['filename'], ImageSource.ImagePlugin) pixmap = QtGui.QPixmap(remove_url_prefix(slide['filename']))
# pixmap = QtGui.QPixmap.fromImage(image)
pixmap = QtGui.QPixmap(slide['filename'].replace('file://', ''))
# pixmap.setDevicePixelRatio(label.devicePixelRatio())
label.setPixmap(pixmap) label.setPixmap(pixmap)
label.setScaledContents(True)
label.setAlignment(QtCore.Qt.AlignCenter)
container = QtWidgets.QWidget() container = QtWidgets.QWidget()
layout = AspectRatioLayout(container, self.screen_ratio) layout = AspectRatioLayout(container, self.screen_ratio)
layout.setContentsMargins(0, 0, 0, 0) layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(label) layout.addWidget(label)
container.setLayout(layout) container.setLayout(layout)
# slide_height = width // self.screen_ratio slide_height = width // self.screen_ratio
# Setup and validate row height cap if in use. max_slide_height = Settings().value('advanced/slide max height')
# max_img_row_height = Settings().value('advanced/slide max height') if slide_height < 0:
# if isinstance(max_img_row_height, int) and max_img_row_height != 0: slide_height = max_slide_height
# if max_img_row_height > 0 and slide_height > max_img_row_height: else:
# # Manual Setting slide_height = min(slide_height, max_slide_height)
# slide_height = max_img_row_height
# elif max_img_row_height < 0 and slide_height > self.auto_row_height:
# # Auto Setting
# slide_height = self.auto_row_height
# label.setMaximumWidth(slide_height * self.screen_ratio)
# label.resize(slide_height * self.screen_ratio, slide_height)
# # Build widget with stretch padding
# container = QtWidgets.QWidget()
# hbox = QtWidgets.QHBoxLayout()
# hbox.setContentsMargins(0, 0, 0, 0)
# hbox.addWidget(label, stretch=1)
# hbox.addStretch(0)
# container.setLayout(hbox)
# # Add to table
# self.setCellWidget(slide_index, 0, container)
# else:
# Add to table
self.setCellWidget(slide_index, 0, container) self.setCellWidget(slide_index, 0, container)
row += 1 row += 1
text.append(str(row)) text.append(str(row))