Hi list,

I was just wondering if it wasn't a good idea to add the with-statement
functionality to the QPainter class. If your program happens to 
raise an exception while QPainter is active, QPainter.end() might
never be called and that leads to a lot of annoying error messages.

I just propose to add to methods to QPainter, like that:

def __enter__(self):
    return self
def __exit__(self, info):
    self.end()
    return False

Then you can write code like this:

with QPainter(image) as p:
    p.drawWhatever()

and you never have the problem with a dangling QPainter.

I guess someone will start yelling "but that's Python 2.5". Indeed,
it is. But well, the changes I propose are perfectly backwards-compatible,
as it only means to add to methods to a class.

Any other thoughts / ideas?

Cheers,

Martin

_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to