So the way to go is to use timeout (or setInterval in javascript). Thanks
Rolf!

On 3 August 2015 at 10:56, Rolf Huehne <rhue...@fli-leibniz.de> wrote:

> On 08/03/2015 03:38 PM, tremato...@gmail.com wrote:
> > I'm doing something like you said:
> >
> > var checkHover;
> > function hoverCallback(a,b,c,d){
> > if(checkHover)
> > clearInterval(checkHover);
> > var res = b.split('.')[0];//get everything until first "."
> > Jmol.script(myJmolOb, 'select '+ res +' ; halo on;');
> >          checkHover = setInterval(function() {
> > Jmol.script(myJmolOb, 'select '+ res +' ; halo off;');
> > }, 1000);
> > }
> >
> >
> > What I did is, every call I cancel the setInterval, then I set the
> > highlight (I'm using halo on here) and finally I start setInterval again.
> > So in the last call (when I move out) the setInterval will not be
> canceled
> > being called after 1 second. It's working.
> >
> > That's really how hovercallback works? This behavior to keep calling the
> > listener also to do not call when move out?
> >
> I obviously didn't remember it correctly and forgot about the timout stuff.
>
> My implementation below works completely within Jmol without any
> Javascript. One advantage of this is that it also works in the Jmol
> application. The 'halo' color is changed to distinguish the 'hover halo'
> from a yellow 'selection halo' which might be already there before the
> 'hover' (setting: "selectionHalos on").
> It took me some time to figure out how to avoid flickering because the
> callback might be fired multiple times for the same atom if the mouse
> pointer rests longer above it. This might not be a problem if
> activating/deactivating the halo is the only action. But in my case
> there was some more stuff which I stripped out here.
> While stripping out the additional stuff I realized that there might
> occur a problem if the 'lastAtomIndexHovered' variable would change too
> fast, although I never observed any problem with it yet. But maybe it
> would be better to provide the atomIndex as a second parameter in the
> "hoverAction('end')" call.
>
> ------ Jmolscript hover callback implementation ---------------
> lastAtomIndexHovered = -1;
> lastHoverUnfinished  = false;
> hoverTimeoutId       = "";
>
> function hoverAction(action) {
>    #print "action=" + action + "  hoverId=" + hoverTimeoutId;
>    if (hoverTimeoutId != "") {
>      timeout ID @hoverTimeoutId off;
>      hoverTimeoutId = "";
>    }
>    var switchOff        = false;
>    var currentSelection = {selected};
>
>    if (action == "end") {
>      if (lastHoverUnfinished) {
>        switchOff = true;
>      }
>    } elseif (action == "start") {
>      if (lastHoverUnfinished) {
>        if (lastAtomIndexHovered != _atomhovered) {
>          switchOff = true;
>        }
>      }
>    }
>
>    #print "action=" + action + "  switchOff=" + switchOff + "
> lastHoverUnfinished=" + lastHoverUnfinished + "  lastAtomIndexHovered="
> + lastAtomIndexHovered + "  _atomhovered=" + _atomhovered;
>
>    if (switchOff) {
>      if (lastAtomIndexHovered >= 0) {
>        select atomindex=@lastAtomIndexHovered;
>        color halo yellow;
>        halo off;
>      }
>      lastAtomIndexHovered = -1;
>      lastHoverUnfinished  = false;
>    }
>
>    if (_atomhovered >= 0 && action == "start") {
>      lastAtomIndexHovered = _atomhovered;
>      select atomindex=@lastAtomIndexHovered;
>      color halo cyan;
>      halo on;
>      lastHoverUnfinished  = true;
>      hoverTimeoutId = "hoverEnd_" + now();
>      timeout ID @hoverTimeoutId 1.0 "hoverAction('end')";
>    }
>
>    select @currentSelection;
> }
>
> set hoverCallback "jmolscript: hoverAction('start');";
> -------------------------------------------------------
>
> Regards,
> Rolf
> --
>
> Rolf Huehne
> Postdoc
>
> Leibniz Institute for Age Research - Fritz Lipmann Institute (FLI)
> Beutenbergstrasse 11
> 07745 Jena, Germany
>
> Phone:   +49 3641 65 6205
> Fax:     +49 3641 65 6210
> E-Mail:  rhue...@fli-leibniz.de
> Website: http://www.fli-leibniz.de
>
>            Scientific Director: Prof. Dr. K. Lenhard Rudolph
>         Head of Administration: Dr. Daniele Barthel
> Chairman of Board of Trustees: Dennys Klein
>
> VAT No: DE 153 925 464
> Register of Associations: No. 230296, Amtsgericht Jena
> Tax Number: 162/141/08228
>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Jmol-users mailing list
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
------------------------------------------------------------------------------
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to