1

wich is the method to get datas of a Treeview?

I have some rows and I'd like to save the data in an XML file, but I don't know how to keep the rows datas to pass to the XML function creator.

Thanks a lot!


Thanks for your reply! Here some code:

def create_xml(self, path, model):
    from lxml import etree
    print len(model) #that's work
        self.model = self.treeview.get_model()

    if(len(model) > 0):
        root = etree.Element("lista_tareas")
        iter = self.model.get_iter_first()

        contatore = 1
        while iter:
            #from here doesn't work, 
            # 'gtk.ListStore' object has no attribute 'COL_DESCRIZIONE'
            descrizione_c = self.model.get_value(iter, self.model.COL_DESCRIZIONE) 
            data_limite_c = model.get_value(iter, COL_DATA_LIMITE)
            priorita_c =  model.get_value(iter, COL_PRIORITA)
            realizzato_c = model.get_value(iter, COL_REALIZZATO)
            root.append(etree.Element("tarea", _id = contatore, realizzato = realizzato_c, data_limite = data_limite_c, priorita = priorita_c))
            root.appendSubElement(tarea, "description")
            tarea.text = descrizione_c

            iter = model.iter_next(iter)
        outFile = open('homemade.xml', 'w')
        doc.write(outFile)

This is the button who call the function:

self.save_button.connect("clicked", self.create_xml, self.model_add)
gpoo
  • 8,408
  • 3
  • 38
  • 53

1 Answers1

0

A) You can easily access the model that holds the data of the treeview with treeview.get_model() and the returned object can easily be iterated through. Exactly how you need to do it is hard to tell since you don't provide any code. In any a case. there should be many examples here on stackoverflow on how to work with treeviews and treemodels.

B) Then you need to make an xml-structure and save it out for which you can use etree (among others, but I find it easy to use) http://docs.python.org/library/xml.etree.elementtree.html#

deinonychusaur
  • 7,094
  • 3
  • 30
  • 44