Some time ago I wrote a desktop application using Python 2 and PyGTK 2. Recently I have been working on updating it to work with Python 3 and PyGObject and GTK3. In one part of this application I use set_focus_chain() to control which widgets automatically receive keyboard focus when pressing the TAB key or the Up or Down arrows.
Below I have pasted a short program that illustrates my use of set_focus_chain(). Note that the TAB key moves the keyboard focus from Entry to Entry, skipping both buttons in each frame. Also, pressing the Up and Down arrows moves the keyboard focus to the entry above or below (if possible).
This all works very well. However, the documentation for set_focus_chain() says that it is deprecated since version 3.24, and that one should use the “focus” signal instead. How would one accomplish the same thing using the “focus” signal instead?
Thank you very much for your help!
James
#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
win = Gtk.Window()
win.set_border_width(5)
win.connect("destroy", Gtk.main_quit)
grid = Gtk.Grid(row_spacing=15, column_spacing=15)
for i in range(3):
for j in range(3):
frame = Gtk.Frame(label="Col: "+str(i)+" Row: "+str(j))
grid.attach(frame, i, j, 1, 1)
frame.show()
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_border_width(5)
frame.add(vbox)
vbox.show()
hbox = Gtk.Box()
vbox.set_focus_chain([hbox])
vbox.pack_start(hbox, False, False, 0)
hbox.show()
entry = Gtk.Entry()
hbox.set_focus_chain([entry])
entry.set_width_chars(10)
hbox.pack_start(entry, False, False, 0)
entry.show()
button1 = Gtk.Button.new_with_label("Label1")
hbox.pack_start(button1, False, False, 0)
button1.show()
button2 = Gtk.Button.new_with_label("Label2")
vbox.pack_start(button2, False, False, 0)
button2.show()
win.add(grid)
grid.show()
win.show()
Gtk.main()