Por que meu Gtk.Notebook não está buscando sua etiqueta corretamente?

0

Estou usando esse método para salvar um arquivo:

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

No entanto, quando corri, recebo esse traceback na janela do Terminal:

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'

Esses métodos criam as guias nos 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()

O que preciso fazer para resolver esse erro?

    
por njallam 01.09.2012 / 19:55

1 resposta

2

self.subjects.get_tab_label(subject_content) obtém uma instância Gtk.Label, mas file_data.add_section espera uma string como parâmetro.

Use

subject_name = self.subjects.get_tab_label(subject_content).get_text()
    
por Florian Diesch 01.09.2012 / 20:32