context.scopes
charshape_scope / parashape_scope / styled_text.
scopes.charshape_scope
context.scopes.charshape_scope(app, **fmt)Apply a char-shape override inside the with block, then restore.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| app | hwpapi.App | Live App instance (or any object exposing .actions and .api). |
required |
| **fmt | Any | Char-shape overrides. Friendly keys — bold, italic, size, color, shade_color, font — are translated to HWP COM names; anything else is passed through. |
{} |
Example
with charshape_scope(app, bold=True, size=1400, color=“#FF0000”): … app.doc.insert_text(“important!”)
scopes.parashape_scope
context.scopes.parashape_scope(app, **fmt)Apply a para-shape override inside the with block, then restore.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| app | hwpapi.App | required | |
| **fmt | Any | Paragraph-shape overrides. Friendly keys — align, line_spacing, left_margin, right_margin, indentation — are translated to HWP COM names. |
{} |
Example
with parashape_scope(app, align=“center”): … app.doc.insert_text(“centred paragraph”)
scopes.styled_text
context.scopes.styled_text(app, text, **fmt)Insert text with a temporary char-shape, then restore.
Shorthand for ::
with charshape_scope(app, **fmt):
app.api.HAction.Run("InsertText") / InsertText action
The function returns None — it’s a side-effecting one-shot, not a context manager.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| app | hwpapi.App | required | |
| text | str | Literal text to insert at the cursor. | required |
| **fmt | Any | Same friendly-key char-shape overrides as :func:charshape_scope. |
{} |
Example
styled_text(app, “Hello”, bold=True, color=“#FF0000”)