I’m working on a flatpak python+gtk4 application which is, roughly speaking, a text editor, and I need a way to save the contents of a TextView including all the tags.
What I know: In Gtk 4, TextView buffer no longer has built-in serialization methods. To seralilize the contents of the buffer it is necessary to create my own serializer, for that I must use gdk_content_register_serializer
(and the corresponding one to create the deserializer). Something like that:
def _r_serializer(self):
Gdk.content_register_serializer(Gtk.TextBuffer,
"text/plain;charset=utf-8",
self._serialize_text,
None,
None)
What I don’t know: While the use of gdk_content_register_serializer
is fairly straightforward and simple, the same is not true about GdkContentSerializeFunc
(self._serialize_text
). From the documentation, I couldn’t understand what this function should be exactly. I tried looking at how Textbuffer’s serializer worked in GTk3, but I’m fairly new to working with Gtk/Gdk and don’t fully understand the workflow, and besides, my knowledge of C is limited.
What I need: I would like a minimal code example (python would be nice, but it can be any language) of a GdkContentSerializeFunc
that serializes at least one tag (italics, for example) to plain text, so that I can use it as a basis for build my own serializer.