openlp/openlp/plugins/presentations/presentationplugin.py

182 lines
8.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2020 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# 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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
"""
The :mod:`openlp.plugins.presentations.presentationplugin` module provides the ability for OpenLP to display
presentations from a variety of document formats.
"""
import logging
2017-12-28 08:08:12 +00:00
import os
2017-10-07 07:05:07 +00:00
from openlp.core.common import extension_loader
2018-04-10 19:26:56 +00:00
from openlp.core.common.i18n import translate
from openlp.core.lib import build_icon
from openlp.core.lib.plugin import Plugin, StringContent
2019-05-18 04:56:15 +00:00
from openlp.core.state import State
2018-10-02 04:39:42 +00:00
from openlp.core.ui.icons import UiIcons
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController
from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem
from openlp.plugins.presentations.lib.presentationtab import PresentationTab
2018-10-02 04:39:42 +00:00
log = logging.getLogger(__name__)
class PresentationPlugin(Plugin):
"""
This plugin allowed a Presentation to be opened, controlled and displayed on the output display. The plugin controls
2018-02-02 21:33:41 +00:00
third party applications such as OpenOffice.org Impress, and Microsoft PowerPoint.
"""
2013-08-31 18:17:38 +00:00
log = logging.getLogger('PresentationPlugin')
2013-01-23 21:05:25 +00:00
def __init__(self):
"""
PluginPresentation constructor.
"""
2013-08-31 18:17:38 +00:00
log.debug('Initialised')
self.controllers = {}
Plugin.__init__(self, 'presentations', None)
self.weight = -8
2018-04-07 19:41:00 +00:00
self.icon_path = UiIcons().presentation
2013-03-19 19:43:22 +00:00
self.icon = build_icon(self.icon_path)
2018-10-26 18:30:59 +00:00
State().add_service('presentation', self.weight, is_plugin=True)
State().update_pre_conditions('presentation', self.check_pre_conditions())
2013-04-05 19:37:15 +00:00
def create_settings_tab(self, parent):
"""
Create the settings Tab.
:param parent: parent UI Element
"""
2013-03-19 19:43:22 +00:00
visible_name = self.get_string(StringContent.VisibleName)
2013-08-31 18:17:38 +00:00
self.settings_tab = PresentationTab(parent, self.name, visible_name['title'], self.controllers, self.icon_path)
def initialise(self):
"""
Initialise the plugin. Determine which controllers are enabled are start their processes.
"""
2013-08-31 18:17:38 +00:00
log.info('Presentations Initialising')
2013-08-01 15:11:03 +00:00
super(PresentationPlugin, self).initialise()
for controller in self.controllers:
if self.controllers[controller].enabled():
try:
self.controllers[controller].start_process()
except Exception:
log.exception('Failed to start controller process')
self.controllers[controller].available = False
2013-03-19 19:43:22 +00:00
self.media_item.build_file_mask_string()
def finalise(self):
"""
Finalise the plugin. Ask all the enabled presentation applications to close down their applications and release
resources.
"""
2013-08-31 18:17:38 +00:00
log.info('Plugin Finalise')
2011-10-03 20:12:57 +00:00
# Ask each controller to tidy up.
for key in self.controllers:
controller = self.controllers[key]
if controller.enabled():
controller.kill()
2013-08-01 15:11:03 +00:00
super(PresentationPlugin, self).finalise()
2013-03-19 17:53:32 +00:00
def create_media_manager_item(self):
"""
Create the Media Manager List.
"""
self.media_item = PresentationMediaItem(self.main_window.media_dock_manager.media_dock, self, self.controllers)
2013-03-19 19:43:22 +00:00
def register_controllers(self, controller):
"""
Register each presentation controller (Impress, PPT etc) and store for later use.
:param controller: controller to register
"""
self.controllers[controller.name] = controller
2013-03-19 17:53:32 +00:00
def check_pre_conditions(self):
"""
Check to see if we have any presentation software available. If not do not install the plugin.
"""
2013-08-31 18:17:38 +00:00
log.debug('check_pre_conditions')
controller_dir = os.path.join('plugins', 'presentations', 'lib')
# Find all files that do not begin with '.' (lp:#1738047) and end with controller.py
glob_pattern = os.path.join(controller_dir, '[!.]*controller.py')
extension_loader(glob_pattern, ['presentationcontroller.py'])
controller_classes = PresentationController.__subclasses__()
for controller_class in controller_classes:
controller = controller_class(self)
2013-03-19 19:43:22 +00:00
self.register_controllers(controller)
2012-04-16 07:02:24 +00:00
return bool(self.controllers)
def app_startup(self):
"""
Perform tasks on application startup.
"""
# TODO: Can be removed when the upgrade path to OpenLP 3.0 is no longer needed, also ensure code in
# PresentationDocument.get_thumbnail_folder and PresentationDocument.get_temp_folder is removed
super().app_startup()
presentation_paths = self.settings.value('presentations/presentations files')
2017-11-18 22:37:24 +00:00
for path in presentation_paths:
self.media_item.clean_up_thumbnails(path, clean_for_update=True)
self.media_item.list_view.clear()
2020-05-07 05:18:37 +00:00
# Update the thumbnail scheme if needed
if self.settings.value('presentations/thumbnail_scheme') != 'sha256file':
for path in presentation_paths:
self.media_item.update_thumbnail_scheme(path)
self.settings.setValue('presentations/thumbnail_scheme', 'sha256file')
2017-11-18 22:37:24 +00:00
self.media_item.validate_and_load(presentation_paths)
2016-01-04 00:18:01 +00:00
@staticmethod
def about():
"""
Return information about this plugin.
"""
about_text = translate('PresentationPlugin', '<strong>Presentation '
2014-03-04 18:49:30 +00:00
'Plugin</strong><br />The presentation plugin provides the '
'ability to show presentations using a number of different '
'programs. The choice of available presentation programs is '
'available to the user in a drop down box.')
return about_text
2013-02-19 21:23:56 +00:00
def set_plugin_text_strings(self):
"""
Called to define all translatable texts of the plugin.
"""
2014-04-12 20:19:22 +00:00
# Name PluginList
2013-03-19 19:43:22 +00:00
self.text_strings[StringContent.Name] = {
2013-08-31 18:17:38 +00:00
'singular': translate('PresentationPlugin', 'Presentation', 'name singular'),
'plural': translate('PresentationPlugin', 'Presentations', 'name plural')
}
2014-04-12 20:19:22 +00:00
# Name for MediaDockManager, SettingsManager
2013-03-19 19:43:22 +00:00
self.text_strings[StringContent.VisibleName] = {
2013-08-31 18:17:38 +00:00
'title': translate('PresentationPlugin', 'Presentations', 'container title')
2010-09-15 17:55:27 +00:00
}
# Middle Header Bar
2011-02-14 17:25:51 +00:00
tooltips = {
2013-08-31 18:17:38 +00:00
'load': translate('PresentationPlugin', 'Load a new presentation.'),
'import': '',
'new': '',
'edit': '',
'delete': translate('PresentationPlugin', 'Delete the selected presentation.'),
'preview': translate('PresentationPlugin', 'Preview the selected presentation.'),
'live': translate('PresentationPlugin', 'Send the selected presentation live.'),
'service': translate('PresentationPlugin', 'Add the selected presentation to the service.')
2011-02-14 18:20:59 +00:00
}
2013-03-19 19:43:22 +00:00
self.set_plugin_ui_text_strings(tooltips)