【发布时间】:2012-08-22 18:48:15
【问题描述】:
我正在使用 Python2.7 和 Gtk3 设计一个文本编辑器式应用程序,我不太确定如何设置处理程序来检查主 TextView 当前是否处于焦点,因此我可以禁用菜单相应的项目(例如编辑 -> 复制等)。
为了创建选项卡式文本编辑器,我使用 Gtk.Notebook 作为主体,每次激活 File -> New 时我都会创建一个新的 ScrolledWindow 和 TextView 以在文本编辑器中创建一个新选项卡:
def on_imagemenuitemNew_activate(self, *args):
editor = Gtk.ScrolledWindow()
editor.add(Gtk.TextView())
editor.set_shadow_type(Gtk.ShadowType.IN)
editor.show_all()
#The instance of Gtk.Notebook is passed to the handler as user data in args[0]
args[0].append_page(editor, Gtk.Label('untitled'))
这很好,但如果我尝试使用:
editor.connect('focus-in-event', self.on_editor_focus_in_event)
在块内然后我的处理程序永远不会注册它:
def on_editor_focus_in_event(self, *args):
print 'Focused!'
我怀疑这个问题可能是由于每个 editor 实例看似相同,但这真的让我很难过。代码写的马马虎虎,我昨天才开始学习GTK,Pygobject/Gtk3文档也不是很好。
【问题讨论】:
标签: python gtk glade gtk3 pygobject