Пример #1
0
 def filter_candidates(self, context):
     for source in self.__current_sources:
         ctx = source.context
         ctx['input'] = context['input']
         all = ctx['all_candidates']
         if ctx['is_async']:
             all += source.gather_candidates(ctx)
         candidates = []
         for i in range(0, len(all), 1000):
             ctx['candidates'] = all[i:i+1000]
             for matcher in [self.__filters[x]
                             for x in source.matchers
                             if x in self.__filters]:
                 ctx['candidates'] = matcher.filter(ctx)
                 candidates += ctx['candidates']
             if len(candidates) >= 1000:
                 break
         ctx['candidates'] = candidates
         for filter in [self.__filters[x]
                        for x in source.sorters + source.converters
                        if x in self.__filters]:
             ctx['candidates'] = filter.filter(ctx)
         candidates = ctx['candidates']
         for c in candidates:
             c['source'] = source.name
         ctx['candidates'] = []
         yield source.name, all, candidates
Пример #2
0
 def filter_candidates(self, context):
     for source in self.__current_sources:
         ctx = source.context
         ctx['input'] = context['input']
         ctx['mode'] = context['mode']
         ctx['is_redraw'] = context['is_redraw']
         all = ctx['all_candidates']
         if ctx['is_async']:
             all += source.gather_candidates(ctx)
         if not all:
             continue
         candidates = []
         for i in range(0, len(all), 1000):
             ctx['candidates'] = all[i:i+1000]
             for matcher in [self.__filters[x]
                             for x in source.matchers
                             if x in self.__filters]:
                 ctx['candidates'] = matcher.filter(ctx)
             candidates += ctx['candidates']
             if len(candidates) >= 1000:
                 break
         ctx['candidates'] = candidates
         for filter in [self.__filters[x]
                        for x in source.sorters + source.converters
                        if x in self.__filters]:
             ctx['candidates'] = filter.filter(ctx)
         candidates = ctx['candidates']
         for c in candidates:
             c['source'] = source.name
         ctx['candidates'] = []
         yield source.name, all, candidates
Пример #3
0
 def filter_candidates(self, context):
     for source in self._current_sources:
         ctx = source.context
         ctx['input'] = context['input']
         if ctx['is_interactive'] and ctx['prev_input'] != ctx['input']:
             ctx['event'] = 'interactive'
             ctx['all_candidates'] = source.gather_candidates(ctx)
             ctx['prev_input'] = ctx['input']
         entire = ctx['all_candidates']
         if ctx['is_async']:
             ctx['event'] = 'async'
             entire += source.gather_candidates(ctx)
         if not entire:
             continue
         partial = []
         ctx['candidates'] = entire
         for i in range(0, len(entire), 1000):
             ctx['candidates'] = entire[i:i + 1000]
             for matcher in [
                     self._filters[x] for x in source.matchers
                     if x in self._filters
             ]:
                 ctx['candidates'] = matcher.filter(ctx)
             partial += ctx['candidates']
             if len(partial) >= 1000:
                 break
         ctx['candidates'] = partial
         for f in [
                 self._filters[x]
                 for x in source.sorters + source.converters
                 if x in self._filters
         ]:
             ctx['candidates'] = f.filter(ctx)
         partial = ctx['candidates']
         for c in partial:
             c['source'] = source.name
         ctx['candidates'] = []
         yield source.name, entire, partial
Пример #4
0
    def gather_candidates(self, context):
        for source in self._current_sources:
            source.context['is_redraw'] = context['is_redraw']
            source.context['messages'] = context['messages']
            source.context['mode'] = context['mode']
            source.context['prev_input'] = context['input']
            source.context['event'] = 'gather'

            candidates = source.gather_candidates(source.context)

            source.context['all_candidates'] = candidates
            source.context['candidates'] = candidates

            context['messages'] = source.context['messages']
Пример #5
0
 def _gather_source_candidates(self, context, source):
     max_len = int(context['max_candidate_width']) * 2
     candidates = source.gather_candidates(context)
     for candidate in [x for x in candidates if len(x['word']) > max_len]:
         candidate['word'] = candidate['word'][:max_len]
     return candidates
Пример #6
0
 def _gather_source_candidates(self, context, source):
     max_len = int(context['max_candidate_width']) * 2
     candidates = source.gather_candidates(context)
     for candidate in [x for x in candidates if len(x['word']) > max_len]:
         candidate['word'] = candidate['word'][: max_len]
     return candidates
Пример #7
0
 def gather_candidates(self, context):
     for source in self.__current_sources:
         candidates = source.gather_candidates(source.context)
         source.context['all_candidates'] = candidates
         source.context['candidates'] = candidates
Пример #8
0
 def gather_candidates(self, context):
     for source in self.__current_sources:
         source.context['is_redraw'] = context['is_redraw']
         candidates = source.gather_candidates(source.context)
         source.context['all_candidates'] = candidates
         source.context['candidates'] = candidates