Little fix in the TkAgg backend

Hi,

whenever I clicked the "save"-button in a plot in my TkAgg and pressed "cancel" in the file dialog, I got the error message

Exception in Tkinter callback
Traceback (most recent call last):
   File "lib-tk/Tkinter.py", line 1406, in __call__
     return self.func(*args)
   File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 641, in save_figure
     bname, fext = os.path.splitext(fname)
   File "posixpath.py", line 92, in splitext
     i = p.rfind('.')
AttributeError: 'tuple' object has no attribute 'rfind'

This obviously happened because tkFileDialog.asksaveasfilename returned an empty tupel rather than an empty string, when the user cancels the file dialog. I fixed it by replacing the line

if fname == "":

by

if fname == "" or fname == ():

in the file backend_tkagg.py.

Thank you,
Michael Zell

backend_tkagg.diff (80 Bytes)

Thanks. This has been committed in SVN revision 4267, and will likely make it into the upcoming release.

Cheers,
Mike

Michael Zell wrote:

···

Hi,

whenever I clicked the "save"-button in a plot in my TkAgg and pressed "cancel" in the file dialog, I got the error message

Exception in Tkinter callback
Traceback (most recent call last):
  File "lib-tk/Tkinter.py", line 1406, in __call__
    return self.func(*args)
  File "/usr/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 641, in save_figure
    bname, fext = os.path.splitext(fname)
  File "posixpath.py", line 92, in splitext
    i = p.rfind('.')
AttributeError: 'tuple' object has no attribute 'rfind'

This obviously happened because tkFileDialog.asksaveasfilename returned an empty tupel rather than an empty string, when the user cancels the file dialog. I fixed it by replacing the line

if fname == "":

by

if fname == "" or fname == ():

in the file backend_tkagg.py.

Thank you,
Michael Zell

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA