GTK 焦点链
GTK Focus Chain
目前我正在开发一个 pyGTK3 应用程序,我想为其设置焦点链。当使用下面的代码(简化版)时,会发生一些有趣的事情 GTK 正确地聚焦在第一个按钮上,但在 tab 上没有任何反应。
一开始我以为是GTK不知道这个链导致的,后来我尝试了shift+tab 导致了链的最后一个元素获得正确的焦点。还有一个 shift+tab 不会将焦点从最后一个按钮移开。
所以我认为他们的代码有问题,我需要手动更新链顺序吗?或者我遗漏了什么?
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))
要为容器内的元素设置焦点链,需要先将父元素的焦点链设置到容器。从那里需要设置容器的焦点链。
因此代码需要如下:
# 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))
所以好像GTK只允许focus chains指向children因此需要用户设置一个chain of focus chain来设置focus chain to grand children
目前我正在开发一个 pyGTK3 应用程序,我想为其设置焦点链。当使用下面的代码(简化版)时,会发生一些有趣的事情 GTK 正确地聚焦在第一个按钮上,但在 tab 上没有任何反应。
一开始我以为是GTK不知道这个链导致的,后来我尝试了shift+tab 导致了链的最后一个元素获得正确的焦点。还有一个 shift+tab 不会将焦点从最后一个按钮移开。
所以我认为他们的代码有问题,我需要手动更新链顺序吗?或者我遗漏了什么?
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))
要为容器内的元素设置焦点链,需要先将父元素的焦点链设置到容器。从那里需要设置容器的焦点链。
因此代码需要如下:
# 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))
所以好像GTK只允许focus chains指向children因此需要用户设置一个chain of focus chain来设置focus chain to grand children