Python-Ref > GUI programming with PyGTK > Data structures > TreeStore
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce
GTK Widgety

TreeStore

Data model for tree like data with columnar internal structure.
TreeStore is an implementation of the TreeModel interface.
The example below shows how a TreeStore is created and manipulated.
Expand/Shrink
  1   import gtk
  2   
  3   # table of 1 string and 1 integer
  4   store = gtk.TreeStore( str, int)
  5   for i in range( 5):
  6     parent_iter = store.append( None, ["Parent %d" % i, i])
  7     for j in range( 3):
  8       child_iter = store.append( parent_iter, ["Child %d-%d" % (i,j), j])
  9       for k in range( 3):
 10         store.append( child_iter, ["Grandchild %d-%d-%d" % (i,j,k), k])
 11     
 12   # iterate over the store
 13   print store[0]
 14   for row in store:
 15     print row[0]
 16     for child in row.iterchildren():
 17       print " ", child[0]
 18       for grandchild in child.iterchildren():
 19         print "   ", grandchild[0]
stdout:
<gtk.TreeModelRow object at 0x2acad3245d50>
Parent 0
  Child 0-0
    Grandchild 0-0-0
    Grandchild 0-0-1
    Grandchild 0-0-2
  Child 0-1
    Grandchild 0-1-0
    Grandchild 0-1-1
    Grandchild 0-1-2
  Child 0-2
    Grandchild 0-2-0
    Grandchild 0-2-1
    Grandchild 0-2-2
Parent 1
  Child 1-0
    Grandchild 1-0-0
    Grandchild 1-0-1
    Grandchild 1-0-2
  Child 1-1
    Grandchild 1-1-0
    Grandchild 1-1-1
    Grandchild 1-1-2
  Child 1-2
    Grandchild 1-2-0
    Grandchild 1-2-1
    Grandchild 1-2-2
Parent 2
  Child 2-0
    Grandchild 2-0-0
    Grandchild 2-0-1
    Grandchild 2-0-2
  Child 2-1
    Grandchild 2-1-0
    Grandchild 2-1-1
    Grandchild 2-1-2
  Child 2-2
    Grandchild 2-2-0
    Grandchild 2-2-1
    Grandchild 2-2-2
Parent 3
  Child 3-0
    Grandchild 3-0-0
    Grandchild 3-0-1
    Grandchild 3-0-2
  Child 3-1
    Grandchild 3-1-0
    Grandchild 3-1-1
    Grandchild 3-1-2
  Child 3-2
    Grandchild 3-2-0
    Grandchild 3-2-1
    Grandchild 3-2-2
Parent 4
  Child 4-0
    Grandchild 4-0-0
    Grandchild 4-0-1
    Grandchild 4-0-2
  Child 4-1
    Grandchild 4-1-0
    Grandchild 4-1-1
    Grandchild 4-1-2
  Child 4-2
    Grandchild 4-2-0
    Grandchild 4-2-1
    Grandchild 4-2-2
Doba běhu: 69.0 ms