我尝试创建一个自定义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)