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.

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?

share|improve this question
    
when asking programming questions, you should always provide a minimal working example that shows the described behaviour. –  xubuntix Sep 2 '12 at 10:34

1 Answer 1

up vote 0 down vote accepted

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()
share|improve this answer
    
page_content is a TextArea. I was following the serialisation instructions from this answer. –  njallam Sep 2 '12 at 6:08

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.