15 Jan 2007 05:17
Re: Newbie Question
Saul Spatz <sspatz <at> kcnet.com>
2007-01-15 04:17:43 GMT
2007-01-15 04:17:43 GMT
Tal Einat wrote: > On 12/27/06, Saul Spatz <sspatz <at> kcnet.com> wrote: >> >> I am rather new to both python and IDLE. The references to IDLE at >> www.python.org seem sadly out-of-date. I have a couple of simple >> enhancements I would like to make to IDLE that are not likely to be of >> general interest. (I want to use IDLE in teaching, and I want to save >> the sessions, both user input and IDLE output. I would like IDLE to >> remember where I saved the last session and default to that directory, >> and I would like it to prompt me if I close the IDLE window without >> having saved the session.) It seems like these should be easy to >> program, but I can't find the IDLE source. >> >> Where is it, please? I assume that I am allowed modify it just for my >> own use. > > > Overcourse you may. > > IDLE is written in Python, so you can simply edit its code, wherever your > Python installation is. > Just look in \Lib\idlelib\. > (For instance, on Windows: C:\Python25\Lib\idlelib\) > > In addition, IDLE's source is in Python's SVN: > http://www.python.org/dev/faq#subversion-svn > (here too, look under Lib\idlelib\.) > > In addition, we'd be glad to hear any about any features you find > missing or > suggestions for improvement regarding IDLE. > > Good luck! > > - Tal > Thanks. I think I've figured out how to modify IDLE to do what I want. Now, I'm having trouble figuring out how best to organize my changes so they don't get clobbered by the next IDLE update. I'm trying to work out how best to deal with packages and python namespaces. Here is a sample of what I have worked out: #idle2.pyw import idlelib.PyShell import time from Tkinter import * EditorWindow = idlelib.EditorWindow.EditorWindow class MyPyShell(idlelib.PyShell.PyShell): def close2(self): format = '%d%b%Y.%H%M%S.log' path = "E:/MyPythonProjects/" filename = path + time.strftime(format) try: log = open(filename,'w') log.write(self.text.get(1.0,END)) log.close() except IOError: pass return EditorWindow.close(self) idlelib.PyShell.PyShell = MyPyShell idlelib.PyShell.main() This seems to work. However, I don't really want the path to be hard-coded into my program. I want to be able to select the directory, and to control the logging behavior interactively. This means that I will have to subclass ConfigDialog.ConfigDialog and perhaps other classes as well. Am I likely to run into trouble with the approach indicated above, and, in any case, is there a better way? I realize that this question has little to do with IDLE development, but I don't know where else to turn for help. I'd be grateful if some guru will give of his wisdom to a beginner. Thanks, Saul
RSS Feed