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