Fix merges

This commit is contained in:
Tim Bentley 2013-01-21 06:52:55 +00:00
commit a54d02f81c
24 changed files with 283 additions and 32 deletions

View File

@ -23,3 +23,5 @@ resources/windows/warnOpenLP.txt
openlp.cfg
.idea
openlp.pro
.kdev4
tests.kdev4

View File

@ -34,7 +34,6 @@ import logging
import os
from urllib import quote_plus as urlquote
from PyQt4 import QtCore
from sqlalchemy import Table, MetaData, Column, types, create_engine
from sqlalchemy.exc import SQLAlchemyError, InvalidRequestError, DBAPIError, OperationalError
from sqlalchemy.orm import scoped_session, sessionmaker, mapper

View File

@ -31,8 +31,6 @@ Provide HTML Tag management and Formatting Tag access class
"""
import cPickle
from PyQt4 import QtCore
from openlp.core.lib import translate, Settings
class FormattingTags(object):

View File

@ -183,6 +183,9 @@ class ServiceItem(object):
self.background_audio = []
self.theme_overwritten = False
self.temporary_edit = False
self.auto_play_slides_once = False
self.auto_play_slides_loop = False
self.timed_slide_interval = 0
self.will_auto_start = False
self.has_original_files = True
self._new_item()
@ -344,6 +347,9 @@ class ServiceItem(object):
u'search': self.search_string,
u'data': self.data_string,
u'xml_version': self.xml_version,
u'auto_play_slides_once': self.auto_play_slides_once,
u'auto_play_slides_loop': self.auto_play_slides_loop,
u'timed_slide_interval': self.timed_slide_interval,
u'start_time': self.start_time,
u'end_time': self.end_time,
u'media_length': self.media_length,
@ -398,6 +404,9 @@ class ServiceItem(object):
self.start_time = header.get(u'start_time', 0)
self.end_time = header.get(u'end_time', 0)
self.media_length = header.get(u'media_length', 0)
self.auto_play_slides_once = header.get(u'auto_play_slides_once', False)
self.auto_play_slides_loop = header.get(u'auto_play_slides_loop', False)
self.timed_slide_interval = header.get(u'timed_slide_interval', 0)
self.will_auto_start = header.get(u'will_auto_start', False)
self.has_original_files = True
if u'background_audio' in header:
@ -427,7 +436,6 @@ class ServiceItem(object):
self.add_from_command(path, text_image[u'title'], text_image[u'image'])
else:
self.add_from_command(text_image[u'path'], text_image[u'title'], text_image[u'image'])
self._new_item()
def get_display_title(self):

View File

@ -29,9 +29,7 @@
"""
The :mod:`ui` module provides the core user interface for OpenLP
"""
from PyQt4 import QtGui
from openlp.core.lib import translate
class HideMode(object):
"""

View File

