##// END OF EJS Templates
Added an option to enable/disable threading as suggested by Ville.
ldufrechou -
Show More
@@ -62,11 +62,10 b' class _Helper(object):'
62 ##############################################################################
62 ##############################################################################
63 class _CodeExecutor(ThreadEx):
63 class _CodeExecutor(ThreadEx):
64 ''' Thread that execute ipython code '''
64 ''' Thread that execute ipython code '''
65 def __init__(self, instance, after):
65 def __init__(self, instance):
66 ThreadEx.__init__(self)
66 ThreadEx.__init__(self)
67 self.instance = instance
67 self.instance = instance
68 self._afterExecute = after
68
69
70 def run(self):
69 def run(self):
71 '''Thread main loop'''
70 '''Thread main loop'''
72 try:
71 try:
@@ -74,7 +73,7 b' class _CodeExecutor(ThreadEx):'
74 self.instance._help_text = None
73 self.instance._help_text = None
75 self.instance._execute()
74 self.instance._execute()
76 # used for uper class to generate event after execution
75 # used for uper class to generate event after execution
77 self._afterExecute()
76 self.instance._afterExecute()
78
77
79 except KeyboardInterrupt:
78 except KeyboardInterrupt:
80 pass
79 pass
@@ -127,7 +126,8 b' class NonBlockingIPShell(object):'
127
126
128 #thread working vars
127 #thread working vars
129 self._line_to_execute = ''
128 self._line_to_execute = ''
130
129 self._threading = True
130
131 #vars that will be checked by GUI loop to handle thread states...
131 #vars that will be checked by GUI loop to handle thread states...
132 #will be replaced later by PostEvent GUI funtions...
132 #will be replaced later by PostEvent GUI funtions...
133 self._doc_text = None
133 self._doc_text = None
@@ -137,7 +137,7 b' class NonBlockingIPShell(object):'
137 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
137 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
138 cin=None, cout=None, cerr=None,
138 cin=None, cout=None, cerr=None,
139 ask_exit_handler=None):
139 ask_exit_handler=None):
140 ''' Initialize an ithon0 instance '''
140 ''' Initialize an ipython0 instance '''
141
141
142 #first we redefine in/out/error functions of IPython
142 #first we redefine in/out/error functions of IPython
143 if cin:
143 if cin:
@@ -199,12 +199,48 b' class NonBlockingIPShell(object):'
199 """
199 """
200
200
201 self._line_to_execute = line
201 self._line_to_execute = line
202 #we launch the ipython line execution in a thread to make it interruptible
202 if self._threading:
203 #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt)
203 #we launch the ipython line execution in a thread to make it interruptible
204 self.ce = _CodeExecutor(self, self._afterExecute)
204 #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt)
205 self.ce.start()
205 self.ce = _CodeExecutor(self)
206
206 self.ce.start()
207 else:
208 try:
209 self._doc_text = None
210 self._help_text = None
211 self._execute()
212 # used for uper class to generate event after execution
213 self._afterExecute()
214
215 except KeyboardInterrupt:
216 pass
207 #----------------------- IPython management section ----------------------
217 #----------------------- IPython management section ----------------------
218 def getThreading(self):
219 """
220 Returns threading status, is set to True, then each command sent to
221 the interpreter will be executed in a separated thread allowing,
222 for example, breaking a long running commands.
223 Disallowing it, permits better compatibilty with instance that is embedding
224 IPython instance.
225
226 @return: Execution method
227 @rtype: bool
228 """
229 return self._threading
230
231 def setThreading(self, state):
232 """
233 Sets threading state, if set to True, then each command sent to
234 the interpreter will be executed in a separated thread allowing,
235 for example, breaking a long running commands.
236 Disallowing it, permits better compatibilty with instance that is embedding
237 IPython instance.
238
239 @param state: Sets threading state
240 @type bool
241 """
242 self._threading = state
243
208 def getDocText(self):
244 def getDocText(self):
209 """
245 """
210 Returns the output of the processing that need to be paged (if any)
246 Returns the output of the processing that need to be paged (if any)
@@ -19,7 +19,7 b' available under the terms of the BSD which accompanies this distribution, and'
19 is available at U{http://www.opensource.org/licenses/bsd-license.php}
19 is available at U{http://www.opensource.org/licenses/bsd-license.php}
20 '''
20 '''
21
21
22 __version__ = 0.8
22 __version__ = 0.9
23 __author__ = "Laurent Dufrechou"
23 __author__ = "Laurent Dufrechou"
24 __email__ = "laurent.dufrechou _at_ gmail.com"
24 __email__ = "laurent.dufrechou _at_ gmail.com"
25 __license__ = "BSD"
25 __license__ = "BSD"
@@ -249,22 +249,15 b' class WxConsoleView(stc.StyledTextCtrl):'
249 @type text: string
249 @type text: string
250 '''
250 '''
251 try:
251 try:
252 #print >>sys.__stdout__,'entering'
253 wx.MutexGuiEnter()
252 wx.MutexGuiEnter()
254 #print >>sys.__stdout__,'locking the GUI'
255
253
256 #be sure not to be interrutpted before the MutexGuiLeave!
254 #be sure not to be interrutpted before the MutexGuiLeave!
257 self.write(text)
255 self.write(text)
258
256
259 #print >>sys.__stdout__,'done'
260
261 except KeyboardInterrupt:
257 except KeyboardInterrupt:
262 #print >>sys.__stdout__,'got keyboard interrupt'
263 wx.MutexGuiLeave()
258 wx.MutexGuiLeave()
264 #print >>sys.__stdout__,'interrupt unlock the GUI'
265 raise KeyboardInterrupt
259 raise KeyboardInterrupt
266 wx.MutexGuiLeave()
260 wx.MutexGuiLeave()
267 #print >>sys.__stdout__,'normal unlock the GUI'
268
261
269
262
270 def write(self, text):
263 def write(self, text):
@@ -565,13 +558,13 b' class IPShellWidget(wx.Panel):'
565 intro=welcome_text,
558 intro=welcome_text,
566 background_color=background_color)
559 background_color=background_color)
567
560
568 self.cout.write = self.text_ctrl.asyncWrite
569
570 option_text = wx.StaticText(self, -1, "Options:")
561 option_text = wx.StaticText(self, -1, "Options:")
571 self.completion_option = wx.CheckBox(self, -1, "Scintilla Completion")
562 self.completion_option = wx.CheckBox(self, -1, "Scintilla Completion")
572 #self.completion_option.SetValue(False)
563 #self.completion_option.SetValue(False)
573 self.background_option = wx.CheckBox(self, -1, "White Background")
564 self.background_option = wx.CheckBox(self, -1, "White Background")
574 #self.background_option.SetValue(False)
565 #self.background_option.SetValue(False)
566 self.threading_option = wx.CheckBox(self, -1, "Execute in thread")
567 #self.threading_option.SetValue(False)
575
568
576 self.options={'completion':{'value':'IPYTHON',
569 self.options={'completion':{'value':'IPYTHON',
577 'checkbox':self.completion_option,'STC':True,'IPYTHON':False,
570 'checkbox':self.completion_option,'STC':True,'IPYTHON':False,
@@ -579,12 +572,20 b' class IPShellWidget(wx.Panel):'
579 'background_color':{'value':'BLACK',
572 'background_color':{'value':'BLACK',
580 'checkbox':self.background_option,'WHITE':True,'BLACK':False,
573 'checkbox':self.background_option,'WHITE':True,'BLACK':False,
581 'setfunc':self.text_ctrl.setBackgroundColor},
574 'setfunc':self.text_ctrl.setBackgroundColor},
575 'threading':{'value':'True',
576 'checkbox':self.threading_option,'True':True,'False':False,
577 'setfunc':self.IP.setThreading},
582 }
578 }
579
580 #self.cout.write dEfault option is asynchroneous because default sate is threading ON
581 self.cout.write = self.text_ctrl.asyncWrite
582 #we reloard options
583 self.reloadOptions(self.options)
583 self.reloadOptions(self.options)
584
584
585 self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress)
585 self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress)
586 self.completion_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionCompletion)
586 self.completion_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionCompletion)
587 self.background_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionBackgroundColor)
587 self.background_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionBackgroundColor)
588 self.threading_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionThreading)
588
589
589 ### making the layout of the panel ###
590 ### making the layout of the panel ###
590 sizer = wx.BoxSizer(wx.VERTICAL)
591 sizer = wx.BoxSizer(wx.VERTICAL)
@@ -596,7 +597,9 b' class IPShellWidget(wx.Panel):'
596 (5, 5),
597 (5, 5),
597 (self.completion_option, 0, wx.ALIGN_CENTER_VERTICAL),
598 (self.completion_option, 0, wx.ALIGN_CENTER_VERTICAL),
598 (8, 8),
599 (8, 8),
599 (self.background_option, 0, wx.ALIGN_CENTER_VERTICAL)
600 (self.background_option, 0, wx.ALIGN_CENTER_VERTICAL),
601 (8, 8),
602 (self.threading_option, 0, wx.ALIGN_CENTER_VERTICAL)
600 ])
603 ])
601 self.SetAutoLayout(True)
604 self.SetAutoLayout(True)
602 sizer.Fit(self)
605 sizer.Fit(self)
@@ -802,7 +805,20 b' class IPShellWidget(wx.Panel):'
802 self.updateOptionTracker('background_color',
805 self.updateOptionTracker('background_color',
803 self.options['background_color']['value'])
806 self.options['background_color']['value'])
804 self.text_ctrl.SetFocus()
807 self.text_ctrl.SetFocus()
805
808
809 def evtCheckOptionThreading(self, event):
810 if event.IsChecked():
811 self.options['threading']['value']='True'
812 self.IP.setThreading(True)
813 self.cout.write = self.text_ctrl.asyncWrite
814 else:
815 self.options['threading']['value']='False'
816 self.IP.setThreading(False)
817 self.cout.write = self.text_ctrl.write
818 self.updateOptionTracker('threading',
819 self.options['threading']['value'])
820 self.text_ctrl.SetFocus()
821
806 def getOptions(self):
822 def getOptions(self):
807 return self.options
823 return self.options
808
824
@@ -813,7 +829,13 b' class IPShellWidget(wx.Panel):'
813 self.options[key]['checkbox'].SetValue(self.options[key][value])
829 self.options[key]['checkbox'].SetValue(self.options[key][value])
814 self.options[key]['setfunc'](value)
830 self.options[key]['setfunc'](value)
815
831
816
832 if self.options['threading']['value']=='True':
833 self.IP.setThreading(True)
834 self.cout.write = self.text_ctrl.asyncWrite
835 else:
836 self.IP.setThreading(False)
837 self.cout.write = self.text_ctrl.write
838
817 #------------------------ Hook Section -----------------------------------
839 #------------------------ Hook Section -----------------------------------
818 def updateOptionTracker(self,name,value):
840 def updateOptionTracker(self,name,value):
819 '''
841 '''
@@ -13,7 +13,7 b' from IPython.gui.wx.ipython_history import IPythonHistoryPanel'
13 #used to create options.conf file in user directory
13 #used to create options.conf file in user directory
14 from IPython.ipapi import get
14 from IPython.ipapi import get
15
15
16 __version__ = 0.8
16 __version__ = 0.9
17 __author__ = "Laurent Dufrechou"
17 __author__ = "Laurent Dufrechou"
18 __email__ = "laurent.dufrechou _at_ gmail.com"
18 __email__ = "laurent.dufrechou _at_ gmail.com"
19 __license__ = "BSD"
19 __license__ = "BSD"
General Comments 0
You need to be logged in to leave comments. Login now