Skip to content

Commit c7f1af6

Browse files
committed
scripts/python/app/NUT-Monitor-py*.in: use the more idiomatic approach to focus order chains [#3514]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent f48164e commit c7f1af6

3 files changed

Lines changed: 46 additions & 24 deletions

File tree

scripts/python/app/NUT-Monitor-py2gtk2.in

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,38 @@ class interface :
297297
self.__widgets["ups_authentication_password"].set_property("can-focus", True)
298298
self.__widgets["ups_connect"].set_property("can-focus", True)
299299

300+
# Set explicit focus chains on containers to ensure TAB/SHIFT-TAB works through all fields
301+
# table1 contains Host, Port, Device, Refresh
302+
self.__widgets["interface"].get_widget("table1").set_focus_chain([
303+
self.__widgets["ups_host_entry"],
304+
self.__widgets["ups_port_entry"],
305+
self.__widgets["ups_list_combo"],
306+
self.__widgets["ups_refresh_button"]
307+
])
308+
# hbox1 contains Login, Password
309+
self.__widgets["interface"].get_widget("hbox1").set_focus_chain([
310+
self.__widgets["ups_authentication_login"],
311+
self.__widgets["ups_authentication_password"]
312+
])
313+
# vbox6 contains table1, checkbutton1, hbox1
314+
self.__widgets["interface"].get_widget("vbox6").set_focus_chain([
315+
self.__widgets["interface"].get_widget("table1"),
316+
self.__widgets["ups_authentication_check"],
317+
self.__widgets["interface"].get_widget("hbox1")
318+
])
319+
# hbox2 contains Connect, Disconnect
320+
self.__widgets["interface"].get_widget("hbox2").set_focus_chain([
321+
self.__widgets["ups_connect"],
322+
self.__widgets["ups_disconnect"]
323+
])
324+
# vbox5 contains vbox6, hbox2
325+
self.__widgets["interface"].get_widget("vbox5").set_focus_chain([
326+
self.__widgets["interface"].get_widget("vbox6"),
327+
self.__widgets["interface"].get_widget("hbox2")
328+
])
329+
300330
# Set initial focus to host field
301331
self.__widgets["ups_host_entry"].grab_focus()
302-
303-
# Chaining focus via move-focus signal or just letting GTK handle it
304-
# since we've ensured they can all focus.
305-
# To be more explicit, we could set the focus chain on their common parents.
306-
# But without knowing the exact hierarchy (which box contains which),
307-
# it's safer to just set the 'tab-next' if we could, but GTK2 doesn't have it.
308-
# However, we can use the 'key-press-event' to override TAB if needed.
309-
# For now, ensuring can-focus is a good first step.
310332
except:
311333
pass
312334

scripts/python/app/NUT-Monitor-py3qt5.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,14 @@ class interface :
248248
#---------------------------------------------------------------
249249

250250
# Set initial tab order
251-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_host_entry"], self.__widgets["ups_port_entry"] )
252-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_port_entry"], self.__widgets["ups_list_combo"] )
253-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_list_combo"], self.__widgets["ups_refresh_button"] )
254-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_refresh_button"], self.__widgets["ups_authentication_check"] )
255-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_authentication_check"], self.__widgets["ups_authentication_login"] )
256-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_authentication_login"], self.__widgets["ups_authentication_password"] )
257-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_authentication_password"], self.__widgets["ups_connect"] )
258-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_connect"], self.__widgets["ups_host_entry"] )
251+
QWidget.setTabOrder( self.__widgets["ups_host_entry"], self.__widgets["ups_port_entry"] )
252+
QWidget.setTabOrder( self.__widgets["ups_port_entry"], self.__widgets["ups_list_combo"] )
253+
QWidget.setTabOrder( self.__widgets["ups_list_combo"], self.__widgets["ups_refresh_button"] )
254+
QWidget.setTabOrder( self.__widgets["ups_refresh_button"], self.__widgets["ups_authentication_check"] )
255+
QWidget.setTabOrder( self.__widgets["ups_authentication_check"], self.__widgets["ups_authentication_login"] )
256+
QWidget.setTabOrder( self.__widgets["ups_authentication_login"], self.__widgets["ups_authentication_password"] )
257+
QWidget.setTabOrder( self.__widgets["ups_authentication_password"], self.__widgets["ups_connect"] )
258+
QWidget.setTabOrder( self.__widgets["ups_connect"], self.__widgets["ups_host_entry"] )
259259

260260
# Set initial focus to host field
261261
self.__widgets["ups_host_entry"].setFocus()

scripts/python/app/NUT-Monitor-py3qt6.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ class interface :
251251
#---------------------------------------------------------------
252252

253253
# Set initial tab order
254-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_host_entry"], self.__widgets["ups_port_entry"] )
255-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_port_entry"], self.__widgets["ups_list_combo"] )
256-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_list_combo"], self.__widgets["ups_refresh_button"] )
257-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_refresh_button"], self.__widgets["ups_authentication_check"] )
258-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_authentication_check"], self.__widgets["ups_authentication_login"] )
259-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_authentication_login"], self.__widgets["ups_authentication_password"] )
260-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_authentication_password"], self.__widgets["ups_connect"] )
261-
self.__widgets["interface"].setTabOrder( self.__widgets["ups_connect"], self.__widgets["ups_host_entry"] )
254+
QWidget.setTabOrder( self.__widgets["ups_host_entry"], self.__widgets["ups_port_entry"] )
255+
QWidget.setTabOrder( self.__widgets["ups_port_entry"], self.__widgets["ups_list_combo"] )
256+
QWidget.setTabOrder( self.__widgets["ups_list_combo"], self.__widgets["ups_refresh_button"] )
257+
QWidget.setTabOrder( self.__widgets["ups_refresh_button"], self.__widgets["ups_authentication_check"] )
258+
QWidget.setTabOrder( self.__widgets["ups_authentication_check"], self.__widgets["ups_authentication_login"] )
259+
QWidget.setTabOrder( self.__widgets["ups_authentication_login"], self.__widgets["ups_authentication_password"] )
260+
QWidget.setTabOrder( self.__widgets["ups_authentication_password"], self.__widgets["ups_connect"] )
261+
QWidget.setTabOrder( self.__widgets["ups_connect"], self.__widgets["ups_host_entry"] )
262262

263263
# Set initial focus to host field
264264
self.__widgets["ups_host_entry"].setFocus()

0 commit comments

Comments
 (0)