This commit is contained in:
rimach crichter@web.de 2011-07-10 23:43:07 +02:00
parent d84098348b
commit 98e1028705
16 changed files with 304 additions and 109 deletions

View File

@ -168,6 +168,7 @@ class Plugin(QtCore.QObject):
self.mediadock = plugin_helpers[u'toolbox']
self.pluginManager = plugin_helpers[u'pluginmanager']
self.formparent = plugin_helpers[u'formparent']
self.mediaManager = plugin_helpers[u'mediamanager']
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'%s_add_service_item' % self.name),
self.processAddServiceEvent)
@ -246,12 +247,6 @@ class Plugin(QtCore.QObject):
"""
pass
def addControllerItems(self, controller, control_panel):
"""
Create items for all controller Panes
"""
pass
def getSettingsTab(self, parent):
"""
Create a tab for the settings window to display the configurable

View File

@ -188,11 +188,6 @@ class PluginManager(object):
if plugin.status is not PluginStatus.Disabled:
plugin.addToolsMenuItem(tools_menu)
def hook_controller_items(self, controller, control_panel):
for plugin in self.plugins:
if plugin.status is not PluginStatus.Disabled:
plugin.addControllerItems(controller, control_panel)
def initialise_plugins(self):
"""
Loop through all the plugins and give them an opportunity to

View File

@ -77,7 +77,7 @@ class Renderer(object):
self.theme_data = None
self.bg_frame = None
self.force_page = False
self.display = MainDisplay(None, None, self.image_manager, False)
self.display = MainDisplay(None, self, self.image_manager, False)
self.display.setup()
def update_display(self):

View File

@ -31,7 +31,7 @@ and play multimedia within OpenLP.
import logging
import os
from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL
from PyQt4.phonon import Phonon
from openlp.core.lib import Receiver, build_html, ServiceItem, image_to_byte, \
@ -87,6 +87,9 @@ class MainDisplay(QtGui.QGraphicsView):
self.retranslateUi()
self.mediaObject = None
self.firstTime = True
self.setViewport(QtOpenGL.QGLWidget())
self.setStyleSheet(u'border: 0px; margin: 0px; padding: 0px;')
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool |
QtCore.Qt.WindowStaysOnTopHint)

View File

@ -38,6 +38,7 @@ from openlp.core.lib.ui import UiStrings, base_action, checkable_action, \
from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \
ThemeManager, SlideController, PluginForm, MediaDockManager, \
ShortcutListForm, DisplayTagForm
from openlp.core.ui.media import MediaManager
from openlp.core.utils import AppLocation, add_actions, LanguageManager, \
get_application_version, delete_file
from openlp.core.utils.actions import ActionList, CategoryOrder
@ -484,6 +485,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.pluginManager = PluginManager(pluginpath)
self.pluginHelpers = {}
self.imageManager = ImageManager()
self.mediaManager = MediaManager(self)
# Set up the interface
self.setupUi(self)
# Load settings after setupUi so default UI sizes are overwritten
@ -565,6 +567,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.pluginHelpers[u'toolbox'] = self.mediaDockManager
self.pluginHelpers[u'pluginmanager'] = self.pluginManager
self.pluginHelpers[u'formparent'] = self
self.pluginHelpers[u'mediamanager'] = self.mediaManager
self.pluginManager.find_plugins(pluginpath, self.pluginHelpers)
# hook methods have to happen after find_plugins. Find plugins needs
# the controllers hence the hooks have moved from setupUI() to here
@ -581,11 +584,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.pluginManager.hook_export_menu(self.fileExportMenu)
# Call the hook method to pull in tools menus.
self.pluginManager.hook_tools_menu(self.toolsMenu)
# Call the hook method to pull in plugin Controller items
self.pluginManager.hook_controller_items(
self.previewController, self.previewController.getControlPanel())
self.pluginManager.hook_controller_items(
self.liveController, self.liveController.getControlPanel())
# Call the initialise method to setup plugins.
log.info(u'initialise plugins')
self.pluginManager.initialise_plugins()

View File

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
class MediaState(object):
"""
An enumeration for possible States of the Media Player
(copied partially from Phonon::State)
"""
Loading = 0
Stopped = 1
Playing = 2
Paused = 4
Off = 6
class MediaType(object):
"""
"""
Audio = 0
Video = 1
Cd = 3
Dvd = 4
class MediaInfo(object):
"""
This class hold the media related infos
"""
file_info = None
volume = 100
isFlash = False
is_background = False
length = 0
start_time = 0
end_time = 0
media_type = MediaType()
from mediaapi import MediaAPI
from mediamanager import MediaManager

View File

@ -25,7 +25,7 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from openlp.plugins.media.lib import MediaState
from openlp.core.ui.media import MediaState
class MediaAPI(object):
"""

