@@ -284,13 +284,15 @@ def disable_synthetic_stages(self, config):
284284 def bind_position_callbacks (self ):
285285 """Binds position_callback() to each axis, records the trace name so we can
286286 unbind later."""
287+ widgets = self .view .get_widgets ()
287288 if not self .position_callbacks_bound :
288289 for axis in ["x" , "y" , "z" , "theta" , "f" ]:
289290 # add event bind to position entry variables
290- cbname = self .widget_vals [axis ].trace_add (
291- "write" , self .position_callback (axis )
292- )
293- self .position_callback_traces [axis ] = cbname
291+ widgets [axis ].widget .bind ("<FocusOut>" , self .position_callback (axis ))
292+ # cbname = self.widget_vals[axis].trace_add(
293+ # "write", self.position_callback(axis)
294+ # )
295+ # self.position_callback_traces[axis] = cbname
294296 self .position_callbacks_bound = True
295297
296298 def unbind_position_callbacks (self ):
@@ -318,13 +320,11 @@ def set_position(self, position):
318320 position : dict
319321 {'x': value, 'y': value, 'z': value, 'theta': value, 'f': value}
320322 """
321- widgets = self .view .get_widgets ()
322323 for axis in ["x" , "y" , "z" , "theta" , "f" ]:
323- self .widget_vals [axis ].set (position .get (axis , 0 ))
324- # validate position value if set through variable
325- if self .stage_limits :
326- widgets [axis ].widget .trigger_focusout_validation ()
327- self .stage_setting_dict [axis ] = position .get (axis , 0 )
324+ if axis not in position :
325+ continue
326+ self .widget_vals [axis ].set (position [axis ])
327+ self .position_callback (axis )()
328328 self .show_verbose_info ("Set stage position" )
329329
330330 def set_position_silent (self , position ):
@@ -335,11 +335,17 @@ def set_position_silent(self, position):
335335 position : dict
336336 {'x': value, 'y': value, 'z': value, 'theta': value, 'f': value}
337337 """
338- self .unbind_position_callbacks ()
339-
340- self .set_position (position )
338+ widgets = self .view .get_widgets ()
339+ for axis in ["x" , "y" , "z" , "theta" , "f" ]:
340+ if axis not in position :
341+ continue
342+ self .widget_vals [axis ].set (position [axis ])
343+ # validate position value if set through variable
344+ if self .stage_limits :
345+ widgets [axis ].widget .trigger_focusout_validation ()
346+ self .stage_setting_dict [axis ] = position .get (axis , 0 )
347+ self .show_verbose_info ("Set stage position" )
341348
342- self .bind_position_callbacks ()
343349
344350 def get_position (self ):
345351 """This function returns current position from the view.
@@ -392,7 +398,7 @@ def handler():
392398 to move."""
393399 stage_direction = - 1 if self .flip_flags [axis ] else 1
394400 try :
395- temp = position_val .get () + step_val .get () * stage_direction
401+ temp = float ( position_val .get () ) + step_val .get () * stage_direction
396402 except tk ._tkinter .TclError :
397403 return
398404 if self .stage_limits is True :
@@ -401,8 +407,9 @@ def handler():
401407 elif temp < self .position_min [axis ]:
402408 temp = self .position_min [axis ]
403409 # guarantee stage won't move out of limits
404- if position_val .get () != temp :
410+ if float ( position_val .get () ) != temp :
405411 position_val .set (temp )
412+ self .position_callback (axis )()
406413
407414 return handler
408415
@@ -432,7 +439,7 @@ def handler():
432439 to move."""
433440 stage_direction = - 1 if self .flip_flags [axis ] else 1
434441 try :
435- temp = position_val .get () - step_val .get () * stage_direction
442+ temp = float ( position_val .get () ) - step_val .get () * stage_direction
436443 except tk ._tkinter .TclError :
437444 return
438445 if self .stage_limits is True :
@@ -441,8 +448,9 @@ def handler():
441448 elif temp > self .position_max [axis ]:
442449 temp = self .position_max [axis ]
443450 # guarantee stage won't move out of limits
444- if position_val .get () != temp :
451+ if float ( position_val .get () ) != temp :
445452 position_val .set (temp )
453+ self .position_callback (axis )()
446454
447455 return handler
448456
@@ -465,6 +473,7 @@ def zero_btn_handler(self, axis):
465473
466474 def handler ():
467475 position_val .set (0 )
476+ self .position_callback (axis )()
468477
469478 return handler
470479
@@ -482,6 +491,8 @@ def xy_zero_btn_handler(self):
482491 def handler ():
483492 x_val .set (0 )
484493 y_val .set (0 )
494+ self .position_callback ("x" )()
495+ self .position_callback ("y" )()
485496
486497 return handler
487498
@@ -547,7 +558,7 @@ def handler(*args):
547558 self .view .after_cancel (self .event_id [axis ])
548559 # if position is not a number, then do not move stage
549560 try :
550- position = position_var .get ()
561+ position = float ( position_var .get () )
551562 if self .stage_limits :
552563 widget .trigger_focusout_validation ()
553564 # if position is not inside limits do not move stage
0 commit comments