0

I am using this method to save a file:

def save(self):
    file_data = ConfigParser.ConfigParser()
    subjects_number = self.subjects.get_n_pages()
    si = range(1, subjects_number)
    for sn in si:
        subject_content = self.subjects.get_nth_page(sn)
        subject_name = self.subjects.get_tab_label(subject_content)
        file_data.add_section(subject_name) #Line 153
        pages_number = self.subjects.get_nth_page(sn)
        pi = range(1, pages_number)
        for pn in pi:
            page_content = subject_content.get_nth_page(pn)
            page_name = pages.get_tab_label(page_content)
            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())
            file_data.set(subject_name, page_name, serial)
    with open(self.current_file, "wb") as this_file:
        file_data.write(this_file)
    print "File Saved:" + self.current_file

However when ran I get this traceback in the Terminal window:

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 153, in save
    file_data.add_section(subject_name)
  File "/usr/lib/python2.7/ConfigParser.py", line 260, in add_section
    if section.lower() == "default":
AttributeError: 'Label' object has no attribute 'lower'

These methods create the tabs in the Gtk.Notebook() widgets:

def add_page(self, pages = None, label = None):
    if pages is None:
        pages = self.get_pages()
    if label is None:
        label = "New Page"
    textview = Gtk.TextView()
    textbuffer = textview.get_buffer()
    pages.append_page(textview, Gtk.Label(label))
    self.window.show_all()

def add_subject(self, label = None):
    if label is None:
        label = "New Subject"
    pages = Gtk.Notebook()
    pages.set_tab_pos(Gtk.PositionType.RIGHT)
    pages.set_scrollable(True)
    self.add_page(pages)
    self.subjects.append_page(pages, Gtk.Label(label))
    self.window.show_all()

What do I need to do to resolve this error?

2

self.subjects.get_tab_label(subject_content) gets you a Gtk.Label instance but file_data.add_section expects a string as parameter.

Use

subject_name = self.subjects.get_tab_label(subject_content).get_text()
1
  • Thanks. There are tons more bugs in my saving script, but I'll keep that debugging fun to myself. :) – njallam Sep 1 '12 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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