3

I try to create a custom Gtk.Image that handles the "clicked" signal but when I try to emit a signal from the custom Gtk.Image ,but can't figure out why doesn't the signal emit when there is a button press event.

class 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 Answers1

1

GtkImage has no signal like 'clicked'. Put your GtkImage within an EventBox and hook your signals to the EventBox.

theGtknerd
  • 3,647
  • 1
  • 13
  • 34
  • Yes , I know that. That is why I am trying to create a new Gtk.Image type that supports the clicked signal . –  Apr 19 '17 at 21:45
  • You will need to subclass an EventBox and then pack your Image inside and hook up all your signals. If you have no experience in subclassing, post what you have tried/want to do and I will see how my time holds out in the next couple days... – theGtknerd Apr 19 '17 at 22:01
  • If that is the case , I would probably not event try to create a custom Gtk.Image. I would pack the image inside a EventBox since it handles button_press_event . But I don't wan't my image to be in a container . I wan't the image to emit a clicked signal when it recieves a Gdk.EventType.BUTTON_PRESS like a regular Gtk.Button would do. –  Apr 19 '17 at 22:34
  • Ok you have two options. Use a button and put your image in it. Or put your GtkImage widget inside a EventBox. I think you should try the EventBox. That type of container is not like other Gtk containers you normally use, it is pretty much transparent except for signals and related actions. The docs at https://developer.gnome.org/gtk3/stable/GtkImage.html#gtk-image-get-icon-set plainly tell you that GtkImage has no event handling without an EventBox. – theGtknerd Apr 20 '17 at 01:35
  • 1
    Ok so I searched very old Gtk2 documents . The thing is that Gtk.Image is not a Window Widget therefore Gdk can't realy send events to it . This means that I either have to create the Image from base Gtk.Widget or I do have to go the way of using a Gtk.EventBox and manipulate the image thought the eventbox couse can't find a way , to set it as Window WIdget after it is already defined as a non-window Widget. –  Apr 21 '17 at 05:36