More cleanups

This commit is contained in:
Tim Bentley 2012-12-09 09:26:47 +00:00
parent 6748266fba
commit 39f7aabeeb

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
############################################################################### ###############################################################################
# OpenLP - Open Source Lyrics Projection # # OpenLP - Open Source Lyrics Projection #
@ -32,15 +32,13 @@ import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, SettingsManager, translate, \
SettingsManager, translate, check_item_selected, Receiver, MediaType, \ check_item_selected, Receiver, MediaType, ServiceItem, ServiceItemContext, check_directory_exists
ServiceItem, build_html, ServiceItemContext
from openlp.core.lib.settings import Settings from openlp.core.lib.settings import Settings
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ from openlp.core.lib.ui import UiStrings, critical_error_message_box, create_horizontal_adjusting_combo_box
create_horizontal_adjusting_combo_box
from openlp.core.ui import DisplayController, Display, DisplayControllerType from openlp.core.ui import DisplayController, Display, DisplayControllerType
from openlp.core.ui.media import get_media_players, set_media_players from openlp.core.ui.media import get_media_players, set_media_players
from openlp.core.utils import locale_compare from openlp.core.utils import AppLocation, locale_compare
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -67,23 +65,16 @@ class MediaMediaItem(MediaManagerItem):
self.displayController = DisplayController(parent) self.displayController = DisplayController(parent)
self.displayController.controllerLayout = QtGui.QVBoxLayout() self.displayController.controllerLayout = QtGui.QVBoxLayout()
self.plugin.mediaController.register_controller(self.displayController) self.plugin.mediaController.register_controller(self.displayController)
self.plugin.mediaController.set_controls_visible(self.displayController, self.plugin.mediaController.set_controls_visible(self.displayController, False)
False) self.displayController.previewDisplay = Display(self.displayController, False, self.displayController)
self.displayController.previewDisplay = Display(self.displayController,
False, self.displayController)
self.displayController.previewDisplay.hide() self.displayController.previewDisplay.hide()
self.displayController.previewDisplay.setGeometry( self.displayController.previewDisplay.setGeometry(QtCore.QRect(0, 0, 300, 300))
QtCore.QRect(0, 0, 300, 300)) self.displayController.previewDisplay.screen = {u'size':self.displayController.previewDisplay.geometry()}
self.displayController.previewDisplay.screen = \
{u'size':self.displayController.previewDisplay.geometry()}
self.displayController.previewDisplay.setup() self.displayController.previewDisplay.setup()
self.plugin.mediaController.setup_display( self.plugin.mediaController.setup_display(self.displayController.previewDisplay, False)
self.displayController.previewDisplay, False)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'video_background_replaced'), QtCore.SIGNAL(u'video_background_replaced'), self.videobackgroundReplaced)
self.videobackgroundReplaced) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.rebuild_players)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.rebuild_players)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'config_screen_changed'), self.displaySetup) QtCore.SIGNAL(u'config_screen_changed'), self.displaySetup)
# Allow DnD from the desktop # Allow DnD from the desktop
@ -115,8 +106,7 @@ class MediaMediaItem(MediaManagerItem):
self.replaceAction = self.toolbar.addToolbarAction(u'replaceAction', self.replaceAction = self.toolbar.addToolbarAction(u'replaceAction',
icon=u':/slides/slide_blank.png', triggers=self.onReplaceClick) icon=u':/slides/slide_blank.png', triggers=self.onReplaceClick)
self.resetAction = self.toolbar.addToolbarAction(u'resetAction', self.resetAction = self.toolbar.addToolbarAction(u'resetAction',
icon=u':/system/system_close.png', visible=False, icon=u':/system/system_close.png', visible=False, triggers=self.onResetClick)
triggers=self.onResetClick)
self.mediaWidget = QtGui.QWidget(self) self.mediaWidget = QtGui.QWidget(self)
self.mediaWidget.setObjectName(u'mediaWidget') self.mediaWidget.setObjectName(u'mediaWidget')
self.displayLayout = QtGui.QFormLayout(self.mediaWidget) self.displayLayout = QtGui.QFormLayout(self.mediaWidget)
@ -124,16 +114,13 @@ class MediaMediaItem(MediaManagerItem):
self.displayLayout.setObjectName(u'displayLayout') self.displayLayout.setObjectName(u'displayLayout')
self.displayTypeLabel = QtGui.QLabel(self.mediaWidget) self.displayTypeLabel = QtGui.QLabel(self.mediaWidget)
self.displayTypeLabel.setObjectName(u'displayTypeLabel') self.displayTypeLabel.setObjectName(u'displayTypeLabel')
self.displayTypeComboBox = create_horizontal_adjusting_combo_box( self.displayTypeComboBox = create_horizontal_adjusting_combo_box(self.mediaWidget, u'displayTypeComboBox')
self.mediaWidget, u'displayTypeComboBox')
self.displayTypeLabel.setBuddy(self.displayTypeComboBox) self.displayTypeLabel.setBuddy(self.displayTypeComboBox)
self.displayLayout.addRow(self.displayTypeLabel, self.displayLayout.addRow(self.displayTypeLabel, self.displayTypeComboBox)
self.displayTypeComboBox)
# Add the Media widget to the page layout # Add the Media widget to the page layout
self.pageLayout.addWidget(self.mediaWidget) self.pageLayout.addWidget(self.mediaWidget)
QtCore.QObject.connect(self.displayTypeComboBox, QtCore.QObject.connect(self.displayTypeComboBox,
QtCore.SIGNAL(u'currentIndexChanged (int)'), QtCore.SIGNAL(u'currentIndexChanged (int)'), self.overridePlayerChanged)
self.overridePlayerChanged)
def overridePlayerChanged(self, index): def overridePlayerChanged(self, index):
player = get_media_players()[0] player = get_media_players()[0]
@ -146,8 +133,7 @@ class MediaMediaItem(MediaManagerItem):
""" """
Called to reset the Live background with the media selected, Called to reset the Live background with the media selected,
""" """
self.plugin.liveController.mediaController.media_reset( self.plugin.liveController.mediaController.media_reset(self.plugin.liveController)
self.plugin.liveController)
self.resetAction.setVisible(False) self.resetAction.setVisible(False)
def videobackgroundReplaced(self): def videobackgroundReplaced(self):
@ -161,32 +147,27 @@ class MediaMediaItem(MediaManagerItem):
Called to replace Live background with the media selected. Called to replace Live background with the media selected.
""" """
if check_item_selected(self.listView, if check_item_selected(self.listView,
translate('MediaPlugin.MediaItem', translate('MediaPlugin.MediaItem', 'You must select a media file to replace the background with.')):
'You must select a media file to replace the background with.')):
item = self.listView.currentItem() item = self.listView.currentItem()
filename = unicode(item.data(QtCore.Qt.UserRole).toString()) filename = unicode(item.data(QtCore.Qt.UserRole).toString())
if os.path.exists(filename): if os.path.exists(filename):
service_item = ServiceItem() service_item = ServiceItem()
service_item.title = u'webkit' service_item.title = u'Automatic'
service_item.shortname = service_item.title service_item.shortname = service_item.title
(path, name) = os.path.split(filename) (path, name) = os.path.split(filename)
service_item.add_from_command(path, name,CLAPPERBOARD) service_item.add_from_command(path, name,CLAPPERBOARD)
if self.plugin.liveController.mediaController.video( if self.plugin.liveController.mediaController.video(
DisplayControllerType.Live, service_item, DisplayControllerType.Live, service_item,videoBehindText=True):
videoBehindText=True):
self.resetAction.setVisible(True) self.resetAction.setVisible(True)
else: else:
critical_error_message_box(UiStrings().LiveBGError, critical_error_message_box(UiStrings().LiveBGError,
translate('MediaPlugin.MediaItem', translate('MediaPlugin.MediaItem', 'There was no display item to amend.'))
'There was no display item to amend.'))
else: else:
critical_error_message_box(UiStrings().LiveBGError, critical_error_message_box(UiStrings().LiveBGError, unicode(translate('MediaPlugin.MediaItem',
unicode(translate('MediaPlugin.MediaItem', 'There was a problem replacing your background, the media file "%s" no longer exists.')) % filename)
'There was a problem replacing your background, '
'the media file "%s" no longer exists.')) % filename)
def generateSlideData(self, service_item, item=None, xmlVersion=False, def generateSlideData(self, service_item, item=None, xmlVersion=False, remote=False,
remote=False, context=ServiceItemContext.Live): context=ServiceItemContext.Live):
if item is None: if item is None:
item = self.listView.currentItem() item = self.listView.currentItem()
if item is None: if item is None:
@ -195,10 +176,8 @@ class MediaMediaItem(MediaManagerItem):
if not os.path.exists(filename): if not os.path.exists(filename):
if not remote: if not remote:
# File is no longer present # File is no longer present
critical_error_message_box( critical_error_message_box(translate('MediaPlugin.MediaItem', 'Missing Media File'),
translate('MediaPlugin.MediaItem', 'Missing Media File'), unicode(translate('MediaPlugin.MediaItem', 'The file %s no longer exists.')) % filename)
unicode(translate('MediaPlugin.MediaItem',
'The file %s no longer exists.')) % filename)
return False return False
service_item.title = unicode(self.displayTypeComboBox.currentText()) service_item.title = unicode(self.displayTypeComboBox.currentText())
service_item.shortname = service_item.title service_item.shortname = service_item.title
@ -213,8 +192,7 @@ class MediaMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.RequiresMedia) service_item.add_capability(ItemCapabilities.RequiresMedia)
service_item.add_capability(ItemCapabilities.HasDetailedTitleDisplay) service_item.add_capability(ItemCapabilities.HasDetailedTitleDisplay)
if Settings().value(self.settingsSection + u'/media auto start', if Settings().value(self.settingsSection + u'/media auto start',
QtCore.QVariant(QtCore.Qt.Unchecked)).toInt()[0]\ QtCore.QVariant(QtCore.Qt.Unchecked)).toInt()[0] == QtCore.Qt.Checked:
== QtCore.Qt.Checked:
service_item.will_auto_start = True service_item.will_auto_start = True
# force a non-existent theme # force a non-existent theme
service_item.theme = -1 service_item.theme = -1
@ -223,6 +201,10 @@ class MediaMediaItem(MediaManagerItem):
def initialise(self): def initialise(self):
self.listView.clear() self.listView.clear()
self.listView.setIconSize(QtCore.QSize(88, 50)) self.listView.setIconSize(QtCore.QSize(88, 50))
self.servicePath = os.path.join(
AppLocation.get_section_data_path(self.settingsSection),
u'thumbnails')
check_directory_exists(self.servicePath)
self.loadList(SettingsManager.load_list(self.settingsSection, u'media')) self.loadList(SettingsManager.load_list(self.settingsSection, u'media'))
self.populateDisplayTypes() self.populateDisplayTypes()
@ -232,15 +214,12 @@ class MediaMediaItem(MediaManagerItem):
the settings the settings
""" """
self.populateDisplayTypes() self.populateDisplayTypes()
self.onNewFileMasks = unicode(translate('MediaPlugin.MediaItem', self.onNewFileMasks = unicode(translate('MediaPlugin.MediaItem', 'Videos (%s);;Audio (%s);;%s (*)')) % (
'Videos (%s);;Audio (%s);;%s (*)')) % (
u' '.join(self.plugin.mediaController.video_extensions_list), u' '.join(self.plugin.mediaController.video_extensions_list),
u' '.join(self.plugin.mediaController.audio_extensions_list), u' '.join(self.plugin.mediaController.audio_extensions_list), UiStrings().AllFiles)
UiStrings().AllFiles)
def displaySetup(self): def displaySetup(self):
self.plugin.mediaController.setup_display( self.plugin.mediaController.setup_display(self.displayController.previewDisplay, False)
self.displayController.previewDisplay, False)
def populateDisplayTypes(self): def populateDisplayTypes(self):
""" """
@ -278,14 +257,12 @@ class MediaMediaItem(MediaManagerItem):
row_list.sort(reverse=True) row_list.sort(reverse=True)
for row in row_list: for row in row_list:
self.listView.takeItem(row) self.listView.takeItem(row)
SettingsManager.set_list(self.settingsSection, SettingsManager.set_list(self.settingsSection, u'media', self.getFileList())
u'media', self.getFileList())
def loadList(self, media): def loadList(self, media):
# Sort the media by its filename considering language specific # Sort the media by its filename considering language specific
# characters. # characters.
media.sort(cmp=locale_compare, media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1])
key=lambda filename: os.path.split(unicode(filename))[1])
for track in media: for track in media:
track_info = QtCore.QFileInfo(track) track_info = QtCore.QFileInfo(track)
if not os.path.exists(track): if not os.path.exists(track):
@ -296,8 +273,7 @@ class MediaMediaItem(MediaManagerItem):
elif track_info.isFile(): elif track_info.isFile():
filename = os.path.split(unicode(track))[1] filename = os.path.split(unicode(track))[1]
item_name = QtGui.QListWidgetItem(filename) item_name = QtGui.QListWidgetItem(filename)
if u'*.%s' % (filename.split(u'.')[-1].lower()) in \ if u'*.%s' % (filename.split(u'.')[-1].lower()) in self.plugin.mediaController.audio_extensions_list:
self.plugin.mediaController.audio_extensions_list:
item_name.setIcon(AUDIO) item_name.setIcon(AUDIO)
else: else:
item_name.setIcon(VIDEO) item_name.setIcon(VIDEO)
@ -312,8 +288,7 @@ class MediaMediaItem(MediaManagerItem):
def getList(self, type=MediaType.Audio): def getList(self, type=MediaType.Audio):
media = SettingsManager.load_list(self.settingsSection, u'media') media = SettingsManager.load_list(self.settingsSection, u'media')
media.sort(cmp=locale_compare, media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1])
key=lambda filename: os.path.split(unicode(filename))[1])
ext = [] ext = []
if type == MediaType.Audio: if type == MediaType.Audio:
ext = self.plugin.mediaController.audio_extensions_list ext = self.plugin.mediaController.audio_extensions_list