Skip to content

Conversation

Baharis
Copy link
Member

@Baharis Baharis commented Sep 20, 2025

Introduces minor changes to the manual control panel aimed to add magnification buttons suggested by @viljarjf in #140 and tighten it a bit, both in terms of code quality/quantity and space taken in the GUI:

  • "Modes" drawback now pulls modes from config instead of using hard-coded ['diff', 'mag1', 'mag2', 'lowmag', 'samag'];
  • "Reset stage" button that otherwise took entire line was moved to the top of the frame, next to other buttons;
  • "Stage (XY)" fields were changed from Entry to Spinbox with 100-nm increment to allow setting with mouse;
  • Wobbler control changed from two mutually-exclusive buttons (Start/Stop) to a checkbutton akin defocus;
  • Magnification "+" and "–" buttons added (@viljarjf );
  • Removed spacing between brightness and focus controls – now the "mechanical" and "beam" controls are split neatly;
  • Fixed minor typos and spacing inconsistencies, generalized some methods.
Before After
image image

Note how the refreshed panel has the same height as the old one despite having a new row.

When I started editing I had large changes in mind, but I decided to scale them down and leave the spotlight on the simulator for the time being. On accident, I also found out that repeatedly turning the alpha wobbler on and off consistently crashes Instamatic. Could not fix it quickly, this is a low-priority issue for the future.

@Baharis Baharis self-assigned this Sep 20, 2025
Copy link
Member

@stefsmeets stefsmeets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, love to see this little panel get some love.

Comment on lines 40 to 41
ranges = config.microscope.ranges
modes = list(ranges.keys())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python always iterates over the dict keys, so it's not necessary to call keys.

Suggested change
ranges = config.microscope.ranges
modes = list(ranges.keys())
modes = list(config.microscope.ranges)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The panels gets only as much love as time I can spare now, unfortunately.
Also, as import this verse 2 proclaimeth, Explicit is better than implicit

Copy link
Contributor

@viljarjf viljarjf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I had some minor comments, but otherwise I think these are useful additions!

One thing I noticed reading through the file is the inconsistency of using the event queue or simply changing things directly in self.ctrl. Is that something to consider? I am not familiar with how the GUI is set up, especially regarding multiple threads/communication with servers

Comment on lines 40 to 43
ranges = config.microscope.ranges
modes = list(ranges.keys())
self.o_mode = OptionMenu(frame, self.var_mode, modes[0], *modes, command=self.set_mode)
self.o_mode.grid(row=8, column=1, sticky='EW')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed when playing around with simulations is that the initial value for the dropdown is not the actual initial value on the microscope (at least using the simulation microscope). I also just noticed that the names of the different modes are inconsistent between FEI and JEOL microscopes, but your implementation here accounts for that.

self.ctrl is only populated in the end of the constructor, so I don't think we can get the initial mode without moving self.ctrl to the start of the constructor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viljarjf Yea, the values were hardcoded here so I suggest pulling them from config. I am not sure why self.ctrl is at the end, I checked and it works at the beginning at least on the simulator. This prevents nice larger changes. @stefsmeets do you remember?

self.ctrl.magnification.decrease()

def reset_stage(self):
self.ctrl.stage.set(0, 0, 0, 0, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctrl.stage.neutral() also exists, but it does exactly the same

Comment on lines +155 to +156
# Magnification
Label(frame, text='Magnification', width=20).grid(row=14, column=0, sticky='W')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any merit to displaying the magnification value as well? Increasing and decreasing with buttons is the way to go I think, but at least for the sim microscope it is useful to see the actual magnification too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@viljarjf I absolutely wanted to display this value and the traces of this idea are in the code (see explicit declaration of ranges = config.microscope.ranges dict with this info) but once I started implementing it I noticed this requires a lot of changes, so I backpedaled for now. Maybe I'll add a print at least.

@stefsmeets
Copy link
Member

One thing I noticed reading through the file is the inconsistency of using the event queue or simply changing things directly in self.ctrl. Is that something to consider? I am not familiar with how the GUI is set up, especially regarding multiple threads/communication with servers

If you directly update ctrl you block the gui completely. By putting it on the queue the task gets handled by a different (non-ui) thread so that the ui remains responsive. It's a good catch though, and it's better to set the task on self.q.

@viljarjf viljarjf mentioned this pull request Sep 22, 2025
Co-authored-by: Viljar Femoen <viljar.femoen@hotmail.no>
@Baharis Baharis marked this pull request as ready for review September 22, 2025 11:54
@Baharis
Copy link
Member Author

Baharis commented Sep 22, 2025

Ok, I applied suggested changes and will be merging tomorrow-ish unless anyone objects. I added print statements on magnification change, ctrl.stage.neutral() instead of setting zeroes, and removed unnecessary declaration. This is by no means a major definitive rework, just a small patch to help testing simulator based on @viljarjf's suggestion.

@Baharis
Copy link
Member Author

Baharis commented Sep 22, 2025

Following #141 testing session, I added another window for stage Z position in line with X and Y. This makes the panel contents slightly wider, but as I discovered is very useful even for simulation.

@Baharis Baharis merged commit 61a3bdb into instamatic-dev:main Sep 23, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants