I'm building a dynamic module, but I'm stuck with a few things i don't know how to deal with.
In particular I'm stuck with the "If" sentence and the refresh inside the dynamic module.
Here's a little module I've made with the problems I have:
DynamicModule[{x, button, pop, kindselects, importbutton, file,
images}, Dynamic[
Refresh[Panel@
Grid[{{Column[{button, kindselects, importbutton, images},
Center]}}, Alignment -> Top], None]],
Initialization :> (
pop = 1;
kindselects =
Grid[{{PopupMenu[Dynamic@pop, {1, 2}],
"Select which kind of profile you want"}}];
If[pop == 1, {some instructions},
{some other instructions}];
importbutton =
Button["Image import, choose your image here", {file =
SystemDialogInput["FileOpen"], images := Import[file]}];
)
]
This module does two things: imports an image and work on If
sentence.
My first problem is with the image. As you can see, I'm importing the image and showing it in a Grid
. While to import a first image is not a problem, the second image I import is not showed. In my opinion that's because I have the refresh set to None
for this grid. I have it so for other mandatory reasons due to the whole module I'm dealing withbut this is preventing the second image to be shown after being imported.
I'm looking for a way to have some sort of button that, after importing, refreshes the whole thing, but still forcing the None
condition in any other case. The mathematica helper this time is not being so useful, and I'm stuck on this.
The second problem is related with the If. I want my module to be such that when I select from a popup menu an option, it does only a prticular kind of calculations, while does other with another option selected. And moreover I'd like it not to proceed with calculations of the non choosen kind, since they would slow down my dynamics.
Unfortunately my coding skill related with dynamic moduleis is at a really early stage, and I'm actually trying to understand how to make the If
working inside of it...
I've managed this other little module, but it seems that something's not working:
DynamicModule[{x, button, pop, kindselects,}, Dynamic[
Refresh[Panel@
Grid[{{Column[{button, kindselects},
Center]}}, Alignment -> Top], None]],
Initialization :> (
pop = 1;
kindselects =
Grid[{{PopupMenu[Dynamic@pop, {1, 2}],
"Select which kind of profile you want"}}];
Dynamic[x[],
If[pop == 1, x[] = Table[Table[i, {i, 1, 10}], {j, 1, 10}],
x[] = Table[Table[i, {i, 1, 100}], {j, 1, 100}]]];
button = ButtonBar[{"test x" :> (test = x[])}];
)
]
This should return me a different value of test, whose value is set to the one of x[], when the chosen "pop" value is changed via the popup menù, but it's not working at all....
I hope someone can help me with at least one of the two problems.
Thanks a lot,
Andrea
Dynamic
can be tricky, but simply, they trigger when visible (don't put rawDynamic
lines inInitialization
then). p.s. If you want to create some kind of event listener which reacts on PopupMenu setting, take a look atDynamicWrapper
. Try to build interface step by step. And read documentation,Initialization
is done only when DM cell is first time visible in session soIf
statement related to variable changed later has not so much sense. $\endgroup$