Images cleaned up

This commit is contained in:
Tim Bentley 2014-03-08 20:39:36 +00:00
parent f86c6bc77d
commit 836886e541
4 changed files with 118 additions and 132 deletions

View File

@ -49,14 +49,9 @@ class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog):
""" """
Show the form. Show the form.
``clear`` :param clear: Set to False if the text input box should not be cleared when showing the dialog (default: True).
Set to False if the text input box should not be cleared when showing the dialog (default: True). :param show_top_level_group: Set to True when "-- Top level group --" should be showed as first item (default: False).
:param selected_group: The ID of the group that should be selected by default when showing the dialog.
``show_top_level_group``
Set to True when "-- Top level group --" should be showed as first item (default: False).
``selected_group``
The ID of the group that should be selected by default when showing the dialog.
""" """
if clear: if clear:
self.name_edit.clear() self.name_edit.clear()
@ -76,7 +71,7 @@ class AddGroupForm(QtGui.QDialog, Ui_AddGroupDialog):
""" """
if not self.name_edit.text(): if not self.name_edit.text():
critical_error_message_box(message=translate('ImagePlugin.AddGroupForm', critical_error_message_box(message=translate('ImagePlugin.AddGroupForm',
'You need to type in a group name.')) 'You need to type in a group name.'))
self.name_edit.setFocus() self.name_edit.setFocus()
return False return False
else: else:

View File

@ -57,16 +57,16 @@ class ImagePlugin(Plugin):
def about(self): def about(self):
about_text = translate('ImagePlugin', '<strong>Image Plugin</strong>' about_text = translate('ImagePlugin', '<strong>Image Plugin</strong>'
'<br />The image plugin provides displaying of images.<br />One ' '<br />The image plugin provides displaying of images.<br />One '
'of the distinguishing features of this plugin is the ability to ' 'of the distinguishing features of this plugin is the ability to '
'group a number of images together in the service manager, making ' 'group a number of images together in the service manager, making '
'the displaying of multiple images easier. This plugin can also ' 'the displaying of multiple images easier. This plugin can also '
'make use of OpenLP\'s "timed looping" feature to create a slide ' 'make use of OpenLP\'s "timed looping" feature to create a slide '
'show that runs automatically. In addition to this, images from ' 'show that runs automatically. In addition to this, images from '
'the plugin can be used to override the current theme\'s ' 'the plugin can be used to override the current theme\'s '
'background, which renders text-based items like songs with the ' 'background, which renders text-based items like songs with the '
'selected image as a background instead of the background ' 'selected image as a background instead of the background '
'provided by the theme.') 'provided by the theme.')
return about_text return about_text
def app_startup(self): def app_startup(self):

View File

@ -80,17 +80,17 @@ def init_schema(url):
# Definition of the "image_groups" table # Definition of the "image_groups" table
image_groups_table = Table('image_groups', metadata, image_groups_table = Table('image_groups', metadata,
Column('id', types.Integer(), primary_key=True), Column('id', types.Integer(), primary_key=True),
Column('parent_id', types.Integer()), Column('parent_id', types.Integer()),
Column('group_name', types.Unicode(128)) Column('group_name', types.Unicode(128))
) )
# Definition of the "image_filenames" table # Definition of the "image_filenames" table
image_filenames_table = Table('image_filenames', metadata, image_filenames_table = Table('image_filenames', metadata,
Column('id', types.Integer(), primary_key=True), Column('id', types.Integer(), primary_key=True),
Column('group_id', types.Integer(), ForeignKey('image_groups.id'), default=None), Column('group_id', types.Integer(), ForeignKey('image_groups.id'), default=None),
Column('filename', types.Unicode(255), nullable=False) Column('filename', types.Unicode(255), nullable=False)
) )
mapper(ImageGroups, image_groups_table) mapper(ImageGroups, image_groups_table)
mapper(ImageFilenames, image_filenames_table) mapper(ImageFilenames, image_filenames_table)

View File

