openlp/openlp/plugins/presentations/presentationplugin.py

176 lines
8.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2013-01-05 22:17:30 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2015-12-31 22:46:06 +00:00
# Copyright (c) 2008-2016 OpenLP Developers #
# --------------------------------------------------------------------------- #
# 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; version 2 of the License. #
# #
# 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, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`presentationplugin` module provides the ability for OpenLP to display presentations from a variety of document
formats.
"""
import os
import logging
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore
2013-01-10 20:41:16 +00:00
2015-01-20 21:56:05 +00:00
from openlp.core.common import AppLocation, Settings, translate
2013-10-13 21:07:28 +00:00
from openlp.core.lib import Plugin, StringContent, build_icon
2013-02-03 21:46:56 +00:00
from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab
log = logging.getLogger(__name__)
2014-03-04 18:49:30 +00:00
__default_settings__ = {'presentations/override app': QtCore.Qt.Unchecked,
'presentations/enable_pdf_program': QtCore.Qt.Unchecked,
'presentations/pdf_program': '',
'presentations/Impress': QtCore.Qt.Checked,
'presentations/Powerpoint': QtCore.Qt.Checked,
'presentations/Powerpoint Viewer': QtCore.Qt.Checked,
'presentations/Pdf': QtCore.Qt.Checked,
2015-01-20 21:56:05 +00:00
'presentations/presentations files': [],
'presentations/thumbnail_scheme': '',
'presentations/powerpoint slide click advance': QtCore.Qt.Unchecked,
'presentations/powerpoint control window': QtCore.Qt.Unchecked
2014-03-04 18:49:30 +00:00
}
class PresentationPlugin(Plugin):
"""
This plugin allowed a Presentation to be opened, controlled and displayed on the output display. The plugin controls
third party applications such as OpenOffice.org Impress, Microsoft PowerPoint and the PowerPoint viewer.
"""
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 = {}
2013-08-31 18:17:38 +00:00
Plugin.__init__(self, 'presentations', __default_settings__, __default_settings__)
self.weight = -8
2013-08-31 18:17:38 +00:00
self.icon_path = ':/plugins/plugin_presentations.png'
2013-03-19 19:43:22 +00:00
self.icon = build_icon(self.icon_path)
2013-04-05 19:37:15 +00:00
def create_settings_tab(self, parent):
"""
Create the settings Tab.
"""
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:
2014-06-30 20:59:22 +00:00
log.warning('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.
"""
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(AppLocation.get_directory(AppLocation.PluginsDir), 'presentations', 'lib')
for filename in os.listdir(controller_dir):
2013-08-31 18:17:38 +00:00
if filename.endswith('controller.py') and not filename == 'presentationcontroller.py':
path = os.path.join(controller_dir, filename)
if os.path.isfile(path):
2013-08-31 18:17:38 +00:00
module_name = 'openlp.plugins.presentations.lib.' + os.path.splitext(filename)[0]
log.debug('Importing controller %s', module_name)
try:
2013-03-16 11:05:52 +00:00
__import__(module_name, globals(), locals(), [])
except ImportError:
2014-06-30 20:59:22 +00:00
log.warning('Failed to import %s on path %s', module_name, path)
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 about(self):
"""
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)