# Path: alot/widgets/search.py
# class ThreadlineWidget(urwid.AttrMap):
#     """
#     selectable line widget that represents a :class:`~alot.db.Thread`
#     in the :class:`~alot.buffers.SearchBuffer`.
#     """
#     def __init__(self, tid, dbman):
#         self.dbman = dbman
#         self.tid = tid
#         self.thread = None  # will be set by refresh()
#         self.tag_widgets = []
#         self.structure = None
#         self.rebuild()
#         normal = self.structure['normal']
#         focussed = self.structure['focus']
#         urwid.AttrMap.__init__(self, self.columns, normal, focussed)
# 
#     def rebuild(self):
#         self.thread = self.dbman.get_thread(self.tid)
#         self.widgets = []
#         self.structure = settings.get_threadline_theming(self.thread)
# 
#         columns = []
# 
#         # combine width info and widget into an urwid.Column entry
#         def add_column(width, part):
#             width_tuple = self.structure[partname]['width']
#             if width_tuple[0] == 'weight':
#                 columnentry = width_tuple + (part,)
#             else:
#                 columnentry = ('fixed', width, part)
#             columns.append(columnentry)
# 
#         # create a column for every part of the threadline
#         for partname in self.structure['parts']:
#             # build widget(s) around this part's content and remember them so
#             # that self.render() may change local attributes.
#             if partname == 'tags':
#                 width, part = build_tags_part(self.thread.get_tags(),
#                                               self.structure['tags']['normal'],
#                                               self.structure['tags']['focus'])
#                 if part:
#                     add_column(width, part)
#                     for w in part.widget_list:
#                         self.widgets.append(w)
#             else:
#                 width, part = build_text_part(partname, self.thread,
#                                               self.structure[partname])
#                 add_column(width, part)
#                 self.widgets.append(part)
# 
#         self.columns = urwid.Columns(columns, dividechars=1)
#         self.original_widget = self.columns
# 
#     def render(self, size, focus=False):
#         for w in self.widgets:
#             w.set_map('focus' if focus else 'normal')
#         return urwid.AttrMap.render(self, size, focus)
# 
#     def selectable(self):
#         return True
# 
#     def keypress(self, size, key):
#         return key
# 
#     def get_thread(self):
#         return self.thread


import urwid
from notmuch2 import NotmuchError
from .buffer import Buffer
from ..settings.const import settings
from ..walker import IterableWalker
from ..widgets.search import ThreadlineWidget
    def get_info(self):
        info = {}
        info['querystring'] = self.querystring
        info['result_count'] = self.result_count
        info['result_count_positive'] = 's' if self.result_count > 1 else ''
        return info

    def rebuild(self, reverse=False, restore_focus=True):
        self.isinitialized = True
        self.reversed = reverse
        selected_thread = None

        if reverse:
            order = self._REVERSE[self.sort_order]
        else:
            order = self.sort_order

        if restore_focus and self.threadlist:
            selected_thread = self.get_selected_thread()

        try:
            self.result_count = self.dbman.count_messages(self.querystring)
            threads = self.dbman.get_threads(self.querystring, order)
        except NotmuchError:
            self.ui.notify('malformed query string: %s' % self.querystring,
                           'error')
            self.listbox = urwid.ListBox([])
            self.body = self.listbox
            return


# Path: alot/widgets/search.py
# class ThreadlineWidget(urwid.AttrMap):
#     """
#     selectable line widget that represents a :class:`~alot.db.Thread`
#     in the :class:`~alot.buffers.SearchBuffer`.
#     """
#     def __init__(self, tid, dbman):
#         self.dbman = dbman
#         self.tid = tid
#         self.thread = None  # will be set by refresh()
#         self.tag_widgets = []
#         self.structure = None
#         self.rebuild()
#         normal = self.structure['normal']
#         focussed = self.structure['focus']
#         urwid.AttrMap.__init__(self, self.columns, normal, focussed)
# 
#     def rebuild(self):
#         self.thread = self.dbman.get_thread(self.tid)
#         self.widgets = []
#         self.structure = settings.get_threadline_theming(self.thread)
# 
#         columns = []
# 
#         # combine width info and widget into an urwid.Column entry
#         def add_column(width, part):
#             width_tuple = self.structure[partname]['width']
#             if width_tuple[0] == 'weight':
#                 columnentry = width_tuple + (part,)
#             else:
#                 columnentry = ('fixed', width, part)
#             columns.append(columnentry)
# 
#         # create a column for every part of the threadline
#         for partname in self.structure['parts']:
#             # build widget(s) around this part's content and remember them so
#             # that self.render() may change local attributes.
#             if partname == 'tags':
#                 width, part = build_tags_part(self.thread.get_tags(),
#                                               self.structure['tags']['normal'],
#                                               self.structure['tags']['focus'])
#                 if part:
#                     add_column(width, part)
#                     for w in part.widget_list:
#                         self.widgets.append(w)
#             else:
#                 width, part = build_text_part(partname, self.thread,
#                                               self.structure[partname])
#                 add_column(width, part)
#                 self.widgets.append(part)
# 
#         self.columns = urwid.Columns(columns, dividechars=1)
#         self.original_widget = self.columns
# 
#     def render(self, size, focus=False):
#         for w in self.widgets:
#             w.set_map('focus' if focus else 'normal')
#         return urwid.AttrMap.render(self, size, focus)
# 
#     def selectable(self):
#         return True
# 
#     def keypress(self, size, key):
#         return key
# 
#     def get_thread(self):
#         return self.thread


# Path: alot/buffers/search.py
import urwid
from notmuch2 import NotmuchError
from .buffer import Buffer
from ..settings.const import settings
from ..walker import IterableWalker
from ..widgets.search import ThreadlineWidget

    def get_info(self):
        info = {}
        info['querystring'] = self.querystring
        info['result_count'] = self.result_count
        info['result_count_positive'] = 's' if self.result_count > 1 else ''
        return info

    def rebuild(self, reverse=False, restore_focus=True):
        self.isinitialized = True
        self.reversed = reverse
        selected_thread = None

        if reverse:
            order = self._REVERSE[self.sort_order]
        else:
            order = self.sort_order

        if restore_focus and self.threadlist:
            selected_thread = self.get_selected_thread()

        try:
            self.result_count = self.dbman.count_messages(self.querystring)
            threads = self.dbman.get_threads(self.querystring, order)
        except NotmuchError:
            self.ui.notify('malformed query string: %s' % self.querystring,
                           'error')
            self.listbox = urwid.ListBox([])
            self.body = self.listbox
            return


        self.threadlist = IterableWalker(threads, ThreadlineWidget,