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

Last change on this file since 1161 was 1158, checked in by Maciej Komosinski, 4 years ago

Cosmetic/minor improvements

  • Property svn:eol-style set to native
File size: 1.6 KB
RevLine 
[1158]1"""An example of iterating through the properties of an ExtValue object and printing their characteristics."""
2
[1151]3import frams
4import sys
5
6frams.init(*(sys.argv[1:]))
7
8
[1158]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)))
[1151]11
[1158]12
[1151]13def printFramsProperties(v):
[1158]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
[1151]19                for p in range(v._propCount()):
[1158]20                        printSingleProperty(v, p)
[1151]21        else:
[1158]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 ;-)
[1151]31                for g in range(G):
[1158]32                        print('\n------------------- Group #%d: %s -------------------' % (g, v._groupName(g)))
[1151]33                        for m in range(v._memberCount(g)):
[1158]34                                p = v._groupMember(g, m)
35                                printSingleProperty(v, p)
36        print('\n\n')
[1151]37
38
[1158]39printFramsProperties(frams.World)
[1151]40
[1158]41printFramsProperties(frams.GenePools[0].add('X'))  # add('X') returns a Genotype object
Note: See TracBrowser for help on using the repository browser.