@ -257,6 +257,20 @@ class ServiceManager(QtGui.QWidget):
text=translate('OpenLP.ServiceManager', 'Create New &Custom Slide'),
icon=u':/general/general_edit.png', triggers=self.create_custom)
self.menu.addSeparator()
# Add AutoPlay menu actions
self.autoPlaySlidesGroup = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Auto play slides'))
self.menu.addMenu(self.autoPlaySlidesGroup)
self.autoPlaySlidesLoop = create_widget_action(self.autoPlaySlidesGroup,
text=translate('OpenLP.ServiceManager', 'Auto play slides &Loop'),
checked=False, triggers=self.toggleAutoPlaySlidesLoop)
self.autoPlaySlidesOnce = create_widget_action(self.autoPlaySlidesGroup,
text=translate('OpenLP.ServiceManager', 'Auto play slides &Once'),
checked=False, triggers=self.toggleAutoPlaySlidesOnce)
self.autoPlaySlidesGroup.addSeparator()
self.timedSlideInterval = create_widget_action(self.autoPlaySlidesGroup,
text=translate('OpenLP.ServiceManager', '&Delay between slides'),
checked=False, triggers=self.onTimedSlideInterval)
self.menu.addSeparator()
self.previewAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', 'Show &Preview'),
icon=u':/general/general_preview.png', triggers=self.makePreview)
# Add already existing make live action to the menu.
@ -766,6 +780,22 @@ class ServiceManager(QtGui.QWidget):
self.maintainAction.setVisible(True)
if item.parent() is None:
self.notesAction.setVisible(True)
if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanLoop) and \
len(serviceItem[u'service_item'].get_frames()) > 1:
self.autoPlaySlidesGroup.menuAction().setVisible(True)
self.autoPlaySlidesOnce.setChecked(serviceItem[u'service_item'].auto_play_slides_once)
self.autoPlaySlidesLoop.setChecked(serviceItem[u'service_item'].auto_play_slides_loop)
self.timedSlideInterval.setChecked(serviceItem[u'service_item'].timed_slide_interval > 0)
if serviceItem[u'service_item'].timed_slide_interval > 0:
delay_suffix = u' '
delay_suffix += unicode(serviceItem[u'service_item'].timed_slide_interval)
delay_suffix += u' s'
else:
delay_suffix = u' ...'
self.timedSlideInterval.setText(translate('OpenLP.ServiceManager', '&Delay between slides') + delay_suffix)
# TODO for future: make group explains itself more visually
else:
self.autoPlaySlidesGroup.menuAction().setVisible(False)
if serviceItem[u'service_item'].is_capable(ItemCapabilities.HasVariableStartTime):
self.timeAction.setVisible(True)
if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive):
@ -811,6 +841,59 @@ class ServiceManager(QtGui.QWidget):
if self.startTimeForm.exec_():
self.repaintServiceList(item, -1)
def toggleAutoPlaySlidesOnce(self):
"""
Toggle Auto play slide once.
Inverts auto play once option for the item
"""
item = self.findServiceItem()[0]
service_item = self.serviceItems[item][u'service_item']
service_item.auto_play_slides_once = not service_item.auto_play_slides_once
if service_item.auto_play_slides_once:
service_item.auto_play_slides_loop = False
self.autoPlaySlidesLoop.setChecked(False)
if service_item.auto_play_slides_once and service_item.timed_slide_interval == 0:
service_item.timed_slide_interval = Settings().value(u'loop delay', 5)
self.setModified()
def toggleAutoPlaySlidesLoop(self):
"""
Toggle Auto play slide loop.
"""
item = self.findServiceItem()[0]
service_item = self.serviceItems[item][u'service_item']
service_item.auto_play_slides_loop = not service_item.auto_play_slides_loop
if service_item.auto_play_slides_loop:
service_item.auto_play_slides_once = False
self.autoPlaySlidesOnce.setChecked(False)
if service_item.auto_play_slides_loop and service_item.timed_slide_interval == 0:
service_item.timed_slide_interval = Settings().value(u'loop delay', 5)
self.setModified()
def onTimedSlideInterval(self):
"""
on set times slide interval.
Shows input dialog for enter interval in seconds for delay
"""
item = self.findServiceItem()[0]
service_item = self.serviceItems[item][u'service_item']
if service_item.timed_slide_interval == 0:
timed_slide_interval = Settings().value(u'loop delay', 5)
else:
timed_slide_interval = service_item.timed_slide_interval
timed_slide_interval, ok = QtGui.QInputDialog.getInteger(self, translate('OpenLP.ServiceManager',
'Input delay'), translate('OpenLP.ServiceManager', 'Delay between slides in seconds.'),
timed_slide_interval, 0, 180, 1)
if ok:
service_item.timed_slide_interval = timed_slide_interval
if service_item.timed_slide_interval <> 0 and not service_item.auto_play_slides_loop\
and not service_item.auto_play_slides_once:
service_item.auto_play_slides_loop = True
elif service_item.timed_slide_interval == 0:
service_item.auto_play_slides_loop = False
service_item.auto_play_slides_once = False
self.setModified()
def onAutoStart(self):
"""
Toggles to Auto Start Setting.
@ -1291,6 +1374,8 @@ class ServiceManager(QtGui.QWidget):
if self.serviceItems and item < len(self.serviceItems) and \
self.serviceItems[item][u'service_item'].is_capable(ItemCapabilities.CanPreview):
self.mainwindow.previewController.addServiceManagerItem(self.serviceItems[item][u'service_item'], 0)
next_item = self.serviceManagerList.topLevelItem(item)
self.serviceManagerList.setCurrentItem(next_item)
self.mainwindow.liveController.previewListWidget.setFocus()
else:
critical_error_message_box(translate('OpenLP.ServiceManager', 'Missing Display Handler'),

View File

@ -31,7 +31,7 @@ The :mod:`settingsform` provides a user interface for the OpenLP settings
"""
import logging
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from openlp.core.lib import Receiver, build_icon, PluginStatus
from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab

