MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Linking EventHandler to a Control Object

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88762] Re: Linking EventHandler to a Control Object
  • From: Januk <ggroup at sarj.ca>
  • Date: Fri, 16 May 2008 05:29:48 -0400 (EDT)
  • References: <g0bt5i$o4l$1@smc.vnet.net>

Hi Todd,

I'm not entirely sure that I understood your precise goal, but you
might try something along the lines of the following.  Use a helper
function and the ability to trigger functions from Dynamic statements:

updateColours := Module[{temp2},
   (color = color /. {Black -> Red, Red -> Green, Green -> Black};
    temp2 = Position[test2, trak2];
    test2 = ReplacePart[test2, temp2 -> Style[trak2, color]];)
   ];

trak2 = SetterBar[
  Evaluate@Dynamic[trak2, (trak2 = #; updateColours) &],
  {"Phe" -> "Phe", "Ser" -> "Ser", "Leu" -> "Leu", "Val" -> "Val"}]
test2 = {"Phe", "Ser", "Leu", "Ser", "Val"}; color = Black;
EventHandler[{Dynamic[trak2], Dynamic[test2]}, {"MouseClicked" :>
updateColours}]

Hope that helps,
Januk

On May 13, 7:13 am, Todd Allen <genesplice... at yahoo.com> wrote:
> Hi folks,
>
>    Have any of you tried to use the new
> (V6)EventHandler command to excute a series of actions
> based on input to a control object such as SetterBar?
>
>    I have had success getting Mathematica to update a
> displayed list every time the displayed list is
> clicked on, but not when I want a control object to be
> clicked on to update the displayed list.
>
>    Probably an example would help clarify:
>
> Example 1: WORKS on my computer
>
> test1 = {"Phe", "Ser", "Leu", "Ser",
>   "Val"}; color = Black; trak = "Ser";
> EventHandler[
>  Dynamic[test1], {"MouseClicked" :> (color =
>      color /. {Black -> Red, Red -> Green, Green ->
> Black};
>     temp1 = Position[test1, trak];
>     test1 = ReplacePart[test1, temp1 -> Style[trak,
> color]];)}]
>
> Example 2: Does NOT work
>
> trak2 = SetterBar[
>   Evaluate[Dynamic[trak2]], {"Phe" -> "Phe", "Ser" ->
> "Ser",
>    "Leu" -> "Leu", "Val" -> "Val"}]
> test2 = {"Phe", "Ser", "Leu", "Ser", "Val"}; color =
> Black;
> EventHandler[{Dynamic[trak2],
>   Dynamic[test2]}, {"MouseClicked" :> (color =
>      color /. {Black -> Red, Red -> Green, Green ->
> Black};
>     temp2 = Position[test2, trak2];
>     test2 = ReplacePart[test2, temp2 -> Style[trak2,
> color]]; test2)}]
>
> Notice how the SetterBar in example 2 is updated, but
> the corresponding list that should be updated is not.
> Its as though the EventHandler command is actually not
> "seeing" the mouse click.
>
> Would you have any thoughts on how to link the input
> at the control object to the desired response of
> updating a displayed list?
>
> Thanks for any advice you might have!
> Todd
>
>       ______________________________________________________________=
_____________=AD_________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/=
;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ



  • Prev by Date: Re: Applying the Integration Function to a List Of Regions
  • Next by Date: Re: DSolve question
  • Previous by thread: Linking EventHandler to a Control Object
  • Next by thread: Testing TOC sidebar palette