aboutsummaryrefslogtreecommitdiffstats
path: root/tagit/widgets
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-02-02 10:04:03 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-02-02 10:04:03 +0100
commitc6856aa6fe2ad478dd5bc6285fb2544c150b2033 (patch)
treeb084d75afbca13c34f2b71b609fd2c63a160522d /tagit/widgets
parent57327d3df562736cad9e278e13beeb55bf3b52ed (diff)
downloadtagit-c6856aa6fe2ad478dd5bc6285fb2544c150b2033.tar.gz
tagit-c6856aa6fe2ad478dd5bc6285fb2544c150b2033.tar.bz2
tagit-c6856aa6fe2ad478dd5bc6285fb2544c150b2033.zip
filter port
Diffstat (limited to 'tagit/widgets')
-rw-r--r--tagit/widgets/filter.py39
-rw-r--r--tagit/widgets/session.py1
2 files changed, 23 insertions, 17 deletions
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):