View File

@ -692,6 +692,14 @@ class SlideController(DisplayController):
self.slideSelected()
else:
self._processItem(item, slidenum)
if self.isLive and item.auto_play_slides_loop and item.timed_slide_interval > 0:
self.playSlidesLoop.setChecked(item.auto_play_slides_loop)
self.delaySpinBox.setValue(int(item.timed_slide_interval))
self.onPlaySlidesLoop()
elif self.isLive and item.auto_play_slides_once and item.timed_slide_interval > 0:
self.playSlidesOnce.setChecked(item.auto_play_slides_once)
self.delaySpinBox.setValue(int(item.timed_slide_interval))
self.onPlaySlidesOnce()
def _processItem(self, serviceItem, slideno):
"""
@ -881,6 +889,7 @@ class SlideController(DisplayController):
Settings().remove(self.parent().generalSettingsSection + u'/screen blank')
self.blankPlugin()
self.updatePreview()
self.onToggleLoop()
def onThemeDisplay(self, checked=None):
"""
@ -899,6 +908,7 @@ class SlideController(DisplayController):
Settings().remove(self.parent().generalSettingsSection + u'/screen blank')
self.blankPlugin()
self.updatePreview()
self.onToggleLoop()
def onHideDisplay(self, checked=None):
"""
@ -917,6 +927,7 @@ class SlideController(DisplayController):
Settings().remove(self.parent().generalSettingsSection + u'/screen blank')
self.hidePlugin(checked)
self.updatePreview()
self.onToggleLoop()
def blankPlugin(self):
"""
@ -1092,7 +1103,8 @@ class SlideController(DisplayController):
"""
Toggles the loop state.
"""
if self.playSlidesLoop.isChecked() or self.playSlidesOnce.isChecked():
hide_mode = self.hideMode()
if hide_mode is None and (self.playSlidesLoop.isChecked() or self.playSlidesOnce.isChecked()):
self.onStartLoop()
else:
self.onStopLoop()
@ -1126,11 +1138,11 @@ class SlideController(DisplayController):
self.playSlidesLoop.setText(UiStrings().StopPlaySlidesInLoop)
self.playSlidesOnce.setIcon(build_icon(u':/media/media_time.png'))
self.playSlidesOnce.setText(UiStrings().PlaySlidesToEnd)
self.playSlidesMenu.setDefaultAction(self.playSlidesLoop)
self.playSlidesOnce.setChecked(False)
else:
self.playSlidesLoop.setIcon(build_icon(u':/media/media_time.png'))
self.playSlidesLoop.setText(UiStrings().PlaySlidesInLoop)
self.playSlidesMenu.setDefaultAction(self.playSlidesLoop)
self.playSlidesOnce.setChecked(False)
self.onToggleLoop()
def onPlaySlidesOnce(self, checked=None):
@ -1147,11 +1159,11 @@ class SlideController(DisplayController):
self.playSlidesOnce.setText(UiStrings().StopPlaySlidesToEnd)
self.playSlidesLoop.setIcon(build_icon(u':/media/media_time.png'))
self.playSlidesLoop.setText(UiStrings().PlaySlidesInLoop)
self.playSlidesMenu.setDefaultAction(self.playSlidesOnce)
self.playSlidesLoop.setChecked(False)
else:
self.playSlidesOnce.setIcon(build_icon(u':/media/media_time'))
self.playSlidesOnce.setText(UiStrings().PlaySlidesToEnd)
self.playSlidesMenu.setDefaultAction(self.playSlidesOnce)
self.playSlidesLoop.setChecked(False)
self.onToggleLoop()
def setAudioItemsVisibility(self, visible):

View File

@ -29,7 +29,7 @@
import logging
from PyQt4 import QtCore, QtGui
from PyQt4 import QtGui
from openlp.core.lib import Plugin, StringContent, build_icon, translate, Settings
from openlp.core.lib.ui import create_action, UiStrings

View File

@ -34,7 +34,7 @@ import logging
import re
from openlp.core.lib import translate, Settings
from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__)

View File

@ -30,8 +30,6 @@
import logging
import os
from PyQt4 import QtCore
from openlp.core.lib import Receiver, SettingsManager, translate, Settings
from openlp.core.utils import AppLocation, delete_file
from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection

View File

