Text Widgets¶
Label¶
Static text with alignment, color, and font options.
Constructor: new Widgets.Label(text, {halign})
Options:
halign– horizontal alignment ("left","center","right")
Methods:
Method |
Description |
|---|---|
|
Set label text. |
|
Return current text. |
|
Set background and foreground colors. |
|
Set horizontal alignment. |
Callbacks: None.
let label = new Widgets.Label("Status: OK", {halign: "left"});
label.set_color(null, "green");
TextEntry¶
Single-line text input with optional line history.
Constructor: new Widgets.TextEntry({text, editable, linehistory, password})
Options:
text– initial texteditable– whether text is editablelinehistory– enable up/down arrow line historypassword– mask input as password
Methods:
Method |
Description |
|---|---|
|
Set text content. |
|
Return current text. |
|
Clear the text field. |
|
Set display width in characters. |
Callbacks:
activated– fired when Enter is pressed.
let entry = new Widgets.TextEntry({linehistory: true});
entry.add_callback('activated', (w) => {
console.log("Entered:", w.get_text());
w.clear();
});
TextEntrySet¶
Text entry with a submit button.
Constructor: new Widgets.TextEntrySet({text, value, editable, linehistory})
Options:
text– button label textvalue– initial entry texteditable– whether text is editablelinehistory– enable line history
Methods:
Method |
Description |
|---|---|
|
Set the button label. |
|
Set entry text. |
|
Return current text. |
|
Clear the text field. |
|
Set display width in characters. |
Callbacks:
activated– fired when the button is pressed or Enter is pressed.
TextArea¶
Multi-line text editor.
Constructor: new Widgets.TextArea(text, {wrap, editable})
Options:
wrap– enable text wrappingeditable– whether text is editable
Methods:
Method |
Description |
|---|---|
|
Set text content. |
|
Return current text. |
|
Append text at the end. |
|
Clear all text. |
|
Set editable state. |
|
Set word-wrap mode. |
|
Limit visible lines (scrollback). |
Callbacks: None.
let log = new Widgets.TextArea("", {wrap: true, editable: false});
log.set_limit(1000);
log.append_text("Application started.\n");
HtmlView¶
Read-only rich HTML content display with pgwidgets-style scrollbars.
Constructor: new Widgets.HtmlView(html)
Methods:
Method |
Description |
|---|---|
|
Set HTML content, replacing existing content. |
|
Return current HTML content. |
|
Append HTML to existing content. |
|
Remove all content. |
|
Scroll to the top. |
|
Scroll to the bottom. |
Callbacks: None.
let view = new Widgets.HtmlView("<h1>Hello</h1><p>Rich content here.</p>");
vbox.add_widget(view, 1);
// Update content dynamically
view.set_html("<h2>Updated</h2><p>New content.</p>");
view.append_html("<p>Another paragraph.</p>");
TextSource¶
Source code editor with line numbers, syntax highlighting support, tags, undo/redo, and find/replace.
Constructor: new Widgets.TextSource(text, {wrap, line_numbers, icon_gutter, editable, font_family, font_size})
Options:
wrap– wrap modeline_numbers– show line numbersicon_gutter– show icon guttereditable– whether text is editablefont_family– font family namefont_size– font size
Methods:
Method |
Description |
|---|---|
|
Set or get text content. |
|
Return text length. |
|
Insert text at offset with optional tags. |
|
Delete text between offsets. |
|
Clear all text. |
|
Set editable state. |
|
Set wrap mode. |
|
Show/hide line numbers. |
|
Show/hide icon gutter. |
|
Set an icon on a line. |
|
Get or set cursor position. |
|
Get or set selection range. |
|
Create a named style tag. |
|
Remove a tag definition. |
|
Apply a tag to a text range. |
|
Remove a tag from a range. |
|
Return tags at offset. |
|
Create a live reference at offset. |
|
Remove a live reference. |
|
Undo or redo. |
|
Check undo/redo availability. |
|
Find next match. |
|
Find all matches. |
|
Find and replace. |
|
Scroll to a position. |
|
Scroll to cursor position. |
Callbacks:
changed– text content changed.cursor_moved– cursor position changed.line_clicked– a line number was clicked.icon_clicked– a gutter icon was clicked.
let editor = new Widgets.TextSource("", {
line_numbers: true,
editable: true,
font_family: "monospace",
font_size: 14
});
editor.create_tag("keyword", {color: "blue", fontWeight: "bold"});
editor.add_callback('changed', (w) => console.log("Modified"));