There is really a general method build into Dynamics in Mathematica meant for these things. It is the second argument of dynamics.
One can think of the second argument of Dynamics as an event callback. In GUI, this acts exactly as an event callback in traditional GUI programming, where when one changes state of a UI control, a callback is fired, where one can do any needed work to take care of the change of state for that one GUI control.
This method is very general and very flexible. It can be used to make very complex GUI much easier than otherwise. This is how Matlab GUI works also btw. Each control has a callback function. Other GUI frameworks also have this idea. OpenGL
has the callback event and callback registration, etc... In Mathematica, the callback is simply the second argument of Dynamics. Same concept, different name.
It all has this pattern same pattern:
control_object [ Dynamic[x, {x=#, callback_code_goes_here }&], reset_of_control ]
In the above, the control_object
is your SetterBar
, PopupMenu
, etc.....
So, in your case, your call to foo[]
will go where the callback code is. It can be as complex as you want it. It is all part of the Dynamic updating processes.
Here is couple of examples: (I do not have the Initialization code in here to keep it simple)
foo[y_, d_] := Row[{" Hello, you pressed ", y, " on ", d}];
y = 1;
Row[{SetterBar[Dynamic[y, {y = #, r = foo[y, Date[]]} &], Range[5]],Dynamic@r}]

foo2[y_, d_] := Row[{" Hello, your menu selection is ", y, " on ", d}];
y2 = "one";
Row[{PopupMenu[
Dynamic[y2, {y2 = #, r2 = foo2[y2, Date[]]} &], {"one", "two","three"}],Dynamic@r2}]

The point is, there is no need to approach things by looking at each case, and trying to solve each problem in some special way. The above approach is general and can be used to solve all these problems.
ButtonBar
what you are looking for, or I missed the point? Well,SetterBar
is for setting things, no need to expect more than that. Even if there is noButtonBar
I would create my own withBotton
andRow
. $\endgroup$ – Kuba♦ Oct 2 '13 at 18:35ButtonBar[# :> Print[#] & /@ Range[5]]
$\endgroup$ – Kuba♦ Oct 2 '13 at 18:38