Add a method to a gtk class?

Wolfnoliir wolfnoliir at gmail.com
Thu Apr 29 11:43:16 EDT 2010


Hi,
I would like to add a method to the gtk.TextBuffer class to save a text
buffer to a file, but I get an error:

line 22, in <module>
    gtk.TextBuffer.save_to_file = gtk_TextBuffer_save_to_file
TypeError: can't set attributes of built-in/extension type 'gtk.TextBuffer'

Here is the code:

10 import gtk
15
16 def gtk_TextBuffer_save_to_file(self, filePath) :
17     with open(filePath, 'w') as file:
18         start = self.get_start_iter()
19         end   = self.get_end_iter()
20         text  = self.get_text(start, end, False)
21         file.write(text)
22 gtk.TextBuffer.save_to_file = gtk_TextBuffer_save_to_file




More information about the Python-list mailing list