From c6856aa6fe2ad478dd5bc6285fb2544c150b2033 Mon Sep 17 00:00:00 2001 From: Matthias Baumgartner Date: Thu, 2 Feb 2023 10:04:03 +0100 Subject: filter port --- tagit/widgets/filter.py | 39 ++++++++++++++++++++++----------------- tagit/widgets/session.py | 1 + 2 files changed, 23 insertions(+), 17 deletions(-) (limited to 'tagit/widgets') diff --git a/tagit/widgets/filter.py b/tagit/widgets/filter.py index 8a7c1a2..15aefd6 100644 --- a/tagit/widgets/filter.py +++ b/tagit/widgets/filter.py @@ -22,8 +22,8 @@ import kivy.properties as kp # tagit imports from tagit import config -#from tagit.parsing.search import ast, ast_to_string # FIXME: mb/port -from tagit.utils import bsfs, errors +from tagit.utils import bsfs, errors, ns +from tagit.utils.bsfs import ast, matcher # inner-module imports from .session import ConfigAwareMixin @@ -120,20 +120,25 @@ class Filter(BoxLayout, ConfigAwareMixin): return query, sort def abbreviate(self, token): - return 'T' - # FIXME: mb/port/parsing - if token.predicate() == 'tag': - return ','.join(list(token.condition())) - elif token.predicate() == 'entity': - return 'R' if isinstance(token.condition(), ast.SetInclude) else 'E' - else: - return { - 'group' : 'G', - 'time' : 'T', - 'altitude' : 'Alt', - 'longitude' : 'Lon', - 'latitude' : 'Lat', - }.get(token.predicate(), token.predicate().title()) + matches = matcher.Filter() + if matches(token, ast.filter.Any(ns.bse.tag, ast.filter.Any(ns.bst.label, matcher.Any()))): + # tag token + return self.root.session.filter_to_string(token) + if matches(token, matcher.Partial(ast.filter.Is)) or \ + matches(token, ast.filter.Or(matcher.Rest(matcher.Partial(ast.filter.Is)))): + # exclusive token + return 'E' + if matches(token, ast.filter.Not(matcher.Partial(ast.filter.Is))) or \ + matches(token, ast.filter.Not(ast.filter.Or(matcher.Rest(matcher.Partial(ast.filter.Is))))): + # reduce token + return 'R' + if matches(token, ast.filter.Any(ns.bse.group, matcher.Any())): + # group token + return 'G' + if matches(token, ast.filter.Any(matcher.Partial(ast.filter.Predicate), matcher.Any())): + # generic token + return token.predicate.predicate.get('fragment', '?').title() + return '?' def show_address_once(self): """Single-shot address mode without changing the search mode.""" @@ -272,7 +277,7 @@ class Addressbar(TextInput): def __init__(self, tokens, **kwargs): super(Addressbar, self).__init__(**kwargs) - self.text = ast_to_string(ast.AND(tokens)) + self.text = self.root.session.filter_to_string(bsfs.ast.filter.And(tokens)) self._last_text = self.text def on_text_validate(self): diff --git a/tagit/widgets/session.py b/tagit/widgets/session.py index e97a688..c233a15 100644 --- a/tagit/widgets/session.py +++ b/tagit/widgets/session.py @@ -40,6 +40,7 @@ class Session(Widget): self.log = log # derived members self.filter_from_string = parsing.filter.FromString(self.storage.schema) + self.filter_to_string = parsing.filter.ToString(self.storage.schema) #self.sort_from_string = parsing.Sort(self.storage.schema) # FIXME: mb/port/parsing def __enter__(self): -- cgit v1.2.3