[Tutor] Saving session in IDLE

SA sarmstrong13@mac.com
Mon, 12 Aug 2002 10:25:47 -0500


On 8/12/02 10:21 AM, "SA" <sarmstrong13@mac.com> wrote:

> On 8/12/02 6:04 AM, "alan.gauld@bt.com" <alan.gauld@bt.com> wrote:
^ Oops. Typo. The first line stating what alan wrote should have been
deleted. My bad.

> Could you not rewrite idle to store each typed line into a file. Keeping the
> file open as you work. Then with a specific command, like exit, you are
> asked whether or not to save the file?
> 
> Basically have all of the commands sitting in a que waiting to be dumped to
> file after you exit?
> 
> Thanks.
> SA
> 
> P.S. One other option would be to take a little Tkinter/Python shell script
> I wrote and tweak it for your own use, (but I would like to see all the
> improvements people come up with just to see the evolution of the program):
> 
> #!/usr/bin/env python
> 
> from Tkinter import *
> import os
> import commands
> import sys
> import tkSimpleDialog
> 
> class PyShell:
>   
>   def clearin(self):
>       self.t1.delete(0.0,END)
>   def clearout(self):
>       self.t2.delete(0.0,END)
>   def expyth(self):
>       self.t2.delete(0.0, END)
>       self.output = commands.getoutput("/sw/bin/python -c '%s'" %
> self.t1.get(0.0, END).strip())
>       self.t2.insert(END, self.output)
>   def doSave(self):
>       SaveDialog = Saving(self.f)
>       filename = SaveDialog.getName()
>       self.saveText(filename)
>       del(saveDialog)
>   def __init__(self, top):
>       self.t1 = Text(top, height="12", width="84", font="Courier 12")
>       self.t1.pack(side=TOP, pady=2)
>       self.f = Frame(top)
>       self.f.pack()
>       self.b1 = Button(self.f, text="Execute", command=self.expyth)
>       self.b1.pack(side=LEFT)
>       self.b2 = Button(self.f, text="Clear Input", command=self.clearin)
>       self.b2.pack(side=LEFT)
>       self.b3 = Button(self.f, text="Clear Output", command=self.clearout)
>       self.b3.pack(side=LEFT)
>       self.b4 = Button(self.f, text="Save Input", command=self.doSave)
>       self.b4.pack(side=LEFT)
>       self.t2 = Text(top, height="12", width="84", bg="lightblue",
> font="Courier 12")
>       self.t2.pack(side=TOP, pady=2)
> 
> class Saving(tkSimpleDialog.Dialog):
>   
>   def body(self, master):
>       Label(master, text="Directory:").grid(row=0)
>       Label(master, text="Filename:").grid(row=1)
>       self.e1 = Entry(master)
>       self.e2 = Entry(master)
>       self.e1.grid(row=0, column=1)
>       self.e2.grid(row=1, column=1)
>       return self.e1
>   def apply(self):
>       dir = self.e1.get()
>       fn = self.e2.get()
>       self.name = dir + fn
>   def getName(self):
>       return self.name
> 
>                  
> root = Tk()
> app = PyShell(root)
> root.mainloop()
> 
>