0
$\begingroup$

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:

fitConsole 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" enter image description here

The options I found in Graphics Options -> RenderingOptions did not seem to affect things much, though the ShowFrameRateCounter was helpful

$\endgroup$
4
  • $\begingroup$ It seems to be working without any delays when I try it. Did you try to restart your kernel and try it? One way that that behavior happens when a Dynamic inside your DynamicModule is causing something the constantly redisplay. $\endgroup$ Commented Jun 13, 2023 at 7:39
  • $\begingroup$ Thank you for your response Craig. I have indeed restarted the kernal, and in fact restarted my machine entirely. If you can see anything in the code that would cause something to constantly redisplay, that would be informative, but I don't see anything myself. I did find a setting in the option inspector->Formatting Options->Expression Formatting->ControlsRendering, which I changed from "System" to "Generic" and was rewarded with a 5x increase in frame rate at the cost of a minor cosmetic change. I'll update my question with that information $\endgroup$ Commented Jun 13, 2023 at 19:55
  • $\begingroup$ If changing that option helped, you should investigate upgrading your video card driver. $\endgroup$
    – ihojnicki
    Commented Jun 13, 2023 at 20:57
  • $\begingroup$ You might also check out ValueTrackCollectTrackEvent` from here: mathematica.stackexchange.com/questions/805/… $\endgroup$ Commented Jun 14, 2023 at 11:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.