diff --git a/commands/update_gui.py b/commands/update_gui.py index a68b89bf..5e1921d9 100644 --- a/commands/update_gui.py +++ b/commands/update_gui.py @@ -162,13 +162,19 @@ def __init__(self, parent, tdb, tdenv): parent.wm_attributes("-topmost", sticky) + def selectWidget(self, widget, newValue=None): + if newValue is not None: + widget.val.set(newValue) + widget.focus_set() + widget.selection_range(0, tk.END) + + def focusOn(self, displayNo, pos): """ Set focus to a widget and select the text in it """ row = self.itemDisplays[displayNo] widget = row[pos][0] - widget.focus_set() - widget.selection_range(0, tk.END) + self.selectWidget(widget) def setValue(self, row, pos, value): @@ -230,8 +236,7 @@ def checkValueAgainstStats(self, widget, stats): cr, minCr, )) if not ok: - widget.val.set("") - widget.focus_set() + self.selectWidget(widget, "") return False widget.configure(bg = '#ff8080') @@ -248,8 +253,7 @@ def checkValueAgainstStats(self, widget, stats): cr, maxCr, )) if not ok: - widget.val.set("") - widget.focus_set() + self.selectWidget(widget, "") return False widget.configure(bg = '#8080ff') @@ -343,8 +347,7 @@ def validate(self, widget): parent=widget, ) if not ok: - widget.val.set("") - widget.focus_set() + self.selectWidget(widget, "") return False return True @@ -373,6 +376,7 @@ def validate(self, widget): "EXAMPLE: If the UI says '2341 LOW', type '2341L'.\n" ) widget.val.set("?") + self.selectWidget(widget) return False return True