Ejemplo n.º 1
0
    def load_idx(self, name, data, parent=None):
        pitem = parent.internalPointer()
        
        if name:
            item = QDictModelItem(None)
            item.name = name
            item.parent = pitem
            
            if isinstance(data, dict):
                item.data = {}
            elif isinstance(data, list):
                item.data = []
            else:
                item.data = data
                return item
        else:
            item = pitem
        
        self.beginInsertRows(parent, self.rowCount(parent), len(data))
        
        self.insertRows(self.rowCount(parent), len(data), parent)
                
        self.endInsertRows()
        
        for n, v in iterate(data):
            idx = self.index(row, 0, parent)
            it = self.load_idx(n, v, item)
            if it:
                item.children.append(it)

        return item
Ejemplo n.º 2
0
 def load_item(self, name, data, parent=None):
     item = QDictModelItem(None)
     item.name = name
     if isinstance(data, dict):
         item.data = {}
     elif isinstance(data, list):
         item.data = []
     else:
         item.data = data
     item.parent = parent
     
     for n, v in iterate(data):
         it = self.load_item(n, v, item)
         if it:
             #it.index = len(item.children)
             item.children.append(it)
     
     #=======================================================================
     # if isinstance(data, dict):
     #    for n, v in data.items():
     #        it = self.load_item(n, v, item)
     #        if it:
     #            it.index = len(item.children)
     #            item.children.append(it)
     #            
     # if isinstance(data, list):
     #    for i, v in enumerate(data):
     #        it = self.load_item(str(i), v, item)
     #        if it:
     #            it.index = len(item.children)
     #            item.children.append(it)
     #=======================================================================
     return item