added wildcard (*?) support
This commit is contained in:
@ -1,3 +1,6 @@
|
||||
import fnmatch
|
||||
import re
|
||||
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
||||
|
||||
from .dictlistwidget import DictListWidget
|
||||
@ -31,11 +34,26 @@ class DictList(QWidget):
|
||||
|
||||
|
||||
def hide_not_matching(self, pattern):
|
||||
pattern = pattern.casefold()
|
||||
g = Globber(pattern)
|
||||
for name, itm in self.lst.items.items():
|
||||
name = name.casefold()
|
||||
state = (pattern not in name)
|
||||
itm.setHidden(state)
|
||||
state = g.match(name)
|
||||
itm.setHidden(not state)
|
||||
|
||||
|
||||
|
||||
class Globber:
|
||||
|
||||
def __init__(self, pattern):
|
||||
pattern = pattern.casefold()
|
||||
pattern = "*" + pattern + "*"
|
||||
regex = fnmatch.translate(pattern)
|
||||
self.pattern = re.compile(regex)
|
||||
|
||||
def match(self, string):
|
||||
string = string.casefold()
|
||||
matches = self.pattern.match(string)
|
||||
state = bool(matches)
|
||||
return state
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user