Fix bugs in searchbox as you type implementation

This commit is contained in:
Kovid Goyal 2010-05-21 20:36:57 -06:00
parent 5b820fe42c
commit 9e110eeec8
2 changed files with 5 additions and 3 deletions

View File

@ -883,7 +883,7 @@ class DeviceBooksModel(BooksModel): # {{{
self.reset() self.reset()
self.last_search = text self.last_search = text
if self.last_search: if self.last_search:
self.searched.emit(False) self.searched.emit(True)
def sort(self, col, order, reset=True): def sort(self, col, order, reset=True):

View File

@ -135,13 +135,12 @@ class SearchBox2(QComboBox):
def text_edited_slot(self, text): def text_edited_slot(self, text):
if self.as_you_type: if self.as_you_type:
text = unicode(text)
self.prev_text = text
self.timer = self.startTimer(self.__class__.INTERVAL) self.timer = self.startTimer(self.__class__.INTERVAL)
def timerEvent(self, event): def timerEvent(self, event):
self.killTimer(event.timerId()) self.killTimer(event.timerId())
if event.timerId() == self.timer: if event.timerId() == self.timer:
self.timer = None
self.do_search() self.do_search()
@property @property
@ -190,6 +189,9 @@ class SearchBox2(QComboBox):
def set_search_string(self, txt): def set_search_string(self, txt):
self.normalize_state() self.normalize_state()
self.setEditText(txt) self.setEditText(txt)
if self.timer is not None: # Turn off any timers that got started in setEditText
self.killTimer(self.timer)
self.timer = None
self.search.emit(txt, False) self.search.emit(txt, False)
self.line_edit.end(False) self.line_edit.end(False)
self.initial_state = False self.initial_state = False