embed ipython in wxPython app

C

chewie54

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()
 
C

chewie54

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

Chris Mellon

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

chewie54

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?

Thanks,
 
C

Chris Mellon

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

chewie54

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top