More code cleanups and bug fixes from previous cleanups

bzr-revno: 2218
This commit is contained in:
Tim Bentley 2013-03-26 07:48:38 +00:00
commit b3d453c9b8
18 changed files with 103 additions and 99 deletions

View File

@ -156,8 +156,7 @@ class OpenLP(QtGui.QApplication):
def is_already_running(self):
"""
Look to see if OpenLP is already running and ask if a 2nd copy
is to be started.
Look to see if OpenLP is already running and ask if a 2nd instance is to be started.
"""
self.shared_memory = QtCore.QSharedMemory('OpenLP')
if self.shared_memory.attach():

View File

@ -38,6 +38,7 @@ from PyQt4 import QtCore, QtGui, Qt
log = logging.getLogger(__name__)
class ServiceItemContext(object):
"""
The context in which a Service Item is being generated

View File

@ -94,7 +94,7 @@ class MediaManagerItem(QtGui.QWidget):
self.remote_triggered = None
self.single_service_item = True
self.quick_preview_allowed = False
self.hasSearch = False
self.has_search = False
self.page_layout = QtGui.QVBoxLayout(self)
self.page_layout.setSpacing(0)
self.page_layout.setMargin(0)

View File

@ -48,7 +48,7 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
self.mimeDataText = name
self.allow_internal_dnd = False
self.header().close()
self.defaultIndentation = self.indentation()
self.default_indentation = self.indentation()
self.setIndentation(0)
self.setAnimated(True)
assert(self.mimeDataText)
@ -125,13 +125,13 @@ class TreeWidgetWithDnD(QtGui.QTreeWidget):
event.accept()
files = []
for url in event.mimeData().urls():
localFile = url.toLocalFile()
if os.path.isfile(localFile):
files.append(localFile)
elif os.path.isdir(localFile):
listing = os.listdir(localFile)
local_file = url.toLocalFile()
if os.path.isfile(local_file):
files.append(local_file)
elif os.path.isdir(local_file):
listing = os.listdir(local_file)
for file_name in listing:
files.append(os.path.join(localFile, file_name))
files.append(os.path.join(local_file, file_name))
Registry().execute(u'%s_dnd' % self.mimeDataText, {'files': files, 'target': self.itemAt(event.pos())})
elif self.allow_internal_dnd:
event.setDropAction(QtCore.Qt.CopyAction)

View File

@ -110,8 +110,8 @@ class MediaController(object):
Registry().register_function(u'playbackPlay', self.media_play_msg)
Registry().register_function(u'playbackPause', self.media_pause_msg)
Registry().register_function(u'playbackStop', self.media_stop_msg)
Registry().register_function(u'seekSlider', self.media_seek_msg)
Registry().register_function(u'volumeSlider', self.media_volume_msg)
Registry().register_function(u'seek_slider', self.media_seek_msg)
Registry().register_function(u'volume_slider', self.media_volume_msg)
Registry().register_function(u'media_hide', self.media_hide)
Registry().register_function(u'media_blank', self.media_blank)
Registry().register_function(u'media_unblank', self.media_unblank)
@ -215,7 +215,7 @@ class MediaController(object):
for source in self.current_media_players.keys():
if self.current_media_players[source].state != MediaState.Paused:
display = self._define_display(self.display_controllers[source])
display.controller.seekSlider.setSliderPosition(0)
display.controller.seek_slider.setSliderPosition(0)
self.timer.stop()
def get_media_display_css(self):
@ -277,32 +277,32 @@ class MediaController(object):
controller.mediabar.add_toolbar_action(u'playbackStop', text=u'media_playback_stop',
icon=u':/slides/media_playback_stop.png',
tooltip=translate('OpenLP.SlideController', 'Stop playing media.'), triggers=controller.send_to_plugins)
# Build the seekSlider.
controller.seekSlider = MediaSlider(QtCore.Qt.Horizontal, self, controller)
controller.seekSlider.setMaximum(1000)
controller.seekSlider.setTracking(True)
controller.seekSlider.setMouseTracking(True)
controller.seekSlider.setToolTip(translate('OpenLP.SlideController', 'Video position.'))
controller.seekSlider.setGeometry(QtCore.QRect(90, 260, 221, 24))
controller.seekSlider.setObjectName(u'seekSlider')
controller.mediabar.add_toolbar_widget(controller.seekSlider)
# Build the volumeSlider.
controller.volumeSlider = QtGui.QSlider(QtCore.Qt.Horizontal)
controller.volumeSlider.setTickInterval(10)
controller.volumeSlider.setTickPosition(QtGui.QSlider.TicksAbove)
controller.volumeSlider.setMinimum(0)
controller.volumeSlider.setMaximum(100)
controller.volumeSlider.setTracking(True)
controller.volumeSlider.setToolTip(translate('OpenLP.SlideController', 'Audio Volume.'))
controller.volumeSlider.setValue(controller.media_info.volume)
controller.volumeSlider.setGeometry(QtCore.QRect(90, 160, 221, 24))
controller.volumeSlider.setObjectName(u'volumeSlider')
controller.mediabar.add_toolbar_widget(controller.volumeSlider)
# Build the seek_slider.
controller.seek_slider = MediaSlider(QtCore.Qt.Horizontal, self, controller)
controller.seek_slider.setMaximum(1000)
controller.seek_slider.setTracking(True)
controller.seek_slider.setMouseTracking(True)
controller.seek_slider.setToolTip(translate('OpenLP.SlideController', 'Video position.'))
controller.seek_slider.setGeometry(QtCore.QRect(90, 260, 221, 24))
controller.seek_slider.setObjectName(u'seek_slider')
controller.mediabar.add_toolbar_widget(controller.seek_slider)
# Build the volume_slider.
controller.volume_slider = QtGui.QSlider(QtCore.Qt.Horizontal)
controller.volume_slider.setTickInterval(10)
controller.volume_slider.setTickPosition(QtGui.QSlider.TicksAbove)
controller.volume_slider.setMinimum(0)
controller.volume_slider.setMaximum(100)
controller.volume_slider.setTracking(True)
controller.volume_slider.setToolTip(translate('OpenLP.SlideController', 'Audio Volume.'))
controller.volume_slider.setValue(controller.media_info.volume)
controller.volume_slider.setGeometry(QtCore.QRect(90, 160, 221, 24))
controller.volume_slider.setObjectName(u'volume_slider')
controller.mediabar.add_toolbar_widget(controller.volume_slider)
controller.controller_layout.addWidget(controller.mediabar)
controller.mediabar.setVisible(False)
# Signals
controller.seekSlider.valueChanged.connect(controller.send_to_plugins)
controller.volumeSlider.valueChanged.connect(controller.send_to_plugins)
controller.seek_slider.valueChanged.connect(controller.send_to_plugins)
controller.volume_slider.valueChanged.connect(controller.send_to_plugins)
def setup_display(self, display, preview):
"""
@ -381,7 +381,7 @@ class MediaController(object):
# stop running videos
self.media_reset(controller)
controller.media_info = MediaInfo()
controller.media_info.volume = controller.volumeSlider.value()
controller.media_info.volume = controller.volume_slider.value()
controller.media_info.is_background = video_behind_text
controller.media_info.file_info = QtCore.QFileInfo(service_item.get_frame_path())
display = self._define_display(controller)
@ -465,12 +465,12 @@ class MediaController(object):
``service_item``
The ServiceItem containing the details to be played.
"""
usedPlayers = get_media_players()[0]
used_players = get_media_players()[0]
if service_item.title != UiStrings().Automatic:
usedPlayers = [service_item.title.lower()]
used_players = [service_item.title.lower()]
if controller.media_info.file_info.isFile():
suffix = u'*.%s' % controller.media_info.file_info.suffix().lower()
for title in usedPlayers:
for title in used_players:
player = self.media_players[title]
if suffix in player.video_extensions_list:
if not controller.media_info.is_background or controller.media_info.is_background and \
@ -486,7 +486,7 @@ class MediaController(object):
controller.media_info.media_type = MediaType.Audio
return True
else:
for title in usedPlayers:
for title in used_players:
player = self.media_players[title]
if player.can_folder:
self.resize(display, player)
@ -515,12 +515,12 @@ class MediaController(object):
The controller to be played
"""
log.debug(u'media_play')
controller.seekSlider.blockSignals(True)
controller.volumeSlider.blockSignals(True)
controller.seek_slider.blockSignals(True)
controller.volume_slider.blockSignals(True)
display = self._define_display(controller)
if not self.current_media_players[controller.controller_type].play(display):
controller.seekSlider.blockSignals(False)
controller.volumeSlider.blockSignals(False)
controller.seek_slider.blockSignals(False)
controller.volume_slider.blockSignals(False)
return False
if controller.media_info.is_background:
self.media_volume(controller, 0)
@ -543,8 +543,8 @@ class MediaController(object):
# Start Timer for ui updates
if not self.timer.isActive():
self.timer.start()
controller.seekSlider.blockSignals(False)
controller.volumeSlider.blockSignals(False)
controller.seek_slider.blockSignals(False)
controller.volume_slider.blockSignals(False)
return True
def media_pause_msg(self, msg):
@ -594,7 +594,7 @@ class MediaController(object):
display.frame.evaluateJavaScript(u'show_blank("black");')
self.current_media_players[controller.controller_type].stop(display)
self.current_media_players[controller.controller_type].set_visible(display, False)
controller.seekSlider.setSliderPosition(0)
controller.seek_slider.setSliderPosition(0)
controller.mediabar.actions[u'playbackPlay'].setVisible(True)
controller.mediabar.actions[u'playbackStop'].setVisible(False)
controller.mediabar.actions[u'playbackPause'].setVisible(False)
@ -620,32 +620,35 @@ class MediaController(object):
log.debug(u'media_volume %d' % volume)
display = self._define_display(controller)
self.current_media_players[controller.controller_type].volume(display, volume)
controller.volumeSlider.setValue(volume)
controller.volume_slider.setValue(volume)
def media_seek_msg(self, msg):
"""
Responds to the request to change the seek Slider of a loaded video
Responds to the request to change the seek Slider of a loaded video via a message
``msg``
First element is the controller which should be used
Second element is a list with the seek Value as first element
Second element is a list with the seek value as first element
"""
log.debug(u'media_seek')
controller = msg[0]
seekVal = msg[1][0]
self.media_seek(controller, seekVal)
seek_value = msg[1][0]
self.media_seek(controller, seek_value)
def media_seek(self, controller, seekVal):
def media_seek(self, controller, seek_value):
"""
Responds to the request to change the seek Slider of a loaded video
``msg``
First element is the controller which should be used
Second element is a list with the seek Value as first element
``controller``
The controller to use.
``seek_value``
The value to set.
"""
log.debug(u'media_seek')
display = self._define_display(controller)
self.current_media_players[controller.controller_type].seek(display, seekVal)
self.current_media_players[controller.controller_type].seek(display, seek_value)
def media_reset(self, controller):
"""

View File

@ -103,7 +103,7 @@ class MediaPlayer(object):
"""
pass
def seek(self, display, seekVal):
def seek(self, display, seek_value):
"""
Change playing position of current Media File
"""

