moved 'No Search Results' code

This commit is contained in:
Andreas Preikschat 2011-05-15 14:11:08 +02:00
parent ed6d9df329
commit c728559862
4 changed files with 20 additions and 29 deletions

View File

@ -223,28 +223,6 @@ def resize_image(image, width, height, background=QtCore.Qt.black):
painter.drawImage((width - realw) / 2, (height - realh) / 2, preview) painter.drawImage((width - realw) / 2, (height - realh) / 2, preview)
return new_image return new_image
def check_search_result(treeWidget, search_results):
"""
Checks if the given ``search_results`` is empty and adds a
"No Search Results" item to the given ``treeWidget``.
``treeWidget``
The ``QTreeWidget`` where the "No Search Results" item should be added
to, if the ``search_results`` is empty.
``search_results``
This can either be a list or a dict.
"""
if search_results or treeWidget.count():
return
message = translate('OpenLP.MediaManagerItem', 'No Search Results')
item = QtGui.QListWidgetItem(message)
item.setFlags(QtCore.Qt.NoItemFlags)
font = QtGui.QFont()
font.setItalic(True)
item.setFont(font)
treeWidget.addItem(item)
def check_item_selected(list_widget, message): def check_item_selected(list_widget, message):
""" """
Check if a list item is selected so an action may be performed on it Check if a list item is selected so an action may be performed on it

View File

@ -244,7 +244,6 @@ class MediaManagerItem(QtGui.QWidget):
""" """
# Add the List widget # Add the List widget
self.listView = ListWidgetWithDnD(self, self.plugin.name) self.listView = ListWidgetWithDnD(self, self.plugin.name)
self.listView.setUniformItemSizes(True)
self.listView.setSpacing(1) self.listView.setSpacing(1)
self.listView.setSelectionMode( self.listView.setSelectionMode(
QtGui.QAbstractItemView.ExtendedSelection) QtGui.QAbstractItemView.ExtendedSelection)
@ -552,6 +551,20 @@ class MediaManagerItem(QtGui.QWidget):
""" """
pass pass
def check_search_result(self):
"""
Checks if the listView is empty and adds a "No Search Results" item.
"""
if self.listView.count():
return
message = translate('OpenLP.MediaManagerItem', 'No Search Results')
item = QtGui.QListWidgetItem(message)
item.setFlags(QtCore.Qt.NoItemFlags)
font = QtGui.QFont()
font.setItalic(True)
item.setFont(font)
self.listView.addItem(item)
def _getIdOfItemToGenerate(self, item, remoteItem): def _getIdOfItemToGenerate(self, item, remoteItem):
""" """
Utility method to check items being submitted for slide generation. Utility method to check items being submitted for slide generation.

View File

@ -29,7 +29,7 @@ import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
translate, check_search_result translate
from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings, add_widget_completer, \ from openlp.core.lib.ui import UiStrings, add_widget_completer, \
media_item_combo_box, critical_error_message_box, find_and_set_in_combo_box media_item_combo_box, critical_error_message_box, find_and_set_in_combo_box
@ -63,7 +63,7 @@ class BibleMediaItem(MediaManagerItem):
self.quickPreviewAllowed = True self.quickPreviewAllowed = True
self.search_results = {} self.search_results = {}
self.second_search_results = {} self.second_search_results = {}
check_search_result(self.listView, self.search_results) self.check_search_result()
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'bibles_load_list'), self.reloadBibles) QtCore.SIGNAL(u'bibles_load_list'), self.reloadBibles)
@ -537,7 +537,7 @@ class BibleMediaItem(MediaManagerItem):
elif self.search_results: elif self.search_results:
self.displayResults(bible, second_bible) self.displayResults(bible, second_bible)
self.advancedSearchButton.setEnabled(True) self.advancedSearchButton.setEnabled(True)
check_search_result(self.listView, self.search_results) self.check_search_result()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')
@ -578,7 +578,7 @@ class BibleMediaItem(MediaManagerItem):
elif self.search_results: elif self.search_results:
self.displayResults(bible, second_bible) self.displayResults(bible, second_bible)
self.quickSearchButton.setEnabled(True) self.quickSearchButton.setEnabled(True)
check_search_result(self.listView, self.search_results) self.check_search_result()
Receiver.send_message(u'cursor_normal') Receiver.send_message(u'cursor_normal')
Receiver.send_message(u'openlp_process_events') Receiver.send_message(u'openlp_process_events')

View File

@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui
from sqlalchemy.sql import or_ from sqlalchemy.sql import or_
from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
translate, check_item_selected, PluginStatus, check_search_result translate, check_item_selected, PluginStatus
from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings from openlp.core.lib.ui import UiStrings
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
@ -199,7 +199,7 @@ class SongMediaItem(MediaManagerItem):
search_results = self.parent.manager.get_all_objects(Song, search_results = self.parent.manager.get_all_objects(Song,
Song.theme_name == search_keywords) Song.theme_name == search_keywords)
self.displayResultsSong(search_results) self.displayResultsSong(search_results)
check_search_result(self.listView, search_results) self.check_search_result()
def onSongListLoad(self): def onSongListLoad(self):
""" """