[Tutor] Problem with 2.4's IDLE
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Wed Dec 1 10:14:33 CET 2004
On Tue, 30 Nov 2004, Dick Moores wrote:
> I installed 2.4 today and find that when using its IDLE, File|Open opens
> to \Documents and Settings\Dick, a long ways from \Python24. Actually,
> I'd prefer \Python24\MyScripts. Same for File|Save. Is there a way to
> control this behavior?
Hi Dick,
Yes, I believe so. The directory that you are finding yourself in,
'\Documents and Settings\Dick', is considered your personal "HOME"
directory, and I suspect IDLE is sending you there initially. You may
want to first change the current working directory to \Python24\MyScripts
instead.
I did some code diving. Here's a sort of running dialog I'm having with
myself to see if we can figure this out.
In idlelib/IOBinding.py, around line 515, there's code that handles the
file open dialog box:
###
def askopenfile(self):
dir, base = self.defaultfilename("open")
if not self.opendialog:
self.opendialog = tkFileDialog.Open(master=self.text,
filetypes=self.filetypes)
return self.opendialog.show(initialdir=dir, initialfile=base)
###
Ok, that looks very promising. The initial directory is defined by some
method called "defaultfilename". Let's see what that looks like.
### idlelib/IOBinding.py, line 522
def defaultfilename(self, mode="open"):
if self.filename:
return os.path.split(self.filename)
elif self.dirname:
return self.dirname, ""
else:
try:
pwd = os.getcwd() ## <-- (dyoo: This looks like it!)
except os.error:
pwd = ""
return pwd, ""
###
Without looking at this more closely, this appears to confirm our
suspicions. If no file has been opened yet, IDLE uses the current working
directory as its initial file-opening default.
If we can somehow change the current working directory that IDLE uses,
then we're all set. Unfortunately, I don't know how things work on
Windows, nor how it sets the current working directory of a double-clicked
application.
If you feel really kludgy, you modify that line in the defaultfilename()
function so that, instead of it doing:
pwd = os.getcwd()
it can be munged to:
pwd = '/Python24/MyScripts'
A better approach, of course, would be to get the IDLE folks to add an
option for changing the default file opening location. *grin*
Try sending them a patch request for a configurable default file-open
directory. If it's not in there already, it actually doesn't seem like a
hard thing to implement.
Good luck to you!
More information about the Tutor
mailing list