Skip to content

Commit

Permalink
Add debug tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapeline committed Dec 21, 2024
1 parent 4e683e1 commit 80afb39
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 1 deletion.
7 changes: 7 additions & 0 deletions embark/localization/en.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ class UI:
ask_title = "Question"
you_sure_want_exit = "Are you sure you want to interrupt the playbook and exit immediately?"
stop_playbook = "Stop execution"

debug = "Debug tools:"
debug_vars = "Debug variables"
debug_exec = "Execute in scope"
debug_vars_section = "Playbook variables"
debug_envs_section = "Environment variables"
execute_expression = "Execute code"
Empty file.
53 changes: 53 additions & 0 deletions embark/ui/debug_frames/exec_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Eval debug UI frame"""

from customtkinter import CTk, CTkFont, CTkLabel, CTkEntry, CTkButton, CTkTextbox

from embark.domain.execution.playbook import Playbook
from embark.localization.i18n import L
from embark.resources import get_resource
from embark.ui import utils


class DebugExecFrame(CTk):
"""Main UI frame"""

def __init__(self, playbook: Playbook):
super().__init__()
self._playbook = playbook
self.title(L("UI.debug_exec"))
self.geometry("500x600")
self.resizable(False, False)
self.iconbitmap(get_resource("icon.ico"))
utils.center(self)
self._font = CTkFont("Consolas", 14, "normal")
self._setup_ui()

def _setup_ui(self):
"""Create and place UI components"""
self._cmd = CTkTextbox(self, font=self._font)
self._execute_btn = CTkButton(
self,
text=L("UI.execute_expression"),
command=self._exec
)
self._result_box = CTkTextbox(self, font=self._font)
self._cmd.pack(anchor="nw", padx=4, pady=4, fill="both", expand=True)
self._execute_btn.pack(anchor="nw", padx=4, pady=4, fill="x")
self._result_box.pack(anchor="nw", padx=4, pady=4, fill="both", expand=True)

def _log(self, *args):
self._result_box.insert("end", " ".join(map(str, args)) + "\n")

def _exec(self):
exec(
self._cmd.get("0.0", "end"),
{
"playbook": self._playbook,
"print": self._log
}
)


def show(playbook):
win = DebugExecFrame(playbook)
win.mainloop()
51 changes: 51 additions & 0 deletions embark/ui/debug_frames/vars_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Variables debug UI frame"""

from customtkinter import CTk, CTkFont, CTkLabel, CTkScrollableFrame

from embark.domain.execution.playbook import Playbook
from embark.localization.i18n import L
from embark.resources import get_resource
from embark.ui import utils


class DebugVariablesFrame(CTk):
"""Main UI frame"""

def __init__(self, playbook: Playbook):
super().__init__()
self._playbook = playbook
self.title(L("UI.debug_vars"))
self.geometry("500x600")
self.resizable(False, False)
self.iconbitmap(get_resource("icon.ico"))
utils.center(self)
self._font = CTkFont("Consolas", 14, "normal")
self._setup_ui()

def _setup_ui(self):
"""Create and place UI components"""
variables = self._playbook.variables.vars.items()
envs = self._playbook.variables.envs.items()
self._scrollable1 = CTkScrollableFrame(self)
self._scrollable = CTkScrollableFrame(self._scrollable1, orientation="horizontal")
for i in range(len(variables) + len(envs) + 2):
self._scrollable.rowconfigure(index=i, weight=1)
self._scrollable.columnconfigure(index=0, weight=1)
self._scrollable.columnconfigure(index=1, weight=1)
self._vars_title = CTkLabel(self._scrollable, text=L("UI.debug_vars_section"))
self._envs_title = CTkLabel(self._scrollable, text=L("UI.debug_envs_section"))
self._vars_title.grid(row=0, column=0, columnspan=2, sticky="nw")
row = 1
for var, val in variables:
var_label = CTkLabel(self._scrollable, text=var, font=self._font)
val_label = CTkLabel(self._scrollable, text=val, font=self._font)
var_label.grid(row=row, column=0, sticky="nw")
val_label.grid(row=row, column=1, sticky="nw", padx=4)
row += 1
self._scrollable.pack(fill="both", expand=True)
self._scrollable1.pack(fill="both", expand=True)


def show(playbook):
win = DebugVariablesFrame(playbook)
win.mainloop()
23 changes: 23 additions & 0 deletions embark/ui/logger_frame/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from embark.localization.i18n import L
from embark.resources import get_resource
from embark.ui import utils
from embark.ui.debug_frames import vars_frame, exec_frame
from embark.ui.logger_frame.components import GUILoggerFrame
from embark.ui.logger_frame.context_factory import GUIContextFactory

Expand Down Expand Up @@ -47,9 +48,23 @@ def _setup_ui(self):
text=L("UI.stop_playbook"),
command=self._stop_playbook_cmd
)
self._lp_debug_title = CTkLabel(self._left_pane, text=L("UI.debug"))
self._lp_debug_vars_btn = CTkButton(
self._left_pane,
text=L("UI.debug_vars"),
command=self._debug_vars_cmd
)
self._lp_debug_eval_btn = CTkButton(
self._left_pane,
text=L("UI.debug_exec"),
command=self._debug_eval_cmd
)
self._lp_title.pack(padx=8, pady=8, fill="x")
self._lp_subtitle.pack(fill="x")
self._lp_stop_btn.pack(padx=8, pady=8, fill="x")
self._lp_debug_title.pack(padx=8, pady=8, fill="x")
self._lp_debug_vars_btn.pack(padx=8, pady=8, fill="x")
self._lp_debug_eval_btn.pack(padx=8, pady=8, fill="x")
self._lp_copyright = CTkLabel(self._left_pane, text="© Tapeline 2024")
self._lp_copyright.pack(side=BOTTOM)

Expand All @@ -63,6 +78,14 @@ def _stop_playbook_cmd(self):
if messagebox.askyesno(L("UI.ask_title"), L("UI.you_sure_want_exit")):
self.destroy()

def _debug_vars_cmd(self):
if self._logger_frame.playbook is not None:
vars_frame.show(self._logger_frame.playbook)

def _debug_eval_cmd(self):
if self._logger_frame.playbook is not None:
exec_frame.show(self._logger_frame.playbook)

def run(self):
self.after(500, self._start_thread)
self.mainloop()
Expand Down
1 change: 0 additions & 1 deletion embark/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Main UI file
"""

from embark.commands import cmd_run
from embark.ui.playbook_choose_frame.frame import ask_for_playbook
from embark.ui.logger_frame.frame import LoggerFrame

Expand Down

0 comments on commit 80afb39

Please sign in to comment.