embed ipython in wxPython app

chewie54 dfabrizio51 at gmail.com
Mon Nov 19 14:23:54 EST 2007


On Nov 19, 1:44 pm, "Chris Mellon" <arka... at gmail.com> wrote:
> On Nov 19, 2007 12:21 PM, chewie54 <dfabrizi... at gmail.com> wrote:
>
>
>
> > On Nov 19, 1:07 pm, "Chris Mellon" <arka... at gmail.com> wrote:
>
> > > On Nov 19, 2007 11:51 AM, chewie54 <dfabrizi... 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.
>
> > Yes,  I have seen the wxPython demo and PyShell example but was
> > looking
> > to use IPython since the user can navigate directories like other
> > unix
> > shells.
>
> > What are these plugins you mentioned?
>
> http://ipython.scipy.org/moin/Cookbook/InterruptingThreads
>
> I'm not sure how these work (the wiki page implies they just run the
> external event loop in a thread, so they're not suitable for embedding
> IPython in such a tool kit). I'm sure there's a way to pump IPython
> though (there must be, since it's embeddable in gtk) so that's where
> you'll want to look.

This was helpful.

ipython -wxthread

run test1_python.py

and the GUI window was displayed and I can see my object definitions.

I'm getting closer,  now I need to imbed ipython -wxthread shell in
the app somehow.


Thanks,



More information about the Python-list mailing list