@ -28,7 +28,6 @@
###############################################################################
import logging
import os
from PyQt4 import QtCore

View File

@ -28,7 +28,7 @@
###############################################################################
import re
from PyQt4 import QtGui, QtCore
from PyQt4 import QtGui
from openlp.core.lib import translate
from openlp.core.utils import CONTROL_CHARS, locale_direct_compare

View File

@ -36,7 +36,6 @@ import re
from sqlalchemy import Column, ForeignKey, Table, types
from sqlalchemy.orm import mapper, relation, reconstructor
from sqlalchemy.sql.expression import func
from PyQt4 import QtCore
from openlp.core.lib.db import BaseModel, init_db

View File

@ -30,8 +30,6 @@
The :mod:`dreambeamimport` module provides the functionality for importing
DreamBeam songs into the OpenLP database.
"""
import os
import sys
import logging
from lxml import etree, objectify

View File

@ -30,8 +30,6 @@
The :mod:`mediashoutimport` module provides the functionality for importing
a MediaShout database into the OpenLP database.
"""
import re
import os
import pyodbc
from openlp.core.lib import translate

View File

@ -31,9 +31,7 @@ The :mod:`songproimport` module provides the functionality for importing SongPro
songs into the OpenLP database.
"""
import re
import os
from openlp.core.lib import translate
from openlp.plugins.songs.lib import strip_rtf
from openlp.plugins.songs.lib.songimport import SongImport

View File

@ -5,7 +5,8 @@ from unittest import TestCase
from mock import MagicMock, patch
from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string
from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string, build_icon, \
image_to_byte, check_item_selected
class TestLib(TestCase):
@ -197,3 +198,104 @@ class TestLib(TestCase):
"""
assert True, u'Impossible to test due to conflicts when mocking out the "open" function'
def build_icon_with_qicon_test(self):
"""
Test the build_icon() function with a QIcon instance
"""
with patch(u'openlp.core.lib.QtGui') as MockedQtGui:
# GIVEN: A mocked QIcon
MockedQtGui.QIcon = MagicMock
mocked_icon = MockedQtGui.QIcon()
# WHEN: We pass a QIcon instance in
result = build_icon(mocked_icon)
# THEN: The result should be our mocked QIcon
assert result is mocked_icon, u'The result should be the mocked QIcon'
def build_icon_with_resource_test(self):
"""
Test the build_icon() function with a resource URI
"""
with patch(u'openlp.core.lib.QtGui') as MockedQtGui, \
patch(u'openlp.core.lib.QtGui.QPixmap') as MockedQPixmap:
# GIVEN: A mocked QIcon and a mocked QPixmap
MockedQtGui.QIcon = MagicMock
MockedQtGui.QIcon.Normal = 1
MockedQtGui.QIcon.Off = 2
MockedQPixmap.return_value = u'mocked_pixmap'
resource_uri = u':/resource/uri'
# WHEN: We pass a QIcon instance in
result = build_icon(resource_uri)
# THEN: The result should be our mocked QIcon
MockedQPixmap.assert_called_with(resource_uri)
# There really should be more assert statements here but due to type checking and things they all break. The
# best we can do is to assert that we get back a MagicMock object.
assert isinstance(result, MagicMock), u'The result should be a MagicMock, because we mocked it out'
def image_to_byte_test(self):
"""
Test the image_to_byte() function
"""
with patch(u'openlp.core.lib.QtCore') as MockedQtCore:
# GIVEN: A set of mocked-out Qt classes
mocked_byte_array = MagicMock()
MockedQtCore.QByteArray.return_value = mocked_byte_array
mocked_byte_array.toBase64.return_value = u'base64mock'
mocked_buffer = MagicMock()
MockedQtCore.QBuffer.return_value = mocked_buffer
MockedQtCore.QIODevice.WriteOnly = u'writeonly'
mocked_image = MagicMock()
# WHEN: We convert an image to a byte array
result = image_to_byte(mocked_image)
# THEN: We should receive a value of u'base64mock'
MockedQtCore.QByteArray.assert_called_with()
MockedQtCore.QBuffer.assert_called_with(mocked_byte_array)
mocked_buffer.open.assert_called_with(u'writeonly')
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
mocked_byte_array.toBase64.assert_called_with()
assert result == u'base64mock', u'The result should be the return value of the mocked out base64 method'
def check_item_selected_true_test(self):
"""
Test that the check_item_selected() function returns True when there are selected indexes.
"""
# GIVEN: A mocked out QtGui module and a list widget with selected indexes
MockedQtGui = patch(u'openlp.core.lib.QtGui')
mocked_list_widget = MagicMock()
mocked_list_widget.selectedIndexes.return_value = True
message = u'message'
# WHEN: We check if there are selected items
result = check_item_selected(mocked_list_widget, message)
# THEN: The selectedIndexes function should have been called and the result should be true
mocked_list_widget.selectedIndexes.assert_called_with()
assert result, u'The result should be True'
def check_item_selected_false_test(self):
"""
Test that the check_item_selected() function returns False when there are no selected indexes.
"""
# GIVEN: A mocked out QtGui module and a list widget with selected indexes
with patch(u'openlp.core.lib.QtGui') as MockedQtGui, \
patch(u'openlp.core.lib.translate') as mocked_translate:
mocked_translate.return_value = u'mocked translate'
mocked_list_widget = MagicMock()
mocked_list_widget.selectedIndexes.return_value = False
mocked_list_widget.parent.return_value = u'parent'
message = u'message'
# WHEN: We check if there are selected items
result = check_item_selected(mocked_list_widget, message)
# THEN: The selectedIndexes function should have been called and the result should be true
mocked_list_widget.selectedIndexes.assert_called_with()
MockedQtGui.QMessageBox.information.assert_called_with(u'parent', u'mocked translate', 'message')
assert not result, u'The result should be False'

