Thursday, April 27, 2006

Lightning 2.0

I've upgraded Lightning Compiler significantly. It is now possible to have more than one editing tab. It is now also possible to run doctest suites, with an external file. As usual, it can be found on sourceforge.

Lightning Compiler (LC) is a wxPython based app. LC's purpose is to provide a friendlier environment to tests Python code snippets than the Python interpreter. It does include an interpreter (pyShell) but it is most likely to be used for its editor. You can execute the code that appears in the editing window and the output is redirected to an output window. raw_input() and input() are handled via dialogs. The basic layout (output window to the side or below the editor window) is customisable.

LC comes in a zip file with a sample app, showing how it can be embedded in other applications, as well as a sample script with doctests and a text file containing additional doctest based tests.

Since LC uses wxPython, it can not be run with a basic Python installation. If there is some interest, I might try and adapt it so that it could use Tkinter instead (as an option. However, I have no experience with Tkinter. Any help would, of course, be appreciated :-)

3 comments:

Anonymous said...

I'm starting to use lightning compiler and it seems very nice to me. I added two little properties to editor for my own purposes: folding and autoindenting:

class PythonSTC():

...

def OnKeyPressed(self, event):
key = event.KeyCode()
# Folding ...
if key == ord(" "):
if event.ControlDown():
if event.ShiftDown():
if self.folded: self.UnFoldAll()
else: self.FoldAll()
return
else:
line = self.LineFromPosition(self.GetCurrentPos())
if not self.GetFoldLevel(line) & stc.STC_FOLDLEVELHEADERFLAG:
line = self.GetFoldParent(line)
self.GotoLine(line)
self.ToggleFold(line)
return
# Indentation
if key == wx.WXK_RETURN:
ind = "\n"
line = self.GetCurLine()[0]
m = re.match(" +", line)
if m:
ind += m.group(0)
if chr(self.GetCharAt(self.GetCurrentPos()-1)) == ":":
ind += " "
self.AddText(ind)
return
event.Skip(True)

Maybe it can be usefull for others too.


Have a nice day.

Milan Melena

Anonymous said...

Sorry for indenting...

....def OnKeyPressed(self, event):
........key = event.KeyCode()
........# Folding ...
........if key == ord(" "):
............if event.ControlDown():
................if event.ShiftDown():
....................if self.folded: self.UnFoldAll()
....................else: self.FoldAll()
....................return
................else:
....................line = self.LineFromPosition(self.GetCurrentPos())
....................if not self.GetFoldLevel(line) & stc.STC_FOLDLEVELHEADERFLAG:
........................line = self.GetFoldParent(line)
........................self.GotoLine(line)
....................self.ToggleFold(line)
....................return
........# Indentation
........if key == wx.WXK_RETURN:
............ind = "\n"
............line = self.GetCurLine()[0]
............m = re.match(" +", line)
............if m:
................ind += m.group(0)
............if chr(self.GetCharAt(self.GetCurrentPos()-1)) == ":":
................ind += "...."
............self.AddText(ind)
............return
........event.Skip(True)

André Roberge said...

Very nice!

I found that I needed to add the following line in __init__():
........self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)

Also, self.folded was not defined (nor was UnFoldAll). I found that replacing
................if event.ShiftDown():
....................if self.folded: self.UnFoldAll()
....................else: self.FoldAll()
....................return
by
................if event.ShiftDown():
....................self.FoldAll()
....................return
worked as one would expect it to.