embed ipython in wxPython app

Chris Mellon arkanes at gmail.com
Mon Nov 19 13:07:17 EST 2007


On Nov 19, 2007 11:51 AM, chewie54 <dfabrizio51 at gmail.com> wrote:
>
> On Nov 18, 8:39 pm, chewie54 <dfabrizi... at gmail.com> wrote:
> > Hi All,
> >
> > I'm evaluting IPython to see if I can it use like Tcl and Tk.     If I
> > start wish8.4,  I get a command line
> > interpreter in xterm,  then I can source tcl progams that draw tk
> > graphics on a canvas in another window.
> >
> > Is there a way to embed IPython in a wxPython app to do that?
> > When I do as shown in the example below the GUI window does not show
> > until I exit IPython.
> >
> > Thanks in advance for any help with this,
> >
> > import wx
> > from IPython.Shell import IPShellEmbed
> >
> > class MyFrame(wx.Frame):
> >     def __init__(self,parent=None, id=-1, title=' '):
> >         wx.Frame.__init__(self,parent,id,title,size=(200,140))
> >         top = wx.Panel(self)
> >         sizer = wx.BoxSizer(wx.VERTICAL)
> >         lb = wx.StaticText(top,-1,'Animals(in pairs; min,pair,
> > max,dozen)')
> >         sizer.Add(lb)
> >
> >         top.SetSizer(sizer)
> >         self.Layout()
> >
> > class MyApp(wx.App):
> >     def OnInit(self):
> >         frame = MyFrame(title="wxWidgets")
> >         frame.Show(True)
> >         self.SetTopWindow(frame)
> >         return True
> >
> > def main():
> >     ipshell = IPShellEmbed()
> >     ipshell()
> >     app = MyApp()
> >     app.MainLoop()
> >
> > if __name__ == '__main__':
> >     main()
>
> I forgot to mention.
>
> I did see an example of embedding IPython in a PyGTK app on
> http://ipython.scipy.org/moin/Cookbook
>
> It would be nice to see an example that shows how to embed
> IPython in a wxPython or Tkinter GUI app.
>


IPython has a custom event loop. You'll need to look at it's sources
and figure out how to drive it externally. There's some plugins for
IPython that may help (or may even work out of the box), they're used
to let you run wx or gtk or other libraries that have their own event
loop within IPython.

Are you aware that wx already has a Python shell implementation? It's
different than IPython, of course, but it has graphical inspection of
objects which is the main reason people tend to use IPython.



More information about the Python-list mailing list