source: framspy/frams-test-props.py @ 1158

Last change on this file since 1158 was 1158, checked in by Maciej Komosinski, 2 weeks ago

Cosmetic/minor improvements

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1"""An example of iterating through the properties of an ExtValue object and printing their characteristics."""
2
3import frams
4import sys
5
6frams.init(*(sys.argv[1:]))
7
8
9def printSingleProperty(v, p):
10        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)))
11
12
13def printFramsProperties(v):
14        N = v._propCount()
15        G = v._groupCount()
16        print("======================= '%s' has %d properties in %d group(s). =======================" % (v._class(), N, G))
17        if G < 2:
18                # No groups, simply iterate all properties
19                for p in range(v._propCount()):
20                        printSingleProperty(v, p)
21        else:
22                # Iterate through groups and iterate all props in a group.
23                # Why the distinction?
24                # First, just to show there are two ways. There is always at least one
25                # group so you can always get all properties by iterating the group.
26                # Second, groups actually do not exist as collections. Iterating in
27                # groups works by checking all properties on each iteration and
28                # testing which one is the m-th property of the group!
29                # So these inefficient _memberCount() and _groupMember() are provided
30                # for the sake of completeness, but don't use them without a good reason ;-)
31                for g in range(G):
32                        print('\n------------------- Group #%d: %s -------------------' % (g, v._groupName(g)))
33                        for m in range(v._memberCount(g)):
34                                p = v._groupMember(g, m)
35                                printSingleProperty(v, p)
36        print('\n\n')
37
38
39printFramsProperties(frams.World)
40
41printFramsProperties(frams.GenePools[0].add('X'))  # add('X') returns a Genotype object
Note: See TracBrowser for help on using the repository browser.