More searcher plugin updates, added additional file settings

This commit is contained in:
2022-10-04 02:30:46 -05:00
parent 982e586936
commit 0dece2cec9
3 changed files with 78 additions and 46 deletions

View File

@@ -10,37 +10,35 @@ from gi.repository import Gtk
class GrepPreviewWidget(Gtk.Box):
def __init__(self, _path, sub_keys, data):
def __init__(self, _path, sub_keys, _data):
super(GrepPreviewWidget, self).__init__()
self.set_orientation(Gtk.Orientation.VERTICAL)
self.line_color = "#e0cc64"
path = base64.urlsafe_b64decode(_path.encode('utf-8')).decode('utf-8')
_label = '/'.join( path.split("/")[-3:] )
title = Gtk.LinkButton.new_with_label(uri=f"file://{path}", label=_label)
path = self.decode_str(_path)
_label = '/'.join( path.split("/")[-3:] )
title = Gtk.LinkButton.new_with_label(uri=f"file://{path}", label=_label)
text_view = Gtk.TextView()
text_view.set_editable(False)
text_view.set_wrap_mode(Gtk.WrapMode.NONE)
buffer = text_view.get_buffer()
for i, key in enumerate(sub_keys):
line_num = self.make_utf8_line_num(self.line_color, key)
text = f"\t\t{ self.decode_str(_data[key]) }"
itr = buffer.get_end_iter()
buffer.insert_markup(itr, line_num, len(line_num))
itr = buffer.get_end_iter()
buffer.insert(itr, text, length=len(text))
self.add(title)
for key in sub_keys:
line_num = key
text = base64.urlsafe_b64decode(data[key].encode('utf-8')).decode('utf-8')
box = Gtk.Box()
number_label = Gtk.Label()
text_view = Gtk.Label(label=text[:-1])
label_text = f"<span foreground='{self.line_color}'>{line_num}</span>"
number_label.set_markup(label_text)
number_label.set_margin_left(15)
number_label.set_margin_right(5)
number_label.set_margin_top(5)
number_label.set_margin_bottom(5)
text_view.set_margin_top(5)
text_view.set_margin_bottom(5)
text_view.set_line_wrap(True)
box.add(number_label)
box.add(text_view)
self.add(box)
self.add(text_view)
self.show_all()
def decode_str(self, target):
return base64.urlsafe_b64decode(target.encode('utf-8')).decode('utf-8')
def make_utf8_line_num(self, color, target):
return bytes(f"\n<span foreground='{color}'>{target}</span>", "utf-8").decode("utf-8")