'Dynamically compute excluded genres.
Run exclude_genre regex against selected genre_source_field to show excluded tags.
Inputs:
current regex
genre_source_field
Output:
self.exclude_genre_results (QLabel): updated to show tags to be excluded as genres'

def exclude_genre_changed(self):

    def _truncated_results(excluded_tags, limit=180):
        '\n                                                Limit    number    of    genres    displayed    to    avoid    dialog    explosion\n                                                '
        start = []
        end = []
        lower = 0
        upper = (len(excluded_tags) - 1)
        excluded_tags.sort()
        while True:
            if (lower > upper):
                break
            elif (lower == upper):
                start.append(excluded_tags[lower])
                break
            start.append(excluded_tags[lower])
            end.insert(0, excluded_tags[upper])
            if ((len(',    '.join(start)) + len(',    '.join(end))) > limit):
                break
            lower += 1
            upper -= 1
        if (excluded_tags == (start + end)):
            return ',    '.join(excluded_tags)
        else:
            return ('%s        ...        %s' % (',    '.join(start), ',    '.join(end)))
    results = _('No    genres    will    be    excluded')
    regex = unicode(getattr(self, 'exclude_genre').text()).strip()
    if (not regex):
        self.exclude_genre_results.clear()
        self.exclude_genre_results.setText(results)
        return
    if (self.genre_source_field_name == _('Tags')):
        all_genre_tags = self.db.all_tags()
    else:
        all_genre_tags = list(self.db.all_custom(self.db.field_metadata.key_to_label(self.genre_source_field_name)))
    try:
        pattern = re.compile(regex)
    except:
        results = (_('regex    error:    %s') % sys.exc_info()[1])
    else:
        excluded_tags = []
        for tag in all_genre_tags:
            hit = pattern.search(tag)
            if hit:
                excluded_tags.append(hit.string)
        if excluded_tags:
            if (set(excluded_tags) == set(all_genre_tags)):
                results = _('All    genres    will    be    excluded')
            else:
                results = _truncated_results(excluded_tags)
    finally:
        if (False and self.DEBUG):
            print ('exclude_genre_changed():    %s' % results)
        self.exclude_genre_results.clear()
        self.exclude_genre_results.setText(results)
