22 """Ce module permet de créer des vues sous forme d'arbre
23 Ces vues sont construites à partir des informations
24 fournies par un modèle
34 Classe pour faire une vue d'un arbre
36 def __init__(self,parent=None,onSelect=None,onDblSelect=None):
37 QListView.__init__(self,parent)
38 self.setCaption(
"Tree")
39 self.setRootIsDecorated(1)
41 self.addColumn(
"Name")
46 self.connect(self,SIGNAL(
'selectionChanged(QListViewItem *)'),
48 self.connect(self,SIGNAL(
'doubleClicked(QListViewItem *, const QPoint &, int)'),
57 node.item.dblselected()
62 node=
Node(self,item.label,item,self.
last)
64 self.children.append(node)
65 CONNECTOR.Connect(item,
"selected",self.
selectItem,())
66 CONNECTOR.Connect(item,
"add",node.addNode,())
71 self.setSelected(node,
True)
75 node=self.selectedItem()
83 it = QListViewItemIterator(self)
92 self.setSelected(node,
True)
95 """Node(parent,text,item,after)
96 Classe pour faire une vue d'un noeud d'un arbre
98 def __init__(self,parent,text,item,after=None):
100 QListViewItem.__init__(self,parent,text)
102 QListViewItem.__init__(self,parent,after,text)
104 self.setPixmap(0,Icons.get_image(item.getIconName()))
105 self.setExpandable(self.item.isExpandable())
109 self.listView().setSelected(self,
True)
117 CONNECTOR.Disconnect(node.item,
"selected",node.selectNode,())
118 CONNECTOR.Disconnect(node.item,
"add",node.addNode,())
119 CONNECTOR.Disconnect(node.item,
"remove",self.
delNode,(node,))
121 self.children.remove(node)
127 node=
Node(self,item.label,item)
128 self.children.append(node)
130 CONNECTOR.Connect(item,
"selected",node.selectNode,())
131 CONNECTOR.Connect(item,
"add",node.addNode,())
132 CONNECTOR.Connect(item,
"remove",self.
delNode,(node,))
136 if o
and not self.childCount():
137 for child
in self.item.getChildren():
139 QListViewItem.setOpen(self,o)
144 for child
in self.item.getChildren():
150 CONNECTOR.Disconnect(node.item,
"selected",node.selectNode,())
151 CONNECTOR.Disconnect(node.item,
"add",node.addNode,())
155 QListViewItem.setOpen(self,o)
158 if __name__ ==
"__main__":
159 from Item
import Item
160 app = QApplication(sys.argv)
162 t.additem(Item(
"item1"))