1 | """An advanced example of iterating through the properties of an ExtValue object and printing their characteristics. |
---|
2 | This example may be useful for some developers, but it is not needed for a regular usage of Framsticks (i.e. simulation and evolution).""" |
---|
3 | |
---|
4 | import frams |
---|
5 | import sys |
---|
6 | |
---|
7 | frams.init(*(sys.argv[1:])) |
---|
8 | |
---|
9 | |
---|
10 | def printSingleProperty(v, p): |
---|
11 | print(' * %s "%s" type="%s" flags=%d group=%d help="%s"' % (v._propId(p), v._propName(p), v._propType(p), v._propFlags(p), v._propGroup(p), v._propHelp(p))) |
---|
12 | |
---|
13 | |
---|
14 | def printFramsProperties(v): |
---|
15 | N = v._propCount() |
---|
16 | G = v._groupCount() |
---|
17 | print("======================= '%s' has %d properties in %d group(s). =======================" % (v._class(), N, G)) |
---|
18 | if G < 2: |
---|
19 | # No groups, simply iterate all properties |
---|
20 | for p in range(v._propCount()): |
---|
21 | printSingleProperty(v, p) |
---|
22 | else: |
---|
23 | # Iterate through groups and iterate all props in a group. |
---|
24 | # Why the distinction? |
---|
25 | # First, just to show there are two ways. There is always at least one |
---|
26 | # group so you can always get all properties by iterating the group. |
---|
27 | # Second, groups actually do not exist as collections. Iterating in |
---|
28 | # groups works by checking all properties on each iteration and |
---|
29 | # testing which one is the m-th property of the group! |
---|
30 | # So these inefficient _memberCount() and _groupMember() are provided |
---|
31 | # for the sake of completeness, but don't use them without a good reason ;-) |
---|
32 | for g in range(G): |
---|
33 | print('\n------------------- Group #%d: %s -------------------' % (g, v._groupName(g))) |
---|
34 | for m in range(v._memberCount(g)): |
---|
35 | p = v._groupMember(g, m) |
---|
36 | printSingleProperty(v, p) |
---|
37 | print('\n\n') |
---|
38 | |
---|
39 | |
---|
40 | printFramsProperties(frams.World) |
---|
41 | |
---|
42 | printFramsProperties(frams.GenePools[0].add('X')) # add('X') returns a Genotype object |
---|