This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients roger.serwy, terry.reedy
Date 2012-07-15.23:17:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1342394243.7.0.336788716257.issue15363@psf.upfronthosting.co.za>
In-reply-to
Content
I have (had ;-) a project file ~template.py with common boilerplate.
To start a new project file, I want to open the above and save as xyz.py. I can edit and 'save' the template to update it just fine. But trying to do a 'save as' to a new name, in Idle editor, on all three current versions, I get (when starting Idle from command window)

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Programs\Python33\lib\tkinter\__init__.py", line 1442, in __call__
    return self.func(*args)
  File "C:\Programs\Python33\lib\idlelib\IOBinding.py", line 347, in save_as
    filename = self.asksavefile()
  File "C:\Programs\Python33\lib\idlelib\IOBinding.py", line 514, in asksavefile

    filename = self.savedialog.show(initialdir=dir, initialfile=base)
  File "C:\Programs\Python33\lib\tkinter\commondialog.py", line 48, in show
    s = w.tk.call(self.command, *w._options(self.options))
_tkinter.TclError: user "template.py" doesn't exist

When starting Idle normally, this causes it to silently close. When run from the cp interpreter, the edit window blinks but continues while the trackback is printed in the cp window.

Just saving does not bring up a dialog; hence no problem. And I understand that '~' has special meaning on *nix, but I am running on Windows.

I changed '~' to '@' and the file still sorts at the top (though above __init__.py rather than below) and save as now works as it should. I know that save as worked for this file last October, but while I think it had the same ~name then, I cannot be sure. Maybe I added '~' after the last time I successfully used the file.

As near as I can tell, asksavefile() passes initialfile = base = '~template.py' to savedialog.show which passes it unchanged and unexamined to tk.call. So the special casing of ~ seems to happen in tcl/tk out of our control. I am not sure if doing this on Windows is a tcl/tk bug or not.

For Windows, just removing '~' or even blanking the name before the .show() might be sensible, but maybe not for *nix.

Instead, we could catch the error instead of letting it crash Idle and put up a message box to the effect that one cannot 'save as' when editing a file named '~xxxx'. More specifically, in IOBinding.py, line 514 or so, replace

filename = self.savedialog.show(initialdir=dir, initialfile=base)

with

try:
    filename = self.savedialog.show(initialdir=dir, initialfile=base)
except TclError as e:
    if e.args[0].startswith('user'):
        xxx display message, click ok
    filename = None

I am assuming the None is the return from canceled dialogs. Certainly, None caused the file save code back up in saveas() (346) to skip the save.

The message could be something like "tcl/tk gives special treatment to file names starting with '~' and returned this error message {}".format(e.args[0])

We could also add "else: message('unanticipated tclerror prevented save as dialog <message>)"
History
Date User Action Args
2012-07-15 23:17:23terry.reedysetrecipients: + terry.reedy, roger.serwy
2012-07-15 23:17:23terry.reedysetmessageid: <1342394243.7.0.336788716257.issue15363@psf.upfronthosting.co.za>
2012-07-15 23:17:23terry.reedylinkissue15363 messages
2012-07-15 23:17:21terry.reedycreate