buglet: fig saving filenames (at least with Tk)

Howdy. This is using Tk, svn build from just now:

In [4]: plot([1,2])
Out[4]: [<matplotlib.lines.Line2D object at 0x31262d0>]

In [5]: savefig('foo')

# Then, click on the 'save' icon in the figure window, and simply type
'foo2' in the dialog. Result:

In [6]: d foo*
-rw-r--r-- 1 fperez 35100 2009-04-15 10:02 foo2png.png
-rw-r--r-- 1 fperez 35100 2009-04-15 10:02 foo.png

The dialog, instead of adding '.png', is adding 'png.png' to the
filename. I'm pretty sure this used to work fine a while ago.

I don't know if the problem exists with all the backends. Wx at least
seems to manually add the .png extension in the right place...

Cheers,

f

Hey Fernando,

Thanks for the report. Apparently there are some longstanding vis-a-vis extension handling issues with the tk dialog asksaveasfilename that we use. Eg,

http://mail.python.org/pipermail/python-list/2002-June/150051.html

I just applied a possible fix which seems to work in my tests – the fix and comments are inlined below in case anyone more knowledgeable than tkagg than I has some feedback::

    # adding a default extension seems to break the
    # asksaveasfilename dialog when you choose various save types
    # from the dropdown.  Passing in the empty string seems to
    # work - JDH

    #defaultextension = self.canvas.get_default_filetype()
    defaultextension = ''
    fname = asksaveasfilename(
        master=self.window,
        title='Save the figure',

        filetypes = tk_filetypes,
        defaultextension = defaultextension
        )

svn up and give this a test drive under a few different save/extension scenarios

JDH

···

On Wed, Apr 15, 2009 at 12:07 PM, Fernando Perez <fperez.net@gmail.com> wrote:

The dialog, instead of adding ‘.png’, is adding ‘png.png’ to the

filename. I’m pretty sure this used to work fine a while ago.

I don’t know if the problem exists with all the backends. Wx at least

seems to manually add the .png extension in the right place…

Thanks! So far, looking good...

Take care,

f

···

On Wed, Apr 15, 2009 at 10:53 AM, John Hunter <jdh2358@...149...> wrote:

svn up and give this a test drive under a few different save/extension
scenarios

Thanks for the report.

As far as I can tell, this has been broken for a long time, at least since r3798 (September 2007). I just hacked at this and arrived at the same conclusion John did.

I have an interesting finding about consistency. For the use case you describe, on my machine at least Gtk, Wx and Tk don't add any extension, whereas Qt and Qt4 implicitly add an extension. In all cases, the matplotlib backend isn't doing anything to the filename -- it's just using the filename handed back from the file dialog. All of this is reasonable, unlike the problem in Fernando's original bug report. I suspect the differences are probably based on differences in HIGs. This wxWidgets bug suggests that not implicitly adding an extension is correct behavior for Gtk+.

   http://trac.wxwidgets.org/ticket/9917

Is it worth making this consistent between backends, or is it more important for each of the toolkits to feel native in their respective worlds. I'm leaning toward the latter -- mainly because it's less work :wink:

These are my versions. I wonder if different toolkit versions may also have different behavior in this regard.
   wxPython: 2.8.6.1
Gtk+: gtk+: 2.10.9, glib: 2.16.1, pygtk: 2.10.4, pygobject: 2.13.1
Qt: Qt: 3.3.3, PyQt: 3.17.2
Qt4: Qt: 4.3.0, PyQt4: 4.2

Cheers,
Mike

Fernando Perez wrote:

···

Howdy. This is using Tk, svn build from just now:

In [4]: plot([1,2])
Out[4]: [<matplotlib.lines.Line2D object at 0x31262d0>]

In [5]: savefig('foo')

# Then, click on the 'save' icon in the figure window, and simply type
'foo2' in the dialog. Result:

In [6]: d foo*
-rw-r--r-- 1 fperez 35100 2009-04-15 10:02 foo2png.png
-rw-r--r-- 1 fperez 35100 2009-04-15 10:02 foo.png

The dialog, instead of adding '.png', is adding 'png.png' to the
filename. I'm pretty sure this used to work fine a while ago.

I don't know if the problem exists with all the backends. Wx at least
seems to manually add the .png extension in the right place...

Cheers,

f

------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA