TTkCanvasπΆοΈ
- class TTkCanvas(width: int = 0, height: int = 0)[source]πΆοΈ
Bases:
objectTTkCanvas:
A low-level drawing surface that stores characters and colors before they are composed into widgets or flushed to the terminal.
- Parameters:
width (int) β the width of the Canvas
height (int) β the height of the Canvas
MethodsπΆοΈ
- copy() TTkCanvas[source]πΆοΈ
Creates a detached copy of the canvas content.
- Returns:
a new canvas with duplicated size and buffers
- Return type:
- copyBuffers() Tuple[List[List[str]], List[List[TTkColor]]][source]πΆοΈ
Duplicates the current character and color buffers.
- Returns:
copies of the data and color buffers
- Return type:
tuple[list[list[str]], list[list[
TTkColor]]]
- drawBox(pos: ~typing.Tuple[int, int], size: ~typing.Tuple[int, int], color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>, grid: int = 0) None[source]πΆοΈ
Draws a rectangular box using the configured grid theme.
- Parameters:
pos (tuple[int, int]) β the top-left position of the box
size (tuple[int, int]) β the width and height of the box
color (
TTkColor) β the color applied to the box bordergrid (int) β the themed grid variant to use
- drawBoxTitle(pos: ~typing.Tuple[int, int], size: ~typing.Tuple[int, int], text: ~TermTk.TTkCore.string.TTkString, align: ~TermTk.TTkCore.constant.TTkConstant.Alignment = Alignment.CENTER_ALIGN, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>, colorText: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws a titled label embedded into the top border of a box.
- Parameters:
pos (tuple[int, int]) β the top-left position of the surrounding box
size (tuple[int, int]) β the size of the surrounding box
text (
TTkString) β the title text to renderalign (
TTkK.Alignment) β the title alignment along the top bordercolor (
TTkColor) β the border color around the titlecolorText (
TTkColor) β the color of the title text
- drawButtonBox(pos: ~typing.Tuple[int, int], size: ~typing.Tuple[int, int], color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>, grid: int = 0) None[source]πΆοΈ
Draws a button-style border using the button box theme.
- Parameters:
pos (tuple[int, int]) β the top-left position of the box
size (tuple[int, int]) β the width and height of the box
color (
TTkColor) β the color applied to the bordergrid (int) β the themed button box variant to use
- drawChar(pos: ~typing.Tuple[int, int], char: str, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws a single character at the given position.
- Parameters:
pos (tuple[int, int]) β the target position
char (str) β the character to draw
color (
TTkColor) β the color applied to the character
- drawGrid(pos: ~typing.Tuple[int, int], size: ~typing.Tuple[int, int], hlines: ~typing.List[int] = [], vlines: ~typing.List[int] = [], color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>, grid: int = 0) None[source]πΆοΈ
Draws a bordered grid with optional internal horizontal and vertical lines.
- Parameters:
pos (tuple[int, int]) β the top-left position of the grid
size (tuple[int, int]) β the width and height of the grid
hlines (list[int]) β row offsets for inner horizontal separators
vlines (list[int]) β column offsets for inner vertical separators
color (
TTkColor) β the color applied to the grid glyphsgrid (int) β the themed grid variant to use
- drawHChart(pos: ~typing.Tuple[int, int], values: ~typing.Tuple[~typing.List[int], ~typing.List[int]], zoom: float = 1.0, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws a compact two-series vertical chart using braille cells.
- Parameters:
pos (tuple[int, int]) β the baseline position of the chart
values (tuple[list[int], list[int]]) β the two value series to combine into each braille cell
zoom (float) β a scale factor applied before rasterizing the chart
color (
TTkColor) β the color applied to the chart glyphs
- drawHLine(pos: ~typing.Tuple[int, int], size: int, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws a themed horizontal line segment.
- Parameters:
pos (tuple[int, int]) β the left position of the line
size (int) β the width of the line
color (
TTkColor) β the color used for the line glyphs
- drawMenuBarBg(pos: ~typing.Tuple[int, int], size: int, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws the themed background strip for a menu bar.
- Parameters:
pos (tuple[int, int]) β the starting position of the menu bar background
size (int) β the total width of the menu bar background
color (
TTkColor) β the color applied to the background glyphs
- drawScroll(pos: ~typing.Tuple[int, int], size: int, slider: ~typing.Tuple[int, int], orientation: ~TermTk.TTkCore.constant.TTkConstant.Direction, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws a horizontal or vertical scrollbar.
- Parameters:
pos (tuple[int, int]) β the top-left position of the scrollbar
size (int) β the total length of the scrollbar including arrow cells
slider (tuple[int, int]) β the slider start and end positions relative to
posorientation (
TTkK.Direction) β the scrollbar orientationcolor (
TTkColor) β the color applied to the scrollbar glyphs
- drawTTkString(pos: ~typing.Tuple[int, int], text: ~TermTk.TTkCore.string.TTkString, width: int | None = None, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>, alignment: ~TermTk.TTkCore.constant.TTkConstant.Alignment = Alignment.NONE, forceColor: bool = False) None[source]πΆοΈ
Draws a
TTkStringwith alignment and optional color override.This method keeps a dedicated fast path because text drawing is used in most widgets and needs to minimize conversion overhead.
- Parameters:
pos (tuple[int, int]) β the top-left position where the string is drawn
text (
TTkString) β the formatted text object to renderwidth (int | None) β the output width, defaults to the string terminal width
color (
TTkColor) β an additional color merged with the string colorsalignment (
TTkK.Alignment) β the alignment used insidewidthforceColor (bool) β
Trueto ignore embedded string colors and use onlycolor
- drawTableLine(pos: Tuple[int, int], items: List[str], sizes: List[int], colors: List[TTkColor], alignments: List[Alignment]) None[source]πΆοΈ
Draws a single row of table cells with per-column formatting.
- Parameters:
pos (tuple[int, int]) β the starting position of the first cell
items (list[str]) β the strings to render in each column
sizes (list[int]) β the width of each column
colors (list[
TTkColor]) β the color used for each columnalignments (list[
TTkK.Alignment]) β the alignment used for each column
- drawText(text: str = '', pos: ~typing.Tuple[int, int] = (0, 0), width: int | None = None, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>, alignment: ~TermTk.TTkCore.constant.TTkConstant.Alignment = Alignment.NONE, forceColor: bool = False) None[source]πΆοΈ
Draws plain text with optional alignment and color.
This method keeps a dedicated fast path because text drawing is used in most widgets and needs to minimize conversion overhead.
- Parameters:
text (str) β the string to render
pos (tuple[int, int]) β the top-left position where the text is drawn
width (int | None) β the output width, defaults to the text length
color (
TTkColor) β the color applied to the textalignment (
TTkK.Alignment) β the alignment used insidewidthforceColor (bool) β kept for API parity with
drawTTkString()
- drawVLine(pos: ~typing.Tuple[int, int], size: int, color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Draws a themed vertical line segment.
- Parameters:
pos (tuple[int, int]) β the top position of the line
size (int) β the height of the line
color (
TTkColor) β the color used for the line glyphs
- enableDoubleBuffer() None[source]πΆοΈ
Initializes the secondary buffer used for buffered terminal updates.
- fill(pos: ~typing.Tuple[int, int] = (0, 0), size: ~typing.Tuple[int, int] | None = None, char: str = ' ', color: ~TermTk.TTkCore.color.TTkColor = <TermTk.TTkCore.color.TTkColor object>) None[source]πΆοΈ
Fills a rectangular region with a character and color.
- Parameters:
pos (tuple[int, int]) β the top-left position of the fill area
size (tuple[int, int] | None) β the width and height of the fill area, defaults to the full canvas
char (str) β the character written into each cell
color (
TTkColor) β the color applied to the filled cells
- paintCanvas(canvas: TTkCanvas, geom: Tuple[int, int, int, int], _slice: Tuple[int, int, int, int], bound: Tuple[int, int, int, int]) None[source]πΆοΈ
Paints another canvas onto this one inside the given geometry and bounds.
- Parameters:
canvas (
TTkCanvas) β the source canvas to compose onto this canvasgeom (tuple[int, int, int, int]) β destination geometry as
(x, y, width, height)_slice (tuple[int, int, int, int]) β reserved slice information for compatibility with callers
bound (tuple[int, int, int, int]) β clipping bounds as
(x, y, width, height)
- pushToTerminal(x: int, y: int, w: int, h: int) None[source]πΆοΈ
Pushes the full canvas to the terminal without diffing.
- Parameters:
x (int) β unused compatibility parameter for the destination x coordinate
y (int) β unused compatibility parameter for the destination y coordinate
w (int) β unused compatibility parameter for the destination width
h (int) β unused compatibility parameter for the destination height
- pushToTerminalBuffered(x: int, y: int, w: int, h: int) None[source]πΆοΈ
Pushes only changed cells to the terminal using the secondary buffer.
- Parameters:
x (int) β unused compatibility parameter for the destination x coordinate
y (int) β unused compatibility parameter for the destination y coordinate
w (int) β unused compatibility parameter for the destination width
h (int) β unused compatibility parameter for the destination height
- pushToTerminalBufferedNew(x: int, y: int, w: int, h: int) None[source]πΆοΈ
Pushes buffered terminal updates with run-length compression.
- Parameters:
x (int) β unused compatibility parameter for the destination x coordinate
y (int) β unused compatibility parameter for the destination y coordinate
w (int) β unused compatibility parameter for the destination width
h (int) β unused compatibility parameter for the destination height
- resize(w: int, h: int) None[source]πΆοΈ
resize the canvas keeping or cutting the current one
- Parameters:
w β the width of the new canvas
h β the height of the new canvas
- setTransparent(tr: bool = True) None[source]πΆοΈ
Enables or disables transparent composition for this canvas.
- Parameters:
tr (bool) β
Trueto preserve destination cells where nothing is drawn
- size() Tuple[int, int][source]πΆοΈ
Returns the current canvas size.
- Returns:
the width and height of the canvas
- Return type:
tuple[int, int]
- toAnsi() str[source]πΆοΈ
Serializes the full canvas content into ANSI text.
- Returns:
the canvas rendered as newline-separated ANSI escape sequences
- Return type:
str