Applications Google
Menu principal

Post a Comment On: Only Python

"Lightning 2.0"

3 Comments -

1 – 3 of 3
Anonymous 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

3:11 AM

Anonymous 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)

3:14 AM

Blogger 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.

7:23 AM

Spammers: none shall pass.
You can use some HTML tags, such as <b>, <i>, <a>

Comments on this blog are restricted to team members.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot