Il giorno sab, 12/11/2011 alle 15.05 +0800, Andrew Rowland ha scritto:
> I have a group of information that is related in a hierarchical
> structure.  I display the structure in a treeview.  I am trying to
> roll up various calculations where, the sum of the lower levels
> becomes the unit value of the next higher level.  Below is, hopefully,
> a helpful example of how the calculations should roll up.
> 
> Description                        Quantity    Unit Cost    Total Cost
> System                                      1             21.42
>    21.42
>    Subsystem 1                        1              12.45
>  12.45
>        Assembly 1                      2                4.85
>    9.70
>            Part 1                            1                0.10
>          0.10
>            Part 2                            2                1.00
>          2.00
>            Part 3                            5                0.55
>          2.75
>        Assembly 2                      1                1.70
>    1.70
>            Part 4                            2                0.55
>          1.10
>            Part 5                            3                0.20
>          0.60
>    Subsystem 2                        1                8.97
>  8.97
>        Assembly 3                      1                8.97
>    8.97
>            Subassembly 1            1                8.97
>  8.97
>                Part 6                        1                2.98
> 2.98
>                Part 7                        1                5.99
> 5.99
> 
> Clearly, things need to be calculated in the correct order starting
> with Part and working up to System.  I am struggling with a good way
> to "walk" up the tree making all the calculations at one level before
> continuing to the next higher level.  I'm sure it's not as difficult
> as I've convinced myself it is.

I'd proceed recursively (untested/pseudo code):

def value (iter):
    if tree.iter_has_child():
        val = 0
        for index in range( tree.iter_n_children( iter ) ):
            val += value( tree.iter_nth_child( iter, i ) )
        return val
    else:
        return  tree.get( iter, 3 )



bye

Pietro

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to