I am hoping to create a user interface for performing gaussian fits on two dimensional data. I made a basic grid of various controls and labels. The tool works, but it's much slower than I anticipated, and causes a significant amount of lag when displayed on the screen. I feel like I must be doing something fundamentally wrong, because otherwise I don't see how any complex interface would be usable if such a limited application is slow. My version is 13.0.1.0.
fitConsole[] :=
DynamicModule[{labels, ampCheck = True, x0Check = True,
y0Check = True, wxCheck = True, wyCheck = True, angleCheck = False,
backgroundCheck = True, checkboxes,
fieldsize = {{6, 6}, {1, Infinity}}, amp = 1, x0 = 150, y0 = 120,
wx = 10, wy = 10, ang = 0, background = 0, inputs, controlpanel},
labels = {"Parameter", "Amplitude", "x0", "y0", "wx", "wy", "angle",
"Background"};
checkboxes = {"Float?", Checkbox[Dynamic[ampCheck]],
Checkbox[Dynamic[x0Check]], Checkbox[Dynamic[y0Check]],
Checkbox[Dynamic[wxCheck]], Checkbox[Dynamic[wyCheck]],
Checkbox[Dynamic[angleCheck]], Checkbox[Dynamic[backgroundCheck]]};
inputs = {"Guess Value",
InputField[Dynamic[amp], FieldSize -> fieldsize,
Enabled -> Dynamic[ampCheck]],
InputField[Dynamic[x0], FieldSize -> fieldsize,
Enabled -> Dynamic[x0Check]],
InputField[Dynamic[y0], FieldSize -> fieldsize,
Enabled -> Dynamic[y0Check]],
InputField[Dynamic[wx], FieldSize -> fieldsize,
Enabled -> Dynamic[wxCheck]],
InputField[Dynamic[wy], FieldSize -> fieldsize,
Enabled -> Dynamic[wyCheck]],
InputField[Dynamic[ang], FieldSize -> fieldsize,
Enabled -> Dynamic[angleCheck]],
InputField[Dynamic[background], FieldSize -> fieldsize,
Enabled -> Dynamic[backgroundCheck]]};
controlpanel = Grid[{labels, inputs, checkboxes}, Frame -> True]
]
fitConsole[]
Which produces this output:
Am I right in suspecting I'm making a beginner mistake somewhere here?
As is likely obvious, I will want to use the values of the various Dynamic[] elements in a separate calculation. Currently I think that's difficult with the code as I wrote it because the relevant values (x0 for example) are local to the DynamicModule. Hopefully this is a separate issue from the question I'm asking, which is "Should this code be slowing the front end so much, and can I fix it?"
By slowing the front end i mean that when the panel is displayed on the screen, scrolling through the notebook becomes very choppy and when editting the InputFields, there is noticable lag between pressing a key and the display updating. When the output panel is deleted, this lag stops. When the notebook is scrolled so the panel is no longer visible, the lag stops. I have read though both Introduction to Dynamic and Advanced Dynamic Functionality, and all the examples I've used from those guides has been acceptably responsive compared to my own attempt here. I'm hopeful that the problem is my fault, because otherwise I simply cannot imagine how a much more complex tool like described in this post works : InputField, PasteButton, and Check not playing nicely with each other
Thank you for your time
EDIT:
I found this option which helped dramatically when i changed it from "System" to "Generic"
The options I found in Graphics Options -> RenderingOptions did not seem to affect things much, though the ShowFrameRateCounter was helpful
ValueTrack
CollectTrackEvent` from here: mathematica.stackexchange.com/questions/805/… $\endgroup$