Skip to content

Commit 5aa2aac

Browse files
Update docs for PySide text elements and --show-code/CGX_DEBUG
Document the new PySide text element support (#191): update the renderer-support note in the template syntax guide, add a Text Content section to the PySide renderer page, and switch the counter examples to text interpolation to match examples/pyside/counter.cgx. Document the --show-code CLI flag and the CGX_DEBUG environment variable (#175) on the CLI page. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d99dd87 commit 5aa2aac

5 files changed

Lines changed: 49 additions & 8 deletions

File tree

docs/getting-started/cli.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ uv run collagraph [OPTIONS] <component.cgx>
2121
| `--renderer {pyside,pygfx,dict}` | `pyside` | Renderer to use |
2222
| `--state <json>` | - | Initial state as JSON string or path to JSON file |
2323
| `--hot-reload`, `-H` | off | Enable hot reload (auto-update on file changes) |
24+
| `--show-code` | off | Pretty print the compiled Python code for the component and exit |
2425

2526
## Examples
2627

@@ -36,4 +37,15 @@ uv run collagraph --state '{"name": "World"}' hello.cgx
3637

3738
# Run with hot reload
3839
uv run collagraph -H examples/pyside/counter.cgx
40+
41+
# Inspect the Python code that is compiled for a component
42+
uv run collagraph --show-code examples/pyside/counter.cgx
43+
```
44+
45+
## Debugging Compiled Components
46+
47+
Templates are compiled to Python render methods. Besides `--show-code`, you can set the `CGX_DEBUG` environment variable to have the generated source written to a temporary file that is used as the compile filename. Debuggers (pdb, PyCharm, VS Code) can then step through the generated render methods with correct source display:
48+
49+
```sh
50+
CGX_DEBUG=1 uv run collagraph examples/pyside/counter.cgx
3951
```

docs/getting-started/first-component.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Create a file `counter.cgx`:
88

99
```html
1010
<widget>
11-
<label :text="f'Count: {count}'" />
12-
<button text="bump" @clicked="bump" />
11+
<label>Count: {{ count }}</label>
12+
<button @clicked="bump">bump</button>
1313
</widget>
1414

1515
<script>
@@ -38,7 +38,7 @@ uv run collagraph counter.cgx
3838
The template defines what gets rendered. Each tag corresponds to a widget or element in the target renderer.
3939

4040
- `<widget>` -- a plain QWidget container (PySide6 renderer)
41-
- `:text="f'Count: {count}'"` -- a dynamic binding (note the `:` prefix). The expression is a Python f-string.
41+
- `Count: {{ count }}` -- text content with interpolation. The expression inside `{{ }}` is evaluated as Python and updates automatically when state changes.
4242
- `@clicked="bump"` -- an event handler. Calls the `bump` method when the button is clicked.
4343

4444
### Script

docs/guide/template-syntax.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ Elements can contain text content, with double curly braces for dynamic expressi
5252
Expressions inside `{{ }}` are evaluated as Python. Static and dynamic parts can be mixed freely, and multiline text is normalized (leading indentation after line breaks is stripped). To render literal braces, escape them with a backslash: `\{{`.
5353

5454
!!! note "Renderer support"
55-
Text content requires the renderer to support text elements. The Pygfx renderer supports it (inside `<text>` elements); the PySide6 renderer does not — with Qt widgets, set text via the `text` attribute instead:
55+
Text content requires the renderer to support text elements. The Pygfx renderer supports it inside `<text>` elements. The PySide6 renderer supports it inside widgets that display text, such as `<label>` and `<button>` (see [PySide6 Renderer](../renderers/pyside.md#text-content)):
5656

5757
```html
58-
<label text="Static text" />
59-
<label :text="f'Hello, {name}'" />
58+
<label>Hello, {{ name }}!</label>
59+
<button @clicked="bump">bump</button>
60+
```
61+
62+
For other Qt widgets, set text via the `text` attribute instead:
63+
64+
```html
65+
<lineedit :text="f'Hello, {name}'" />
6066
```
6167

6268
## Attribute Binding

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Collagraph lets you build declarative UIs using class-based components with a Vu
88

99
```html title="counter.cgx"
1010
<widget>
11-
<label :text="f'Count: {count}'" />
12-
<button text="bump" @clicked="bump" />
11+
<label>Count: {{ count }}</label>
12+
<button @clicked="bump">bump</button>
1313
</widget>
1414

1515
<script>

docs/renderers/pyside.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ Dynamic attributes use Python expressions:
8484
<slider :value="self.state['position']" />
8585
```
8686

87+
## Text Content
88+
89+
Widgets that display text can take their text as element content, including `{{ }}` interpolation:
90+
91+
```html
92+
<label>Count: {{ count }}</label>
93+
<button @clicked="bump">bump</button>
94+
```
95+
96+
This is supported for `QLabel` and all `QAbstractButton` subclasses (`<button>`, `<checkbox>`, `<radiobutton>`, ...). The joined content of all text children is displayed through the widget's `setText()` method, so text can be mixed with directives:
97+
98+
```html
99+
<label>
100+
Hello<template v-if="name">, {{ name }}</template>!
101+
</label>
102+
```
103+
104+
For other widgets, set text via the `text` attribute instead:
105+
106+
```html
107+
<lineedit :text="initial_value" />
108+
```
109+
87110
## Layouts
88111

89112
Child widgets are laid out using layout elements:

0 commit comments

Comments
 (0)