generated from itdominator/Python-With-Gtk-Template
Added traceback on log output entry; changed js method call
This commit is contained in:
parent
cb7b441365
commit
01f4d17ccc
|
@ -96,6 +96,8 @@ class BridgeController:
|
|||
file_type = event.ftype
|
||||
encoding_type = "utf-8"
|
||||
event_system.emit(f"set_info_labels", (path, line_char, file_type, encoding_type,))
|
||||
case "load_javascript":
|
||||
event_system.emit(f"handle_file_event_{event.originator}", (event,))
|
||||
case "error":
|
||||
content = base64.b64decode( event.content.encode() ).decode("utf-8")
|
||||
logger.info(content)
|
||||
|
|
|
@ -94,6 +94,19 @@ class FilesController:
|
|||
_gfiles,
|
||||
)
|
||||
)
|
||||
case "load_javascript":
|
||||
gfile = Gio.File.new_for_uri(event.fpath)
|
||||
|
||||
result, \
|
||||
data, \
|
||||
etag_out = gfile.load_contents(None)
|
||||
|
||||
if result:
|
||||
content = base64.b64encode( data ).decode("utf-8")
|
||||
event_system.emit(
|
||||
f"send_script_data_{self.INDEX}",
|
||||
(gfile.get_basename(), content,)
|
||||
)
|
||||
case _:
|
||||
return
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Python imports
|
||||
import json
|
||||
import traceback
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
@ -45,6 +46,7 @@ class AceEditor(WebKit2.WebView):
|
|||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe(f"load_file_{self.INDEX}", self.load_file)
|
||||
event_system.subscribe(f"send_script_data_{self.INDEX}", self.send_script_data)
|
||||
event_system.subscribe(f"new_session_{self.INDEX}", self.new_session)
|
||||
event_system.subscribe(f"switch_session_{self.INDEX}", self.switch_session)
|
||||
event_system.subscribe(f"updated_session_{self.INDEX}", self.updated_session)
|
||||
|
@ -87,12 +89,16 @@ class AceEditor(WebKit2.WebView):
|
|||
event.originator = self.INDEX
|
||||
event_system.emit("handle_bridge_event", (event,))
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
logger.info(traceback.format_exc())
|
||||
|
||||
def load_file(self, ftype: str, fname: str, fpath: str, content: str, line: int = 0):
|
||||
command = f"loadFile('{ftype}', '{fname}', '{fpath}', '{content}', '{line}')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
||||
def send_script_data(self, fname, content):
|
||||
command = f"importScriptFromBackendResponse('{fname}','{content}')"
|
||||
self.run_javascript(command, None, None)
|
||||
|
||||
def new_session(self):
|
||||
command = f"newSession()"
|
||||
self.run_javascript(command, None, None)
|
||||
|
@ -153,4 +159,4 @@ class AceEditor(WebKit2.WebView):
|
|||
|
||||
def run_javascript(self, script, cancellable, callback):
|
||||
logger.debug(script)
|
||||
super().run_javascript(script, cancellable, callback)
|
||||
super().run_javascript(script, cancellable, callback)
|
|
@ -43,4 +43,4 @@ class Editor(Gtk.Box):
|
|||
FilesController(self.INDEX)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add( FixedBox(self.INDEX) )
|
||||
self.add( FixedBox(self.INDEX) )
|
||||
|
|
Loading…
Reference in New Issue