+ 'deleted_text',
+ lambda a, b, c: self.widget.filter_input.add_css_class('temp'))
+
+ def passes_filter(self, value: str | int | float) -> bool:
+ """Return if value passes filter defined by .name and .filter_text."""
+ number_attributes = (set(s.lower() for s in GEN_PARAMS_INT) |
+ set(s.lower() for s in GEN_PARAMS_FLOAT) |
+ {'bookmarked'})
+ if value is None:
+ return False
+ if self.name not in number_attributes:
+ assert isinstance(value, str)
+ return bool(re_search(self.filter_text, value))
+ assert isinstance(value, (int, float))
+ use_float = self.name in {s.lower() for s in GEN_PARAMS_FLOAT}
+ numbers_or, unequal = (set(),) * 2
+ less_than, less_or_equal, more_or_equal, more_than = (None,) * 4
+ for constraint_string in self.filter_text.split(','):
+ toks = constraint_string.split()
+ if len(toks) == 1:
+ tok = toks[0]
+ if tok[0] in '<>!': # operator sans space after: split, re-try
+ if '=' == tok[1]:
+ toks = [tok[:2], tok[2:]]
+ else:
+ toks = [tok[:1], tok[1:]]
+ else:
+ pattern_number = float(tok) if use_float else int(tok)
+ numbers_or.add(pattern_number)
+ if len(toks) == 2: # assume operator followed by number
+ pattern_number = float(toks[1]) if use_float else int(toks[1])
+ if toks[0] == '!=':
+ unequal.add(pattern_number)
+ elif toks[0] == '<':
+ if less_than is None or less_than >= pattern_number:
+ less_than = pattern_number
+ elif toks[0] == '<=':
+ if less_or_equal is None or less_or_equal > pattern_number:
+ less_or_equal = pattern_number
+ elif toks[0] == '>=':
+ if more_or_equal is None or more_or_equal < pattern_number:
+ more_or_equal = pattern_number
+ elif toks[0] == '>':
+ if more_than is None or more_than <= pattern_number:
+ more_than = pattern_number
+ if value in numbers_or:
+ return True
+ if len(numbers_or) > 0 and (less_than == less_or_equal ==
+ more_or_equal == more_than):
+ return False
+ if value in unequal:
+ return False
+ return ((less_than is None or value < less_than)
+ and (less_or_equal is None or value <= less_or_equal)
+ and (more_or_equal is None or value >= more_or_equal)
+ and (more_than is None or value > more_than))