Exemplo n.º 1
0
 def func2((elt, subindex)): #070320
     if is_expr_Instance(elt):
         res = elt
     elif is_pure_expr(elt):
         # new feature 070320: if function(element) gives an expr, instantiate it with a suitable choice of index
         eli = self.instance_function( elt, (subindex, index), permit_expr_to_vary = True)
         assert is_expr_Instance(eli) #e error message with elt and eli
         res = eli
     else:
         assert is_expr_Instance(elt) or is_pure_expr(elt) #e message
     assert is_expr_Instance(res) # sanity check, can remove when works
     return res
Exemplo n.º 2
0
def mt_node_id(
    node
):  # 070207; the name 'node_id' itself conflicts with a function in Utility.py (which we import and use here, btw)
    """
    return the mt_node_id property of the node, regardless of which
    model tree node interface it's trying to use [slight kluge]
    """
    # look for value of ModelTreeNodeInterface attr
    try:
        node.mt_node_id
    except AttributeError:
        pass
    else:
        if print_mt_node_id:
            print "this node %r has mt_node_id %r" % (node, node.mt_node_id)
            # old Q: where do our Rects get it?
            # A: they don't -- the bug fixed by bugfix070218 meant this was never called except for World!!
            # [note: on 070302 the comments about bugfix070218, and the code affected by it, was rewritten and removed
            #  (becoming MapListToExpr).
            #  it might still be in an outtakes file not in cvs on bruce's g5 -- or in cvs rev 1.21 or earlier of this file.]
            # btw, we want it to be for the
            # underlying model object... sort of like how we ask for name or type... [bug noticed 070218 late; see below comment]
        return node.mt_node_id


##    assert not is_expr_Instance(node), "what node is this? %r" % (node,) # most to the point
    if is_expr_Instance(node):
        # All Instances ought to have that, or delegate to something which does -- which ought to be their contained ModelObject.
        ####FIX SOMETIME (implem that properly)
        # Until that's implemented properly (hard now -- see _e_model_type_you_make for the hoops you have to jump thru now),
        # use the ipath (non-ideal, since captures wrappers like Draggable etc, but tolerable,
        # esp since this effectively means use the world-index, which will work ok for now [070218 late])
        return node.ipath  ###e should intern it as optim

    assert not is_Expr(
        node), "pure exprs like %r don't belong as nodes in the model tree" % (
            node, )

    # look for legacy Node property
    from foundation.Utility import node_id
    res = node_id(
        node
    )  # not sure what to do if this fails -- let it be an error for now -- consider using id(node) if we need to
    if print_mt_node_id:
        print "legacy node %r has effective mt_node_id %r" % (node, res)
    return res
Exemplo n.º 3
0
def mt_node_id(
    node
):  # 070207; the name 'node_id' itself conflicts with a function in Utility.py (which we import and use here, btw)
    """
    return the mt_node_id property of the node, regardless of which
    model tree node interface it's trying to use [slight kluge]
    """
    # look for value of ModelTreeNodeInterface attr
    try:
        node.mt_node_id
    except AttributeError:
        pass
    else:
        if print_mt_node_id:
            print "this node %r has mt_node_id %r" % (node, node.mt_node_id)
            # old Q: where do our Rects get it?
            # A: they don't -- the bug fixed by bugfix070218 meant this was never called except for World!!
            # [note: on 070302 the comments about bugfix070218, and the code affected by it, was rewritten and removed
            #  (becoming MapListToExpr).
            #  it might still be in an outtakes file not in cvs on bruce's g5 -- or in cvs rev 1.21 or earlier of this file.]
            # btw, we want it to be for the
            # underlying model object... sort of like how we ask for name or type... [bug noticed 070218 late; see below comment]
        return node.mt_node_id

    ##    assert not is_expr_Instance(node), "what node is this? %r" % (node,) # most to the point
    if is_expr_Instance(node):
        # All Instances ought to have that, or delegate to something which does -- which ought to be their contained ModelObject.
        ####FIX SOMETIME (implem that properly)
        # Until that's implemented properly (hard now -- see _e_model_type_you_make for the hoops you have to jump thru now),
        # use the ipath (non-ideal, since captures wrappers like Draggable etc, but tolerable,
        # esp since this effectively means use the world-index, which will work ok for now [070218 late])
        return node.ipath  ###e should intern it as optim

    assert not is_Expr(node), "pure exprs like %r don't belong as nodes in the model tree" % (node,)

    # look for legacy Node property
    from foundation.Utility import node_id

    res = node_id(
        node
    )  # not sure what to do if this fails -- let it be an error for now -- consider using id(node) if we need to
    if print_mt_node_id:
        print "legacy node %r has effective mt_node_id %r" % (node, res)
    return res