mjhoptics / ray-optics

geometric ray tracing for optical systems
BSD 3-Clause "New" or "Revised" License
269 stars 57 forks source link

plotview: parse plot user scale, etc with float #14

Closed ajeddeloh closed 3 years ago

ajeddeloh commented 3 years ago

Use float() instead of eval() to parse user input. This prevents a lot of crashes and generally insures the data entered is numeric.

It does prevent the user from doing calculations in the text box however.

Originally I thought eval() was being used to allow referencing variables defined elsewhere, but then I learned that eval() does not include any variables in the environment by default.

Also switched from the 7.4f format to .7g which is probably what users expect.

Fixes https://github.com/mjhoptics/ray-optics/issues/13

PR marked as draft until I hunt down all the text boxes that act the same way.

ajeddeloh commented 3 years ago

Reworked dockpanels too. Hopefully its clear what's going on in the new code. As a bonus by using the QDoubleValidator we don't even need to worry about data entered not being numeric.

ajeddeloh commented 3 years ago

I added some more comments, hopefully it's more clear now.

setitem is needed instead of setattr for when the parent of the part of the model being set is a list (and thus the "field" being set is a list index). This is used when setting things in the wavelengths list.