class SearchBuffer(Buffer): threads = [] def __init__(self, ui, initialquery=''): self.dbman = ui.dbman self.ui = ui self.querystring = initialquery self.result_count = 0 self.isinitialized = False self.rebuild() Buffer.__init__(self, ui, self.body, 'search') self.autoparms = {'thread': self.get_selected_thread} def __str__(self): return '%s (%d threads)' % (self.querystring, self.result_count) def rebuild(self): if self.isinitialized: focusposition = self.threadlist.get_focus()[1] else: focusposition = 0 self.isinitialized = True self.result_count = self.dbman.count_messages(self.querystring) try: self.tids = self.dbman.search_thread_ids(self.querystring) except NotmuchError: self.ui.notify('malformed query string: %s' % self.querystring, 'error') self.tids = [] self.threadlist = IteratorWalker(iter(self.tids), widgets.ThreadlineWidget, dbman=self.dbman) self.listbox = urwid.ListBox(self.threadlist) #self.threadlist.set_focus(focusposition) self.body = self.listbox def debug(self): self.ui.logger.debug(self.threadlist.lines) def get_selected_threadline(self): (threadlinewidget, size) = self.threadlist.get_focus() return threadlinewidget def get_selected_thread(self): threadlinewidget = self.get_selected_threadline() thread = None if threadlinewidget: thread = threadlinewidget.get_thread() return thread
def rebuild(self): if self.isinitialized: focusposition = self.threadlist.get_focus()[1] else: focusposition = 0 self.isinitialized = True self.result_count = self.dbman.count_messages(self.querystring) try: self.tids = self.dbman.search_thread_ids(self.querystring) except NotmuchError: self.ui.notify('malformed query string: %s' % self.querystring, 'error') self.tids = [] self.threadlist = IteratorWalker(iter(self.tids), widgets.ThreadlineWidget, dbman=self.dbman) self.listbox = urwid.ListBox(self.threadlist) #self.threadlist.set_focus(focusposition) self.body = self.listbox