0

Mu to Python

I am trying to use the recordPixelInfo(event) within a def pointerLocation(self, event) function.  This seg faults so I trying to replicate the function to see where it is going wrong as:


    def recordPixelInfoTEST(self, event):
        print "--------- recordPixelInfoTEST"
        state = data()
        print dir(data())
        setActiveState()
        pi = imagesAtPixel(event.pointer(), "", True)
    
        if pi and state.pixelInfo:
            if not pi.size() == state.pixelInfo.size():
                redraw()
            else:
                #for_index (i; pi)
                print "--------- pi = %s" % pi
                if not pi[i].name == state.pixelInfo[i].name:
                    redraw()
                    #break
        elif pi or state.pixelInfo:
            redraw()

          .............

 

"state = data()"  seems to make a blank state with no properties such that state.pixelInfo is undefined and it errors.  I have been through the mu code and cannot figure this out.

Help greatly appreciated.

1 条评论

  • 0
    Avatar
    Jon Morley

    Hi Dominique,

    The state object does not have symmetric access from Mu and Python and that call you have there only works from Mu. Therefore if you want to get access to things like the pixelInfo you will need to make use of the Mu/Python runtime bridge like so:

    from rv import runtime

    pinfoName = runtime.eval ("{rvtypes.State s = commands.data(); s.pixelInfo.front().name;}", ["commands", "rvtypes"])
    pinfoPX = runtime.eval ("{rvtypes.State s = commands.data(); s.pixelInfo.front().px;}", ["commands", "rvtypes"])
    pinfoPY = runtime.eval ("{rvtypes.State s = commands.data(); s.pixelInfo.front().py;}", ["commands", "rvtypes"])

    Note that everything returned from runtime is a string so you will have to cast the return values if you want to use the result as an integer, boolean, or float.

    Give this a shot and let me know if that will work.

    Thanks,

    Jon

请先登录再写评论。