@ -76,8 +76,8 @@ class ImageMediaItem(MediaManagerItem):
self.on_new_prompt = translate('ImagePlugin.MediaItem', 'Select Image(s)') self.on_new_prompt = translate('ImagePlugin.MediaItem', 'Select Image(s)')
file_formats = get_images_filter() file_formats = get_images_filter()
self.on_new_file_masks = '%s;;%s (*.*) (*)' % (file_formats, UiStrings().AllFiles) self.on_new_file_masks = '%s;;%s (*.*) (*)' % (file_formats, UiStrings().AllFiles)
self.addGroupAction.setText(UiStrings().AddGroup) self.add_group_action.setText(UiStrings().AddGroup)
self.addGroupAction.setToolTip(UiStrings().AddGroup) self.add_group_action.setToolTip(UiStrings().AddGroup)
self.replace_action.setText(UiStrings().ReplaceBG) self.replace_action.setText(UiStrings().ReplaceBG)
self.replace_action.setToolTip(UiStrings().ReplaceLiveBG) self.replace_action.setToolTip(UiStrings().ReplaceLiveBG)
self.reset_action.setText(UiStrings().ResetBG) self.reset_action.setText(UiStrings().ResetBG)
@ -120,31 +120,36 @@ class ImageMediaItem(MediaManagerItem):
# define and add the context menu # define and add the context menu
self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.list_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
if self.has_edit_icon: if self.has_edit_icon:
create_widget_action(self.list_view, create_widget_action(
self.list_view,
text=self.plugin.get_string(StringContent.Edit)['title'], text=self.plugin.get_string(StringContent.Edit)['title'],
icon=':/general/general_edit.png', icon=':/general/general_edit.png',
triggers=self.on_edit_click) triggers=self.on_edit_click)
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
if self.has_delete_icon: if self.has_delete_icon:
create_widget_action(self.list_view, create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Delete.title()),
text=self.plugin.get_string(StringContent.Delete)['title'], text=self.plugin.get_string(StringContent.Delete)['title'],
icon=':/general/general_delete.png', icon=':/general/general_delete.png',
can_shortcuts=True, triggers=self.on_delete_click) can_shortcuts=True, triggers=self.on_delete_click)
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Preview.title()),
text=self.plugin.get_string(StringContent.Preview)['title'], text=self.plugin.get_string(StringContent.Preview)['title'],
icon=':/general/general_preview.png', icon=':/general/general_preview.png',
can_shortcuts=True, can_shortcuts=True,
triggers=self.on_preview_click) triggers=self.on_preview_click)
create_widget_action(self.list_view, create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Live.title()),
text=self.plugin.get_string(StringContent.Live)['title'], text=self.plugin.get_string(StringContent.Live)['title'],
icon=':/general/general_live.png', icon=':/general/general_live.png',
can_shortcuts=True, can_shortcuts=True,
triggers=self.on_live_click) triggers=self.on_live_click)
create_widget_action(self.list_view, create_widget_action(
self.list_view,
'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()), 'listView%s%sItem' % (self.plugin.name.title(), StringContent.Service.title()),
can_shortcuts=True, can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)['title'], text=self.plugin.get_string(StringContent.Service)['title'],
@ -152,7 +157,8 @@ class ImageMediaItem(MediaManagerItem):
triggers=self.on_add_click) triggers=self.on_add_click)
if self.add_to_service_item: if self.add_to_service_item:
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, create_widget_action(
self.list_view,
text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'), text=translate('OpenLP.MediaManagerItem', '&Add to selected Service Item'),
icon=':/general/general_add.png', icon=':/general/general_add.png',
triggers=self.on_add_edit_click) triggers=self.on_add_edit_click)
@ -170,9 +176,11 @@ class ImageMediaItem(MediaManagerItem):
Add custom actions to the context menu. Add custom actions to the context menu.
""" """
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, create_widget_action(
self.list_view,
text=UiStrings().AddGroup, icon=':/images/image_new_group.png', triggers=self.on_add_group_click) text=UiStrings().AddGroup, icon=':/images/image_new_group.png', triggers=self.on_add_group_click)
create_widget_action(self.list_view, create_widget_action(
self.list_view,
text=self.plugin.get_string(StringContent.Load)['tooltip'], text=self.plugin.get_string(StringContent.Load)['tooltip'],
icon=':/general/general_open.png', triggers=self.on_file_click) icon=':/general/general_open.png', triggers=self.on_file_click)
@ -180,17 +188,20 @@ class ImageMediaItem(MediaManagerItem):
""" """
Add custom buttons to the start of the toolbar. Add custom buttons to the start of the toolbar.
""" """
self.addGroupAction = self.toolbar.add_toolbar_action('addGroupAction', self.add_group_action = self.toolbar.add_toolbar_action('add_group_action',
icon=':/images/image_new_group.png', triggers=self.on_add_group_click) icon=':/images/image_new_group.png',
triggers=self.on_add_group_click)
def add_end_header_bar(self): def add_end_header_bar(self):
""" """
Add custom buttons to the end of the toolbar Add custom buttons to the end of the toolbar
""" """
self.replace_action = self.toolbar.add_toolbar_action('replace_action', self.replace_action = self.toolbar.add_toolbar_action('replace_action',
icon=':/slides/slide_blank.png', triggers=self.on_replace_click) icon=':/slides/slide_blank.png',
triggers=self.on_replace_click)
self.reset_action = self.toolbar.add_toolbar_action('reset_action', self.reset_action = self.toolbar.add_toolbar_action('reset_action',
icon=':/system/system_close.png', visible=False, triggers=self.on_reset_click) icon=':/system/system_close.png',
visible=False, triggers=self.on_reset_click)
def recursively_delete_group(self, image_group): def recursively_delete_group(self, image_group):
""" """
@ -215,7 +226,7 @@ class ImageMediaItem(MediaManagerItem):
# Turn off auto preview triggers. # Turn off auto preview triggers.
self.list_view.blockSignals(True) self.list_view.blockSignals(True)
if check_item_selected(self.list_view, translate('ImagePlugin.MediaItem', if check_item_selected(self.list_view, translate('ImagePlugin.MediaItem',
'You must select an image or group to delete.')): 'You must select an image or group to delete.')):
item_list = self.list_view.selectedItems() item_list = self.list_view.selectedItems()
self.application.set_busy_cursor() self.application.set_busy_cursor()
self.main_window.display_progress_bar(len(item_list)) self.main_window.display_progress_bar(len(item_list))
@ -230,12 +241,14 @@ class ImageMediaItem(MediaManagerItem):
row_item.parent().removeChild(row_item) row_item.parent().removeChild(row_item)
self.manager.delete_object(ImageFilenames, row_item.data(0, QtCore.Qt.UserRole).id) self.manager.delete_object(ImageFilenames, row_item.data(0, QtCore.Qt.UserRole).id)
elif isinstance(item_data, ImageGroups): elif isinstance(item_data, ImageGroups):
if QtGui.QMessageBox.question(self.list_view.parent(), if QtGui.QMessageBox.question(
self.list_view.parent(),
translate('ImagePlugin.MediaItem', 'Remove group'), translate('ImagePlugin.MediaItem', 'Remove group'),
translate('ImagePlugin.MediaItem', translate('ImagePlugin.MediaItem',
'Are you sure you want to remove "%s" and everything in it?') % item_data.group_name, 'Are you sure you want to remove "%s" and everything in it?') %
item_data.group_name,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
QtGui.QMessageBox.No)) == QtGui.QMessageBox.Yes: QtGui.QMessageBox.No)) == QtGui.QMessageBox.Yes:
self.recursively_delete_group(item_data) self.recursively_delete_group(item_data)
self.manager.delete_object(ImageGroups, row_item.data(0, QtCore.Qt.UserRole).id) self.manager.delete_object(ImageGroups, row_item.data(0, QtCore.Qt.UserRole).id)
if item_data.parent_id == 0: if item_data.parent_id == 0:
@ -253,11 +266,8 @@ class ImageMediaItem(MediaManagerItem):
""" """
Recursively add subgroups to the given parent group in a QTreeWidget. Recursively add subgroups to the given parent group in a QTreeWidget.
``group_list`` :param group_list: The List object that contains all QTreeWidgetItems.
The List object that contains all QTreeWidgetItems. :param parent_group_id: The ID of the group that will be added recursively.
``parent_group_id``
The ID of the group that will be added recursively.
""" """
image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parent_group_id) image_groups = self.manager.get_all_objects(ImageGroups, ImageGroups.parent_id == parent_group_id)
image_groups.sort(key=lambda group_object: get_locale_key(group_object.group_name)) image_groups.sort(key=lambda group_object: get_locale_key(group_object.group_name))
@ -278,14 +288,10 @@ class ImageMediaItem(MediaManagerItem):
""" """
Recursively add groups to the combobox in the 'Add group' dialog. Recursively add groups to the combobox in the 'Add group' dialog.
``combobox`` :param combobox: The QComboBox to add the options to.
The QComboBox to add the options to. :param parent_group_id: The ID of the group that will be added.
:param prefix: A string containing the prefix that will be added in front of the groupname for each level of
``parent_group_id`` the tree.
The ID of the group that will be added.
``prefix``
A string containing the prefix that will be added in front of the groupname for each level of the tree.
""" """
if parent_group_id == 0: if parent_group_id == 0:
combobox.clear() combobox.clear()
@ -300,11 +306,8 @@ class ImageMediaItem(MediaManagerItem):
""" """
Expand groups in the widget recursively. Expand groups in the widget recursively.
``group_id`` :param group_id: The ID of the group that will be expanded.
The ID of the group that will be expanded. :param root_item: This option is only used for recursion purposes.
``root_item``
This option is only used for recursion purposes.
""" """
return_value = False return_value = False
if root_item is None: if root_item is None:
@ -323,14 +326,9 @@ class ImageMediaItem(MediaManagerItem):
""" """
Replace the list of images and groups in the interface. Replace the list of images and groups in the interface.
``images`` :param images: A List of Image Filenames objects that will be used to reload the mediamanager list.
A List of ImageFilenames objects that will be used to reload the mediamanager list. :param initial_load: When set to False, the busy cursor and progressbar will be shown while loading images.
:param open_group: ImageGroups object of the group that must be expanded after reloading the list in the interface.
``initial_load``
When set to False, the busy cursor and progressbar will be shown while loading images.
``open_group``
ImageGroups object of the group that must be expanded after reloading the list in the interface.
""" """
if not initial_load: if not initial_load:
self.application.set_busy_cursor() self.application.set_busy_cursor()
@ -375,11 +373,8 @@ class ImageMediaItem(MediaManagerItem):
Process a list for files either from the File Dialog or from Drag and Drop. Process a list for files either from the File Dialog or from Drag and Drop.
This method is overloaded from MediaManagerItem. This method is overloaded from MediaManagerItem.
``files`` :param files: A List of strings containing the filenames of the files to be loaded
A List of strings containing the filenames of the files to be loaded :param target_group: The QTreeWidgetItem of the group that will be the parent of the added files
``target_group``
The QTreeWidgetItem of the group that will be the parent of the added files
""" """
self.application.set_normal_cursor() self.application.set_normal_cursor()
self.load_list(files, target_group) self.load_list(files, target_group)
@ -390,14 +385,9 @@ class ImageMediaItem(MediaManagerItem):
""" """
Add new images to the database. This method is called when adding images using the Add button or DnD. Add new images to the database. This method is called when adding images using the Add button or DnD.
``images`` :param images: A List of strings containing the filenames of the files to be loaded
A List of strings containing the filenames of the files to be loaded :param target_group: The QTreeWidgetItem of the group that will be the parent of the added files
:param initial_load: When set to False, the busy cursor and progressbar will be shown while loading images
``target_group``
The QTreeWidgetItem of the group that will be the parent of the added files
``initial_load``
When set to False, the busy cursor and progressbar will be shown while loading images
""" """
parent_group = None parent_group = None
if target_group is None: if target_group is None:
@ -464,30 +454,25 @@ class ImageMediaItem(MediaManagerItem):
# Save the new images in the database # Save the new images in the database
self.save_new_images_list(images, group_id=parent_group.id, reload_list=False) self.save_new_images_list(images, group_id=parent_group.id, reload_list=False)
self.load_full_list(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename), self.load_full_list(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename),
initial_load=initial_load, open_group=parent_group) initial_load=initial_load, open_group=parent_group)
self.application.set_normal_cursor() self.application.set_normal_cursor()
def save_new_images_list(self, images_list, group_id=0, reload_list=True): def save_new_images_list(self, images_list, group_id=0, reload_list=True):
""" """
Convert a list of image filenames to ImageFilenames objects and save them in the database. Convert a list of image filenames to ImageFilenames objects and save them in the database.
``images_list`` :param images_list: A List of strings containing image filenames
A List of strings containing image filenames :param group_id: The ID of the group to save the images in
:param reload_list: This boolean is set to True when the list in the interface should be reloaded after saving the new images
``group_id``
The ID of the group to save the images in
``reload_list``
This boolean is set to True when the list in the interface should be reloaded after saving the new images
""" """
for filename in images_list: for filename in images_list:
if not isinstance(filename, str): if not isinstance(filename, str):
continue continue
log.debug('Adding new image: %s', filename) log.debug('Adding new image: %s', filename)
imageFile = ImageFilenames() image_file = ImageFilenames()
imageFile.group_id = group_id image_file.group_id = group_id
imageFile.filename = str(filename) image_file.filename = str(filename)
self.manager.save_object(imageFile) self.manager.save_object(image_file)
self.main_window.increment_progress_bar() self.main_window.increment_progress_bar()
if reload_list and images_list: if reload_list and images_list:
self.load_full_list(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename)) self.load_full_list(self.manager.get_all_objects(ImageFilenames, order_by_ref=ImageFilenames.filename))
@ -496,8 +481,7 @@ class ImageMediaItem(MediaManagerItem):
""" """
Handle drag-and-drop moving of images within the media manager Handle drag-and-drop moving of images within the media manager
``target`` :param target: This contains the QTreeWidget that is the target of the DnD action
This contains the QTreeWidget that is the target of the DnD action
""" """
items_to_move = self.list_view.selectedItems() items_to_move = self.list_view.selectedItems()
# Determine group to move images to # Determine group to move images to
@ -538,10 +522,16 @@ class ImageMediaItem(MediaManagerItem):
image_items.sort(key=lambda item: get_locale_key(item.text(0))) image_items.sort(key=lambda item: get_locale_key(item.text(0)))
target_group.addChildren(image_items) target_group.addChildren(image_items)
def generate_slide_data(self, service_item, item=None, xml_version=False, def generate_slide_data(self, service_item, item=None, xml_version=False, remote=False,
remote=False, context=ServiceItemContext.Service): context=ServiceItemContext.Service):
""" """
Generate the slide data. Needs to be implemented by the plugin. Generate the slide data. Needs to be implemented by the plugin.
:param service_item: The service item to be built on
:param item: The Song item to be used
:param xml_version: The xml version (not used)
:param remote: Triggered from remote
:param context: Why is it being generated
""" """
background = QtGui.QColor(Settings().value(self.settings_section + '/background color')) background = QtGui.QColor(Settings().value(self.settings_section + '/background color'))
if item: if item:
@ -561,40 +551,41 @@ class ImageMediaItem(MediaManagerItem):
service_item.add_capability(ItemCapabilities.CanAppend) service_item.add_capability(ItemCapabilities.CanAppend)
# force a nonexistent theme # force a nonexistent theme
service_item.theme = -1 service_item.theme = -1
missing_items_filenames = [] missing_items_file_names = []
images_filenames = [] images_file_names = []
# Expand groups to images # Expand groups to images
for bitem in items: for bitem in items:
if isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageGroups) or bitem.data(0, QtCore.Qt.UserRole) is None: if isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageGroups) or bitem.data(0, QtCore.Qt.UserRole) is None:
for index in range(0, bitem.childCount()): for index in range(0, bitem.childCount()):
if isinstance(bitem.child(index).data(0, QtCore.Qt.UserRole), ImageFilenames): if isinstance(bitem.child(index).data(0, QtCore.Qt.UserRole), ImageFilenames):
images_filenames.append(bitem.child(index).data(0, QtCore.Qt.UserRole).filename) images_file_names.append(bitem.child(index).data(0, QtCore.Qt.UserRole).filename)
elif isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageFilenames): elif isinstance(bitem.data(0, QtCore.Qt.UserRole), ImageFilenames):
images_filenames.append(bitem.data(0, QtCore.Qt.UserRole).filename) images_file_names.append(bitem.data(0, QtCore.Qt.UserRole).filename)
# Don't try to display empty groups # Don't try to display empty groups
if not images_filenames: if not images_file_names:
return False return False
# Find missing files # Find missing files
for filename in images_filenames: for filename in images_file_names:
if not os.path.exists(filename): if not os.path.exists(filename):
missing_items_filenames.append(filename) missing_items_file_names.append(filename)
# We cannot continue, as all images do not exist. # We cannot continue, as all images do not exist.
if not images_filenames: if not images_file_names:
if not remote: if not remote:
critical_error_message_box( critical_error_message_box(
translate('ImagePlugin.MediaItem', 'Missing Image(s)'), translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s') % translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s')
'\n'.join(missing_items_filenames)) % '\n'.join(missing_items_file_names))
return False return False
# We have missing as well as existing images. We ask what to do. # We have missing as well as existing images. We ask what to do.
elif missing_items_filenames and QtGui.QMessageBox.question(self, elif missing_items_file_names and QtGui.QMessageBox.question(
translate('ImagePlugin.MediaItem', 'Missing Image(s)'), self, translate('ImagePlugin.MediaItem', 'Missing Image(s)'),
translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s\n' translate('ImagePlugin.MediaItem', 'The following image(s) no longer exist: %s\n'
'Do you want to add the other images anyway?') % '\n'.join(missing_items_filenames), 'Do you want to add the other images anyway?') % '\n'.join(missing_items_file_names),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == QtGui.QMessageBox.No: QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)) == \
QtGui.QMessageBox.No:
return False return False
# Continue with the existing images. # Continue with the existing images.
for filename in images_filenames: for filename in images_file_names:
name = os.path.split(filename)[1] name = os.path.split(filename)[1]
service_item.add_from_image(filename, name, background) service_item.add_from_image(filename, name, background)
return True return True
@ -603,8 +594,7 @@ class ImageMediaItem(MediaManagerItem):
""" """
Returns *True* if the given Group already exists in the database, otherwise *False*. Returns *True* if the given Group already exists in the database, otherwise *False*.
``new_group`` :param new_group: The ImageGroups object that contains the name of the group that will be checked
The ImageGroups object that contains the name of the group that will be checked
""" """
groups = self.manager.get_all_objects(ImageGroups, ImageGroups.group_name == new_group.group_name) groups = self.manager.get_all_objects(ImageGroups, ImageGroups.group_name == new_group.group_name)
if groups: if groups:
@ -633,8 +623,8 @@ class ImageMediaItem(MediaManagerItem):
group_name=self.add_group_form.name_edit.text()) group_name=self.add_group_form.name_edit.text())
if not self.check_group_exists(new_group): if not self.check_group_exists(new_group):
if self.manager.save_object(new_group): if self.manager.save_object(new_group):
self.load_full_list(self.manager.get_all_objects(ImageFilenames, self.load_full_list(self.manager.get_all_objects(
order_by_ref=ImageFilenames.filename)) ImageFilenames, order_by_ref=ImageFilenames.filename))
self.expand_group(new_group.id) self.expand_group(new_group.id)
self.fill_groups_combobox(self.choose_group_form.group_combobox) self.fill_groups_combobox(self.choose_group_form.group_combobox)
self.fill_groups_combobox(self.add_group_form.parent_group_combobox) self.fill_groups_combobox(self.add_group_form.parent_group_combobox)
@ -659,9 +649,10 @@ class ImageMediaItem(MediaManagerItem):
def on_replace_click(self): def on_replace_click(self):
""" """
Called to replace Live backgound with the image selected. Called to replace Live background with the image selected.
""" """
if check_item_selected(self.list_view, if check_item_selected(
self.list_view,
translate('ImagePlugin.MediaItem', 'You must select an image to replace the background with.')): translate('ImagePlugin.MediaItem', 'You must select an image to replace the background with.')):
background = QtGui.QColor(Settings().value(self.settings_section + '/background color')) background = QtGui.QColor(Settings().value(self.settings_section + '/background color'))
bitem = self.list_view.selectedItems()[0] bitem = self.list_view.selectedItems()[0]
@ -673,24 +664,24 @@ class ImageMediaItem(MediaManagerItem):
if self.live_controller.display.direct_image(filename, background): if self.live_controller.display.direct_image(filename, background):
self.reset_action.setVisible(True) self.reset_action.setVisible(True)
else: else:
critical_error_message_box(UiStrings().LiveBGError, critical_error_message_box(
UiStrings().LiveBGError,
translate('ImagePlugin.MediaItem', 'There was no display item to amend.')) translate('ImagePlugin.MediaItem', 'There was no display item to amend.'))
else: else:
critical_error_message_box(UiStrings().LiveBGError, critical_error_message_box(
UiStrings().LiveBGError,
translate('ImagePlugin.MediaItem', 'There was a problem replacing your background, ' translate('ImagePlugin.MediaItem', 'There was a problem replacing your background, '
'the image file "%s" no longer exists.') % filename) 'the image file "%s" no longer exists.') % filename)
def search(self, string, show_error=True): def search(self, string, show_error=True):
""" """
Perform a search on the image file names. Perform a search on the image file names.
``string`` :param string: The glob to search for
The glob to search for :param show_error: Unused.
``show_error``
Unused.
""" """
files = self.manager.get_all_objects(ImageFilenames, filter_clause=ImageFilenames.filename.contains(string), files = self.manager.get_all_objects(
ImageFilenames, filter_clause=ImageFilenames.filename.contains(string),
order_by_ref=ImageFilenames.filename) order_by_ref=ImageFilenames.filename)
results = [] results = []
for file_object in files: for file_object in files: