generated from itdominator/Python-With-Gtk-Template
Improved log view usability
This commit is contained in:
parent
6b99c5c0d7
commit
b7bac2d5ae
|
@ -30,9 +30,15 @@ class LogList(Gtk.ListBox):
|
||||||
self.set_selection_mode(Gtk.SelectionMode.NONE)
|
self.set_selection_mode(Gtk.SelectionMode.NONE)
|
||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
# self.connect("row-activated", sink_call)
|
def tggl_row_view(lb, row):
|
||||||
# self.connect("row-selected", sink_call)
|
frame = row.get_child()
|
||||||
...
|
revealer = frame.get_children()[0]
|
||||||
|
revealer.set_reveal_child(not revealer.get_reveal_child())
|
||||||
|
|
||||||
|
del frame
|
||||||
|
del revealer
|
||||||
|
|
||||||
|
self.connect("row-activated", tggl_row_view)
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
...
|
...
|
||||||
|
@ -40,26 +46,35 @@ class LogList(Gtk.ListBox):
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
def add_log_entry(self, data: str or dict):
|
def add_log_entry(self, m_type: str, data: str or dict):
|
||||||
message = None
|
message = None
|
||||||
|
json_data = None
|
||||||
|
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
parts = data.split("\n", 2)
|
parts = data.split("\n", 2)
|
||||||
jsonStr = parts[2]
|
jsonStr = parts[2]
|
||||||
messageStr = json.dumps(json.loads(jsonStr), separators = (',', ':'), indent = 4)
|
json_data = json.loads(jsonStr)
|
||||||
|
messageStr = json.dumps(json_data, separators = (',', ':'), indent = 4)
|
||||||
message = f"{parts[0]}\r\n\r\n{messageStr}"
|
message = f"{parts[0]}\r\n\r\n{messageStr}"
|
||||||
|
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
|
json_data = data
|
||||||
message = json.dumps(data, separators = (',', ':'), indent = 4)
|
message = json.dumps(data, separators = (',', ':'), indent = 4)
|
||||||
|
|
||||||
box = Gtk.Frame()
|
frame = Gtk.Frame()
|
||||||
|
revealer = Gtk.Revealer()
|
||||||
label = Gtk.Label(label=message)
|
label = Gtk.Label(label=message)
|
||||||
|
|
||||||
label.set_xalign(0.010)
|
label.set_xalign(0.010)
|
||||||
|
frame.set_label( f"> {m_type}: {json_data['id']}" if "id" in json_data.keys() else f"> {m_type}" )
|
||||||
|
frame.set_label_align(0.010, 0.5)
|
||||||
|
revealer.set_reveal_child(False)
|
||||||
|
|
||||||
box.set_label(">")
|
revealer.add(label)
|
||||||
box.set_label_align(0.010, 0.5)
|
frame.add(revealer)
|
||||||
|
self.add(frame)
|
||||||
|
|
||||||
box.add(label)
|
frame.show_all()
|
||||||
self.add(box)
|
|
||||||
|
|
||||||
box.show_all()
|
del message
|
||||||
|
del json_data
|
||||||
|
|
|
@ -154,8 +154,7 @@ class LSPMessageBox(Gtk.Box):
|
||||||
message_size = len(message_str)
|
message_size = len(message_str)
|
||||||
message = f"Content-Length: {message_size}\r\n\r\n{message_str}"
|
message = f"Content-Length: {message_size}\r\n\r\n{message_str}"
|
||||||
|
|
||||||
self.get_parent().log_list.add_log_entry(message)
|
self.get_parent().log_list.add_log_entry("Client Message", message)
|
||||||
event_system.subscribe("add-log-entry", message)
|
|
||||||
|
|
||||||
with self.write_lock:
|
with self.write_lock:
|
||||||
self.lsp_process.stdin.write( message.encode("utf-8") )
|
self.lsp_process.stdin.write( message.encode("utf-8") )
|
||||||
|
@ -261,7 +260,7 @@ class LSPMessageBox(Gtk.Box):
|
||||||
GLib.idle_add(self.handle_lsp_response, response_id, lsp_result)
|
GLib.idle_add(self.handle_lsp_response, response_id, lsp_result)
|
||||||
|
|
||||||
def handle_lsp_response(self, id: int, lsp_result: {}):
|
def handle_lsp_response(self, id: int, lsp_result: {}):
|
||||||
self.get_parent().log_list.add_log_entry(lsp_result)
|
self.get_parent().log_list.add_log_entry("LSP Response Message", lsp_result)
|
||||||
|
|
||||||
keys = lsp_result.keys()
|
keys = lsp_result.keys()
|
||||||
if "error" in keys:
|
if "error" in keys:
|
||||||
|
|
Loading…
Reference in New Issue