Revision: 6411
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6411&view=rev
Author:   mdboom
Date:     2008-11-17 19:34:28 +0000 (Mon, 17 Nov 2008)

Log Message:
-----------
Fixed all Gtk memory leaks exercised by D2Hitman's recent thread.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py     2008-11-17 
15:20:06 UTC (rev 6410)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py     2008-11-17 
19:34:28 UTC (rev 6411)
@@ -538,16 +538,6 @@
         NavigationToolbar2.__init__(self, canvas)
         self._idle_draw_id = 0
 
-        self.connect("destroy", self.destroy)
-
-    def destroy(self, *args):
-        gtk.Toolbar.destroy(self)
-        self.fileselect.destroy()
-        self.tooltips.destroy()
-        self.canvas.destroy()
-        if self._idle_draw_id != 0:
-            gobject.remove_source(self._idle_draw_id)
-
     def set_message(self, s):
         if self._idle_draw_id == 0:
             self.message.set_label(s)
@@ -635,11 +625,6 @@
         self.append_widget(self.message, None, None)
         self.message.show()
 
-        self.fileselect = FileSelection(title='Save the figure',
-                                        parent=self.win,)
-
-
-
     def _init_toolbar2_4(self):
         basedir = os.path.join(matplotlib.rcParams['datapath'],'images')
         self.tooltips = gtk.Tooltips()
@@ -670,15 +655,19 @@
 
         self.show_all()
 
-        self.fileselect = FileChooserDialog(
-            title='Save the figure',
-            parent=self.win,
-            filetypes=self.canvas.get_supported_filetypes(),
-            default_filetype=self.canvas.get_default_filetype())
+    def get_filechooser(self):
+        if gtk.pygtk_version >= (2,4,0):
+            return FileChooserDialog(
+                title='Save the figure',
+                parent=self.win,
+                filetypes=self.canvas.get_supported_filetypes(),
+                default_filetype=self.canvas.get_default_filetype())
+        else:
+            return FileSelection(title='Save the figure',
+                                 parent=self.win,)
 
-
     def save_figure(self, button):
-        fname, format = self.fileselect.get_filename_from_user()
+        fname, format = self.get_filechooser().get_filename_from_user()
         if fname:
             try:
                 self.canvas.print_figure(fname, format=format)
@@ -781,11 +770,6 @@
         self.show_all()
         self.update()
 
-        def destroy(*args):
-            self.fileselect.destroy()
-            del self.fileselect
-        self.connect("destroy", destroy)
-
     def _create_toolitems_2_4(self):
         # use the GTK+ 2.4 GtkToolbar API
         iconSize = gtk.ICON_SIZE_SMALL_TOOLBAR
@@ -970,9 +954,19 @@
         self.canvas.draw()
         return True
 
+    def get_filechooser(self):
+        if gtk.pygtk_version >= (2,4,0):
+            return FileChooserDialog(
+                title='Save the figure',
+                parent=self.win,
+                filetypes=self.canvas.get_supported_filetypes(),
+                default_filetype=self.canvas.get_default_filetype())
+        else:
+            return FileSelection(title='Save the figure',
+                                 parent=self.win)
 
     def save_figure(self, button):
-        fname, format = self.fileselect.get_filename_from_user()
+        fname, format = self.get_filechooser().get_filename_from_user()
         if fname:
             try:
                 self.canvas.print_figure(fname, format=format)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to