forked from openlp/openlp
Add Search to Custom and cleanups
This commit is contained in:
parent
9fc67eba68
commit
70660b7b71
@ -29,13 +29,22 @@ 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, \
|
||||||
check_item_selected
|
check_item_selected, translate, check_search_result
|
||||||
|
from openlp.core.lib.searchedit import SearchEdit
|
||||||
from openlp.core.lib.ui import UiStrings
|
from openlp.core.lib.ui import UiStrings
|
||||||
from openlp.plugins.custom.lib import CustomXMLParser
|
from openlp.plugins.custom.lib import CustomXMLParser
|
||||||
from openlp.plugins.custom.lib.db import CustomSlide
|
from openlp.plugins.custom.lib.db import CustomSlide
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class CustomSearch(object):
|
||||||
|
"""
|
||||||
|
An enumeration for song search methods.
|
||||||
|
"""
|
||||||
|
Titles = 1
|
||||||
|
Themes = 2
|
||||||
|
|
||||||
|
|
||||||
class CustomMediaItem(MediaManagerItem):
|
class CustomMediaItem(MediaManagerItem):
|
||||||
"""
|
"""
|
||||||
This is the custom media manager item for Custom Slides.
|
This is the custom media manager item for Custom Slides.
|
||||||
@ -53,6 +62,42 @@ class CustomMediaItem(MediaManagerItem):
|
|||||||
self.manager = parent.manager
|
self.manager = parent.manager
|
||||||
|
|
||||||
def addEndHeaderBar(self):
|
def addEndHeaderBar(self):
|
||||||
|
self.addToolbarSeparator()
|
||||||
|
## Song Maintenance Button ##
|
||||||
|
self.searchWidget = QtGui.QWidget(self)
|
||||||
|
self.searchWidget.setObjectName(u'searchWidget')
|
||||||
|
self.searchLayout = QtGui.QVBoxLayout(self.searchWidget)
|
||||||
|
self.searchLayout.setObjectName(u'searchLayout')
|
||||||
|
self.searchTextLayout = QtGui.QFormLayout()
|
||||||
|
self.searchTextLayout.setObjectName(u'searchTextLayout')
|
||||||
|
self.searchTextLabel = QtGui.QLabel(self.searchWidget)
|
||||||
|
self.searchTextLabel.setObjectName(u'searchTextLabel')
|
||||||
|
self.searchTextEdit = SearchEdit(self.searchWidget)
|
||||||
|
self.searchTextEdit.setObjectName(u'searchTextEdit')
|
||||||
|
self.searchTextLabel.setBuddy(self.searchTextEdit)
|
||||||
|
self.searchTextLayout.addRow(self.searchTextLabel, self.searchTextEdit)
|
||||||
|
self.searchLayout.addLayout(self.searchTextLayout)
|
||||||
|
self.searchButtonLayout = QtGui.QHBoxLayout()
|
||||||
|
self.searchButtonLayout.setObjectName(u'searchButtonLayout')
|
||||||
|
self.searchButtonLayout.addStretch()
|
||||||
|
self.searchTextButton = QtGui.QPushButton(self.searchWidget)
|
||||||
|
self.searchTextButton.setObjectName(u'searchTextButton')
|
||||||
|
self.searchButtonLayout.addWidget(self.searchTextButton)
|
||||||
|
self.searchLayout.addLayout(self.searchButtonLayout)
|
||||||
|
self.pageLayout.addWidget(self.searchWidget)
|
||||||
|
# Signals and slots
|
||||||
|
QtCore.QObject.connect(self.searchTextEdit,
|
||||||
|
QtCore.SIGNAL(u'returnPressed()'), self.onSearchTextButtonClick)
|
||||||
|
QtCore.QObject.connect(self.searchTextButton,
|
||||||
|
QtCore.SIGNAL(u'pressed()'), self.onSearchTextButtonClick)
|
||||||
|
QtCore.QObject.connect(self.searchTextEdit,
|
||||||
|
QtCore.SIGNAL(u'textChanged(const QString&)'),
|
||||||
|
self.onSearchTextEditChanged)
|
||||||
|
QtCore.QObject.connect(self.searchTextEdit,
|
||||||
|
QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick)
|
||||||
|
QtCore.QObject.connect(self.searchTextEdit,
|
||||||
|
QtCore.SIGNAL(u'searchTypeChanged(int)'),
|
||||||
|
self.onSearchTextButtonClick)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'custom_edit'), self.onRemoteEdit)
|
QtCore.SIGNAL(u'custom_edit'), self.onRemoteEdit)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
@ -62,9 +107,22 @@ class CustomMediaItem(MediaManagerItem):
|
|||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick)
|
QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick)
|
||||||
|
|
||||||
|
def retranslateUi(self):
|
||||||
|
self.searchTextLabel.setText(u'%s:' % UiStrings().Search)
|
||||||
|
self.searchTextButton.setText(UiStrings().Search)
|
||||||
|
|
||||||
def initialise(self):
|
def initialise(self):
|
||||||
|
self.searchTextEdit.setSearchTypes([
|
||||||
|
(CustomSearch.Titles, u':/songs/song_search_title.png',
|
||||||
|
translate('SongsPlugin.MediaItem', 'Titles')),
|
||||||
|
(CustomSearch.Themes, u':/slides/slide_theme.png',
|
||||||
|
UiStrings().Themes)
|
||||||
|
])
|
||||||
self.loadList(self.manager.get_all_objects(
|
self.loadList(self.manager.get_all_objects(
|
||||||
CustomSlide, order_by_ref=CustomSlide.title))
|
CustomSlide, order_by_ref=CustomSlide.title))
|
||||||
|
self.searchTextEdit.setCurrentSearchType(QtCore.QSettings().value(
|
||||||
|
u'%s/last search type' % self.settingsSection,
|
||||||
|
QtCore.QVariant(SongSearch.Entire)).toInt()[0])
|
||||||
# Called to redisplay the custom list screen edith from a search
|
# Called to redisplay the custom list screen edith from a search
|
||||||
# or from the exit of the Custom edit dialog. If remote editing is
|
# or from the exit of the Custom edit dialog. If remote editing is
|
||||||
# active trigger it and clean up so it will not update again.
|
# active trigger it and clean up so it will not update again.
|
||||||
@ -162,3 +220,45 @@ class CustomMediaItem(MediaManagerItem):
|
|||||||
raw_footer.append(u'')
|
raw_footer.append(u'')
|
||||||
service_item.raw_footer = raw_footer
|
service_item.raw_footer = raw_footer
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def onSearchTextButtonClick(self):
|
||||||
|
# Save the current search type to the configuration.
|
||||||
|
QtCore.QSettings().setValue(u'%s/last search type' %
|
||||||
|
self.settingsSection,
|
||||||
|
QtCore.QVariant(self.searchTextEdit.currentSearchType()))
|
||||||
|
# Reload the list considering the new search type.
|
||||||
|
search_keywords = unicode(self.searchTextEdit.displayText())
|
||||||
|
search_results = []
|
||||||
|
search_type = self.searchTextEdit.currentSearchType()
|
||||||
|
if search_type == CustomSearch.Titles:
|
||||||
|
log.debug(u'Titles Search')
|
||||||
|
search_results = self.parent.manager.get_all_objects(CustomSlide,
|
||||||
|
CustomSlide.title.like(u'%' + self.whitespace.sub(u' ',
|
||||||
|
search_keywords) + u'%'))
|
||||||
|
self.loadList(search_results)
|
||||||
|
elif search_type == CustomSearch.Themes:
|
||||||
|
log.debug(u'Theme Search')
|
||||||
|
search_results = self.parent.manager.get_all_objects(CustomSlide,
|
||||||
|
CustomSlide.theme_name.like(u'%' + self.whitespace.sub(u' ',
|
||||||
|
search_keywords) + u'%'))
|
||||||
|
self.loadList(search_results)
|
||||||
|
check_search_result(self.listView, search_results)
|
||||||
|
|
||||||
|
def onSearchTextEditChanged(self, text):
|
||||||
|
"""
|
||||||
|
If search as type enabled invoke the search on each key press.
|
||||||
|
If the Lyrics are being searched do not start till 7 characters
|
||||||
|
have been entered.
|
||||||
|
"""
|
||||||
|
search_length = 2
|
||||||
|
if len(text) > search_length:
|
||||||
|
self.onSearchTextButtonClick()
|
||||||
|
elif len(text) == 0:
|
||||||
|
self.onClearTextButtonClick()
|
||||||
|
|
||||||
|
def onClearTextButtonClick(self):
|
||||||
|
"""
|
||||||
|
Clear the search text.
|
||||||
|
"""
|
||||||
|
self.searchTextEdit.clear()
|
||||||
|
self.onSearchTextButtonClick()
|
||||||
|
@ -197,7 +197,8 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
elif search_type == SongSearch.Themes:
|
elif search_type == SongSearch.Themes:
|
||||||
log.debug(u'Theme Search')
|
log.debug(u'Theme Search')
|
||||||
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.like(u'%' + self.whitespace.sub(u' ',
|
||||||
|
search_keywords) + u'%'))
|
||||||
self.displayResultsSong(search_results)
|
self.displayResultsSong(search_results)
|
||||||
check_search_result(self.listView, search_results)
|
check_search_result(self.listView, search_results)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user