1

I would like to ignore some key events in a text view, now i do the following

def on_key_press_event(self,source,event):
    keyname = Gdk.keyval_name(event.keyval)
    if(keyname=="Return"):
            tv = self.builder.get_object('txtMsg')
            buf = tv.get_buffer()
            msg = buf.get_text(buf.get_start_iter(),buf.get_end_iter(),self)
            msg=msg.replace("\n","")
            buf.set_text(msg)

Is there any function equivalent to Java function event.consume() in python?

1
  • @LordofTime Programming (development) questions are explicitly listed in the FAQ askubuntu.com/faq#questions as reasonable questions to ask here. If it were a general Python question, vs. how to use GTK+ in Python, I might agree.
    – dobey
    Jul 6, 2012 at 17:28

1 Answer 1

3

To stop an event from propagating (unless the event has been set up using connect_after), you can run

object.emit_stop_by_name(event_name)

For instance, if I connected the key-press-event like this:

self.textview.connect("key-press-event", self.on_key_press)

I can stop it propagating like this:

def on_key_press(self, widget, event):
    self.textview.emit_stop_by_name("key-press-event")
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .