From a9c2b9fa18e50858e8872c584a7b9cb004e2893e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 28 Dec 2010 23:12:20 +0200 Subject: [PATCH 1/9] Added a new SearchEdit GUI object. --- openlp/core/lib/searchedit.py | 191 ++++++++++++++++++++++ openlp/plugins/songs/lib/mediaitem.py | 59 ++++--- resources/images/general_search_clear.png | Bin 0 -> 644 bytes resources/images/openlp-2.qrc | 4 + resources/images/song_search_all.png | Bin 0 -> 607 bytes resources/images/song_search_author.png | Bin 0 -> 409 bytes resources/images/song_search_lyrics.png | Bin 0 -> 335 bytes resources/images/song_search_title.png | Bin 0 -> 245 bytes 8 files changed, 223 insertions(+), 31 deletions(-) create mode 100644 openlp/core/lib/searchedit.py create mode 100644 resources/images/general_search_clear.png create mode 100644 resources/images/song_search_all.png create mode 100644 resources/images/song_search_author.png create mode 100644 resources/images/song_search_lyrics.png create mode 100644 resources/images/song_search_title.png diff --git a/openlp/core/lib/searchedit.py b/openlp/core/lib/searchedit.py new file mode 100644 index 000000000..738661e14 --- /dev/null +++ b/openlp/core/lib/searchedit.py @@ -0,0 +1,191 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2011 Raoul Snyman # +# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael # +# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian # +# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # +# Carsten Tinggaard, Frode Woldsund # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### + +import logging + +from PyQt4 import QtCore, QtGui + +from openlp.core.lib import build_icon + +log = logging.getLogger(__name__) + +class SearchEdit(QtGui.QLineEdit): + """ + This is a specialised QLineEdit with a "clear" button inside for searches. + """ + + def __init__(self, parent): + """ + Constructor. + """ + QtGui.QLineEdit.__init__(self, parent) + self._currentSearchType = -1 + self.clearButton = QtGui.QToolButton(self) + self.clearButton.setIcon(build_icon(u':/system/clear_shortcut.png')) + self.clearButton.setCursor(QtCore.Qt.ArrowCursor) + self.clearButton.setStyleSheet( + u'QToolButton { border: none; padding: 0px; }') + self.clearButton.resize(18, 18) + self.clearButton.hide() + QtCore.QObject.connect( + self.clearButton, + QtCore.SIGNAL(u'clicked()'), + self._onClearButtonClicked + ) + QtCore.QObject.connect( + self, + QtCore.SIGNAL(u'textChanged(const QString&)'), + self._onSearchEditTextChanged + ) + self._updateStyleSheet() + + def _updateStyleSheet(self): + """ + Internal method to update the stylesheet depending on which widgets are + available and visible. + """ + frameWidth = self.style().pixelMetric( + QtGui.QStyle.PM_DefaultFrameWidth) + rightPadding = self.clearButton.sizeHint().width() + frameWidth + if hasattr(self, u'menuButton'): + leftPadding = self.menuButton.width() + self.setStyleSheet( + u'QLineEdit { padding-left: %spx; padding-right: %spx; } ' % \ + (leftPadding, rightPadding)) + else: + self.setStyleSheet(u'QLineEdit { padding-right: %spx; } ' % \ + rightPadding) + msz = self.minimumSizeHint(); + self.setMinimumSize( + max(msz.width(), + self.clearButton.sizeHint().width() + (frameWidth * 2) + 2), + max(msz.height(), + self.clearButton.height() + (frameWidth * 2) + 2) + ) + + def resizeEvent(self, event): + """ + Reimplemented method to react to resizing of the widget. + + ``event`` + The event that happened. + """ + sz = self.clearButton.sizeHint() + frameWidth = self.style().pixelMetric( + QtGui.QStyle.PM_DefaultFrameWidth) + self.clearButton.move(self.rect().right() - frameWidth - sz.width(), + (self.rect().bottom() + 1 - sz.height()) / 2) + if hasattr(self, u'menuButton'): + sz = self.menuButton.sizeHint() + self.menuButton.move(self.rect().left() + frameWidth + 2, + (self.rect().bottom() + 1 - sz.height()) / 2) + + def currentSearchType(self): + """ + Readonly property to return the current search type. + """ + return self._currentSearchType + + def setSearchTypes(self, items): + """ + A list of tuples to be used in the search type menu. The first item in + the list will be preselected as the default. + + ``items`` + The list of tuples to use. The tuples should contain an integer + identifier, an icon (QIcon instance or string) and a title for the + item in the menu. In short, they should look like this:: + + (, , ) + + For instance:: + + (1, <QIcon instance>, "Titles") + + Or:: + + (2, ":/songs/authors.png", "Authors") + """ + menu = QtGui.QMenu(self) + first = None + for identifier, icon, title in items: + action = QtGui.QAction(build_icon(icon), title, menu) + action.setData(QtCore.QVariant(identifier)) + menu.addAction(action) + QtCore.QObject.connect(action, QtCore.SIGNAL(u'triggered(bool)'), + self._onMenuActionTriggered) + if first is None: + first = action + self._currentSearchType = identifier + if not hasattr(self, u'menuButton'): + self.menuButton = QtGui.QToolButton(self) + self.menuButton.setIcon(build_icon(u':/system/clear_shortcut.png')) + self.menuButton.setCursor(QtCore.Qt.ArrowCursor) + self.menuButton.setPopupMode(QtGui.QToolButton.InstantPopup) + self.menuButton.setStyleSheet( + u'QToolButton { border: none; padding: 0px 10px 0px 0px; }') + self.menuButton.resize(QtCore.QSize(28, 18)) + self.menuButton.setMenu(menu) + self.menuButton.setDefaultAction(first) + self.menuButton.show() + self._updateStyleSheet() + + def _onSearchEditTextChanged(self, text): + """ + Internally implemented slot to react to when the text in the line edit + has changed so that we can show or hide the clear button. + + ``text`` + A :class:`~PyQt4.QtCore.QString` instance which represents the text + in the line edit. + """ + self.clearButton.setVisible(not text.isEmpty()) + + def _onClearButtonClicked(self): + """ + Internally implemented slot to react to the clear button being pressed + to clear the line edit. Once it has cleared the line edit, it emits the + ``cleared()`` signal so that an application can react to the clearing + of the line edit. + """ + self.clear() + self.emit(QtCore.SIGNAL(u'cleared()')) + + def _onMenuActionTriggered(self): + """ + Internally implemented slot to react to the select of one of the search + types in the menu. Once it has set the correct action on the button, + and set the current search type (using the list of identifiers provided + by the developer), the ``searchTypeChanged(int)`` signal is emitted + with the identifier. + """ + sender = self.sender() + for action in self.menuButton.menu().actions(): + action.setChecked(False) + self.menuButton.setDefaultAction(sender) + self._currentSearchType = sender.data().toInt()[0] + self.emit(QtCore.SIGNAL(u'searchTypeChanged(int)'), + self._currentSearchType) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 3be60dec4..8c06431ed 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -29,6 +29,7 @@ import locale import re from PyQt4 import QtCore, QtGui +from sqlalchemy.sql import or_ from openlp.core.lib import MediaManagerItem, BaseListWithDnD, Receiver, \ ItemCapabilities, translate, check_item_selected @@ -36,6 +37,7 @@ from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ SongImportForm from openlp.plugins.songs.lib import SongXMLParser, OpenLyricsParser from openlp.plugins.songs.lib.db import Author, Song +from openlp.core.lib.searchedit import SearchEdit log = logging.getLogger(__name__) @@ -88,20 +90,10 @@ class SongMediaItem(MediaManagerItem): self.SearchTextLabel.setObjectName(u'SearchTextLabel') self.SearchLayout.setWidget( 0, QtGui.QFormLayout.LabelRole, self.SearchTextLabel) - self.SearchTextEdit = QtGui.QLineEdit(self) + self.SearchTextEdit = SearchEdit(self) self.SearchTextEdit.setObjectName(u'SearchTextEdit') self.SearchLayout.setWidget( 0, QtGui.QFormLayout.FieldRole, self.SearchTextEdit) - self.SearchTypeLabel = QtGui.QLabel(self) - self.SearchTypeLabel.setAlignment( - QtCore.Qt.AlignBottom|QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft) - self.SearchTypeLabel.setObjectName(u'SearchTypeLabel') - self.SearchLayout.setWidget( - 1, QtGui.QFormLayout.LabelRole, self.SearchTypeLabel) - self.SearchTypeComboBox = QtGui.QComboBox(self) - self.SearchTypeComboBox.setObjectName(u'SearchTypeComboBox') - self.SearchLayout.setWidget( - 1, QtGui.QFormLayout.FieldRole, self.SearchTypeComboBox) self.pageLayout.addLayout(self.SearchLayout) self.SearchButtonLayout = QtGui.QHBoxLayout() self.SearchButtonLayout.setMargin(0) @@ -113,9 +105,6 @@ class SongMediaItem(MediaManagerItem): self.SearchTextButton = QtGui.QPushButton(self) self.SearchTextButton.setObjectName(u'SearchTextButton') self.SearchButtonLayout.addWidget(self.SearchTextButton) - self.ClearTextButton = QtGui.QPushButton(self) - self.ClearTextButton.setObjectName(u'ClearTextButton') - self.SearchButtonLayout.addWidget(self.ClearTextButton) self.pageLayout.addLayout(self.SearchButtonLayout) # Signals and slots QtCore.QObject.connect(Receiver.get_receiver(), @@ -124,8 +113,6 @@ class SongMediaItem(MediaManagerItem): QtCore.SIGNAL(u'returnPressed()'), self.onSearchTextButtonClick) QtCore.QObject.connect(self.SearchTextButton, QtCore.SIGNAL(u'pressed()'), self.onSearchTextButtonClick) - QtCore.QObject.connect(self.ClearTextButton, - QtCore.SIGNAL(u'pressed()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.SearchTextEdit, QtCore.SIGNAL(u'textChanged(const QString&)'), self.onSearchTextEditChanged) @@ -139,6 +126,11 @@ class SongMediaItem(MediaManagerItem): QtCore.SIGNAL(u'songs_edit'), self.onRemoteEdit) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_edit_clear'), self.onRemoteEditClear) + QtCore.QObject.connect(self.SearchTextEdit, + QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick) + QtCore.QObject.connect(self.SearchTextEdit, + QtCore.SIGNAL(u'searchTypeChanged(int)'), + self.onSearchTextButtonClick) def configUpdated(self): self.searchAsYouType = QtCore.QSettings().value( @@ -154,39 +146,44 @@ class SongMediaItem(MediaManagerItem): def retranslateUi(self): self.SearchTextLabel.setText( translate('SongsPlugin.MediaItem', 'Search:')) - self.SearchTypeLabel.setText( - translate('SongsPlugin.MediaItem', 'Type:')) - self.ClearTextButton.setText( - translate('SongsPlugin.MediaItem', 'Clear')) self.SearchTextButton.setText( translate('SongsPlugin.MediaItem', 'Search')) def initialise(self): - self.SearchTypeComboBox.addItem( - translate('SongsPlugin.MediaItem', 'Titles')) - self.SearchTypeComboBox.addItem( - translate('SongsPlugin.MediaItem', 'Lyrics')) - self.SearchTypeComboBox.addItem( - translate('SongsPlugin.MediaItem', 'Authors')) + self.SearchTextEdit.setSearchTypes([ + (1, u':/songs/song_search_all.png', translate('SongsPlugin.MediaItem', 'Entire Song')), + (2, u':/songs/song_search_title.png', translate('SongsPlugin.MediaItem', 'Titles')), + (3, u':/songs/song_search_lyrics.png', translate('SongsPlugin.MediaItem', 'Lyrics')), + (4, u':/songs/song_search_author.png', translate('SongsPlugin.MediaItem', 'Authors')) + ]) self.configUpdated() def onSearchTextButtonClick(self): search_keywords = unicode(self.SearchTextEdit.displayText()) search_results = [] - search_type = self.SearchTypeComboBox.currentIndex() - if search_type == 0: + # search_type = self.SearchTypeComboBox.currentIndex() + search_type = self.SearchTextEdit.currentSearchType() + if search_type == 1: + log.debug(u'Entire Song Search') + search_results = self.parent.manager.get_all_objects(Song, + or_(Song.search_title.like(u'%' + self.whitespace.sub(u' ', + search_keywords.lower()) + u'%'), + Song.search_lyrics.like(u'%' + search_keywords.lower() + \ + u'%')), Song.search_title.asc()) + self.displayResultsSong(search_results) + if search_type == 2: log.debug(u'Titles Search') search_results = self.parent.manager.get_all_objects(Song, Song.search_title.like(u'%' + self.whitespace.sub(u' ', search_keywords.lower()) + u'%'), Song.search_title.asc()) self.displayResultsSong(search_results) - elif search_type == 1: + elif search_type == 3: log.debug(u'Lyrics Search') search_results = self.parent.manager.get_all_objects(Song, Song.search_lyrics.like(u'%' + search_keywords.lower() + u'%'), Song.search_lyrics.asc()) self.displayResultsSong(search_results) - elif search_type == 2: + elif search_type == 4: log.debug(u'Authors Search') search_results = self.parent.manager.get_all_objects(Author, Author.display_name.like(u'%' + search_keywords + u'%'), @@ -457,4 +454,4 @@ class SongMediaItem(MediaManagerItem): """ Locale aware collation of song titles """ - return locale.strcoll(unicode(song_1.title), unicode(song_2.title)) \ No newline at end of file + return locale.strcoll(unicode(song_1.title), unicode(song_2.title)) diff --git a/resources/images/general_search_clear.png b/resources/images/general_search_clear.png new file mode 100644 index 0000000000000000000000000000000000000000..6c4b83b7ac6e451f461973dac0c9a6c53dedef25 GIT binary patch literal 644 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJbFq_W2nPqp?T7vkfLzW3kH}&M z2FBeW%xLxI@gtz1WQl7;NpOBzNqJ&XDnogBxn5>oc5!lIL8@MUQTpt6Hc~*<rU5=7 zuK)l42dcMnvI3GiMmj)JK|ujXii!#WNmf=?TRR&d!`99^IXM}~U}R)8Fw|#aVp366 z0g@6D;w&sIyu7?XaUd7S25MnrV`FD$2Rf05hX*JnARr(jA}k^zA}J{eG+a?hQAtTj zU0qGzK+n+7(8$=(+}zyC$_i+Oy}i975IEVpxH`MKy1Ki&djWyBhqt%4ub;Oc5cvBB z1Ox;J2Zw}&goTBMg@;5$hDAn3Mn^}dq$H=LC8cGgWMpJy0YP?pVPRouX=!C;WmQ#G zOG`^zTU%FG*MtcZ=FgwMX3d&)>(*`Bv~l~6?FSDYJaY8Nv17;1UpRl|%9VTf?mc|? z@cHxSFJHcV_3G8zw{Jgu`0)Aj=PzHr{QC9l_wV0-{`@KR`o0Pn77`^ve!&d#@_Ksq z_8}pusXI=cy7Kht(+?kh{P_EqYvr0*Ks9qcT^vIsB<CJv7Gq*$U_CHD_x85j+hx(! z|CL*89p0NV|LN4@3TF9{bn4Y($NlDSw$%Pe(C#u$3X&K6yhu7fCUn)d`a9w*l_zg9 zelWf0v#F%Q=47;D5{tq|cc+67rl`yh?hoc}SiUVHxAXAV65D4bR(lGku>JkEM|1so z>*;dxIy;s3ojI<x+U-Dte%qDV>&$kq&AP_I<(sjr<Ku1am?9a8z1sZxK!-ATy85}S Ib4q9e0FX@VYXATM literal 0 HcmV?d00001 diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index e9ec5c0a3..6b9d6dd54 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -1,5 +1,9 @@ <RCC> <qresource prefix="songs"> + <file>song_search_all.png</file> + <file>song_search_author.png</file> + <file>song_search_lyrics.png</file> + <file>song_search_title.png</file> <file>topic_edit.png</file> <file>author_add.png</file> <file>author_delete.png</file> diff --git a/resources/images/song_search_all.png b/resources/images/song_search_all.png new file mode 100644 index 0000000000000000000000000000000000000000..cedee77007ae3f4b236a482c0c882038fef9c93a GIT binary patch literal 607 zcmV-l0-*hgP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004b3#c}2nYxW zd<bNS00009a7bBm0005I0005I0XppC;s5{u8FWQhbW?9;ba!ELWdL_~cP?peYja~^ zaAhuUa%Y?FJQ@H10o+MMK~y-6rBh976HydB_oef}WM*JmT1)*XmS$10#a04>bP>d5 z-TD)XxNzx86n{ZiE((I+O0uo4goYxBM&d`o*g}<PDA6|QWYQ$__1<%3YV9;A-rc?D zaPGP9aY#yu|EYn0A=3h#)b!K^+cAwF%WfV3D9HikNQa4;v(uyVW8*{f&WLs1vFuYr zwxbQE9lUx`ezUSz$R6up_S*R3l}ouL1_gc)q2mYWw0wN2d021NP^o@v^gThb6s*2| zheqh488_jEO$aUmMEJ-!Z7FT$^%d|bP&U6;Ui)fPfQI)_@d0golJ{ji`Q*f9uhhBI zSHK>&LbXsYb{~hg|HMqv5im}D1q`M$B2W^hrA(%$;vUA5NSsS{41_q0C=v%hm&j^{ zU2wq@1@@wSbfRvrPduR!w85n~G|TOfSzSY>zM)Qr@xk6i2X4?pEaG0Dc|g}kx96(q z36xYLeCU7nwIdGZ@-)oO;og1))4>Kt;vL%hg$29FmcN!PW0t`h!%I&SH;)L^xAAmg z=4!S)RfM<h#_dSn1pp#404&!sD2hF@`7YlC&>|uxr4+p^oW7-AOizg$17{G{9`R@O tJf2G_{lu62tqz5Wh*AIu0GEH6^Plm<$@(331Frx8002ovPDHLkV1hRG5Jvz2 literal 0 HcmV?d00001 diff --git a/resources/images/song_search_author.png b/resources/images/song_search_author.png new file mode 100644 index 0000000000000000000000000000000000000000..c974107d2829beeb5ba40bd4abfc536c1b5fe3b1 GIT binary patch literal 409 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!60wlNoGJgf6n2Mb|LpV4>-?)JUISV`@iy0Ug zcY`pa)tkqUfP#`Gt`Q}{`DrEPiAAXl<>lpinR(g8$%zH2dih1^v)|cB0aZ(Qx;Tbt zoKOC7zM<hz9oO+G=RABLi#T*BdKP<W&inpf{`>vk`wt2Faq_S(id`k2^Pm0i_5b<& zAxc~Md>Q+9-#UNbf82lGf7wh6Z`MDS-!o5x%Vn4DKkGl?&CZkmKjID$>3CoMZ~e!3 zNj}qm-m;E?3T3B%?SE8XsiILP>)QB1(075Iq>6@txGQ7%%rEs*|6lsAx-j5}UAuM{ z6PwsNyNCIU{yPRdu}@bQ=AYJ(<SqC^`-?nFB=g1=mCcOD-TwU-I8oYkwZBntT|?vC ztqp%WKKPp_7!)=yyk7shevf#>YKff=)1Gg>e}#!{-R=6F|78MB{EdIV|9Jh||9AK! zv?L<--()=8``%ugO@#SZ_h)ftZG$R_LWc=P3@@X9THg5(T@DOL22WQ%mvv4FO#rj_ Bsq6p% literal 0 HcmV?d00001 diff --git a/resources/images/song_search_lyrics.png b/resources/images/song_search_lyrics.png new file mode 100644 index 0000000000000000000000000000000000000000..1ab7145c6520bc770aedc33259b26d1df59f1361 GIT binary patch literal 335 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJbFq_W2nPqp?T7vkfLzW3kH}&M z2FBeW%xLxI@gtz1WQl7;NpOBzNqJ&XDnogBxn5>oc5!lIL8@MUQTpt6Hc~)E9sxcf zuK)l42Qs<RK2)v!%9Z{BWMIZS?u>W(4WB}%e<@${og@7nN9H?@3?TWQBjY_sI*9D< z?gpxa10dJu!nw~tzF0|+UoeBTk&%ge1qf7DRoB$k)i*S??EDrrc?M8LxTlL_h=gS8 z!AQO)2L{#+TAvsMkL2$7@2jeJ^3TOh>n+2jc(j<S*1K2kTO)02#eVdld;5YPoJ~!o z${e|wwXA`hkM{lJTqNY8YH@ekQ>*irOC*oWysc)|Il#i*CwBG^$WflIelF{r5}E*( C9&~j8 literal 0 HcmV?d00001 diff --git a/resources/images/song_search_title.png b/resources/images/song_search_title.png new file mode 100644 index 0000000000000000000000000000000000000000..2323757e0e94760b6aec976d52da09ee2584bb7d GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPF<E_U(^;o#u7{m}mbkjq)%5n0T@ zz_=TP8Li$tegqVhEOCt}3C>R|DNig)WhgH%*UQYyE>2D?NY%?PN}v7CMhd7%J-{c# z_5c6>9WXF)(u7^Rb{;r*;ONn#7cO3S^XARlw{PFQdk0jr(_cj#sD-&C$S;_|`i9?` zLLiU9(9^{+gyVX0f&vqVWOJiZ^RG8|9X4$4IQVMDaY==UGYPe7Y)5YNv@(V>UuQLE aH)mjws#a^|o9@yJ((UQ$=d#Wzp$PyKYFkPG literal 0 HcmV?d00001 From 6f26c6fc0a2d0001e9395a68445827db32068094 Mon Sep 17 00:00:00 2001 From: Raoul Snyman <raoul.snyman@saturnlaboratories.co.za> Date: Tue, 28 Dec 2010 23:41:12 +0200 Subject: [PATCH 2/9] Fix up a small bug left over from the changeover to the new search edit. --- openlp/plugins/songs/lib/mediaitem.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 8c06431ed..c94753d61 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -252,7 +252,9 @@ class SongMediaItem(MediaManagerItem): """ if self.searchAsYouType: search_length = 1 - if self.SearchTypeComboBox.currentIndex() == 1: + if self.SearchTextEdit.currentSearchType() == 1: + search_length = 3 + elif self.SearchTextEdit.currentSearchType() == 3: search_length = 7 if len(text) > search_length: self.onSearchTextButtonClick() From 87c1074cfe3801ccc0b034be8bd329e13d044c59 Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Wed, 29 Dec 2010 09:14:13 +0000 Subject: [PATCH 3/9] Add guard for missing filename --- openlp/core/lib/mediamanageritem.py | 4 +- openlp/plugins/images/lib/mediaitem.py | 4 +- openlp/plugins/media/lib/mediaitem.py | 4 +- .../presentations/lib/impresscontroller.py | 5 ++- openlp/plugins/presentations/lib/mediaitem.py | 43 +++++++++++-------- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 50e43afd0..102fc1f23 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -381,7 +381,7 @@ class MediaManagerItem(QtGui.QWidget): if os.path.exists(thumb): filedate = os.stat(file).st_mtime thumbdate = os.stat(thumb).st_mtime - #if file updated rebuild icon + # if file updated rebuild icon if filedate > thumbdate: self.iconFromFile(file, thumb) else: @@ -544,4 +544,4 @@ class MediaManagerItem(QtGui.QWidget): Method to add processing when a service has been loaded and individual service items need to be processed by the plugins """ - pass \ No newline at end of file + pass diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index fabad8e8c..99b8f624f 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -132,7 +132,7 @@ class ImageMediaItem(MediaManagerItem): os.remove(os.path.join(self.servicePath, unicode(text.text()))) except OSError: - #if not present do not worry + # if not present do not worry pass self.listView.takeItem(row) SettingsManager.set_list(self.settingsSection, @@ -195,4 +195,4 @@ class ImageMediaItem(MediaManagerItem): self.resetButton.setVisible(True) def onPreviewClick(self): - MediaManagerItem.onPreviewClick(self) \ No newline at end of file + MediaManagerItem.onPreviewClick(self) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index e2309ea76..d6719970f 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -89,7 +89,7 @@ class MediaMediaItem(MediaManagerItem): self.ImageWidget.sizePolicy().hasHeightForWidth()) self.ImageWidget.setSizePolicy(sizePolicy) self.ImageWidget.setObjectName(u'ImageWidget') - #Replace backgrounds do not work at present so remove functionality. + # Replace backgrounds do not work at present so remove functionality. self.blankButton = self.toolbar.addToolbarButton( translate('MediaPlugin.MediaItem', 'Replace Background'), u':/slides/slide_blank.png', @@ -159,4 +159,4 @@ class MediaMediaItem(MediaManagerItem): img = QtGui.QPixmap(u':/media/media_video.png').toImage() item_name.setIcon(build_icon(img)) item_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(file)) - self.listView.addItem(item_name) \ No newline at end of file + self.listView.addItem(item_name) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 6ec90c853..d7407b729 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -255,8 +255,9 @@ class ImpressDocument(PresentationDocument): self.document = desktop.loadComponentFromURL(url, u'_blank', 0, properties) except: - log.exception(u'Failed to load presentation') + log.exception(u'Failed to load presentation %s' % url) return False + self.presentation = self.document.getPresentation() self.presentation.Display = \ self.controller.plugin.renderManager.screens.current_display + 1 @@ -478,4 +479,4 @@ class ImpressDocument(PresentationDocument): shape = notes.getByIndex(idx) if shape.supportsService("com.sun.star.drawing.Text"): text += shape.getString() + '\n' - return text \ No newline at end of file + return text diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 4b1067e8e..acd82d4f7 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -153,7 +153,7 @@ class PresentationMediaItem(MediaManagerItem): """ self.DisplayTypeComboBox.clear() for item in self.controllers: - #load the drop down selection + # load the drop down selection if self.controllers[item].enabled(): self.DisplayTypeComboBox.addItem(item) if self.DisplayTypeComboBox.count() > 1: @@ -197,7 +197,7 @@ class PresentationMediaItem(MediaManagerItem): doc.load_presentation() preview = doc.get_thumbnail_path(1, True) doc.close_presentation() - if preview and self.validate(preview, thumb): + if preview and self.validate(preview, file): icon = build_icon(thumb) else: icon = build_icon(u':/general/general_delete.png') @@ -254,22 +254,27 @@ class PresentationMediaItem(MediaManagerItem): for item in items: bitem = self.listView.item(item.row()) filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) - if shortname == self.Automatic: - service_item.shortname = self.findControllerByType(filename) - if not service_item.shortname: - return False - controller = self.controllers[service_item.shortname] - (path, name) = os.path.split(filename) - doc = controller.add_doc(filename) - if doc.get_thumbnail_path(1, True) is None: - doc.load_presentation() - i = 1 - img = doc.get_thumbnail_path(i, True) - while img: - service_item.add_from_command(path, name, img) - i = i + 1 + if os.path.exists(filename): + if shortname == self.Automatic: + service_item.shortname = \ + self.findControllerByType(filename) + if not service_item.shortname: + return False + controller = self.controllers[service_item.shortname] + (path, name) = os.path.split(filename) + doc = controller.add_doc(filename) + if doc.get_thumbnail_path(1, True) is None: + doc.load_presentation() + i = 1 img = doc.get_thumbnail_path(i, True) - doc.close_presentation() + while img: + service_item.add_from_command(path, name, img) + i = i + 1 + img = doc.get_thumbnail_path(i, True) + doc.close_presentation() + else: + # File is no longer present + return False return True else: return False @@ -280,7 +285,7 @@ class PresentationMediaItem(MediaManagerItem): file type. This is used if "Automatic" is set as the preferred controller. Find the first (alphabetic) enabled controller which "supports" the extension. If none found, then look for a controller - which "alsosupports" it instead. + which "also supports" it instead. """ filetype = filename.split(u'.')[1] if not filetype: @@ -293,4 +298,4 @@ class PresentationMediaItem(MediaManagerItem): if self.controllers[controller].enabled(): if filetype in self.controllers[controller].alsosupports: return controller - return None \ No newline at end of file + return None From ad346d8e05cd9ddbc541691df1af591c172fcb68 Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Wed, 29 Dec 2010 09:27:13 +0000 Subject: [PATCH 4/9] Add message popup and guard Images and Media as well --- openlp/plugins/images/lib/mediaitem.py | 15 ++++++++--- openlp/plugins/media/lib/mediaitem.py | 27 ++++++++++++------- openlp/plugins/presentations/lib/mediaitem.py | 7 ++++- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 99b8f624f..f7d576913 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -172,9 +172,18 @@ class ImageMediaItem(MediaManagerItem): for item in items: bitem = self.listView.item(item.row()) filename = unicode(bitem.data(QtCore.Qt.UserRole).toString()) - (path, name) = os.path.split(filename) - service_item.add_from_image(filename, name) - return True + if os.path.exists(filename): + (path, name) = os.path.split(filename) + service_item.add_from_image(filename, name) + return True + else: + # File is no longer present + QtGui.QMessageBox.critical( + self, translate('ImagePlugin.MediaItem', + 'Missing Image'), + unicode(translate('ImagePlugin.MediaItem', + 'The Image %s no longer exists.')) % filename) + return False else: return False diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index d6719970f..a8bb6456b 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -122,15 +122,24 @@ class MediaMediaItem(MediaManagerItem): if item is None: return False filename = unicode(item.data(QtCore.Qt.UserRole).toString()) - service_item.title = unicode( - translate('MediaPlugin.MediaItem', 'Media')) - service_item.add_capability(ItemCapabilities.RequiresMedia) - # force a nonexistent theme - service_item.theme = -1 - frame = u':/media/image_clapperboard.png' - (path, name) = os.path.split(filename) - service_item.add_from_command(path, name, frame) - return True + if os.path.exists(filename): + service_item.title = unicode( + translate('MediaPlugin.MediaItem', 'Media')) + service_item.add_capability(ItemCapabilities.RequiresMedia) + # force a nonexistent theme + service_item.theme = -1 + frame = u':/media/image_clapperboard.png' + (path, name) = os.path.split(filename) + service_item.add_from_command(path, name, frame) + return True + else: + # File is no longer present + QtGui.QMessageBox.critical( + self, translate('MediaPlugin.MediaItem', + 'Missing Media File'), + unicode(translate('MediaPlugin.MediaItem', + 'The file %s no longer exists.')) % filename) + return False def initialise(self): self.listView.setSelectionMode( diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index acd82d4f7..4176fd58e 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -272,10 +272,15 @@ class PresentationMediaItem(MediaManagerItem): i = i + 1 img = doc.get_thumbnail_path(i, True) doc.close_presentation() + return True else: # File is no longer present + QtGui.QMessageBox.critical( + self, translate('PresentationPlugin.MediaItem', + 'Missing Presentation'), + unicode(translate('PresentationPlugin.MediaItem', + 'The Presentation %s no longer exists.')) % filename) return False - return True else: return False From bb10026b63a6189a65ccb4d76d4725364dfe202e Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Wed, 29 Dec 2010 09:37:36 +0000 Subject: [PATCH 5/9] Correct change in error --- openlp/plugins/presentations/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 4176fd58e..c39371eff 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -197,7 +197,7 @@ class PresentationMediaItem(MediaManagerItem): doc.load_presentation() preview = doc.get_thumbnail_path(1, True) doc.close_presentation() - if preview and self.validate(preview, file): + if preview and self.validate(preview, thumb): icon = build_icon(thumb) else: icon = build_icon(u':/general/general_delete.png') From 89a2280f4e1eae3b3709534e267bb54d7abc9730 Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Wed, 29 Dec 2010 09:43:02 +0000 Subject: [PATCH 6/9] Add css files to manifest file Fixes: https://launchpad.net/bugs/694079 --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index efccdf79d..992685bcf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,6 +3,7 @@ recursive-include openlp *.sqlite recursive-include openlp *.csv recursive-include openlp *.html recursive-include openlp *.js +recursive-include openlp *.css recursive-include openlp *.qm recursive-include documentation * recursive-include resources/forms * From 8cdf4d39bf2b98e323c3aef74bc8fa73305411cb Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Wed, 29 Dec 2010 12:45:16 +0000 Subject: [PATCH 7/9] Add muppet exit guard --- openlp/core/ui/mainwindow.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 1fbf40837..7fbe4c55a 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -825,8 +825,18 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): else: event.ignore() else: - self.cleanUp() - event.accept() + ret = QtGui.QMessageBox.question(self, + translate('OpenLP.MainWindow', 'Close OpenLP'), + translate('OpenLP.MainWindow', 'Are you sure you want to Exit.'), + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.Cancel | + QtGui.QMessageBox.Ok), + QtGui.QMessageBox.Ok) + if ret == QtGui.QMessageBox.Ok: + self.cleanUp() + event.accept() + else: + event.ignore() def cleanUp(self): """ From 0ec22826a8c7838a345a6ddc740ec920120a765e Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Wed, 29 Dec 2010 17:26:03 +0000 Subject: [PATCH 8/9] Fix message text --- openlp/core/ui/mainwindow.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 7fbe4c55a..b88f69910 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -827,12 +827,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): else: ret = QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'Close OpenLP'), - translate('OpenLP.MainWindow', 'Are you sure you want to Exit.'), + translate('OpenLP.MainWindow', 'Are you sure you want to Exit?'), QtGui.QMessageBox.StandardButtons( - QtGui.QMessageBox.Cancel | - QtGui.QMessageBox.Ok), - QtGui.QMessageBox.Ok) - if ret == QtGui.QMessageBox.Ok: + QtGui.QMessageBox.Yes | + QtGui.QMessageBox.No), + QtGui.QMessageBox.Yes) + if ret == QtGui.QMessageBox.Yes: self.cleanUp() event.accept() else: From cd74645379e27b1193dc8eebbffa070790a7f623 Mon Sep 17 00:00:00 2001 From: Tim Bentley <tim.bentley@gmail.com> Date: Thu, 30 Dec 2010 09:13:39 +0000 Subject: [PATCH 9/9] Fix bug where blank hides the screen on restart. Presentations unblank the screen and reset the display flags and setting. Fixes: https://launchpad.net/bugs/660448 --- openlp/core/lib/serviceitem.py | 4 +-- openlp/core/ui/slidecontroller.py | 26 ++++++++++++++++--- openlp/plugins/presentations/lib/mediaitem.py | 3 ++- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 271d3107e..f18605711 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -58,7 +58,7 @@ class ItemCapabilities(object): NoLineBreaks = 7 OnLoadUpdate = 8 AddIfNewItem = 9 - + ProvidesOwnDisplay = 10 class ServiceItem(object): """ @@ -397,4 +397,4 @@ class ServiceItem(object): """ Returns the path of the raw frame """ - return self._raw_frames[row][u'path'] \ No newline at end of file + return self._raw_frames[row][u'path'] diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 728c86a08..0d658dfe9 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -393,6 +393,7 @@ class SlideController(QtGui.QWidget): """ # We need to make this circuit, because we have to consider the other # slidecontroller as well. + log.debug(u'paintEvent live = %s' % self.isLive) self.parent.previewController.previewSizeChanged() self.parent.liveController.previewSizeChanged() @@ -561,6 +562,8 @@ class SlideController(QtGui.QWidget): if self.serviceItem.is_media(): self.onMediaClose() if self.isLive: + if serviceItem.is_capable(ItemCapabilities.ProvidesOwnDisplay): + self._forceUnblank() blanked = self.BlankScreen.isChecked() else: blanked = False @@ -568,8 +571,6 @@ class SlideController(QtGui.QWidget): [serviceItem, self.isLive, blanked, slideno]) self.slideList = {} width = self.parent.ControlSplitter.sizes()[self.split] - # Set pointing cursor when we have something to point at - self.PreviewListWidget.setCursor(QtCore.Qt.PointingHandCursor) self.serviceItem = serviceItem self.PreviewListWidget.clear() self.PreviewListWidget.setRowCount(0) @@ -698,7 +699,7 @@ class SlideController(QtGui.QWidget): """ log.debug(u'mainDisplaySetBackground live = %s' % self.isLive) if not self.display.primary: - self.onHideDisplay(True) + self.onBlankDisplay(True) def onSlideBlank(self): """ @@ -1041,3 +1042,22 @@ class SlideController(QtGui.QWidget): self.video.hide() self.SlidePreview.clear() self.SlidePreview.show() + + def _forceUnblank(self): + """ + Used by command items which provide their own displays to reset the + screen hide attributes + """ + if self.BlankScreen.isChecked: + self.BlankScreen.setChecked(False) + self.HideMenu.setDefaultAction(self.BlankScreen) + QtCore.QSettings().setValue( + self.parent.generalSettingsSection + u'/screen blank', + QtCore.QVariant(False)) + if self.ThemeScreen.isChecked: + self.ThemeScreen.setChecked(False) + self.HideMenu.setDefaultAction(self.ThemeScreen) + if self.DesktopScreen.isChecked: + self.DesktopScreen.setChecked(False) + self.HideMenu.setDefaultAction(self.DesktopScreen) + diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index c39371eff..127230cff 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -30,7 +30,7 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ - SettingsManager, translate, check_item_selected, Receiver + SettingsManager, translate, check_item_selected, Receiver, ItemCapabilities from openlp.plugins.presentations.lib import MessageListener log = logging.getLogger(__name__) @@ -249,6 +249,7 @@ class PresentationMediaItem(MediaManagerItem): return False service_item.title = unicode(self.DisplayTypeComboBox.currentText()) service_item.shortname = unicode(self.DisplayTypeComboBox.currentText()) + service_item.add_capability(ItemCapabilities.ProvidesOwnDisplay) shortname = service_item.shortname if shortname: for item in items: