Search box now indicates successfully parsed queries

This commit is contained in:
Kovid Goyal 2009-07-08 13:27:26 -06:00
parent 8443a11abe
commit 6ac009886c
2 changed files with 28 additions and 7 deletions

View File

@ -244,12 +244,15 @@ class BooksModel(QAbstractTableModel):
try:
self.db.search(text)
except ParseException:
self.emit(SIGNAL('parse_exception()'))
self.emit(SIGNAL('searched(PyQt_PyObject)'), False)
return
self.last_search = text
if reset:
self.clear_caches()
self.reset()
if self.last_search:
self.emit(SIGNAL('searched(PyQt_PyObject)'), True)
def sort(self, col, order, reset=True):
if not self.db:
@ -743,14 +746,20 @@ class BooksView(TableView):
def set_editable(self, editable):
self._model.set_editable(editable)
def connect_to_search_box(self, sb):
def connect_to_search_box(self, sb, search_done):
QObject.connect(sb, SIGNAL('search(PyQt_PyObject, PyQt_PyObject)'),
self._model.search)
self._search_done = search_done
self.connect(self._model, SIGNAL('searched(PyQt_PyObject)'),
self.search_done)
def connect_to_book_display(self, bd):
QObject.connect(self._model, SIGNAL('new_bookdisplay_data(PyQt_PyObject)'),
bd)
def search_done(self, ok):
self._search_done(self, ok)
class DeviceBooksView(BooksView):
@ -864,7 +873,7 @@ class DeviceBooksModel(BooksModel):
try:
matches = self.search_engine.parse(text)
except ParseException:
self.emit(SIGNAL('parse_exception()'))
self.emit(SIGNAL('searched(PyQt_PyObject)'), False)
return
self.map = []
@ -875,6 +884,9 @@ class DeviceBooksModel(BooksModel):
if reset:
self.reset()
self.last_search = text
if self.last_search:
self.emit(SIGNAL('searched(PyQt_PyObject)'), True)
def resort(self, reset):
self.sort(self.sorted_on[0], self.sorted_on[1], reset=reset)
@ -1068,11 +1080,15 @@ class SearchBox(QLineEdit):
self.setText(self.help_text)
self.home(False)
self.initial_state = True
self.setStyleSheet("background-color: white")
def clear(self):
self.clear_to_help()
self.emit(SIGNAL('search(PyQt_PyObject, PyQt_PyObject)'), '', False)
def search_done(self, ok):
col = 'rgba(0,255,0,25%)' if ok else 'rgb(255,0,0,25%)'
self.setStyleSheet('background-color: '+col)
def keyPressEvent(self, event):
if self.initial_state:

View File

@ -394,13 +394,14 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
QObject.connect(self.library_view,
SIGNAL('files_dropped(PyQt_PyObject)'),
self.files_dropped, Qt.QueuedConnection)
for func, target in [
('connect_to_search_box', self.search),
for func, args in [
('connect_to_search_box', (self.search,
self.search_done)),
('connect_to_book_display',
self.status_bar.book_info.show_data),
(self.status_bar.book_info.show_data,)),
]:
for view in (self.library_view, self.memory_view, self.card_a_view, self.card_b_view):
getattr(view, func)(target)
getattr(view, func)(*args)
self.memory_view.connect_dirtied_signal(self.upload_booklists)
self.card_a_view.connect_dirtied_signal(self.upload_booklists)
@ -631,6 +632,10 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.match_any.setVisible(False)
self.popularity.setVisible(False)
def search_done(self, view, ok):
if view is self.current_view():
self.search.search_done(ok)
def sync_cf_to_listview(self, index, *args):
if not hasattr(index, 'row') and \
self.library_view.currentIndex().row() != index: