diff --git a/IPython/gui/wx/ipshell_nonblocking.py b/IPython/gui/wx/ipshell_nonblocking.py index be9d47b..35f6aa8 100644 --- a/IPython/gui/wx/ipshell_nonblocking.py +++ b/IPython/gui/wx/ipshell_nonblocking.py @@ -62,11 +62,10 @@ class _Helper(object): ############################################################################## class _CodeExecutor(ThreadEx): ''' Thread that execute ipython code ''' - def __init__(self, instance, after): + def __init__(self, instance): ThreadEx.__init__(self) self.instance = instance - self._afterExecute = after - + def run(self): '''Thread main loop''' try: @@ -74,7 +73,7 @@ class _CodeExecutor(ThreadEx): self.instance._help_text = None self.instance._execute() # used for uper class to generate event after execution - self._afterExecute() + self.instance._afterExecute() except KeyboardInterrupt: pass @@ -127,7 +126,8 @@ class NonBlockingIPShell(object): #thread working vars self._line_to_execute = '' - + self._threading = True + #vars that will be checked by GUI loop to handle thread states... #will be replaced later by PostEvent GUI funtions... self._doc_text = None @@ -137,7 +137,7 @@ class NonBlockingIPShell(object): def initIpython0(self, argv=[], user_ns={}, user_global_ns=None, cin=None, cout=None, cerr=None, ask_exit_handler=None): - ''' Initialize an ithon0 instance ''' + ''' Initialize an ipython0 instance ''' #first we redefine in/out/error functions of IPython if cin: @@ -199,12 +199,48 @@ class NonBlockingIPShell(object): """ self._line_to_execute = line - #we launch the ipython line execution in a thread to make it interruptible - #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt) - self.ce = _CodeExecutor(self, self._afterExecute) - self.ce.start() - + if self._threading: + #we launch the ipython line execution in a thread to make it interruptible + #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt) + self.ce = _CodeExecutor(self) + self.ce.start() + else: + try: + self._doc_text = None + self._help_text = None + self._execute() + # used for uper class to generate event after execution + self._afterExecute() + + except KeyboardInterrupt: + pass #----------------------- IPython management section ---------------------- + def getThreading(self): + """ + Returns threading status, is set to True, then each command sent to + the interpreter will be executed in a separated thread allowing, + for example, breaking a long running commands. + Disallowing it, permits better compatibilty with instance that is embedding + IPython instance. + + @return: Execution method + @rtype: bool + """ + return self._threading + + def setThreading(self, state): + """ + Sets threading state, if set to True, then each command sent to + the interpreter will be executed in a separated thread allowing, + for example, breaking a long running commands. + Disallowing it, permits better compatibilty with instance that is embedding + IPython instance. + + @param state: Sets threading state + @type bool + """ + self._threading = state + def getDocText(self): """ Returns the output of the processing that need to be paged (if any) diff --git a/IPython/gui/wx/ipython_view.py b/IPython/gui/wx/ipython_view.py index c189780..ae24110 100644 --- a/IPython/gui/wx/ipython_view.py +++ b/IPython/gui/wx/ipython_view.py @@ -19,7 +19,7 @@ available under the terms of the BSD which accompanies this distribution, and is available at U{http://www.opensource.org/licenses/bsd-license.php} ''' -__version__ = 0.8 +__version__ = 0.9 __author__ = "Laurent Dufrechou" __email__ = "laurent.dufrechou _at_ gmail.com" __license__ = "BSD" @@ -249,22 +249,15 @@ class WxConsoleView(stc.StyledTextCtrl): @type text: string ''' try: - #print >>sys.__stdout__,'entering' wx.MutexGuiEnter() - #print >>sys.__stdout__,'locking the GUI' #be sure not to be interrutpted before the MutexGuiLeave! self.write(text) - #print >>sys.__stdout__,'done' - except KeyboardInterrupt: - #print >>sys.__stdout__,'got keyboard interrupt' wx.MutexGuiLeave() - #print >>sys.__stdout__,'interrupt unlock the GUI' raise KeyboardInterrupt wx.MutexGuiLeave() - #print >>sys.__stdout__,'normal unlock the GUI' def write(self, text): @@ -565,13 +558,13 @@ class IPShellWidget(wx.Panel): intro=welcome_text, background_color=background_color) - self.cout.write = self.text_ctrl.asyncWrite - option_text = wx.StaticText(self, -1, "Options:") self.completion_option = wx.CheckBox(self, -1, "Scintilla Completion") #self.completion_option.SetValue(False) self.background_option = wx.CheckBox(self, -1, "White Background") #self.background_option.SetValue(False) + self.threading_option = wx.CheckBox(self, -1, "Execute in thread") + #self.threading_option.SetValue(False) self.options={'completion':{'value':'IPYTHON', 'checkbox':self.completion_option,'STC':True,'IPYTHON':False, @@ -579,12 +572,20 @@ class IPShellWidget(wx.Panel): 'background_color':{'value':'BLACK', 'checkbox':self.background_option,'WHITE':True,'BLACK':False, 'setfunc':self.text_ctrl.setBackgroundColor}, + 'threading':{'value':'True', + 'checkbox':self.threading_option,'True':True,'False':False, + 'setfunc':self.IP.setThreading}, } + + #self.cout.write dEfault option is asynchroneous because default sate is threading ON + self.cout.write = self.text_ctrl.asyncWrite + #we reloard options self.reloadOptions(self.options) self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress) self.completion_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionCompletion) self.background_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionBackgroundColor) + self.threading_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionThreading) ### making the layout of the panel ### sizer = wx.BoxSizer(wx.VERTICAL) @@ -596,7 +597,9 @@ class IPShellWidget(wx.Panel): (5, 5), (self.completion_option, 0, wx.ALIGN_CENTER_VERTICAL), (8, 8), - (self.background_option, 0, wx.ALIGN_CENTER_VERTICAL) + (self.background_option, 0, wx.ALIGN_CENTER_VERTICAL), + (8, 8), + (self.threading_option, 0, wx.ALIGN_CENTER_VERTICAL) ]) self.SetAutoLayout(True) sizer.Fit(self) @@ -802,7 +805,20 @@ class IPShellWidget(wx.Panel): self.updateOptionTracker('background_color', self.options['background_color']['value']) self.text_ctrl.SetFocus() - + + def evtCheckOptionThreading(self, event): + if event.IsChecked(): + self.options['threading']['value']='True' + self.IP.setThreading(True) + self.cout.write = self.text_ctrl.asyncWrite + else: + self.options['threading']['value']='False' + self.IP.setThreading(False) + self.cout.write = self.text_ctrl.write + self.updateOptionTracker('threading', + self.options['threading']['value']) + self.text_ctrl.SetFocus() + def getOptions(self): return self.options @@ -813,7 +829,13 @@ class IPShellWidget(wx.Panel): self.options[key]['checkbox'].SetValue(self.options[key][value]) self.options[key]['setfunc'](value) - + if self.options['threading']['value']=='True': + self.IP.setThreading(True) + self.cout.write = self.text_ctrl.asyncWrite + else: + self.IP.setThreading(False) + self.cout.write = self.text_ctrl.write + #------------------------ Hook Section ----------------------------------- def updateOptionTracker(self,name,value): ''' diff --git a/IPython/gui/wx/wxIPython.py b/IPython/gui/wx/wxIPython.py index 0d0d249..759ab73 100755 --- a/IPython/gui/wx/wxIPython.py +++ b/IPython/gui/wx/wxIPython.py @@ -13,7 +13,7 @@ from IPython.gui.wx.ipython_history import IPythonHistoryPanel #used to create options.conf file in user directory from IPython.ipapi import get -__version__ = 0.8 +__version__ = 0.9 __author__ = "Laurent Dufrechou" __email__ = "laurent.dufrechou _at_ gmail.com" __license__ = "BSD"