View File

@ -195,7 +195,7 @@ class PhononPlayer(MediaPlayer):
self.seek(display, controller.media_info.start_time * 1000)
self.volume(display, controller.media_info.volume)
controller.media_info.length = int(display.media_object.totalTime() / 1000)
controller.seekSlider.setMaximum(controller.media_info.length * 1000)
controller.seek_slider.setMaximum(controller.media_info.length * 1000)
self.state = MediaState.Playing
display.phonon_widget.raise_()
return True
@ -225,11 +225,11 @@ class PhononPlayer(MediaPlayer):
vol = float(vol) / float(100)
display.audio.setVolume(vol)
def seek(self, display, seekVal):
def seek(self, display, seek_value):
"""
Go to a particular point in the current media item
"""
display.media_object.seek(seekVal)
display.media_object.seek(seek_value)
def reset(self, display):
"""
@ -259,10 +259,10 @@ class PhononPlayer(MediaPlayer):
if display.media_object.currentTime() > controller.media_info.end_time * 1000:
self.stop(display)
self.set_visible(display, False)
if not controller.seekSlider.isSliderDown():
controller.seekSlider.blockSignals(True)
controller.seekSlider.setSliderPosition(display.media_object.currentTime())
controller.seekSlider.blockSignals(False)
if not controller.seek_slider.isSliderDown():
controller.seek_slider.blockSignals(True)
controller.seek_slider.setSliderPosition(display.media_object.currentTime())
controller.seek_slider.blockSignals(False)
def get_media_display_css(self):
"""

