def populate_tree(self, parentItem, children_list):
        """Recursive method to create each item (and associated data) in the tree."""
        for child_key in children_list:
            self.item_depth += 1
            (filename, line_number, function_name, file_and_line, node_type
             ) = self.function_info(child_key)

            ((total_calls, total_calls_dif), (loc_time, loc_time_dif), (cum_time,
             cum_time_dif)) = self.format_output(child_key)

            child_item = TreeWidgetItem(parentItem)
            self.item_list.append(child_item)
            self.set_item_data(child_item, filename, line_number)

            # FIXME: indexes to data should be defined by a dictionary on init
            child_item.setToolTip(0, _('Function or module name'))
            child_item.setData(0, Qt.DisplayRole, function_name)
            child_item.setIcon(0, self.icon_list[node_type])

            child_item.setToolTip(1, _('Time in function '\
                                       '(including sub-functions)'))
            child_item.setData(1, Qt.DisplayRole, cum_time)
            child_item.setTextAlignment(1, Qt.AlignRight)
            
            child_item.setData(2, Qt.DisplayRole, cum_time_dif[0])
            child_item.setForeground(2, QColor(cum_time_dif[1]))
            child_item.setTextAlignment(2, Qt.AlignLeft)

            child_item.setToolTip(3, _('Local time in function '\
                                      '(not in sub-functions)'))

            child_item.setData(3, Qt.DisplayRole, loc_time)
            child_item.setTextAlignment(3, Qt.AlignRight)
            
            child_item.setData(4, Qt.DisplayRole, loc_time_dif[0])
            child_item.setForeground(4, QColor(loc_time_dif[1]))
            child_item.setTextAlignment(4, Qt.AlignLeft)

            child_item.setToolTip(5, _('Total number of calls '\
                                       '(including recursion)'))

            child_item.setData(5, Qt.DisplayRole, total_calls)
            child_item.setTextAlignment(5, Qt.AlignRight)
            
            child_item.setData(6, Qt.DisplayRole, total_calls_dif[0])
            child_item.setForeground(6, QColor(total_calls_dif[1]))
            child_item.setTextAlignment(6, Qt.AlignLeft)

            child_item.setToolTip(7, _('File:line '\
                                       'where function is defined'))
            child_item.setData(7, Qt.DisplayRole, file_and_line)
            #child_item.setExpanded(True)
            if self.is_recursive(child_item):
                child_item.setData(7, Qt.DisplayRole, '(%s)' % _('recursion'))
                child_item.setDisabled(True)
            else:
                callees = self.find_callees(child_key)
                if self.item_depth < 3:
                    self.populate_tree(child_item, callees)
                elif callees:
                    child_item.setChildIndicatorPolicy(child_item.ShowIndicator)
                    self.items_to_be_shown[id(child_item)] = callees
            self.item_depth -= 1
def populate_tree ( self , parentItem , children_list ) : for child_key in children_list : self . item_depth += 1 ( filename , line_number , function_name , file_and_line , node_type ) = self . function_info ( child_key ) ( ( total_calls , total_calls_dif ) , ( loc_time , loc_time_dif ) , ( cum_time , cum_time_dif ) ) = self . format_output ( child_key ) child_item = TreeWidgetItem ( parentItem ) self . item_list . append ( child_item ) self . set_item_data ( child_item , filename , line_number ) child_item . setToolTip ( 0 , _ ( 'Function or module name' ) ) child_item . setData ( 0 , Qt . DisplayRole , function_name ) child_item . setIcon ( 0 , self . icon_list [ node_type ] ) child_item . setToolTip ( 1 , _ ( 'Time in function ' '(including sub-functions)' ) ) child_item . setData ( 1 , Qt . DisplayRole , cum_time ) child_item . setTextAlignment ( 1 , Qt . AlignRight ) child_item . setData ( 2 , Qt . DisplayRole , cum_time_dif [ 0 ] ) child_item . setForeground ( 2 , QColor ( cum_time_dif [ 1 ] ) ) child_item . setTextAlignment ( 2 , Qt . AlignLeft ) child_item . setToolTip ( 3 , _ ( 'Local time in function ' '(not in sub-functions)' ) ) child_item . setData ( 3 , Qt . DisplayRole , loc_time ) child_item . setTextAlignment ( 3 , Qt . AlignRight ) child_item . setData ( 4 , Qt . DisplayRole , loc_time_dif [ 0 ] ) child_item . setForeground ( 4 , QColor ( loc_time_dif [ 1 ] ) ) child_item . setTextAlignment ( 4 , Qt . AlignLeft ) child_item . setToolTip ( 5 , _ ( 'Total number of calls ' '(including recursion)' ) ) child_item . setData ( 5 , Qt . DisplayRole , total_calls ) child_item . setTextAlignment ( 5 , Qt . AlignRight ) child_item . setData ( 6 , Qt . DisplayRole , total_calls_dif [ 0 ] ) child_item . setForeground ( 6 , QColor ( total_calls_dif [ 1 ] ) ) child_item . setTextAlignment ( 6 , Qt . AlignLeft ) child_item . setToolTip ( 7 , _ ( 'File:line ' 'where function is defined' ) ) child_item . setData ( 7 , Qt . DisplayRole , file_and_line ) if self . is_recursive ( child_item ) : child_item . setData ( 7 , Qt . DisplayRole , '(%s)' % _ ( 'recursion' ) ) child_item . setDisabled ( True ) else : callees = self . find_callees ( child_key ) if self . item_depth < 3 : self . populate_tree ( child_item , callees ) elif callees : child_item . setChildIndicatorPolicy ( child_item . ShowIndicator ) self . items_to_be_shown [ id ( child_item ) ] = callees self . item_depth -= 1
Recursive method to create each item (and associated data) in the tree.