0

While trying to follow the serialisation instructions from this answer I encountered a few problems.

The following is supposed to serialise a TextArea's content to a string. The first two line complete fine, however I have problems from then onwards.

page_content = subject_content.get_nth_page(pn) //TextArea widget returned
page_name = subject_content.get_tab_label(page_content).get_text()
c_buffer = page_content.get_buffer()
c_format = c_buffer.register_serialize_tagset()
serial = c_buffer.serialize(c_format, c_buffer.get_start_iter(), c_buffer.get_end_iter())

The first error I get is:

Traceback (most recent call last):
  File "/home/nja/notetaker/notetaker/NotetakerWindow.py", line 251, in on_btn_save_clicked
    self.save()
  File "/home/nja/notetaker/notetaker/NotetakerWindow.py", line 160, in save
    c_format = c_buffer.register_serialize_tagset()
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
TypeError: register_serialize_tagset() takes exactly 2 arguments (1 given)

When inserting None as a parameter to c_format = c_buffer.register_serialize_tagset() that line completes, however the next one doesn't work:

Traceback (most recent call last):
  File "/home/nja/notetaker/notetaker/NotetakerWindow.py", line 251, in on_btn_save_clicked
    self.save()
  File "/home/nja/notetaker/notetaker/NotetakerWindow.py", line 161, in save
    serial = c_buffer.serialize(c_format, c_buffer.get_start_iter(), c_buffer.get_end_iter())
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
TypeError: serialize() takes exactly 5 arguments (4 given)

I have no idea of a workaround for that, however I shouldn't have to fill None in that other function in the first place.

What is happening here?

1
  • when asking programming questions, you should always provide a minimal working example that shows the described behaviour.
    – xubuntix
    Sep 2, 2012 at 10:34

1 Answer 1

0

The Gtk docs say that c_buffer.register_serialize_tagset() needs a utf8 string as an argument.

It looks like you need:
c_buffer.register_serialize_tagset(c_buffer.get_text().encode('utf-8'))
or similar

This works:

from gi.repository import Gtk

win = Gtk.Window()
box = Gtk.Box()
win.add(box)

text = Gtk.TextView()
box.add(text)

buffer = text.get_buffer()

buffer.set_text("Sample text")

this = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), False)

format = buffer.register_serialize_tagset(this)

data = buffer.serialize(buffer, format, buffer.get_start_iter(), buffer.get_end_iter())

print data

Gtk.main()
1
  • page_content is a TextArea. I was following the serialisation instructions from this answer.
    – njallam
    Sep 2, 2012 at 6:08

You must log in to answer this question.

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