Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
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 '12 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 '12 at 17:39
    
pastebin.com/7kKv61XX –  Deluxo Nov 2 '12 at 18:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.