[Tutor] Problem with 2.4's IDLE

Kent Johnson kent37 at tds.net
Wed Dec 1 11:44:39 CET 2004


If I start IDLE from the shortcut in the Start / Programs / Python24 menu, the open dialog defaults 
to C:=Python24. Looking at the shortcut properties (just right-click on IDLE in the menu) it says, 
Start in C:\Python24\. So if you start IDLE from the menu (or a similarly configured shortcut 
somewhere else) it should do what you want without changing any code.

I think I'll change it to D:\ - I don' put my programs in the Python24 directory...hey, it works!

Sweet!
Kent

Danny Yoo wrote:
> 
> 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!
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list