Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6f8434

Browse files
committed
Fix exception when using Gtk+ file chooser to save a file and the user
provides no extension. svn path=/trunk/matplotlib/; revision=3484
1 parent 493f425 commit e6f8434

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/matplotlib/backends/backend_gtk.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,13 +1067,15 @@ def __init__ (self,
10671067
for item in IMAGE_FORMAT:
10681068
cbox.append_text (item)
10691069
cbox.set_active (IMAGE_FORMAT.index (IMAGE_FORMAT_DEFAULT))
1070+
self.ext = IMAGE_FORMAT_DEFAULT
10701071

10711072
def cb_cbox_changed (cbox, data=None):
10721073
"""File extension changed"""
10731074
head, filename = os.path.split(self.get_filename())
10741075
root, ext = os.path.splitext(filename)
10751076
ext = ext[1:]
10761077
new_ext = IMAGE_FORMAT[cbox.get_active()]
1078+
self.ext = new_ext
10771079

10781080
if ext in IMAGE_FORMAT:
10791081
filename = filename.replace(ext, new_ext)
@@ -1092,11 +1094,10 @@ def get_filename_from_user (self):
10921094
if self.run() != gtk.RESPONSE_OK:
10931095
break
10941096
filename = self.get_filename()
1095-
menu_ext = IMAGE_FORMAT[self.cbox.get_active()]
10961097
root, ext = os.path.splitext (filename)
10971098
ext = ext[1:]
10981099
if ext == '':
1099-
ext = menu_ext
1100+
ext = self.ext
11001101
filename += '.' + ext
11011102

11021103
if ext in IMAGE_FORMAT:
@@ -1106,7 +1107,7 @@ def get_filename_from_user (self):
11061107
error_msg_gtk ('Image format "%s" is not supported' % ext,
11071108
parent=self)
11081109
self.set_current_name (os.path.split(root)[1] + '.' +
1109-
menu_ext)
1110+
self.ext)
11101111

11111112
self.hide()
11121113
return filename

0 commit comments

Comments
 (0)