View File

@ -177,13 +177,13 @@ class VlcPlayer(MediaPlayer):
controller.media_info.length = int(display.vlcMediaPlayer.get_media().get_duration() / 1000)
return True
def media_state_wait(self, display, mediaState):
def media_state_wait(self, display, media_state):
"""
Wait for the video to change its state
Wait no longer than 60 seconds. (loading an iso file needs a long time)
"""
start = datetime.now()
while not mediaState == display.vlcMedia.get_state():
while not media_state == display.vlcMedia.get_state():
if display.vlcMedia.get_state() == vlc.State.Error:
return False
self.application.process_events()
@ -212,7 +212,7 @@ class VlcPlayer(MediaPlayer):
if start_time > 0:
self.seek(display, controller.media_info.start_time * 1000)
controller.media_info.length = int(display.vlcMediaPlayer.get_media().get_duration() / 1000)
controller.seekSlider.setMaximum(controller.media_info.length * 1000)
controller.seek_slider.setMaximum(controller.media_info.length * 1000)
self.state = MediaState.Playing
display.vlcWidget.raise_()
return True
@ -241,12 +241,12 @@ class VlcPlayer(MediaPlayer):
if display.has_audio:
display.vlcMediaPlayer.audio_set_volume(vol)
def seek(self, display, seekVal):
def seek(self, display, seek_value):
"""
Go to a particular position
"""
if display.vlcMediaPlayer.is_seekable():
display.vlcMediaPlayer.set_time(seekVal)
display.vlcMediaPlayer.set_time(seek_value)
def reset(self, display):
"""
@ -275,10 +275,10 @@ class VlcPlayer(MediaPlayer):
if display.vlcMediaPlayer.get_time() > controller.media_info.end_time * 1000:
self.stop(display)
self.set_visible(display, False)
if not controller.seekSlider.isSliderDown():
controller.seekSlider.blockSignals(True)
controller.seekSlider.setSliderPosition(display.vlcMediaPlayer.get_time())
controller.seekSlider.blockSignals(False)
if not controller.seek_slider.isSliderDown():
controller.seek_slider.blockSignals(True)
controller.seek_slider.setSliderPosition(display.vlcMediaPlayer.get_time())
controller.seek_slider.blockSignals(False)
def get_info(self):
"""

View File

@ -393,27 +393,27 @@ class WebkitPlayer(MediaPlayer):
display.frame.evaluateJavaScript(u'show_video("stop");')
self.state = MediaState.Stopped
def volume(self, display, vol):
def volume(self, display, volume):
"""
Set the volume
"""
controller = display.controller
# 1.0 is the highest value
if display.has_audio:
vol = float(vol) / float(100)
vol = float(volume) / float(100)
if not controller.media_info.is_flash:
display.frame.evaluateJavaScript(u'show_video(null, null, %s);' % str(vol))
def seek(self, display, seekVal):
def seek(self, display, seek_value):
"""
Go to a position in the video
"""
controller = display.controller
if controller.media_info.is_flash:
seek = seekVal
seek = seek_value
display.frame.evaluateJavaScript(u'show_flash("seek", null, null, "%s");' % (seek))
else:
seek = float(seekVal) / 1000
seek = float(seek_value) / 1000
display.frame.evaluateJavaScript(u'show_video("seek", null, null, null, "%f");' % (seek))
def reset(self, display):
@ -462,11 +462,11 @@ class WebkitPlayer(MediaPlayer):
length = int(length * 1000)
if currentTime > 0:
controller.media_info.length = length
controller.seekSlider.setMaximum(length)
if not controller.seekSlider.isSliderDown():
controller.seekSlider.blockSignals(True)
controller.seekSlider.setSliderPosition(currentTime)
controller.seekSlider.blockSignals(False)
controller.seek_slider.setMaximum(length)
if not controller.seek_slider.isSliderDown():
controller.seek_slider.blockSignals(True)
controller.seek_slider.setSliderPosition(currentTime)
controller.seek_slider.blockSignals(False)
def get_info(self):
"""

View File

@ -98,8 +98,9 @@ class SlideController(DisplayController):
u'loop_separator',
u'delay_spin_box'
]
# audioPauseItem is also in Settings so any changes need to be paired
self.audio_list = [
u'audio_pause_item',
u'audioPauseItem',
u'audio_time_label'
]
self.wide_menu = [

View File

@ -87,11 +87,11 @@ class AlertsManager(QtCore.QObject):
if not self.alert_list:
return
text = self.alert_list.pop(0)
alertTab = self.parent().settingsTab
self.live_controller.display.alert(text, alertTab.location)
alert_tab = self.parent().settings_tab
self.live_controller.display.alert(text, alert_tab.location)
# Check to see if we have a timer running.
if self.timer_id == 0:
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
self.timer_id = self.startTimer(int(alert_tab.timeout) * 1000)
def timerEvent(self, event):
"""
@ -103,7 +103,7 @@ class AlertsManager(QtCore.QObject):
"""
log.debug(u'timer event')
if event.timerId() == self.timer_id:
alertTab = self.parent().settingsTab
alertTab = self.parent().settings_tab
self.live_controller.display.alert(u'', alertTab.location)
self.killTimer(self.timer_id)
self.timer_id = 0

View File

@ -67,7 +67,7 @@ class BibleMediaItem(MediaManagerItem):
# Place to store the search results for both bibles.
self.settings = self.plugin.settings_tab
self.quick_preview_allowed = True
self.hasSearch = True
self.has_search = True
self.search_results = {}
self.second_search_results = {}
self.check_search_result()

View File

@ -60,7 +60,7 @@ class CustomMediaItem(MediaManagerItem):
self.edit_custom_form = EditCustomForm(self, self.main_window, self.plugin.manager)
self.single_service_item = False
self.quick_preview_allowed = True
self.hasSearch = True
self.has_search = True
# Holds information about whether the edit is remotely triggered and
# which Custom is required.
self.remoteCustom = -1

View File

@ -53,7 +53,7 @@ class ImageMediaItem(MediaManagerItem):
self.icon_path = u'images/image'
MediaManagerItem.__init__(self, parent, plugin)
self.quick_preview_allowed = True
self.hasSearch = True
self.has_search = True
self.manager = plugin.manager
self.choose_group_form = ChooseGroupForm(self)
self.add_group_form = AddGroupForm(self)
@ -89,7 +89,7 @@ class ImageMediaItem(MediaManagerItem):
log.debug(u'initialise')
self.list_view.clear()
self.list_view.setIconSize(QtCore.QSize(88, 50))
self.list_view.setIndentation(self.list_view.defaultIndentation)
self.list_view.setIndentation(self.list_view.default_indentation)
self.list_view.allow_internal_dnd = True
self.servicePath = os.path.join(AppLocation.get_section_data_path(self.settings_section), u'thumbnails')
check_directory_exists(self.servicePath)

View File

@ -59,7 +59,7 @@ class MediaMediaItem(MediaManagerItem):
self.automatic = u''
MediaManagerItem.__init__(self, parent, plugin)
self.single_service_item = False
self.hasSearch = True
self.has_search = True
self.media_object = None
self.display_controller = DisplayController(parent)
self.display_controller.controller_layout = QtGui.QVBoxLayout()

View File

@ -58,7 +58,7 @@ class PresentationMediaItem(MediaManagerItem):
self.Automatic = u''
MediaManagerItem.__init__(self, parent, plugin)
self.message_listener = MessageListener(self)
self.hasSearch = True
self.has_search = True
self.single_service_item = False
Registry().register_function(u'mediaitem_presentation_rebuild', self.populate_display_types)
Registry().register_function(u'mediaitem_suffixes', self.build_file_mask_string)

View File

@ -492,7 +492,7 @@ class HttpConnection(object):
if action == u'search':
searches = []
for plugin in self.plugin_manager.plugins:
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.mediaItem.hasSearch:
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search:
searches.append([plugin.name, unicode(plugin.textStrings[StringContent.Name][u'plural'])])
return HttpResponse(json.dumps({u'results': {u'items': searches}}), {u'Content-Type': u'application/json'})
@ -509,7 +509,7 @@ class HttpConnection(object):
return HttpResponse(code=u'400 Bad Request')
text = urllib.unquote(text)
plugin = self.plugin_manager.get_plugin_by_name(plugin_name)
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.mediaItem.hasSearch:
if plugin.status == PluginStatus.Active and plugin.media_item and plugin.media_item.has_search:
results = plugin.media_item.search(text, False)
else:
results = []

View File

@ -81,7 +81,7 @@ class SongMediaItem(MediaManagerItem):
self.remoteSong = -1
self.editItem = None
self.quick_preview_allowed = True
self.hasSearch = True
self.has_search = True
def _updateBackgroundAudio(self, song, item):
song.media_files = []