Exemple #1
0
def _buildTree(tw):
    s = set(data.agents.keys())
    tw.clear()

    def addChildren(i, s):
        i.setExpanded(True)
        s.discard(i.aId)
        for c in data.agents[i.aId].children:
            child = QTreeWidgetItem(i)
            child.setText(0, c.name)
            child.aId = c.aId
            addChildren(child, s)

    for a in data.agents:
        if not data.agents[a].parent:
            i = QTreeWidgetItem(tw)
            i.setText(0, data.agents[a].name)
            i.aId = a
            addChildren(i, s)
    if len(s):
        i = QTreeWidgetItem(tw)
        i.setText(0, "Items perdus")
        i.setExpanded(True)
        i.aId = 0
        for a in s:
            c = QTreeWidgetItem(i)
            c.setText(0, data.agents[a].name)
            c.aId = a
Exemple #2
0
 def addChildren(i, s):
     i.setExpanded(True)
     s.discard(i.aId)
     for c in data.agents[i.aId].children:
         child = QTreeWidgetItem(i)
         child.setText(0, c.name)
         child.aId = c.aId
         addChildren(child, s)
Exemple #3
0
 def _addChildren(i):
     i.setExpanded(True)
     if i.aId == self.a.parentId:
         self.parentLabel.setText(self.a.parent.name)
         self.parentTreeWidget.setCurrentItem(i)
     for c in data.agents[i.aId].children:
         child = QTreeWidgetItem(i)
         child.setText(0, c.name)
         child.aId = c.aId
         _addChildren(child)
Exemple #4
0
    def selectAgent(self, i, previousItem):
        if i.aId:
            try:
                self.a.setParent(self.a.oldParent)
            except:
                pass

            self.a = data.agents[i.aId]
            self.nameEdit.setText(self.a.name)
            self.parentLabel.setText("Aucun")
            self.a.newParent = self.a.parentId

            try:
                self.parentTreeWidget.disconnect()
            except:
                pass

            self.parentTreeWidget.clear()

            def _addChildren(i):
                i.setExpanded(True)
                if i.aId == self.a.parentId:
                    self.parentLabel.setText(self.a.parent.name)
                    self.parentTreeWidget.setCurrentItem(i)
                for c in data.agents[i.aId].children:
                    child = QTreeWidgetItem(i)
                    child.setText(0, c.name)
                    child.aId = c.aId
                    _addChildren(child)

            i = QTreeWidgetItem(self.parentTreeWidget)
            i.setText(0, "Aucun")
            i.aId = 0

            for a in data.agents:
                if not data.agents[a].parent:
                    i = QTreeWidgetItem(self.parentTreeWidget)
                    i.setText(0, data.agents[a].name)
                    i.aId = a
                    _addChildren(i)

            self.parentTreeWidget.currentItemChanged.connect(self.selectParent)
Exemple #5
0
 def addAgent(self):
     t = QInputDialog.getText(self, "Nom", "Nom de l'élément à ajouter :")
     if len(t[0]) and t[1]:
         i = QTreeWidgetItem(self.selectTreeWidget)
         i.setText(0, t[0])
         i.aId = data.addAgent(t[0])
         self.selectTreeWidget.setCurrentItem(i)
         try:
             _buildTree(mwh.treeWidget)
         except:
             pass