Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
@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 '12 at 17:28

1 Answer 1

up vote 2 down vote accepted

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")
share|improve this answer
    
Thank you very much :-), Problem Solved –  Vishnu V Jul 7 '12 at 0:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.