Skip to content

Commit f5425d9

Browse files
committed
use nodebpy
1 parent 559d414 commit f5425d9

8 files changed

Lines changed: 188 additions & 411 deletions

File tree

build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
WHL_PATH = ADDON_DIR / "wheels"
2424

2525
# Instead of reading from pyproject.toml, define the required packages here:
26-
required_packages = ["typst", "databpy" ,"svg.path" , "lxml"]
26+
required_packages = ["typst", "databpy", "svg.path", "lxml", "nodebpy==520.5.2"]
2727

2828
def run_python(args: str | List[str]):
2929
python = os.path.realpath(sys.executable)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ version = "0.0.1" # Placeholder; the real version is defined in blender_manifes
44
description = "Blender extension to render Typst files"
55
license = { text = "AGPL-3.0-or-later" }
66
readme = "README.md"
7-
dependencies = ["typst", "svg.path" , "lxml", "databpy"]
8-
requires-python = ">=3.11.0"
7+
dependencies = ["typst", "svg.path", "lxml", "databpy", "nodebpy==520.5.2"]
8+
requires-python = ">=3.13.0"
99
keywords = ["blender", "python", "typst"]
1010
maintainers = [
1111
{ name = "Jan-Hendrik Müller", email = "jan-hendrik.mueller@uni-goettingen.de" }

tests/test_core_workflows_blender52.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6+
from types import SimpleNamespace
67

78
import bpy
89
import pytest
910

1011
import typst_importer
12+
from typst_importer.operators import textbox_import
1113
from typst_importer.node_groups import (
1214
create_follow_curve_node_group,
1315
modifier_input,
@@ -146,6 +148,27 @@ def test_textbox_curve_importer_smoke_test(tmp_path: Path):
146148
assert {obj.type for obj in collection.objects} == {"CURVE"}
147149

148150

151+
def test_textbox_import_prepends_the_header_displayed_in_the_panel():
152+
captured = {}
153+
154+
def fake_typst_import(typst_file, **_kwargs):
155+
captured["content"] = typst_file.read_text()
156+
return SimpleNamespace(name="Test Collection")
157+
158+
bpy.context.scene.typst_text = "#text[Hello]"
159+
bpy.context.window_manager.typst_use_custom_header = True
160+
bpy.context.window_manager.typst_custom_header = "#set text(size: 24pt)\n"
161+
162+
operator = SimpleNamespace(
163+
import_typst=lambda typst_file, _origin_to_char: fake_typst_import(typst_file),
164+
report=lambda _level, _message: None,
165+
)
166+
result = textbox_import.ImportFromTextboxOperator.execute(operator, bpy.context)
167+
168+
assert result == {"FINISHED"}
169+
assert captured["content"] == "#set text(size: 24pt)\n#text[Hello]"
170+
171+
149172
def test_addon_registers_and_unregisters_cleanly():
150173
typst_importer.register()
151174
try:

typst_importer/__init__.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040

4141
from .operators.textbox_import import (
42+
DEFAULT_CUSTOM_HEADER,
4243
ImportFromTextboxAsCurveOperator,
4344
ImportFromTextboxAsGreasePencilOperator,
4445
ImportFromTextboxAsMeshOperator,
@@ -72,10 +73,17 @@
7273
# Property for custom header checkbox
7374
bpy.types.WindowManager.typst_use_custom_header = bpy.props.BoolProperty(
7475
name="Use Custom Header",
75-
description="Use default Typst header (page settings and text size). If unchecked, uses the content as-is.",
76+
description="Prepend the custom Typst header below. If unchecked, use the content as-is.",
7677
default=True,
7778
)
7879

80+
# The header prepended to textbox imports when enabled above.
81+
bpy.types.WindowManager.typst_custom_header = bpy.props.StringProperty(
82+
name="Custom Header",
83+
description="Typst code prepended to the textbox content before importing",
84+
default=DEFAULT_CUSTOM_HEADER,
85+
)
86+
7987
# Property for SVG export path (default: user's Downloads folder)
8088
bpy.types.WindowManager.typst_export_filepath = bpy.props.StringProperty(
8189
name="Export Path",
@@ -91,6 +99,7 @@ class VIEW3D_PT_typst_textbox_import(bpy.types.Panel):
9199
bl_region_type = "UI"
92100
bl_category = "Typst Tools"
93101
bl_label = "Typst Input"
102+
bl_order = 0
94103

95104
def draw(self, context):
96105
layout = self.layout
@@ -103,46 +112,56 @@ def draw(self, context):
103112
box.textbox(scene, "typst_text")
104113

105114
# Import options
106-
box = layout.box()
107-
box.label(text="Import Options")
115+
options_box = layout.box()
116+
options_box.label(text="Import Options")
108117

109118
# Origin to character option
110-
box.prop(wm, "typst_origin_to_char", text="Origin to Character")
119+
options_box.prop(wm, "typst_origin_to_char", text="Origin to Character")
111120

112121
# Custom header option
113-
box.prop(wm, "typst_use_custom_header", text="Use Custom Header")
122+
options_box.prop(wm, "typst_use_custom_header", text="Use Custom Header")
123+
124+
header, header_body = layout.panel(
125+
"typst_custom_header",
126+
default_closed=True,
127+
)
128+
header.enabled = wm.typst_use_custom_header
129+
header.label(text="Custom Header", icon="TEXT")
130+
if header_body and wm.typst_use_custom_header:
131+
header_body.textbox(wm, "typst_custom_header")
114132

115133
# Disable buttons if the textbox is empty
116134
has_content = bool(scene.typst_text.strip())
117-
row = box.row()
135+
import_box = layout.box()
136+
row = import_box.row()
118137
row.operator(
119138
ImportFromTextboxAsUnfilledCurveOperator.bl_idname,
120139
text="Import as Unfilled Curve",
121140
icon="CURVE_BEZCURVE",
122141
)
123142
row.enabled = has_content
124143

125-
row = box.row()
144+
row = import_box.row()
126145
row.operator(
127146
ImportFromTextboxAsCurveOperator.bl_idname,
128147
text="Import as Curve",
129148
icon="CURVE_DATA",
130149
)
131150
row.enabled = has_content
132151

133-
row = box.row()
152+
row = import_box.row()
134153
row.operator(
135-
ImportFromTextboxAsGreasePencilOperator.bl_idname,
136-
text="Import as Grease Pencil",
137-
icon="GREASEPENCIL",
154+
ImportFromTextboxAsMeshOperator.bl_idname,
155+
text="Import as Mesh",
156+
icon="MESH_DATA",
138157
)
139158
row.enabled = has_content
140159

141-
row = box.row()
160+
row = import_box.row()
142161
row.operator(
143-
ImportFromTextboxAsMeshOperator.bl_idname,
144-
text="Import as Mesh",
145-
icon="MESH_DATA",
162+
ImportFromTextboxAsGreasePencilOperator.bl_idname,
163+
text="Import as Grease Pencil",
164+
icon="GREASEPENCIL",
146165
)
147166
row.enabled = has_content
148167

@@ -152,7 +171,8 @@ class VIEW3D_PT_typst_animation_tools(bpy.types.Panel):
152171
bl_space_type = "VIEW_3D"
153172
bl_region_type = "UI"
154173
bl_category = "Typst Tools"
155-
bl_label = "Animation Tools"
174+
bl_label = "Tools"
175+
bl_order = 10
156176

157177
def draw(self, context):
158178
layout = self.layout

typst_importer/blender_manifest.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ copyright = [
2727
]
2828
wheels = [
2929
"./wheels/databpy-0.7.0-py3-none-any.whl",
30+
"./wheels/nodebpy-520.5.2-py3-none-any.whl",
3031
"./wheels/lxml-6.0.2-cp313-cp313-macosx_10_13_universal2.whl",
3132
"./wheels/lxml-6.0.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
3233
"./wheels/lxml-6.0.2-cp313-cp313-win_amd64.whl",

0 commit comments

Comments
 (0)