pyside - Is there a way of getting log information for every event in the event loop?

I'm developing an application with PySide, and I was wondering if there is a way of logging which events enter the main event loop and which ones leave. my application use no threads, it is complete asynchronous, but I wanted to have log registries of the event loop for debugging purpose. I use logging as my logging facility (duh).

Pax et bonum.

Answers


As a good user on reddit replies:

Check this out: http://qt-project.org/doc/qt-4.8/qcoreapplication.html#notify. The event loop is implemented in QCoreApplication, so you can subclass and install your own code to inspect events.

class Application(QApplication): events = {constant: name for name,constant in QEvent.dict.items() if name[0].isupper() and isinstance(constant, int)}

def notify(self, obj, event):
    print("{:<20}{}".format(Application.events[event.type()], obj))
    return super().notify(obj, event)

Works pretty well. http://i.imgur.com/mMLqQ5Y.png

Of course, you will still have to work out which events are being consumed. That super call returns True or False, but almost every event I saw was returning True. Your might have to traverse object relationships or something—I'm not sure because I haven't done this, but there appears to be pretty good support for getting down into that loop and doing what you like.


However, I'm more inclined to follow the third option listed on Qt's documentation:

3. Installing an event filter on QCoreApplication::instance(). Such an event filter is able to process all events for all widgets, so it's just as powerful as reimplementing notify(); furthermore, it's possible to have more than one application-global event filter. Global event filters even see mouse events for disabled widgets. Note that application event filters are only called for objects that live in the main thread.


Need Your Help

Delayed_job in development

ruby-on-rails

Right now my Usermailer is written so I have UserMailer.delay.deliver_blah. Everything works perfect, but like before I'd like the contents of the email printed out in the console for debugging. ...

Launch file after PHP service restart/reload

php

Is it possible to execute a file after a regular PHP service restart ?