Debian Codegraph @

sandbox/common.py

raw symbols SCIP
1 from __future__ import annotations
2
3 import pytermgui as ptg
4
5
6 class DebuggerWindow(ptg.Window):
7 is_noblur = True
8 overflow = ptg.Overflow.RESIZE
9
10 def get_lines(self) -> list[str]:
11 self._widgets = []
12 for widget in self._get_widgets():
13 self.lazy_add(widget)
14
15 return super().get_lines()
16
17 def _update_content(self) -> None:
18 raise NotImplementedError
19
20
21 class FocusedWindowDebugger(DebuggerWindow):
22 def _get_widgets(self) -> None:
23 if self.manager is None or self.manager.focused is None:
24 return []
25
26 window = self.manager.focused
27
28 return [
29 ptg.Label("Focused window debugger", style="bold foreground1 background1"),
30 "",
31 {"Elements #": ptg.Label(str(len(window)), style="foreground2")},
32 {
33 "Dimensions": ptg.Label(
34 f"{window.width}x{window.height}", style="foreground2"
35 )
36 },
37 {
38 "Position": ptg.Label(
39 f"({window.pos[0]};{window.pos[1]})", style="foreground2"
40 )
41 },
42 {"Rect": f"{window.rect}"},
43 ]
44
45
46 class MouseDebugger(DebuggerWindow):
47 _event: ptg.MouseEvent | None = None
48
49 def __init__(self, manager: ptg.WindowManager, **attrs: Any) -> None:
50 super().__init__(**attrs)
51
52 manager.bind(ptg.MouseEvent, self.on_mouse_move)
53
54 def on_mouse_move(self, _, event: ptg.MouseEvent) -> None:
55 self._event = event
56
57 def _get_widgets(self) -> None:
58 if self._event is None:
59 return []
60
61 return [
62 ptg.Label("Mouse debugger", style="bold foreground1 background1"),
63 "",
64 {"Action": str(self._event.action.name)},
65 {"Position": str(self._event.position)},
66 ]
67
68
69 def set_default_styles():
70 ptg.tim.alias("foreground1", "#AEAEAE")
71 ptg.tim.alias("foreground2", "#8E8E8E")
72 ptg.tim.alias("background1", "@#161314")
73 ptg.tim.alias("background2", "@#56494E")
74
75 ptg.Label.styles = ptg.Label.styles.branch(ptg.Label)
76 ptg.Label.styles.value = "foreground1 background1"
77
78 ptg.Window.styles.fill = "foreground1 background1"
79 ptg.Container.styles.fill = "foreground1 background1"
80 ptg.Window.styles.border__corner = f"background1 #2C2628"
81
82 ptg.Splitter.styles.fill__separator = "foreground1 background1"
83 ptg.Splitter.set_char("separator", " │ ")
84
85 box = ptg.boxes.Box([" ", " x ", " "])
86 box.set_chars_of(ptg.Window)
87 ptg.boxes.HEAVY.set_chars_of(ptg.Container)