Hello everyone,
I have the following problem with my application, which allows
you to
manipulate some of properties of a plot through the use of a
gui-style
property editor:
Whenever I set the y-axis scale to logarithmic, but have the y
range
include a negative value, I will get a ValueError upon
expose_event. The
bad thing is now, that my application catches all exceptions
and
displays a user-friendly dialog, explaining or listing the
exception and
offering the user to mail the output to the dumb author of the
program.
But whenever the user quits the dialog, a new expose event of
the canvas
will be triggered, leading to an unstoppable series of
exceptions
(except when using xkill of course).
So what I would like to propose is a modification of
expose_event
located in backends/backend_gtk.py to better handle any
exceptions that
it might trigger.
One not so nice solution of mine was to wrap the method in a
try...finally statement, which ensures that False is returned
and the
expose_event is stopped:
def expose_event(self, widget, event):
"""Expose_event for all GTK backends. Should not be
overridden.
"""
if _debug: print 'FigureCanvasGTK.%s' % fn_name()
try:
if GTK_WIDGET_DRAWABLE(self):
if self._need_redraw:
x, y, w, h = self.allocation
self._pixmap_prepare (w, h)
self._render_figure(self._pixmap, w, h)
self._need_redraw = False
x, y, w, h = event.area
self.window.draw_drawable
(self.style.fg_gc[self.state],
self._pixmap, x, y, x, y, w, h)
finally:
return False # finish event propagation?
Of course, this has the obvious disadvantage, that no
exception is
triggered at all, which is undesirable.
I don't understand, the exception is still raised after the 'finally'
clause.
Are there any better approaches to this?
Best regards,
Niklas Volbers.
You could simply popup the user-friendly dialog and then kill the
program after the user has read the message and clicked "OK".
When you use semilogy(), matplotlib ignores the values <= 0 (I'm not
sure where the code is that does that), I think an application should do
the same.
If we add try ... finally to expose_event() that would mean we are
handling application errors within library code, which I don't think is
right. Also, this problem would affect all backends so it would probably
be better to handle it (if it is needed) in the Figure.draw() rather
than having to modify every backend.
Steve
Send instant messages to your online friends http://au.messenger.yahoo.com
···
On Tue, 2006-04-18 at 20:11 -0700, matplotlib-devel-request@lists.sourceforge.net wrote: