diff --git a/IPython/gui/wx/ipython_view.py b/IPython/gui/wx/ipython_view.py index 7dee619..599d7d6 100644 --- a/IPython/gui/wx/ipython_view.py +++ b/IPython/gui/wx/ipython_view.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: iso-8859-15 -*- ''' -Provides IPython WX console widget. +Provides IPython WX console widgets. @author: Laurent Dufrechou laurent.dufrechou _at_ gmail.com @@ -33,7 +33,6 @@ import sys import os import locale import time -#from ThreadEx import Thread from StringIO import StringIO try: import IPython @@ -41,11 +40,11 @@ except Exception,e: raise "Error importing IPython (%s)" % str(e) -from ipython_interactive_shell import * +from non_blocking_ip_shell import * -class WxIterableIPShell(IterableIPShell): +class WxNonBlockingIPShell(NonBlockingIPShell): ''' - An IterableIPShell Thread that is WX dependent. + An NonBlockingIPShell Thread that is WX dependent. Thus it permits direct interaction with a WX GUI without OnIdle event state machine trick... ''' def __init__(self,wx_instance, @@ -54,7 +53,7 @@ class WxIterableIPShell(IterableIPShell): exit_handler=None,time_loop = 0.1): user_ns['addGUIShortcut'] = self.addGUIShortcut - IterableIPShell.__init__(self,argv,user_ns,user_global_ns, + NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns, cin, cout, cerr, exit_handler,time_loop) @@ -464,8 +463,10 @@ class WxIPythonViewPanel(wx.Panel): I've choosed to derivate from a wx.Panel because it seems to be ore usefull Any idea to make it more 'genric' welcomed. ''' - def __init__(self,parent,exit_handler=None,intro=None, - background_color="BLACK",add_button_handler=None): + def __init__(self, parent, exit_handler=None, intro=None, + background_color="BLACK", add_button_handler=None, + wx_ip_shell=None, + ): ''' Initialize. Instanciate an IPython thread. @@ -480,7 +481,10 @@ class WxIPythonViewPanel(wx.Panel): self.add_button_handler = add_button_handler self.exit_handler = exit_handler - self.IP = WxIterableIPShell(self, + if wx_ip_shell is not None: + self.IP = wx_ip_shell + else: + self.IP = WxNonBlockingIPShell(self, cout=self.cout,cerr=self.cout, exit_handler = exit_handler, time_loop = 0.1) @@ -526,7 +530,7 @@ class WxIPythonViewPanel(wx.Panel): # 'SHOW_PROMPT'] self.cur_state = 'IDLE' - self.pager_state = 'DONE' + self.pager_state = 'DONE' #wx.CallAfter(self.runStateMachine) # This creates a new Event class and a EVT binder function @@ -578,9 +582,9 @@ class WxIPythonViewPanel(wx.Panel): if rv: rv = rv.strip('\n') self.text_ctrl.showReturned(rv) self.cout.truncate(0) - self.IP.initHistoryIndex() - self.cur_state = 'IDLE' - + self.IP.initHistoryIndex() + self.cur_state = 'IDLE' + ## def runStateMachine(self,event): ## #print >>sys.__stdout__,"state:",self.cur_state ## self.updateStatusTracker(self.cur_state) @@ -598,8 +602,8 @@ class WxIPythonViewPanel(wx.Panel): ## self.doc = self.IP.getDocText() ## if self.doc: ## self.pager_state = 'INIT' -## self.cur_state = 'SHOW_DOC' -## #if self.button: +## self.cur_state = 'SHOW_DOC' +## #if self.button: ## #self.IP.doExecute('print "cool"')#self.button['func']) ## #self.updateHistoryTracker(self.text_ctrl.getCurrentLine()) ## diff --git a/IPython/gui/wx/ipython_interactive_shell.py b/IPython/gui/wx/non_blocking_ip_shell.py similarity index 97% rename from IPython/gui/wx/ipython_interactive_shell.py rename to IPython/gui/wx/non_blocking_ip_shell.py index 70a0815..9336465 100644 --- a/IPython/gui/wx/ipython_interactive_shell.py +++ b/IPython/gui/wx/non_blocking_ip_shell.py @@ -23,7 +23,7 @@ import os import locale import time import pydoc,__builtin__,site -from ThreadEx import Thread +from thread_ex import ThreadEx from StringIO import StringIO try: @@ -57,13 +57,13 @@ class _Helper(object): return pydoc.help(*args, **kwds) -class IterableIPShell(Thread): +class NonBlockingIPShell(ThreadEx): ''' Create an IPython instance inside a dedicated thread. Does not start a blocking event loop, instead allow single iterations. This allows embedding in any GUI without blockage. The thread is a slave one, in that it doesn't interact directly with the GUI. - Note Thread class comes from ThreadEx that supports asynchroneous function call + Note ThreadEx class supports asynchroneous function call via raise_exc() ''' @@ -89,7 +89,7 @@ class IterableIPShell(Thread): @param time_loop: Define the sleep time between two thread's loop @type int ''' - Thread.__init__(self) + ThreadEx.__init__(self) #first we redefine in/out/error functions of IPython if cin: diff --git a/IPython/gui/wx/ThreadEx.py b/IPython/gui/wx/thread_ex.py similarity index 92% rename from IPython/gui/wx/ThreadEx.py rename to IPython/gui/wx/thread_ex.py index 071f50a..741af3e 100644 --- a/IPython/gui/wx/ThreadEx.py +++ b/IPython/gui/wx/thread_ex.py @@ -1,3 +1,8 @@ +""" +Thread subclass that can deal with asynchronously function calls via +raise_exc. +""" + import threading import inspect import ctypes @@ -17,7 +22,7 @@ def _async_raise(tid, exctype): raise SystemError("PyThreadState_SetAsyncExc failed") -class Thread(threading.Thread): +class ThreadEx(threading.Thread): def _get_my_tid(self): """determines this (self's) thread id""" if not self.isAlive():