B8vrede
B8vrede

Reputation: 4532

GTK Focus Chain

Currently I'm working on a pyGTK3 application for which I want to set the focus chain. When using the code below (simplified version) something interesting happens GTK focuses correctly on the first button but on tab nothing happens.

At first I thought this was caused by GTK not knowing the chain, but then I tried shift+tab which resulted in the last element of the chain get the focus which is correct. Yet another shift+tab doesn't move the focus away from the last button.

So I figured that their is something wrong with my code, do I need to update the chain order by hand? Or I am missing something?

class Screen(Gtk.Grid):
  def __init__(self, parent, core, video_widget):
    Gtk.Grid.__init__(self)

    # adds the control buttons
    self.controls = load_controls(self)

    self.set_focus_chain((self.controls.play, self.controls.backward, self.controls.recording))

Upvotes: 3

Views: 1339

Answers (1)

B8vrede
B8vrede

Reputation: 4532

In order to set the focus chain for elements within containers it is required to first set the focus chain of the parent to the container. From there the focus chain for the container needs to be set.

Thus the code needs to be as follows:

# Points Gtk toward the container first
self.set_focus_chain([self.controls]) 

# Sets the focus chain inside the container
self.controls.set_focus_chain((self.controls.play, self.controls.backward, self.controls.recording, self.controls.end_inspection))

So it seems that GTK only allows focus chains towards children thus requiring users to set a chain of focus chain to set the focus chain to grand children.

Upvotes: 1

Related Questions