Stefano Palazzo
Stefano Palazzo

Reputation: 4332

Catching PyGTK RuntimeWarning on gtk.Builder.connect_signals

gtk.Builder.connect_signals() issues a RuntimeWarning when a signal handler is not present:

__init__.py:16: RuntimeWarning: missing handler 'on_window_destroy'
  self.builder.connect_signals(self)

How do I keep it from issuing the warning and handle it myself?

I'd like the warning to not be printed (without requiring the user to pipe it to /dev/null)

Note: I'm not asking what the warning means, rather how to handle the Warning sort of as if it were an exception, at the moment, it seems a message to stderr is the only thing that happens, I can't do much with that in the program.

Upvotes: 1

Views: 810

Answers (1)

adw
adw

Reputation: 5021

You could use the warnings module.

However, in this case I think it would be easier to check the return value of connect_signals. From the documentation:

Also, if there is at least one such missing handler, connect_signals will return a list of their names, else return value is None.

Upvotes: 1

Related Questions