[Edu-sig] xturtleDemo hack to mark current executing line
Jurgis Pralgauskis
jurgis.pralgauskis at gmail.com
Thu Nov 27 00:08:16 CET 2008
Hello,
I made a small trick,
inspired by rur-ple "Code and Learn" environment
see methods my_trace and set_line_number (left the names same as in
rur-ple cpu.py)
I don't know TkInter, so I just put *** in front of the current line
there are a few issues I don't know how to resolve:
* if the line is outside the textbox, it isn't seen,
as the text is each time rewritten to textbox (there should be
some scroll to line function, I hope)
* I'd like to have step (inside of the loaded module)
functionallity (as in rur-ple),
but it is still magic for me...
you can find the modified file
http://files.akl.lt/users/jurgis/python/xturtle-hacks/
and I paste the essence here for archiving purposes:
def my_trace(self, frame, event, arg):
#same called in rur-ple cpu.py
if event == "line":
if self.code_src == "file" and self.module.__name__ in
str(frame.f_code):
time.sleep(0.5)
self.set_line_number(frame.f_lineno)
# print "my_trace: event, frame:", event,
inspect.getframeinfo(frame)
return self.my_trace
def set_line_number(self, lineno): # could be called highlight_line
lines = map(lambda x: " "+x, self.code.split("\n") )
lineno = lineno - 1 # the real one :)
lines[lineno] = "*** " + lines[lineno][4:]
self.text.delete("1.0", "end")
self.text.insert("1.0", "\n".join(lines) )
# in start_demo(...)
sys.settrace(self.my_trace)
result = self.module.main()
sys.settrace(None) # this should be also called in StopIt
--
Jurgis Pralgauskis
tel: 8-616 77613;
jabber: jurgis at akl.lt; skype: dz0rdzas;
Don't worry, be happy and make things better ;)
More information about the Edu-sig
mailing list