View File

@ -32,7 +32,8 @@ from PyQt4 import QtCore, QtGui, QtWebKit
from openlp.core.lib import OpenLPToolbar, Receiver, translate
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.plugins.media.lib import MediaAPI, MediaState, MediaInfo
from openlp.core.ui.media import MediaAPI, MediaState, MediaInfo
from openlp.core.utils import AppLocation
log = logging.getLogger(__name__)
@ -64,6 +65,7 @@ class MediaManager(object):
self.Timer = QtCore.QTimer()
self.Timer.setInterval(200)
self.withLivePreview = False
self.checkPreConditions()
#Signals
QtCore.QObject.connect(self.Timer,
QtCore.SIGNAL("timeout()"), self.video_state)
@ -90,6 +92,46 @@ class MediaManager(object):
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'media_unblank'), self.video_unblank)
def registerControllers(self, controller):
"""
Register each media API controller (Webkit, Phonon, etc) and
store for later use
"""
if controller.check_available():
self.APIs[controller.name] = controller
def checkPreConditions(self):
"""
Check to see if we have any media API's available
If Not do not install the plugin.
"""
log.debug(u'checkPreConditions')
controller_dir = os.path.join(
AppLocation.get_directory(AppLocation.AppDir),
u'core', u'ui', u'media')
for filename in os.listdir(controller_dir):
if filename.endswith(u'api.py') and \
not filename == 'mediaapi.py':
path = os.path.join(controller_dir, filename)
if os.path.isfile(path):
modulename = u'openlp.core.ui.media.' + \
os.path.splitext(filename)[0]
log.debug(u'Importing controller %s', modulename)
try:
__import__(modulename, globals(), locals(), [])
except ImportError:
log.warn(u'Failed to import %s on path %s',
modulename, path)
controller_classes = MediaAPI.__subclasses__()
for controller_class in controller_classes:
controller = controller_class(self)
self.registerControllers(controller)
if self.APIs:
return True
else:
return False
def video_state(self):
"""
Check if there is an assigned media API and do some

View File

@ -33,7 +33,7 @@ from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon
from openlp.core.lib import Receiver
from openlp.plugins.media.lib import MediaAPI, MediaState
from openlp.core.ui.media import MediaAPI, MediaState
log = logging.getLogger(__name__)
@ -76,7 +76,7 @@ class PhononAPI(MediaAPI):
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.parent.serviceManager.supportedSuffixes(extension[1:])
#self.parent.parent.serviceManagerContents.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s extensions: %s' % (mimetype,
u' '.join(extensions)))
# Add extensions for this mimetype from self.additional_extensions.
@ -87,7 +87,7 @@ class PhononAPI(MediaAPI):
ext = u'*%s' % extension
if ext not in list:
list.append(ext)
self.parent.serviceManager.supportedSuffixes(extension[1:])
#self.parent.parent.serviceManagerContents.supportedSuffixes(extension[1:])
log.info(u'MediaPlugin: %s additional extensions: %s' % (mimetype,
u' '.join(self.additional_extensions[mimetype])))
@ -96,7 +96,6 @@ class PhononAPI(MediaAPI):
def setup(self, display):
display.phononWidget = Phonon.VideoWidget(display)
display.phononWidget.setVisible(False)
display.phononWidget.resize(display.size())
display.mediaObject = Phonon.MediaObject(display)
display.audio = Phonon.AudioOutput( \
@ -184,7 +183,8 @@ class PhononAPI(MediaAPI):
def reset(self, display):
display.mediaObject.stop()
display.mediaObject.clearQueue()
display.phononWidget.setVisible(False)
self.set_visible(display, False)
display.phononWidgetProxy.setVisible(False)
self.state = MediaState.Off
def set_visible(self, display, status):

View File

@ -0,0 +1,177 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Michael Gorven, Scott Guerrieri, Matthias Hub, Meinert Jordan, #
# Armin Köhler, Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias #
# Põldaru, Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
import logging
import sys, os
from datetime import datetime
try:
import vlc
vlc_available = True
except ImportError:
vlc_available = False
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver
from openlp.core.ui.media import MediaAPI, MediaState
log = logging.getLogger(__name__)
class VlcAPI(MediaAPI):
"""
Specialiced MediaAPI class
to reflect Features of the Vlc API
"""
def __init__(self, parent):
MediaAPI.__init__(self, parent, u'Vlc')
self.parent = parent
self.video_extensions_list = [
u'*.3gp'
, u'*.asf', u'*.wmv'
, u'*.au'
, u'*.avi'
, u'*.flv'
, u'*.mov'
, u'*.mp4'
, u'*.ogm', u'*.ogg'
, u'*.mkv', u'*.mka'
, u'*.ts', u'*.mpg'
, u'*.mpg', u'*.mp3', u'*.mp2'
, u'*.nsc'
, u'*.nsv'
, u'*.nut'
, u'*.ra', u'*.ram', u'*.rm', u'*.rv' ,u'*.rmbv'
, u'*.a52', u'*.dts', u'*.aac', u'*.flac' ,u'*.dv', u'*.vid'
, u'*.tta', u'*.tac'
, u'*.ty'
, u'*.wav', u'*.dts'
, u'*.xa'
, u'*.iso'
]
def setup_controls(self, controller, control_panel):
pass
def setup(self, display):
display.vlcWidget = QtGui.QFrame(display)
# creating a basic vlc instance
if display.hasAudio:
display.vlcInstance = vlc.Instance()
else:
display.vlcInstance = vlc.Instance('--no-audio')
display.vlcInstance.set_log_verbosity(2)
# creating an empty vlc media player
display.vlcMediaPlayer = display.vlcInstance.media_player_new()
display.vlcWidget.resize(display.size())
display.vlcWidget.raise_()
display.vlcWidget.hide()
# the media player has to be 'connected' to the QFrame
# (otherwise a video would be displayed in it's own window)
# this is platform specific!
# you have to give the id of the QFrame (or similar object) to
# vlc, different platforms have different functions for this
if sys.platform == "linux2": # for Linux using the X Server
display.vlcMediaPlayer.set_xwindow(int(display.vlcWidget.winId()))
elif sys.platform == "win32": # for Windows
display.vlcMediaPlayer.set_hwnd(int(display.vlcWidget.winId()))
elif sys.platform == "darwin": # for MacOS
display.vlcMediaPlayer.set_agl(int(display.vlcWidget.winId()))
self.hasOwnWidget = True
def check_available(self):
return vlc_available
def load(self, display):
log.debug(u'load vid in Vlc Controller')
controller = display.controller
volume = controller.media_info.volume
file_path = str(
controller.media_info.file_info.absoluteFilePath().toUtf8())
path = os.path.normcase(file_path)
# create the media
display.vlcMedia = display.vlcInstance.media_new_path(path)
# put the media in the media player
display.vlcMediaPlayer.set_media(display.vlcMedia)
# parse the metadata of the file
display.vlcMedia.parse()
self.volume(display, volume)
return True
def mediaStateWait(self, display, mediaState):
"""
Wait for the video to change its state
Wait no longer than 5 seconds.
"""
start = datetime.now()
while not mediaState == display.vlcMedia.get_state():
if display.vlcMedia.get_state() == vlc.State.Error:
return False
Receiver.send_message(u'openlp_process_events')
if (datetime.now() - start).seconds > 5:
return False
return True
def resize(self, display):
display.vlcWidget.resize(display.size())
def play(self, display):
self.set_visible(display, True)
display.vlcMediaPlayer.play()
if self.mediaStateWait(display, vlc.State.Playing):
self.state = MediaState.Playing
def pause(self, display):
display.vlcMediaPlayer.pause()
if self.mediaStateWait(display, vlc.State.Paused):
self.state = MediaState.Paused
def stop(self, display):
display.vlcMediaPlayer.stop()
self.state = MediaState.Stopped
def volume(self, display, vol):
if display.hasAudio:
display.vlcMediaPlayer.audio_set_volume(vol)
def seek(self, display, seekVal):
if display.vlcMediaPlayer.is_seekable():
display.vlcMediaPlayer.set_position(seekVal/1000.0)
def reset(self, display):
display.vlcMediaPlayer.stop()
display.vlcWidget.setVisible(False)
self.state = MediaState.Off
def set_visible(self, display, status):
if self.hasOwnWidget:
display.vlcWidget.setVisible(status)
def update_ui(self, display):
controller = display.controller
controller.seekSlider.setMaximum(1000)
if not controller.seekSlider.isSliderDown():
currentPos = display.vlcMediaPlayer.get_position() * 1000
controller.seekSlider.setSliderPosition(currentPos)

View File

@ -30,7 +30,7 @@ import logging
from PyQt4 import QtCore, QtGui, QtWebKit
from openlp.core.lib import OpenLPToolbar, translate
from openlp.plugins.media.lib import MediaAPI, MediaState
from openlp.core.ui.media import MediaAPI, MediaState
log = logging.getLogger(__name__)
@ -267,7 +267,7 @@ class WebkitAPI(MediaAPI):
display.webView.resize(display.size())
display.webView.raise_()
self.hasOwnWidget = False
display.webView.hide()
#display.webView.hide()
def check_available(self):
return True

View File

@ -64,6 +64,7 @@ class SlideController(QtGui.QWidget):
self.ratio = float(self.screens.current[u'size'].width()) / \
float(self.screens.current[u'size'].height())
self.imageManager = self.parent().imageManager
self.mediaManager = self.parent().mediaManager
self.loopList = [
u'Play Slides Menu',
u'Loop Separator',
@ -232,6 +233,8 @@ class SlideController(QtGui.QWidget):
'Edit and reload song preview.'),
self.onEditSong)
self.controllerLayout.addWidget(self.toolbar)
# Build the Media Toolbar
self.mediaManager.addControllerItems(self, self.controllerLayout)
if self.isLive:
# Build the Song Toolbar
self.songMenu = QtGui.QToolButton(self.toolbar)

View File

@ -25,41 +25,7 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
class MediaState(object):
"""
An enumeration for possible States of the Media Player
(copied partially from Phonon::State)
"""
Loading = 0
Stopped = 1
Playing = 2
Paused = 4
Off = 6
class MediaType(object):
"""
"""
Audio = 0
Video = 1
Cd = 3
Dvd = 4
class MediaInfo(object):
"""
This class hold the media related infos
"""
file_info = None
volume = 100
isFlash = False
is_background = False
length = 0
start_time = 0
end_time = 0
media_type = MediaType()
from mediaitem import MediaMediaItem
from mediatab import MediaTab
from mediaapi import MediaAPI
from mediamanager import MediaManager
__all__ = ['MediaMediaItem']

View File

@ -34,7 +34,6 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
SettingsManager, translate, check_item_selected, Receiver
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from PyQt4.phonon import Phonon
log = logging.getLogger(__name__)

View File

@ -29,9 +29,7 @@ import logging
import os
from openlp.core.lib import Plugin, StringContent, build_icon, translate
from openlp.core.utils import AppLocation
from openlp.plugins.media.lib import MediaMediaItem, MediaTab, MediaManager, \
MediaAPI
from openlp.plugins.media.lib import MediaMediaItem, MediaTab
log = logging.getLogger(__name__)
@ -46,7 +44,6 @@ class MediaPlugin(Plugin):
self.icon = build_icon(self.icon_path)
# passed with drag and drop messages
self.dnd_id = u'Media'
self.mediaManager = MediaManager(self)
self.audio_extensions_list = \
self.mediaManager.get_audio_extensions_list()
self.video_extensions_list = \
@ -65,9 +62,6 @@ class MediaPlugin(Plugin):
'<br />The media plugin provides playback of audio and video.')
return about_text
def addControllerItems(self, controller, control_panel):
self.mediaManager.addControllerItems(controller, control_panel)
def setPluginTextStrings(self):
"""
Called to define all translatable texts of the plugin
@ -104,44 +98,6 @@ class MediaPlugin(Plugin):
self.mediaManager.video_reset(self.previewController)
self.mediaManager.video_reset(self.liveController)
def registerControllers(self, controller):
"""
Register each media API controller (Webkit, Phonon, etc) and
store for later use
"""
self.mediaManager.APIs[controller.name] = controller
def checkPreConditions(self):
"""
Check to see if we have any media API's available
If Not do not install the plugin.
"""
log.debug(u'checkPreConditions')
controller_dir = os.path.join(
AppLocation.get_directory(AppLocation.PluginsDir),
u'media', u'lib')
for filename in os.listdir(controller_dir):
if filename.endswith(u'api.py') and \
not filename == 'mediaapi.py':
path = os.path.join(controller_dir, filename)
if os.path.isfile(path):
modulename = u'openlp.plugins.media.lib.' + \
os.path.splitext(filename)[0]
log.debug(u'Importing controller %s', modulename)
try:
__import__(modulename, globals(), locals(), [])
except ImportError:
log.warn(u'Failed to import %s on path %s',
modulename, path)
controller_classes = MediaAPI.__subclasses__()
for controller_class in controller_classes:
controller = controller_class(self)
self.registerControllers(controller)
if self.mediaManager.APIs:
return True
else:
return False
def getDisplayCss(self):
"""
Add css style sheets to htmlbuilder