Improve service loading

This commit is contained in:
Tomas Groth 2018-10-28 17:34:17 +01:00
parent 055d165830
commit 4d8661b669
5 changed files with 28 additions and 25 deletions

View File

@ -354,15 +354,15 @@ class ServiceItem(RegistryProperties):
}
service_data = []
if self.service_item_type == ServiceItemType.Text:
service_data = [slide for slide in self._raw_frames]
service_data = [slide for slide in self.slides]
elif self.service_item_type == ServiceItemType.Image:
if lite_save:
for slide in self._raw_frames:
for slide in self.slides:
service_data.append({'title': slide['title'], 'path': slide['path']})
else:
service_data = [slide['title'] for slide in self._raw_frames]
service_data = [slide['title'] for slide in self.slides]
elif self.service_item_type == ServiceItemType.Command:
for slide in self._raw_frames:
for slide in self.slides:
service_data.append({'title': slide['title'], 'image': slide['image'], 'path': slide['path'],
'display_title': slide['display_title'], 'notes': slide['notes']})
return {'header': service_header, 'data': service_data}
@ -414,7 +414,7 @@ class ServiceItem(RegistryProperties):
self.theme_overwritten = header.get('theme_overwritten', False)
if self.service_item_type == ServiceItemType.Text:
for slide in service_item['serviceitem']['data']:
self._raw_frames.append(slide)
self.add_from_text(slide['raw_slide'], slide['verseTag'])
elif self.service_item_type == ServiceItemType.Image:
settings_section = service_item['serviceitem']['header']['name']
background = QtGui.QColor(Settings().value(settings_section + '/background color'))
@ -538,7 +538,7 @@ class ServiceItem(RegistryProperties):
Returns the frames for the ServiceItem
"""
if self.service_item_type == ServiceItemType.Text:
return self._display_frames
return self._display_slides
else:
return self.slides
@ -583,8 +583,8 @@ class ServiceItem(RegistryProperties):
"""
Remove the specified frame from the item
"""
if frame in self._raw_frames:
self._raw_frames.remove(frame)
if frame in self.slides:
self.slides.remove(frame)
def get_media_time(self):
"""
@ -633,7 +633,7 @@ class ServiceItem(RegistryProperties):
"""
Returns if there are any frames in the service item
"""
return not bool(self._raw_frames)
return not bool(self.slides)
def validate_item(self, suffix_list=None):
"""

View File

@ -51,7 +51,7 @@ class ServiceItemEditForm(QtWidgets.QDialog, Ui_ServiceItemEditDialog, RegistryP
self.item_list = []
if self.item.is_image():
self.data = True
self.item_list.extend(self.item._raw_frames)
self.item_list.extend(self.item.slides)
self.load_data()
self.list_widget.setCurrentItem(self.list_widget.currentItem())
@ -60,7 +60,7 @@ class ServiceItemEditForm(QtWidgets.QDialog, Ui_ServiceItemEditDialog, RegistryP
Get the modified service item.
"""
if self.data:
self.item._raw_frames = []
self.item.slides = []
if self.item.is_image():
for item in self.item_list:
self.item.add_from_image(item['path'], item['title'])

View File

@ -351,7 +351,7 @@ class CustomMediaItem(MediaManagerItem):
else:
custom.credits = ''
custom_xml = CustomXMLBuilder()
for (idx, slide) in enumerate(item._raw_frames):
for (idx, slide) in enumerate(item.slides):
custom_xml.add_verse_to_lyrics('custom', str(idx + 1), slide['raw_slide'])
custom.text = str(custom_xml.extract_xml(), 'utf-8')
self.plugin.db_manager.save_object(custom)

View File

@ -151,7 +151,8 @@ class TestServiceManager(TestCase):
service_item.add_capability(capability)
service_item.service_item_type = ServiceItemType.Text
service_item.edit_id = 1
service_item._display_frames.append(MagicMock())
service_item._display_slides = []
service_item._display_slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()
@ -184,7 +185,7 @@ class TestServiceManager(TestCase):
assert service_manager.theme_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
# THEN we add a 2nd display frame
service_item._display_frames.append(MagicMock())
service_item._display_slides.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
@ -215,7 +216,8 @@ class TestServiceManager(TestCase):
service_item.add_capability(capability)
service_item.service_item_type = ServiceItemType.Text
service_item.edit_id = 1
service_item._display_frames.append(MagicMock())
service_item._display_slides = []
service_item._display_slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()
@ -248,7 +250,7 @@ class TestServiceManager(TestCase):
assert service_manager.theme_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
# THEN we add a 2nd display frame
service_item._display_frames.append(MagicMock())
service_item._display_slides.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
@ -280,7 +282,8 @@ class TestServiceManager(TestCase):
service_item.add_capability(ItemCapabilities.OnLoadUpdate)
service_item.service_item_type = ServiceItemType.Text
service_item.edit_id = 1
service_item._display_frames.append(MagicMock())
service_item._display_slides = []
service_item._display_slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()
@ -313,7 +316,7 @@ class TestServiceManager(TestCase):
assert service_manager.theme_menu.menuAction().setVisible.call_count == 2, \
'Should have be called twice'
# THEN we add a 2nd display frame
service_item._display_frames.append(MagicMock())
service_item._display_slides.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
@ -343,7 +346,7 @@ class TestServiceManager(TestCase):
service_item.add_capability(ItemCapabilities.CanEditTitle)
service_item.service_item_type = ServiceItemType.Image
service_item.edit_id = 1
service_item._raw_frames.append(MagicMock())
service_item.slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()
@ -376,7 +379,7 @@ class TestServiceManager(TestCase):
assert service_manager.theme_menu.menuAction().setVisible.call_count == 1, \
'Should have be called once'
# THEN we add a 2nd display frame and regenerate the menu.
service_item._raw_frames.append(MagicMock())
service_item.slides.append(MagicMock())
service_manager.context_menu(1)
# THEN the following additional calls should have occurred.
assert service_manager.auto_play_slides_menu.menuAction().setVisible.call_count == 2, \
@ -404,7 +407,7 @@ class TestServiceManager(TestCase):
service_item.add_capability(ItemCapabilities.RequiresMedia)
service_item.service_item_type = ServiceItemType.Command
service_item.edit_id = 1
service_item._raw_frames.append(MagicMock())
service_item.slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()
@ -462,7 +465,7 @@ class TestServiceManager(TestCase):
service_item.add_capability(ItemCapabilities.CanAppend)
service_item.service_item_type = ServiceItemType.Command
service_item.edit_id = 1
service_item._raw_frames.append(MagicMock())
service_item.slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()
@ -512,7 +515,7 @@ class TestServiceManager(TestCase):
service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay)
service_item.service_item_type = ServiceItemType.Command
service_item.edit_id = 1
service_item._raw_frames.append(MagicMock())
service_item.slides.append(MagicMock())
service_manager.service_items.insert(1, {'service_item': service_item})
service_manager.edit_action = MagicMock()
service_manager.rename_action = MagicMock()

View File

@ -226,8 +226,8 @@ class TestServiceManager(TestCase, TestMixin):
# 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")
service_item.slides.append("One")
service_item.slides.append("Two")
self.service_manager.service_items = [{'service_item': service_item}]
q_point = None
# Mocked actions.