View File

@ -20,7 +20,7 @@ VERSE = u'The Lord said to {r}Noah{/r}: \n'\
'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
FOOTER = [u'Arky Arky (Unknown)', u'Public Domain', u'CCLI 123456']
TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'resources'))
TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources'))
class TestServiceItem(TestCase):
@ -167,6 +167,7 @@ class TestServiceItem(TestCase):
# THEN the service item should not be valid
assert service_item.is_valid is False, u'The service item is not valid'
def serviceitem_load_custom_from_service_test(self):
"""
Test the Service Item - adding a custom slide from a saved service

View File

@ -0,0 +1,56 @@
"""
Package to test the openlp.core.ui package.
"""
import sys
from unittest import TestCase
from mock import MagicMock, patch
from openlp.core.ui import starttimeform
from PyQt4 import QtGui, QtTest
class TestStartTimeDialog(TestCase):
def setUp(self):
"""
Create the UI
"""
self.app = QtGui.QApplication(sys.argv)
self.window = QtGui.QMainWindow()
self.form = starttimeform.StartTimeForm(self.window)
def ui_defaults_test(self):
"""
Test StartTimeDialog defaults
"""
self.assertEqual(self.form.hourSpinBox.minimum(), 0)
self.assertEqual(self.form.hourSpinBox.maximum(), 4)
self.assertEqual(self.form.minuteSpinBox.minimum(), 0)
self.assertEqual(self.form.minuteSpinBox.maximum(), 59)
self.assertEqual(self.form.secondSpinBox.minimum(), 0)
self.assertEqual(self.form.secondSpinBox.maximum(), 59)
self.assertEqual(self.form.hourFinishSpinBox.minimum(), 0)
self.assertEqual(self.form.hourFinishSpinBox.maximum(), 4)
self.assertEqual(self.form.minuteFinishSpinBox.minimum(), 0)
self.assertEqual(self.form.minuteFinishSpinBox.maximum(), 59)
self.assertEqual(self.form.secondFinishSpinBox.minimum(), 0)
self.assertEqual(self.form.secondFinishSpinBox.maximum(), 59)
def time_display_test(self):
"""
Test StartTimeDialog display initialisation
"""
# GIVEN: A service item with with time
mocked_serviceitem = MagicMock()
mocked_serviceitem.start_time = 61
mocked_serviceitem.end_time = 3701
# WHEN displaying the UI and pressing enter
self.form.item = mocked_serviceitem
with patch(u'openlp.core.lib.QtGui.QDialog') as MockedQtGuiQDialog:
MockedQtGuiQDialog.return_value = True
self.form.exec_()
# THEN the following values are returned
self.assertEqual(self.form.hourSpinBox.value(), 1)
self.assertEqual(self.form.minuteSpinBox.value(), 1)
self.assertEqual(self.form.secondSpinBox.value(), 1)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 213 KiB

View File

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 213 KiB