将button_press_event添加到Gtk.Image?

时间:2017-04-19 11:33:52

标签: python-3.x gtk3 pygobject gobject-introspection

我尝试创建一个自定义Gtk.Image来处理"点击"信号,但当我尝试从自定义Gtk.Image发出信号时,但无法确定当按下按钮事件时信号不会发出的原因。

类WindowButton(Gtk.Image):      gtype_name =" WindowButton"

__gsignals__ = {
    "clicked" : (GObject.SIGNAL_ACTION,None,(Gdk.Event,))
}

def __init__(self,*args,**kwargs):
    Gtk.Image.__init__(self,*args,**kwargs)

    self.set_from_stock(Gtk.STOCK_OK,Gtk.IconSize.SMALL_TOOLBAR)

    self.event = Gdk.Event.new(Gdk.EventType.BUTTON_PRESS)

    self.emit("button-press-event",self.event)

    self.connect("button-press-event",self.on_button_press_event)
    self.connect("clicked",self.do_clicked)

def on_button_press_event(self,event):
    print(ButtonPressEvent)
    print(event)

    self.emit("clicked",self.event)

def do_clicked(self,event):
    print('clicked')
    print(event)

1 个答案:

答案 0 :(得分:1)

GtkImage没有像'clicked'这样的信号。将您的GtkImage放在EventBox中,并将信号挂钩到EventBox