Skip to content

Debugger Windows

rafageist edited this page Dec 3, 2026 · 4 revisions

Debugger Windows

turboframe.ui.debugwindows has the windows of Turbo Pascal's debugger: cyan, black text, the chosen line white on red. They show what a debugger tells you (the call stack, the watches, the variables, the breakpoints). What the debugger is (DAP, DBGp, a tracer of your own) and what its windows hold stay in your application.

Use it for the call stack, watches, variables, breakpoints: lines you choose from
Import from turboframe.ui.debugwindows import CallStackWindow, ListWindow, PickList, debug_css
Needs nothing beyond TurboFrame
Extend subclass ListWindow (activate, EMPTY, HINT); select_frame(index) on your application

ListWindow: lines to choose from

ListWindow(title, number=0) is a TVWindow (see Windows and Lists) holding a PickList: a list you filter by typing, where Enter or a double click calls the window's activate(index). The index is the line's index in what you showed, whatever the filter hides.

from turboframe.ui.debugwindows import ListWindow

from myapp.i18n import N_, _   # your application's domain: see Translating Your Application


class BreakpointsWindow(ListWindow):
    EMPTY = N_("(no breakpoints)")                           # marked for your catalogue

    def __init__(self, number: int = 0) -> None:
        super().__init__(_("Breakpoints"), number=number)   # _: your application's gettext
        self.HINT = _("Enter go to the breakpoint")

    def empty_text(self) -> str:
        return _(self.EMPTY)                                 # in your domain

    def activate(self, index: int) -> None:
        path, row = self.app.breakpoints[index]
        self.app.go_to_breakpoint(path, row)
Member
show(lines, keep=None) show lines (a list of str). When only their text changes (the same count), the chosen line stays chosen; keep chooses another. Showing the same lines again does nothing.
activate(index) a line was chosen (Enter, a double click). Nothing by default: override it.
EMPTY what an empty window says: "(not running)" by default
empty_text() EMPTY translated, as an empty window shows it: TurboFrame's _() by default; override it to translate your own EMPTY in your domain (since v0.2.1)
HINT what your status line says while the window is active (empty by default; see below)
lines, list the lines shown, and the PickList

show([]) shows empty_text(), also the first time, so a new window never looks broken. By default that is EMPTY through TurboFrame's _(), where a text of your own is not found and is shown untranslated; override empty_text(), as above, to translate it in your domain. (In v0.2.0, without the hook, set self.EMPTY already translated in __init__.)

CallStackWindow: where the program is

CallStackWindow(number=0) is a ListWindow titled "Call stack", the innermost call first. Enter on a frame runs your application's select_frame(index), a coroutine, as a worker in the group CallStackWindow.GROUP ("debug-view"). Show that frame's place and its variables there:

from turboframe.ui.app import DesktopApp
from turboframe.ui.debugwindows import CallStackWindow, ListWindow


class MyApp(DesktopApp):
    stack: CallStackWindow | None = None
    variables: ListWindow                                  # a ListWindow titled "Variables"

    def show_stack(self, frames) -> None:                 # the debugger stopped
        self.frames = frames
        if self.stack is None:
            self.stack = CallStackWindow(number=self.free_number())
            self.insert_window(self.stack)
        self.stack.show([f"{f.function}  {f.path.name}:{f.line}" for f in frames])

    async def select_frame(self, index: int) -> None:     # Enter in the call stack
        frame = self.frames[index]
        names = await self.debugger.variables(frame)      # your debugger
        self.variables.show([f"{name} = {value}" for name, value in names])
        self.goto_location(frame.path, frame.offset)

Without a select_frame on the application, Enter does nothing.

The status line hint

The windows do not write the status line themselves. Show a window's HINT when it comes up, for example in raise_window, which Alt+1..9 and F6 go through (see The Desktop):

from turboframe import i18n

class MyApp(DesktopApp):
    def raise_window(self, window) -> None:
        super().raise_window(window)
        self.hint(i18n._(getattr(window, "HINT", "")))    # CallStackWindow's is a TurboFrame text

Colours, and a window of your own

The windows take their colours from the theme's debug-* roles: debug-bg, debug-text, debug-frame, debug-frame-passive, debug-title, debug-selected and debug-selected-bg (see Themes and Colors). A subclass of ListWindow gets them. A debugger window of another kind (a tree of variables, say) takes them with debug_css(name), the CSS for a window whose class is name:

from turboframe.ui.debugwindows import debug_css
from turboframe.ui.windows import TVWindow


class VariablesWindow(TVWindow):
    DEFAULT_CSS = debug_css("VariablesWindow")

PickList is the list alone, on the same colours: put it in a window of your own and give the window an activate(index), or subclass ListWindow, whose PickList looks for the nearest ListWindow above it.

The editor's side

The editor shows where the program is and where it stops (see The Editor):

  • CodeEditor.set_debug_marks(breakpoints, execution): the breakpoints' rows in red, the row about to run in cyan (0-based rows), with glyphs on the monochrome themes.
  • In a language of CodeEditor.BREAKPOINT_LANGUAGES, a click on a line number calls your application's toggle_breakpoint_at(editor, row).

Start the debugger itself with turboframe.process.start so it ends with your application (see Processes).

API: turboframe.ui.debugwindows.

Clone this wiki locally