Skip to content

Commit

Permalink
Filtering result format changed. Highlight merging added.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiborsimon committed Jun 11, 2016
1 parent d0b29ff commit dbd7444
Show file tree
Hide file tree
Showing 5 changed files with 596 additions and 94 deletions.
49 changes: 49 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import urwid
from projects.filter import Filter

ll = [
'projects',
'matlab-library-system',
'intervallum',
'skillmath',
'optimal-position',
'site',
'something',
'regular-army-knife'
]

f = Filter(ll)


def generate_string(data):
ret = []
for item in data:

for
ret.append(item['string']+'\n')
return ret


def exit_on_q(key):
key = key.lower()
if key in ('delete', 'backspace'):
f.remove_key()
else:
f.add_key(key)
fl = f.filter()
s = generate_string(fl)
txt.set_text(s)
if key in ('esc',):
raise urwid.ExitMainLoop()

palette = [
('text', 'light gray', 'black'),
('highlight', 'black', 'yellow'),
('bg', 'black', 'dark blue')]

txt = urwid.Text([('text', u"Hello World\n"), ('highlight', "Hello")], align='left')
map1 = urwid.AttrMap(txt, 'streak')
fill = urwid.Filler(map1)
pad = urwid.Padding(fill, align='center', width=30)
loop = urwid.MainLoop(pad, palette, unhandled_input=exit_on_q)
loop.run()
71 changes: 70 additions & 1 deletion projects/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ def sort_structure(data):
return data


def merge_neighbour_selections(data):
for node in data:
merged = []
last = ()
if len(node['selection']) < 2:
return
for s in node['selection']:
if last:
if last[1] == s[0]:
new_s = (last[0], s[1])
if merged:
merged.pop()
merged.append(new_s)
last = new_s
else:
if not merged:
merged.append(last)
elif merged[-1] != last:
merged.append(last)
merged.append(s)
last = s
else:
last = s
node['selection'] = tuple(merged)


def generate_data_structure_for_search_string(pattern, search_string):
p = re.compile(pattern)
ret = []
Expand All @@ -42,14 +68,57 @@ def generate_data_structure_for_search_string(pattern, search_string):
'string': line,
'selection': selection
})
merge_neighbour_selections(ret)
return ret


def transform_data(data):
ret = []
for item in data:
node = []
if item['selection']:
index = 0
line = item['string']
for s in item['selection']:
if s[0] == 0:
node.append({
'string': line[:s[1]],
'highlight': True
})
else:
node.append({
'string': line[index-index:s[0]-index],
'highlight': False
})
node.append({
'string': line[s[0]-index:s[1]-index],
'highlight': True
})
line = line[s[1]-index:]
index = s[1]

else:
if line:
node.append({
'string': line,
'highlight': False
})
else:
node.append({
'string': item['string'],
'highlight': False
})
ret.append(node)
return ret



def filter_data(keys, data):
pattern = _get_pattern(keys)
data = generate_data_structure_for_search_string(pattern, data)
sorted_data = sort_structure(data)
return sorted_data
final_data = transform_data(sorted_data)
return final_data


class Filter(object):
Expand Down
15 changes: 0 additions & 15 deletions projects/gui.py

This file was deleted.

9 changes: 7 additions & 2 deletions projects/p.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
def main(args):
try:
conf = config.get()
print(conf)
except:
pass
if paths.inside_project(conf['projects-path']):
# print('Inside')
print('Inside')
pass
else:
# print('Outside')
print('Outside')
pass

if __name__ == '__main__':
main('hello')

Loading

0 comments on commit dbd7444

Please sign in to comment.