需要GtkTextBuffer(GtkTextView)序列化/反序列化的示例/帮助 [英] Need example/help with GtkTextBuffer (of GtkTextView) serialize/deserialize

查看:297
本文介绍了需要GtkTextBuffer(GtkTextView)序列化/反序列化的示例/帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将用户的粗体/斜体/字体/ etc标签保存在GtkTextView中。
使用GtkTextBuffer.get_text()不会返回标签。



我发现的最佳文档是:
http://www.pygtk.org/docs/ pygtk / class-gtktextbuffer.html#method-gtktextbuffer - register-serialize-format

然而,我不明白函数参数。
举例说明如何使用这些标签来保存/加载带有标签的textview。



编辑:我想澄清我正在努力完成的事情。基本上我想保存/加载textview的文本+标签。我不想做任何比这更复杂的事情。我使用pickle作为文件格式,所以在这里我不需要任何帮助来保存它或以什么格式。只需要一种方法来拉取/推送数据,这样用户就不会失去他/她在屏幕上看到的任何东西。谢谢。

解决方案

如果您需要保存标记,因为您只是想将文本复制到另一个文本缓冲区中,则可以使用 gtk.TextBuffer.insert_range()



如果您需要将带有标签的文本保存为另一种可读格式通过其他程序,我曾经写过一个带有GTK文本缓冲区序列化器的库到RTF和从RTF开始。但它没有任何Python绑定。但是在任何情况下,代码都是如何使用串行器设备的一个很好的例子。链接: Osxcart


I am trying to save user's bold/italic/font/etc tags in a GtkTextView. Using GtkTextBuffer.get_text() does not return the tags.

The best documentation I have found on this is: http://www.pygtk.org/docs/pygtk/class-gtktextbuffer.html#method-gtktextbuffer--register-serialize-format

However, I do not understand the function arguments. It would be infinitely handy to have an example of how these are used to save/load a textview with tags in it.

Edit: I would like to clarify what I am trying to accomplish. Basically I want to save/load the textview's text+tags. I have no desire to do anything more complicated than that. I am using pickle as the file format, so I dont need any help here on how to save it or in what format. Just need a way to pull/push the data so that the user loses nothing that he/she sees on screen. Thank you.

解决方案

If you need to save the tags because you just want to copy the text into another text buffer, you can use gtk.TextBuffer.insert_range().

If you need to save the text with tags into another format readable by other programs, I once wrote a library with a GTK text buffer serializer to and from RTF. It doesn't have any Python bindings though. But in any case the code is a good example of how to use the serializer facility. Link: Osxcart

这篇关于需要GtkTextBuffer(GtkTextView)序列化/反序列化的示例/帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