Skip to content

Commit 40cf710

Browse files
committed
add all SetText funcs to use python lists for text_run_array
1 parent ec60680 commit 40cf710

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

bindings/interface/TextView.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,30 @@ py::class_<BTextView, PyBTextView, BView, std::unique_ptr<BTextView,py::nodelete
202202
BTextView::FreeRunArray(tra);
203203
}
204204
}, "", py::arg("text"), py::arg("runs"))
205+
.def("SetText", [](BTextView& self, const char* text, int32 length, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL)
206+
if (!runs.is_none()) {
207+
auto len = runs.size();
208+
text_run_array* tra = BTextView::AllocRunArray(len);
209+
int i = 0; for (auto item : runs) {
210+
if (i >= len) break; // Evita overflow
211+
tra->runs[i] = item.cast<text_run>(); ++i;
212+
}
213+
self.SetText(text, length, tra);
214+
BTextView::FreeRunArray(tra);
215+
}
216+
}, "", py::arg("text"), py::arg("length"), py::arg("runs"))
217+
.def("SetText", [](BTextView& self, BFile* file, int32 offset, int32 length, const py::list& runs){//&SetTextWrapper, "", py::arg("text"), py::arg("runs")=NULL)
218+
if (!runs.is_none()) {
219+
auto len = runs.size();
220+
text_run_array* tra = BTextView::AllocRunArray(len);
221+
int i = 0; for (auto item : runs) {
222+
if (i >= len) break; // Evita overflow
223+
tra->runs[i] = item.cast<text_run>(); ++i;
224+
}
225+
self.SetText(file, offset, length, tra);
226+
BTextView::FreeRunArray(tra);
227+
}
228+
}, "", py::arg("file"), py::arg("offset"), py::arg("length"), py::arg("runs"))
205229
.def("Insert", py::overload_cast<const char *, const text_run_array *>(&BTextView::Insert), "", py::arg("text"), py::arg("runs")=NULL)
206230
.def("Insert", py::overload_cast<const char *, int32, const text_run_array *>(&BTextView::Insert), "", py::arg("text"), py::arg("length"), py::arg("runs")=NULL)
207231
.def("Insert", py::overload_cast<int32, const char *, int32, const text_run_array *>(&BTextView::Insert), "", py::arg("offset"), py::arg("text"), py::arg("length"), py::arg("runs")=NULL)

0 commit comments

Comments
 (0)