Skip to content

Commit

Permalink
wxWidgets editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ppaez committed Feb 26, 2011
1 parent 728c506 commit 15f399d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions editor-wx.py
@@ -0,0 +1,30 @@
#! /usr/bin/env python

import wx
from arithmetic import Parser

class Editor(wx.Frame):
'A minimal editor.'
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(800,600))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.control.Bind( wx.EVT_KEY_DOWN, calculate)
self.Show(True)

def calculate(event):
if event.GetKeyCode() == wx.WXK_F5:
control = event.GetEventObject()
nlines = control.GetNumberOfLines()
lines = []
for i in range(nlines):
lines.append( control.GetLineText(i) )
text = '\n'.join( lines )
parser = Parser()
text = parser.parse(text)
end = control.GetLastPosition()
control.Replace( 0, end, text )
event.Skip()

app = wx.App(False)
frame = Editor(None, 'wxWidgets editor')
app.MainLoop()

0 comments on commit 15f399d

Please sign in to comment.