[SciPy-dev] Odd result from plt.IsShown()

eric eric at scipy.org
Mon Nov 5 10:07:04 EST 2001


Hey Mangus,

This may have to do with a few bugs (fixed in the CVS) in gui_thread.py and
not in plt.... or it could be in plt.  Can you post the code and I'll take a
look around.

thanks,
eric

----- Original Message -----
From: "Magnus Lyckå" <magnus at thinkware.se>
To: <scipy-user at scipy.net>; <scipy-dev at scipy.net>
Sent: Saturday, November 03, 2001 10:29 AM
Subject: [SciPy-dev] Odd result from plt.IsShown()


> I'm using plt to display some x-y diagrams in a wxPython app,
> and I update the plot when I shift or change my data if it's visible,
> checking plt.IsShown(). This works as it should. When I close
> the app, I also close the plot window if IsShown() returns true,
> but sometimes this fails, which causes a Windows error message
> when I try to close a non-existing window.
>
> I start showing my data when I press a "Plot button" like this:
>
>      def OnPlotButton(self, evt):
>          #Construction of "age" and "y" lists snipped
>          self.plot = plt.plot(age, y)
>          plt.title(self.case.idNr)
>          plt.xtitle('Age (years)')
>          plt.ytitle('Height / Weight (cm /kg)')
>
> This works OK. When I change data set, or modify my data
> set, I do the following:
>
>      if self.plot.IsShown():
>          self.OnPlotButton(None)
>
> This always works. If the diagram is showing, the data is
> updated, but if it was closed, or never opened, no new plot
> will be shown. In other words, IsShown() works as expected.
> It always runs OnPlotButton when a plot window is open, and
> it never starts a new window it it's closed. I'll have to
> press the plot button again, just as I intended.
>
> When I close the application, I run:
>
>      def OnClose(self, event):
>          self.db.close()
>          print "Saving and exiting"
>          try:
>              print "In try block"
>              if self.plot.IsShown():
>                  print "In if..."
>                  self.plot.Close()
>                  print "After close"
>              else:
>                  print "In else"
>          except:
>              print "In except"
>              pass
>          event.Skip()
>
> If I never used plot, all is fine. self.plot doesn't exist,
> so I get an attribute error which I catch in my except clause,
> printing "In except" before returning my prompt.
>
> If the plot windows is active, it will close nicely.
>
> If I have used plotting, closed the plot window and then changed
> data set or modified the current data set before I close the app,
> all is fine.
>
> But if I close the plot window, and then close the app directly,
> I get a crash on exit. The program prints "Saving and exiting",
> and then "In if...", indicating that IsShown() quite unexpectedly
> returned 1! I might have pressed my save button, or clicked away
> in some other way after closing the plot window, but I haven't changed
> data in such a way that there would have been a re-plot in case the
> plot window had been open. I'm quite stunned here, because it seems
> self.plot.IsShown() acts quite differently in the different places in
> my code! (And yes, it's all in the same class. :-)
>
> I can make my program available if someone would like to take a
> closer look at it.
>
> Another unexpected thing is that I get a Python prompt in the command
> window where I started my app when I open my plot window! I can't
> type anything in it, and it closes when I exit my app.
>
> BTW, plot seems to leak memory. On a normal exit it says:
> 16:04:20: There were memory leaks.
> 16:04:20: ----- Memory dump -----
> 16:04:20: wxPrintData at $1B8E4E0, size 112
> 16:04:20: wxFont at $1B8EEF8, size 12
> 16:04:20: wxFont at $1B8D2C0, size 12
> 16:04:20: wxFont at $1B8C940, size 12
> 16:04:20: wxFont at $1B8C1D0, size 12
> 16:04:20: wxFont at $1B8B500, size 12
> 16:04:20: wxEvtHandler at $1B8A830, size 40
> 16:04:20: wxPyCallback at $1B88AB0, size 12
> 16:04:20: wxObject at $1B88A20, size 28
> 16:04:20:
> 16:04:20:
> 16:04:20: ----- Memory statistics -----
> 16:04:20: 1 objects of class wxObject, total size 28
> 16:04:20: 1 objects of class wxPyCallback, total size 12
> 16:04:20: 1 objects of class wxEvtHandler, total size 40
> 16:04:20: 5 objects of class wxFont, total size 60
> 16:04:20: 1 objects of class wxPrintData, total size 112
> 16:04:20:
> 16:04:20: Number of object items: 9
> 16:04:20: Number of non-object items: 0
> 16:04:20: Total allocated size: 252
> 16:04:20:
> 16:04:20:
>
>
> --
> Magnus Lyckå, Thinkware AB
> Älvans väg 99, SE-907 50 UMEÅ
> tel 070-582 80 65, fax: 070-612 80 65
> http://www.thinkware.se/  mailto:magnus at thinkware.se
>
> _______________________________________________
> Scipy-dev mailing list
> Scipy-dev at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-dev
>





More information about the SciPy-Dev mailing list