IDLE mini-hack & ?

Isidor rodisi01 at my-deja.com
Wed Jul 21 09:53:53 EDT 1999


Hello Pythonates -

I like IDLE. It's very nice. Thank you GvR.

I am working on learning Tkinter, so I thought, hey, why not look
at this cool app sitting in front of me called IDLE? (Can anyone
say "in over your head"?). (All of the following material refers
to the IDLE that came with 1.5.2 win32 binary.)

Here's a little something I did that someone else might like to
do as well: add a "start up date/time stamp" after the copyright
notice.

1. Start-up date/time stamp

In PyShell.py (your python-directory|Tools|idle), line 371 is
where the "begin" function of class PyShell(OutputWindow) is
defined. A few lines down, we find:

self.write("Python %s on %s\n%s\n" %
                   (sys.version, sys.platform, sys.copyright))

which does something pretty obvious. So, to add a startup
date/time stamp, I added the following line after the "Python
ver, platform, copyright" line:

self.write("Start time: " + time.strftime("%Y%m%d.%H%M",
time.localtime(time.time())))

which prints the date and time like so: "19990719.1422". You may
not like that format (probably don't), but you can read the docs
on the time module to find out about all the other formatting
options.

Of course, for this to work, you need to import the time module
somewhere in PyShell, either at the top of the module, at the
start of the class, or the start of the function. I suspect that
the first option is the best, but I'm not sure.

2.     Adding a command to a menu

Well, I figured, if I can add a date/time stamp there, why not
make it a command that can be executed anytime (in comments or
where ever.) Yeah, right. This is where I got really lost. I came
close...I got stuff to appear on the menu drop down list, but
when I clicked on it, all hell would break loose (actually, an
exception was raised):

>>> Exception in Tkinter callback
Traceback (innermost last):
  File "C:\Program Files\Python152\Lib\lib-tk\Tkinter.py", line
764, in __call__
    return apply(self.func, args)
TypeError: no arguments expected

Ok, what did I do to make this mess (in a second copy of the idle
directory):

A. To Bindings.py

in the menudefs dictionary, at the end of the list of the edit
tuple, I added:

('_DateTime', "<<date-time-stamp>>")

B. To EditorWindow.py

i. at the beginning, where all the "#$ [menu definitions]"
reside, I added

#$ event <<date-time-stamp>>
#$ win <Control-Shift-T>
#$ unix <Control-Shift-T>

to the end of the edit menu.

ii. in the beginning of the __init__ function of the class
EditorWindow, I added the line that follows the remark

text.bind("<<remove-selection>>", self.remove_selection)
##Next 1 line added by IFR 19990716:0212
text.bind("<<date-time-stamp>>", self.date_time_stamp)
text.bind("<3>", self.right_menu_event)


iii. later on, near the bottom of class EditorWindow, I added the
following function. The commented-out parts are different things
I've tried unsuccessfully.

##def date_time_stamp(self):
def date_time_stamp():
        ##from OutputWindow import OutputWindow
        ##import time
        ##OutputWindow.write("##DateTime: " +
time.strftime("%Y%m%d:%H%M", time.localtime(time.time())))
        ##print "cheese"
     ##self.write("cheese")
     tkMessageBox.showerror(
                "blah",
                "blah2",
                master=self.text)
     self.text.write("cheese")

Basically, I'm really clueless and I'm banging around inside IDLE
like a ...like a...madman at a cocktail party (?). I'm sure that
if I got a decent night's sleep and followed all the function
calls from one module to another and one class to another, I
could figure it out. Until that happens, though, I'd love to
receive some small clues or hints.   ;^)

Thanks in advance,

Isidor

"hacking IDLE, idly hacking"






More information about the Python-list mailing list