1

I am writing a note taking app with python and glade. I've been searching the web for the how to save and retrieve textbuffer with tags from simple app made with python and glade. I would like to get an in-depth answer as I am just starting to know python a little. So here's the situation:

Text loads fine, but tags that have been applied are lost upon opening the my editor again.

Heres my read,write solution on how to save and open file with textbuffer into textview:

def on_saver_clicked(self, widget):
    print "Saved"
    start, end = self.textbuffer.get_bounds()   
    text = self.textbuffer.get_text(start, end, False)
    file = open("note.txt", "w")
    file.write(text)
    file.close()

def on_opener_clicked(self, widget):
    print "Loaded"
    file = open("note.txt", "r")
    text = file.read()
    file.close()     
    self.textbuffer.set_text(text)

Any ideas on how to save and retrieve the applied tags to the text? Also, could anybody tell me how to properly setup

gtk.TextBuffer.register_serialize_format ?

1 Answer 1

0

I haven't done this before, but looking at the gtk.TextBuffer documentation it has a serialize() and deserialize() method which seems exactly what you need.

From docs:

This method serializes the portion of text between start and end in the rich text format represented by format.

3
  • Thank You, I know this method, and I appreciate the research, but as i mentioned, I would like to get a help on how to implement it, because I have no clue what arguments exactly must be given in the serialization.
    – Deluxo
    Nov 2, 2012 at 14:30
  • Do you have a link to your full source? I'm a bit busy right now to write a testapp.
    – Timo
    Nov 2, 2012 at 17:39
  • pastebin.com/7kKv61XX
    – Deluxo
    Nov 2, 2012 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .