Editor to interpretor

Hello everyone…

I have created a simple editor. The editor will have some python commands and I want them to be sent to python and get back the answer…

For example suppose on the editor if I typed x=2 y=3 x+y and then press solve it should do the operation x+y and return 5…

Any Ideas…

Balaji

Balaji Balaraman wrote:

Hello everyone..
I have created a simple editor. The editor will have some python commands and I want them to be sent to python and get back the answer..
For example suppose on the editor if I typed x=2 y=3 x+y and then press solve it should do the operation x+y and return 5..
Any Ideas...
Balaji

Well, if you are okay with making it real python code, you could always just use a wx.TextCtrl with the wx.TE_PROCESS_ENTER flag set, and then on wx.EVT_TEXT_ENTER you use ret = eval(text)

As a more complete demo (not tested):

import wx
class myPanel(wx.Panel):
  def __init__(self, parent):
    wx.Panel.__init__(self, id=-1, parent=parent
      , size=wx.Size(400, 400))
    self.txtCommand = wx.TextCtrl(parent=self
      , style=wx.TE_PROCESS_ENTER)
    self.txtResult = wx.TextCtrl(parent=self
      , style=wx.TE_MULTILINE)
    self.sizer = wx.BoxSizer()
    self.sizer.Add(self.txtCommand, 0, 10
      , wx.EXPAND | wx.ALL)
    self.sizer.Add(self.txtResult, 1, 10
      , wx.EXPAND | wx.ALL)
    self.SetSizer(self.sizer)

    wx.Bind(wx.EVT_TEXT_ENTER, self.txtCommand
      , self.OnEnter)

  def OnEnter(self, evt):
    res = eval(self.txtCommand.GetValue())
    self.txtResult.AddText('%s\n' % res)

Or at least something like that.

John
=:->