How to use the vpython.vpython.baseObj.glow.comm.send function in vpython

To help you get started, we’ve selected a few vpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpython / vpython-jupyter / vpython / vpython.py View on Github external
if 'attr' in commcmds[L]: del commcmds[L]['attr'] # if left over from previous use of slot
                    method = m[0]
                    data = m[1]
                    commcmds[L]['idx'] = ob.idx
                    commcmds[L]['method'] = method
                    if method == 'add_to_trail': data = data.value
                    commcmds[L]['val'] = data
                    L += 1
                ob.methodsupdt = []
                
            if L > baseObj.qSize:
                baseObj.glow.comm.send(encode_attr(commcmds[:L]))  # Send attributes and methods to glowcomm
                L = 0
                
        if L > 0:
            baseObj.glow.comm.send(encode_attr(commcmds[:L]))  # Send attributes and methods to glowcomm

    finally:
        _sent = True
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
# to send another signal to Python. If trigger() finds rate.active to be False, it
    # calls commsend(), otherwise it checks to see whether there it has been several rate
    # periods since the last execution of a rate statement, which indicates that the loop
    # that contained the rate statement has exited, in which case trigger() calls commsend().
    # Note that a typical VPython program starts out by creating objects (constructors) and
    # specifying their attributes. The 30 ms signal from the browser is adequate to ensure
    # prompt data transmissions to the browser. Following this setup phase of the user
    # program, a rate statement is encountered, wich calls sendtofrontend() which sets
    # rate.active to True, thereby blocking trigger() from interfering with sendtofrontend's
    # own calls to commsend().
    
    global commcmds, _sent
    _sent = False
    try:
        if len(baseObj.cmds) > 0:
            baseObj.glow.comm.send(baseObj.cmds)
            baseObj.cmds = []

        ## update every attach_arrow if relevant vector has changed    
        for aa in attach_arrows:
            ob = object_registry[aa._obj]
            vval = getattr(ob, aa._attr)
            if not isinstance(vval, vector):
                continue
            if (isinstance(aa._last_val, vector) and aa._last_val.equals(vval)) :
                continue
            ob.addattr(aa._attr)
            aa._last_val = vval
            
        ## update every attach_trail that depends on a function
        for aa in attach_trails:
            if aa._obj == '_funcvalue':
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
L += 1
                            
            if (ob is not None) and (hasattr(ob,'methodsupdt')) and (len(ob.methodsupdt) > 0 ):
                for m in ob.methodsupdt: # a list
                    if 'attr' in commcmds[L]: del commcmds[L]['attr'] # if left over from previous use of slot
                    method = m[0]
                    data = m[1]
                    commcmds[L]['idx'] = ob.idx
                    commcmds[L]['method'] = method
                    if method == 'add_to_trail': data = data.value
                    commcmds[L]['val'] = data
                    L += 1
                ob.methodsupdt = []
                
            if L > baseObj.qSize:
                baseObj.glow.comm.send(encode_attr(commcmds[:L]))  # Send attributes and methods to glowcomm
                L = 0
                
        if L > 0:
            baseObj.glow.comm.send(encode_attr(commcmds[:L]))  # Send attributes and methods to glowcomm

    finally:
        _sent = True
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def trigger(): # called by a canvas update event from browser
    if rate.active:
        dt = clock() - rate.lasttime # time elapsed since last time sendtofrontend was executed
        if dt > 5/rate.rval:
            rate.active = False
    length = len(baseObj.cmds)
    if _sent and (not rate.active): # don't interrupt commsend; don't call if rate is handling updates
        commsend()
    baseObj.glow.comm.send([{'trigger':1, '_pass':1, 'len1':length, 'len2':len(baseObj.cmds)}])
github vpython / vpython-jupyter / vpython / vpython.py View on Github external
def delete(self):
        baseObj.decrObjCnt()
        cmd = {"cmd": "delete", "idx": self.idx}
        if (baseObj.glow != None):
            baseObj.glow.comm.send([cmd])
        else:
            self.appendcmd(cmd)
        #baseObj.cmds.append(cmd)