I have made many functions that connect to a MySQL database perform operations then export exel spreadsheet. I also import spreadsheet data into the database. I would like to get many of these function into a simple GUI that allows me to do many of these functions easily. I have run into many problems with my little GUI. I have tired to create the simplest code that demo's some of these issues.
Clear[pmWorkHorseTest]
Options[pmWorkHorseTest] = {};
pmWorkHorseTest[opts : OptionsPattern[pmWorkHorseTest]] := Module[{},
CreateWindow[CreateDialog[
Column[{
DynamicModule[{x = 0, t = False, wait, ts, te},
TabView[{
"Method Example" -> Column[{
Row[{
Button["Start", t = True; x = 0; While[t, x++],
Method -> "Queued", Enabled -> Dynamic@Not@t],
Button["Stop", t = False, Method -> "Preemptive",
Enabled -> Dynamic@t],
Button["Stop", t = False, Method -> "Preemptive"],
Button["Stop", t = False, Method -> "Preemptive",
Enabled -> Dynamic@Not@Not@t],
"x=",
Dynamic[Refresh[x, UpdateInterval -> 0]]}]
}],
"Queued/Preemptive Pause" -> Column[{
PopupMenu[Dynamic@wait, Range[10]],
Row[Button[ToString[#], wait = #] & /@ Range[10]],
Row[{"wait =",
Dynamic[Refresh[wait, UpdateInterval -> 0]]}],
Row[{
Button["Queued", Pause[Evaluate@Dynamic@wait],
Method -> "Queued"],
Button["Preemptive", Pause[Dynamic@wait],
Method -> "Preemptive"]
}],
Row[Button["Q: " <> ToString[#], ts = AbsoluteTime[];
Pause[#]; te = AbsoluteTime[],
Method -> "Queued"] & /@ Range[10]],
Row[Button["P " <> ToString[#], Pause[#],
Method -> "Preemptive"] & /@ Range[10]],
Row[{"Time wasted ->", Dynamic[te - ts]}]
}]
}](*End Tabview*)
],(*End DynamicModule*)
DefaultButton["Done", DialogReturn[]]
}]
], WindowTitle -> "AutoPM Work Horse",
DynamicEvaluationTimeout -> 5]
];
pmWorkHorseTest[];
Questions:
- I would like to toggle the
Enabled
state of button as things change. The "Start" button works as expected. But the "Stop" buttons do not. I would have expected the first "Stop" button to toggle its state. But notice that the last "Stop" button does work when I do something sillyEnabled -> Dynamic@Not@Not@t
(The middle "Stop" button is to stop when the others do not work.) What is the best way to mange state? - One of my buttons calls a function that gets data from the database then writes out a spreadsheet. This takes some time. The function by itself works find but the button times out. I have tried
Method -> "Queued"
. Which with the database/spreadsheet function does nothing. WithMethod -> "Preemptive"
it times out. I've tried changingDynamicEvaluationTimeout
but I can't get that to work either. In the example code on the "Queued/Preemptive Pause" tab I try to use buttons that use "Preemptive" and "Queued" where I can pick thePause[]
time. No matter what I have tired I cannot seam to change the Time out time. What is the best way to deal with functions that take a long time? - Also in the "Queued/Preemptive Pause" why can't I use the
Dynamic
value ofwait
to set thePause[wait]
time?