forked from openlp/openlp
Start to fix ServiceManager and extent tests
This commit is contained in:
parent
27d651a129
commit
c8a3b33044
@ -137,6 +137,7 @@ class OpenLP(QtGui.QApplication):
|
||||
self.main_window = MainWindow()
|
||||
Registry().execute('bootstrap_initialise')
|
||||
Registry().execute('bootstrap_post_set_up')
|
||||
Registry().initialise = False
|
||||
self.main_window.show()
|
||||
if show_splash:
|
||||
# now kill the splashscreen
|
||||
|
@ -4,8 +4,8 @@
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Copyright (c) 2008-2014 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
@ -33,7 +33,7 @@ import logging
|
||||
import inspect
|
||||
|
||||
from openlp.core.common import trace_error_handler
|
||||
DO_NOT_TRACE_EVENTS = ['timerEvent', 'paintEvent']
|
||||
DO_NOT_TRACE_EVENTS = ['timerEvent', 'paintEvent', 'drag_enter_event', 'drop_event']
|
||||
|
||||
|
||||
class OpenLPMixin(object):
|
||||
@ -68,13 +68,13 @@ class OpenLPMixin(object):
|
||||
|
||||
def log_debug(self, message):
|
||||
"""
|
||||
Common log debug handler which prints the calling path
|
||||
Common log debug handler
|
||||
"""
|
||||
self.logger.debug(message)
|
||||
|
||||
def log_info(self, message):
|
||||
"""
|
||||
Common log info handler which prints the calling path
|
||||
Common log info handler
|
||||
"""
|
||||
self.logger.info(message)
|
||||
|
||||
|
@ -63,6 +63,7 @@ class Registry(object):
|
||||
registry.service_list = {}
|
||||
registry.functions_list = {}
|
||||
registry.running_under_test = False
|
||||
registry.initialising = True
|
||||
# Allow the tests to remove Registry entries but not the live system
|
||||
if 'nose' in sys.argv[0]:
|
||||
registry.running_under_test = True
|
||||
@ -78,9 +79,10 @@ class Registry(object):
|
||||
if key in self.service_list:
|
||||
return self.service_list[key]
|
||||
else:
|
||||
trace_error_handler(log)
|
||||
log.error('Service %s not found in list' % key)
|
||||
#raise KeyError('Service %s not found in list' % key)
|
||||
if not self.initialising:
|
||||
trace_error_handler(log)
|
||||
log.error('Service %s not found in list' % key)
|
||||
raise KeyError('Service %s not found in list' % key)
|
||||
|
||||
def register(self, key, reference):
|
||||
"""
|
||||
|
@ -4,8 +4,8 @@
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Copyright (c) 2008-2014 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
|
@ -4,8 +4,8 @@
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Copyright (c) 2008-2014 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
@ -42,7 +42,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.common import Registry, AppLocation, Settings, ThemeLevel, check_directory_exists, UiStrings, translate
|
||||
from openlp.core.common import Registry, AppLocation, Settings, ThemeLevel, OpenLPMixin, RegistryMixin, \
|
||||
check_directory_exists, UiStrings, translate
|
||||
from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, PluginStatus, build_icon
|
||||
from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box
|
||||
from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm
|
||||
@ -75,7 +76,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
|
||||
self.service_manager.on_move_selection_down()
|
||||
event.accept()
|
||||
elif event.key() == QtCore.Qt.Key_Delete:
|
||||
self.service_manager.onDeleteFromService()
|
||||
self.service_manager.on_delete_from_service()
|
||||
event.accept()
|
||||
event.ignore()
|
||||
else:
|
||||
@ -99,7 +100,7 @@ class ServiceManagerList(QtGui.QTreeWidget):
|
||||
drag.start(QtCore.Qt.CopyAction)
|
||||
|
||||
|
||||
class ServiceManagerDialog(object):
|
||||
class Ui_ServiceManager(object):
|
||||
"""
|
||||
UI part of the Service Manager
|
||||
"""
|
||||
@ -107,6 +108,10 @@ class ServiceManagerDialog(object):
|
||||
"""
|
||||
Define the UI
|
||||
"""
|
||||
# start with the layout
|
||||
self.layout = QtGui.QVBoxLayout(self)
|
||||
self.layout.setSpacing(0)
|
||||
self.layout.setMargin(0)
|
||||
# Create the top toolbar
|
||||
self.toolbar = OpenLPToolbar(self)
|
||||
self.toolbar.add_toolbar_action('newService', text=UiStrings().NewService, icon=':/general/general_new.png',
|
||||
@ -154,48 +159,58 @@ class ServiceManagerDialog(object):
|
||||
self.order_toolbar = OpenLPToolbar(self)
|
||||
action_list = ActionList.get_instance()
|
||||
action_list.add_category(UiStrings().Service, CategoryOrder.standard_toolbar)
|
||||
self.service_manager_list.move_top = self.order_toolbar.add_toolbar_action('moveTop',
|
||||
self.service_manager_list.move_top = self.order_toolbar.add_toolbar_action(
|
||||
'moveTop',
|
||||
text=translate('OpenLP.ServiceManager', 'Move to &top'), icon=':/services/service_top.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Move item to the top of the service.'),
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.onServiceTop)
|
||||
self.service_manager_list.move_up = self.order_toolbar.add_toolbar_action('moveUp',
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.on_service_top)
|
||||
self.service_manager_list.move_up = self.order_toolbar.add_toolbar_action(
|
||||
'moveUp',
|
||||
text=translate('OpenLP.ServiceManager', 'Move &up'), icon=':/services/service_up.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Move item up one position in the service.'),
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.onServiceUp)
|
||||
self.service_manager_list.move_down = self.order_toolbar.add_toolbar_action('moveDown',
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.on_service_up)
|
||||
self.service_manager_list.move_down = self.order_toolbar.add_toolbar_action(
|
||||
'moveDown',
|
||||
text=translate('OpenLP.ServiceManager', 'Move &down'), icon=':/services/service_down.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Move item down one position in the service.'),
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.onServiceDown)
|
||||
self.service_manager_list.move_bottom = self.order_toolbar.add_toolbar_action('moveBottom',
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.on_service_down)
|
||||
self.service_manager_list.move_bottom = self.order_toolbar.add_toolbar_action(
|
||||
'moveBottom',
|
||||
text=translate('OpenLP.ServiceManager', 'Move to &bottom'), icon=':/services/service_bottom.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Move item to the end of the service.'),
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.onServiceEnd)
|
||||
self.service_manager_list.down = self.order_toolbar.add_toolbar_action('down',
|
||||
can_shortcuts=True, category=UiStrings().Service, triggers=self.on_service_end)
|
||||
self.service_manager_list.down = self.order_toolbar.add_toolbar_action(
|
||||
'down',
|
||||
text=translate('OpenLP.ServiceManager', 'Move &down'), can_shortcuts=True,
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Moves the selection down the window.'), visible=False,
|
||||
triggers=self.on_move_selection_down)
|
||||
action_list.add_action(self.service_manager_list.down)
|
||||
self.service_manager_list.up = self.order_toolbar.add_toolbar_action('up',
|
||||
self.service_manager_list.up = self.order_toolbar.add_toolbar_action(
|
||||
'up',
|
||||
text=translate('OpenLP.ServiceManager', 'Move up'), can_shortcuts=True,
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Moves the selection up the window.'), visible=False,
|
||||
triggers=self.on_move_selection_up)
|
||||
action_list.add_action(self.service_manager_list.up)
|
||||
self.order_toolbar.addSeparator()
|
||||
self.service_manager_list.delete = self.order_toolbar.add_toolbar_action('delete', can_shortcuts=True,
|
||||
self.service_manager_list.delete = self.order_toolbar.add_toolbar_action(
|
||||
'delete', can_shortcuts=True,
|
||||
text=translate('OpenLP.ServiceManager', '&Delete From Service'), icon=':/general/general_delete.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Delete the selected item from the service.'),
|
||||
triggers=self.onDeleteFromService)
|
||||
triggers=self.on_delete_from_service)
|
||||
self.order_toolbar.addSeparator()
|
||||
self.service_manager_list.expand = self.order_toolbar.add_toolbar_action('expand', can_shortcuts=True,
|
||||
self.service_manager_list.expand = self.order_toolbar.add_toolbar_action(
|
||||
'expand', can_shortcuts=True,
|
||||
text=translate('OpenLP.ServiceManager', '&Expand all'), icon=':/services/service_expand_all.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Expand all the service items.'),
|
||||
category=UiStrings().Service, triggers=self.on_expand_all)
|
||||
self.service_manager_list.collapse = self.order_toolbar.add_toolbar_action('collapse', can_shortcuts=True,
|
||||
self.service_manager_list.collapse = self.order_toolbar.add_toolbar_action(
|
||||
'collapse', can_shortcuts=True,
|
||||
text=translate('OpenLP.ServiceManager', '&Collapse all'), icon=':/services/service_collapse_all.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Collapse all the service items.'),
|
||||
category=UiStrings().Service, triggers=self.on_collapse_all)
|
||||
self.order_toolbar.addSeparator()
|
||||
self.service_manager_list.make_live = self.order_toolbar.add_toolbar_action('make_live', can_shortcuts=True,
|
||||
self.service_manager_list.make_live = self.order_toolbar.add_toolbar_action(
|
||||
'make_live', can_shortcuts=True,
|
||||
text=translate('OpenLP.ServiceManager', 'Go Live'), icon=':/general/general_live.png',
|
||||
tooltip=translate('OpenLP.ServiceManager', 'Send the selected item to Live.'),
|
||||
category=UiStrings().Service,
|
||||
@ -287,12 +302,12 @@ class ServiceManagerDialog(object):
|
||||
Accept Drag events
|
||||
|
||||
``event``
|
||||
Handle of the event pint passed
|
||||
Handle of the event passed
|
||||
"""
|
||||
event.accept()
|
||||
|
||||
|
||||
class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
class ServiceManager(OpenLPMixin, RegistryMixin, QtGui.QWidget, Ui_ServiceManager):
|
||||
"""
|
||||
Manages the services. This involves taking text strings from plugins and adding them to the service. This service
|
||||
can then be zipped up with all the resources used into one OSZ or oszl file for use on any OpenLP v2 installation.
|
||||
@ -305,7 +320,6 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
super(ServiceManager, self).__init__(parent)
|
||||
self.active = build_icon(':/media/auto-start_active.png')
|
||||
self.inactive = build_icon(':/media/auto-start_inactive.png')
|
||||
Registry().register('service_manager', self)
|
||||
self.service_items = []
|
||||
self.suffixes = []
|
||||
self.drop_position = 0
|
||||
@ -314,17 +328,21 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self._modified = False
|
||||
self._file_name = ''
|
||||
self.service_has_all_original_files = True
|
||||
self.service_note_form = ServiceNoteForm()
|
||||
self.service_item_edit_form = ServiceItemEditForm()
|
||||
self.start_time_form = StartTimeForm()
|
||||
# start with the layout
|
||||
self.layout = QtGui.QVBoxLayout(self)
|
||||
self.layout.setSpacing(0)
|
||||
self.layout.setMargin(0)
|
||||
|
||||
def bootstrap_initialise(self):
|
||||
print(self)
|
||||
self.setup_ui(self)
|
||||
# Need to use event as called across threads and UI is updated
|
||||
QtCore.QObject.connect(self, QtCore.SIGNAL('servicemanager_set_item'), self.on_set_item)
|
||||
|
||||
def bootstrap_post_set_up(self):
|
||||
"""
|
||||
Can be set up as a late setup
|
||||
"""
|
||||
self.service_note_form = ServiceNoteForm()
|
||||
self.service_item_edit_form = ServiceItemEditForm()
|
||||
self.start_time_form = StartTimeForm()
|
||||
|
||||
def set_modified(self, modified=True):
|
||||
"""
|
||||
Setter for property "modified". Sets whether or not the current service has been modified.
|
||||
@ -432,7 +450,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
|
||||
QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save)
|
||||
|
||||
def on_recent_service_clicked(self):
|
||||
def on_recent_service_clicked(self, field=None):
|
||||
"""
|
||||
Load a recent file as the service triggered by mainwindow recent service list.
|
||||
"""
|
||||
@ -656,8 +674,8 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
'(*.oszl)'))
|
||||
else:
|
||||
file_name = QtGui.QFileDialog.getSaveFileName(self.main_window, UiStrings().SaveService, path,
|
||||
translate('OpenLP.ServiceManager', 'OpenLP Service Files (*'
|
||||
'.osz);;'))
|
||||
translate('OpenLP.ServiceManager',
|
||||
'OpenLP Service Files (*.osz);;'))
|
||||
if not file_name:
|
||||
return False
|
||||
if os.path.splitext(file_name)[1] == '':
|
||||
@ -1016,7 +1034,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
"""
|
||||
Makes a specific item in the service live.
|
||||
"""
|
||||
if index >= 0 and index < self.service_manager_list.topLevelItemCount():
|
||||
if 0 >= index < self.service_manager_list.topLevelItemCount():
|
||||
item = self.service_manager_list.topLevelItem(index)
|
||||
self.service_manager_list.setCurrentItem(item)
|
||||
self.make_live()
|
||||
@ -1071,7 +1089,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
pos = item.data(0, QtCore.Qt.UserRole)
|
||||
self.service_items[pos - 1]['expanded'] = True
|
||||
|
||||
def onServiceTop(self):
|
||||
def on_service_top(self):
|
||||
"""
|
||||
Move the current ServiceItem to the top of the list.
|
||||
"""
|
||||
@ -1083,7 +1101,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self.repaint_service_list(0, child)
|
||||
self.set_modified()
|
||||
|
||||
def onServiceUp(self):
|
||||
def on_service_up(self):
|
||||
"""
|
||||
Move the current ServiceItem one position up in the list.
|
||||
"""
|
||||
@ -1095,7 +1113,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self.repaint_service_list(item - 1, child)
|
||||
self.set_modified()
|
||||
|
||||
def onServiceDown(self):
|
||||
def on_service_down(self):
|
||||
"""
|
||||
Move the current ServiceItem one position down in the list.
|
||||
"""
|
||||
@ -1107,7 +1125,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self.repaint_service_list(item + 1, child)
|
||||
self.set_modified()
|
||||
|
||||
def onServiceEnd(self):
|
||||
def on_service_end(self):
|
||||
"""
|
||||
Move the current ServiceItem to the bottom of the list.
|
||||
"""
|
||||
@ -1119,7 +1137,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self.repaint_service_list(len(self.service_items) - 1, child)
|
||||
self.set_modified()
|
||||
|
||||
def onDeleteFromService(self):
|
||||
def on_delete_from_service(self):
|
||||
"""
|
||||
Remove the current ServiceItem from the list.
|
||||
"""
|
||||
@ -1218,7 +1236,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
if os.path.exists(os.path.join(self.service_path, 'audio')):
|
||||
shutil.rmtree(os.path.join(self.service_path, 'audio'), True)
|
||||
|
||||
def on_theme_combo_box_selected(self, currentIndex):
|
||||
def on_theme_combo_box_selected(self, current_index):
|
||||
"""
|
||||
Set the theme for the current service.
|
||||
"""
|
||||
@ -1274,17 +1292,17 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self.repaint_service_list(-1, -1)
|
||||
self.application.set_normal_cursor()
|
||||
|
||||
def replace_service_item(self, newItem):
|
||||
def replace_service_item(self, new_item):
|
||||
"""
|
||||
Using the service item passed replace the one with the same edit id if found.
|
||||
"""
|
||||
for item_count, item in enumerate(self.service_items):
|
||||
if item['service_item'].edit_id == newItem.edit_id and item['service_item'].name == newItem.name:
|
||||
newItem.render()
|
||||
newItem.merge(item['service_item'])
|
||||
item['service_item'] = newItem
|
||||
if item['service_item'].edit_id == new_item.edit_id and item['service_item'].name == new_item.name:
|
||||
new_item.render()
|
||||
new_item.merge(item['service_item'])
|
||||
item['service_item'] = new_item
|
||||
self.repaint_service_list(item_count + 1, 0)
|
||||
self.live_controller.replace_service_manager_item(newItem)
|
||||
self.live_controller.replace_service_manager_item(new_item)
|
||||
self.set_modified()
|
||||
|
||||
def add_service_item(self, item, rebuild=False, expand=None, replace=False, repaint=True, selected=False):
|
||||
@ -1324,8 +1342,8 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
self.repaint_service_list(len(self.service_items) - 1, -1)
|
||||
else:
|
||||
self.service_items.insert(self.drop_position,
|
||||
{'service_item': item, 'order': self.drop_position,
|
||||
'expanded': expand, 'selected': selected})
|
||||
{'service_item': item, 'order': self.drop_position,
|
||||
'expanded': expand, 'selected': selected})
|
||||
self.repaint_service_list(self.drop_position, -1)
|
||||
# if rebuilding list make sure live is fixed.
|
||||
if rebuild:
|
||||
@ -1357,7 +1375,7 @@ class ServiceManager(QtGui.QWidget, ServiceManagerDialog):
|
||||
else:
|
||||
return self.service_items[item]['service_item']
|
||||
|
||||
def on_make_live(self):
|
||||
def on_make_live(self, field=None):
|
||||
"""
|
||||
Send the current item to the Live slide controller but triggered by a tablewidget click event.
|
||||
"""
|
||||
|
@ -304,8 +304,8 @@ class ThemeManager(RegistryMixin, OpenLPMixin, QtGui.QWidget, ThemeManagerHelper
|
||||
Delete a theme
|
||||
"""
|
||||
if self._validate_theme_action(translate('OpenLP.ThemeManager', 'You must select a theme to delete.'),
|
||||
translate('OpenLP.ThemeManager', 'Delete Confirmation'),
|
||||
translate('OpenLP.ThemeManager', 'Delete %s theme?')):
|
||||
translate('OpenLP.ThemeManager', 'Delete Confirmation'),
|
||||
translate('OpenLP.ThemeManager', 'Delete %s theme?')):
|
||||
item = self.theme_list_widget.currentItem()
|
||||
theme = item.text()
|
||||
row = self.theme_list_widget.row(item)
|
||||
@ -472,7 +472,7 @@ class ThemeManager(RegistryMixin, OpenLPMixin, QtGui.QWidget, ThemeManagerHelper
|
||||
self.log_debug('No theme data - using default theme')
|
||||
return ThemeXML()
|
||||
else:
|
||||
return self._create_theme_from_Xml(xml, self.path)
|
||||
return self._create_theme_from_xml(xml, self.path)
|
||||
|
||||
def over_write_message_box(self, theme_name):
|
||||
"""
|
||||
@ -548,8 +548,8 @@ class ThemeManager(RegistryMixin, OpenLPMixin, QtGui.QWidget, ThemeManagerHelper
|
||||
if not abort_import:
|
||||
# As all files are closed, we can create the Theme.
|
||||
if file_xml:
|
||||
theme = self._create_theme_from_Xml(file_xml, self.path)
|
||||
self.generate_and_save_image(directory, theme_name, theme)
|
||||
theme = self._create_theme_from_xml(file_xml, self.path)
|
||||
self.generate_and_save_image(theme_name, theme)
|
||||
# Only show the error message, when IOError was not raised (in
|
||||
# this case the error message has already been shown).
|
||||
elif theme_zip is not None:
|
||||
@ -611,9 +611,9 @@ class ThemeManager(RegistryMixin, OpenLPMixin, QtGui.QWidget, ThemeManagerHelper
|
||||
except IOError as xxx_todo_changeme:
|
||||
shutil.Error = xxx_todo_changeme
|
||||
self.log_exception('Failed to save theme image')
|
||||
self.generate_and_save_image(self.path, name, theme)
|
||||
self.generate_and_save_image(name, theme)
|
||||
|
||||
def generate_and_save_image(self, directory, name, theme):
|
||||
def generate_and_save_image(self, name, theme):
|
||||
"""
|
||||
Generate and save a preview image
|
||||
"""
|
||||
@ -632,7 +632,7 @@ class ThemeManager(RegistryMixin, OpenLPMixin, QtGui.QWidget, ThemeManagerHelper
|
||||
self.main_window.display_progress_bar(len(self.theme_list))
|
||||
for theme in self.theme_list:
|
||||
self.main_window.increment_progress_bar()
|
||||
self.generate_and_save_image(self.path, theme, self.get_theme_data(theme))
|
||||
self.generate_and_save_image(theme, self.get_theme_data(theme))
|
||||
self.main_window.finished_progress_bar()
|
||||
self.load_themes()
|
||||
|
||||
@ -657,7 +657,7 @@ class ThemeManager(RegistryMixin, OpenLPMixin, QtGui.QWidget, ThemeManagerHelper
|
||||
"""
|
||||
return os.path.join(self.path, theme + '.png')
|
||||
|
||||
def _create_theme_from_Xml(self, theme_xml, path):
|
||||
def _create_theme_from_xml(self, theme_xml, path):
|
||||
"""
|
||||
Return a theme object using information parsed from XML
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2013 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Copyright (c) 2008-2014 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan #
|
||||
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
|
||||
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
|
||||
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
|
||||
|
@ -7,7 +7,7 @@ from unittest import TestCase
|
||||
from PyQt4 import QtGui
|
||||
|
||||
from openlp.core.common import Registry
|
||||
from openlp.core.lib import ScreenList, ServiceItem
|
||||
from openlp.core.lib import ScreenList, ServiceItem, ItemCapabilities
|
||||
from openlp.core.ui.mainwindow import MainWindow
|
||||
from tests.interfaces import MagicMock, patch
|
||||
|
||||
@ -39,16 +39,18 @@ class TestServiceManager(TestCase):
|
||||
"""
|
||||
# GIVEN: A New Service Manager instance
|
||||
|
||||
# WHEN I have an empty display
|
||||
# WHEN I have set up the display
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
# THEN the count of items should be zero
|
||||
self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0,
|
||||
'The service manager list should be empty ')
|
||||
|
||||
def context_menu_test(self):
|
||||
def default_context_menu_test(self):
|
||||
"""
|
||||
Test the context_menu() method.
|
||||
Test the context_menu() method with a default service item
|
||||
"""
|
||||
# GIVEN: A service item added
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
||||
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
||||
patch('PyQt4.QtGui.QMenu.exec_'):
|
||||
@ -84,3 +86,223 @@ class TestServiceManager(TestCase):
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
|
||||
|
||||
def edit_context_menu_test(self):
|
||||
"""
|
||||
Test the context_menu() method with a edit service item
|
||||
"""
|
||||
# GIVEN: A service item added
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
||||
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
||||
patch('PyQt4.QtGui.QMenu.exec_'):
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.parent.return_value = None
|
||||
mocked_item_at_method.return_value = mocked_item
|
||||
# We want 1 to be returned for the position
|
||||
mocked_item.data.return_value = 1
|
||||
# A service item without capabilities.
|
||||
service_item = ServiceItem()
|
||||
service_item.add_capability(ItemCapabilities.CanEdit)
|
||||
service_item.edit_id = 1
|
||||
self.service_manager.service_items = [{'service_item': service_item}]
|
||||
q_point = None
|
||||
# Mocked actions.
|
||||
self.service_manager.edit_action.setVisible = MagicMock()
|
||||
self.service_manager.create_custom_action.setVisible = MagicMock()
|
||||
self.service_manager.maintain_action.setVisible = MagicMock()
|
||||
self.service_manager.notes_action.setVisible = MagicMock()
|
||||
self.service_manager.time_action.setVisible = MagicMock()
|
||||
self.service_manager.auto_start_action.setVisible = MagicMock()
|
||||
|
||||
# WHEN: Show the context menu.
|
||||
self.service_manager.context_menu(q_point)
|
||||
|
||||
# THEN: The following actions should be not visible.
|
||||
self.service_manager.edit_action.setVisible.assert_called_with(True), \
|
||||
'The action should be set visible.'
|
||||
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
||||
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
|
||||
def maintain_context_menu_test(self):
|
||||
"""
|
||||
Test the context_menu() method with a maintain
|
||||
"""
|
||||
# GIVEN: A service item added
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
||||
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
||||
patch('PyQt4.QtGui.QMenu.exec_'):
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.parent.return_value = None
|
||||
mocked_item_at_method.return_value = mocked_item
|
||||
# We want 1 to be returned for the position
|
||||
mocked_item.data.return_value = 1
|
||||
# A service item without capabilities.
|
||||
service_item = ServiceItem()
|
||||
service_item.add_capability(ItemCapabilities.CanMaintain)
|
||||
self.service_manager.service_items = [{'service_item': service_item}]
|
||||
q_point = None
|
||||
# Mocked actions.
|
||||
self.service_manager.edit_action.setVisible = MagicMock()
|
||||
self.service_manager.create_custom_action.setVisible = MagicMock()
|
||||
self.service_manager.maintain_action.setVisible = MagicMock()
|
||||
self.service_manager.notes_action.setVisible = MagicMock()
|
||||
self.service_manager.time_action.setVisible = MagicMock()
|
||||
self.service_manager.auto_start_action.setVisible = MagicMock()
|
||||
|
||||
# WHEN: Show the context menu.
|
||||
self.service_manager.context_menu(q_point)
|
||||
|
||||
# THEN: The following actions should be not visible.
|
||||
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.maintain_action.setVisible.assert_called_with(True), \
|
||||
'The action should be set visible.'
|
||||
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
||||
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
|
||||
def loopy_context_menu_test(self):
|
||||
"""
|
||||
Test the context_menu() method with a loop
|
||||
"""
|
||||
# GIVEN: A service item added
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
||||
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
||||
patch('PyQt4.QtGui.QMenu.exec_'):
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.parent.return_value = None
|
||||
mocked_item_at_method.return_value = mocked_item
|
||||
# We want 1 to be returned for the position
|
||||
mocked_item.data.return_value = 1
|
||||
# A service item without capabilities.
|
||||
service_item = ServiceItem()
|
||||
service_item.add_capability(ItemCapabilities.CanLoop)
|
||||
service_item._raw_frames.append("One")
|
||||
service_item._raw_frames.append("Two")
|
||||
self.service_manager.service_items = [{'service_item': service_item}]
|
||||
q_point = None
|
||||
# Mocked actions.
|
||||
self.service_manager.edit_action.setVisible = MagicMock()
|
||||
self.service_manager.create_custom_action.setVisible = MagicMock()
|
||||
self.service_manager.maintain_action.setVisible = MagicMock()
|
||||
self.service_manager.notes_action.setVisible = MagicMock()
|
||||
self.service_manager.time_action.setVisible = MagicMock()
|
||||
self.service_manager.auto_start_action.setVisible = MagicMock()
|
||||
|
||||
# WHEN: Show the context menu.
|
||||
self.service_manager.context_menu(q_point)
|
||||
|
||||
# THEN: The following actions should be not visible.
|
||||
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
||||
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
|
||||
def start_time_context_menu_test(self):
|
||||
"""
|
||||
Test the context_menu() method with a start time
|
||||
"""
|
||||
# GIVEN: A service item added
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
||||
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
||||
patch('PyQt4.QtGui.QMenu.exec_'):
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.parent.return_value = None
|
||||
mocked_item_at_method.return_value = mocked_item
|
||||
# We want 1 to be returned for the position
|
||||
mocked_item.data.return_value = 1
|
||||
# A service item without capabilities.
|
||||
service_item = ServiceItem()
|
||||
service_item.add_capability(ItemCapabilities.HasVariableStartTime)
|
||||
self.service_manager.service_items = [{'service_item': service_item}]
|
||||
q_point = None
|
||||
# Mocked actions.
|
||||
self.service_manager.edit_action.setVisible = MagicMock()
|
||||
self.service_manager.create_custom_action.setVisible = MagicMock()
|
||||
self.service_manager.maintain_action.setVisible = MagicMock()
|
||||
self.service_manager.notes_action.setVisible = MagicMock()
|
||||
self.service_manager.time_action.setVisible = MagicMock()
|
||||
self.service_manager.auto_start_action.setVisible = MagicMock()
|
||||
|
||||
# WHEN: Show the context menu.
|
||||
self.service_manager.context_menu(q_point)
|
||||
|
||||
# THEN: The following actions should be not visible.
|
||||
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
||||
self.service_manager.time_action.setVisible.assert_called_with(True), \
|
||||
'The action should be set visible.'
|
||||
self.service_manager.auto_start_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
|
||||
def auto_start_context_menu_test(self):
|
||||
"""
|
||||
Test the context_menu() method with can auto start
|
||||
"""
|
||||
# GIVEN: A service item added
|
||||
self.service_manager.setup_ui(self.service_manager)
|
||||
with patch('PyQt4.QtGui.QTreeWidget.itemAt') as mocked_item_at_method, \
|
||||
patch('PyQt4.QtGui.QWidget.mapToGlobal'), \
|
||||
patch('PyQt4.QtGui.QMenu.exec_'):
|
||||
mocked_item = MagicMock()
|
||||
mocked_item.parent.return_value = None
|
||||
mocked_item_at_method.return_value = mocked_item
|
||||
# We want 1 to be returned for the position
|
||||
mocked_item.data.return_value = 1
|
||||
# A service item without capabilities.
|
||||
service_item = ServiceItem()
|
||||
service_item.add_capability(ItemCapabilities.CanAutoStartForLive)
|
||||
self.service_manager.service_items = [{'service_item': service_item}]
|
||||
q_point = None
|
||||
# Mocked actions.
|
||||
self.service_manager.edit_action.setVisible = MagicMock()
|
||||
self.service_manager.create_custom_action.setVisible = MagicMock()
|
||||
self.service_manager.maintain_action.setVisible = MagicMock()
|
||||
self.service_manager.notes_action.setVisible = MagicMock()
|
||||
self.service_manager.time_action.setVisible = MagicMock()
|
||||
self.service_manager.auto_start_action.setVisible = MagicMock()
|
||||
|
||||
# WHEN: Show the context menu.
|
||||
self.service_manager.context_menu(q_point)
|
||||
|
||||
# THEN: The following actions should be not visible.
|
||||
self.service_manager.edit_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.create_custom_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.maintain_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.notes_action.setVisible.assert_called_with(True), 'The action should be set visible.'
|
||||
self.service_manager.time_action.setVisible.assert_called_once_with(False), \
|
||||
'The action should be set invisible.'
|
||||
self.service_manager.auto_start_action.setVisible.assert_called_with(True), \
|
||||
'The action should be set visible.'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user