Show More
@@ -62,11 +62,10 b' class _Helper(object):' | |||
|
62 | 62 | ############################################################################## |
|
63 | 63 | class _CodeExecutor(ThreadEx): |
|
64 | 64 | ''' Thread that execute ipython code ''' |
|
65 |
def __init__(self, instance |
|
|
65 | def __init__(self, instance): | |
|
66 | 66 | ThreadEx.__init__(self) |
|
67 | 67 | self.instance = instance |
|
68 | self._afterExecute = after | |
|
69 | ||
|
68 | ||
|
70 | 69 | def run(self): |
|
71 | 70 | '''Thread main loop''' |
|
72 | 71 | try: |
@@ -74,7 +73,7 b' class _CodeExecutor(ThreadEx):' | |||
|
74 | 73 | self.instance._help_text = None |
|
75 | 74 | self.instance._execute() |
|
76 | 75 | # used for uper class to generate event after execution |
|
77 | self._afterExecute() | |
|
76 | self.instance._afterExecute() | |
|
78 | 77 | |
|
79 | 78 | except KeyboardInterrupt: |
|
80 | 79 | pass |
@@ -127,7 +126,8 b' class NonBlockingIPShell(object):' | |||
|
127 | 126 | |
|
128 | 127 | #thread working vars |
|
129 | 128 | self._line_to_execute = '' |
|
130 | ||
|
129 | self._threading = True | |
|
130 | ||
|
131 | 131 | #vars that will be checked by GUI loop to handle thread states... |
|
132 | 132 | #will be replaced later by PostEvent GUI funtions... |
|
133 | 133 | self._doc_text = None |
@@ -137,7 +137,7 b' class NonBlockingIPShell(object):' | |||
|
137 | 137 | def initIpython0(self, argv=[], user_ns={}, user_global_ns=None, |
|
138 | 138 | cin=None, cout=None, cerr=None, |
|
139 | 139 | ask_exit_handler=None): |
|
140 | ''' Initialize an ithon0 instance ''' | |
|
140 | ''' Initialize an ipython0 instance ''' | |
|
141 | 141 | |
|
142 | 142 | #first we redefine in/out/error functions of IPython |
|
143 | 143 | if cin: |
@@ -199,12 +199,48 b' class NonBlockingIPShell(object):' | |||
|
199 | 199 | """ |
|
200 | 200 | |
|
201 | 201 | self._line_to_execute = line |
|
202 | #we launch the ipython line execution in a thread to make it interruptible | |
|
203 | #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt) | |
|
204 | self.ce = _CodeExecutor(self, self._afterExecute) | |
|
205 | self.ce.start() | |
|
206 | ||
|
202 | if self._threading: | |
|
203 | #we launch the ipython line execution in a thread to make it interruptible | |
|
204 | #with include it in self namespace to be able to call ce.raise_exc(KeyboardInterrupt) | |
|
205 | self.ce = _CodeExecutor(self) | |
|
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 | 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 | 244 | def getDocText(self): |
|
209 | 245 | """ |
|
210 | 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 | 19 | is available at U{http://www.opensource.org/licenses/bsd-license.php} |
|
20 | 20 | ''' |
|
21 | 21 | |
|
22 |
__version__ = 0. |
|
|
22 | __version__ = 0.9 | |
|
23 | 23 | __author__ = "Laurent Dufrechou" |
|
24 | 24 | __email__ = "laurent.dufrechou _at_ gmail.com" |
|
25 | 25 | __license__ = "BSD" |
@@ -249,22 +249,15 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
249 | 249 | @type text: string |
|
250 | 250 | ''' |
|
251 | 251 | try: |
|
252 | #print >>sys.__stdout__,'entering' | |
|
253 | 252 | wx.MutexGuiEnter() |
|
254 | #print >>sys.__stdout__,'locking the GUI' | |
|
255 | 253 | |
|
256 | 254 | #be sure not to be interrutpted before the MutexGuiLeave! |
|
257 | 255 | self.write(text) |
|
258 | 256 | |
|
259 | #print >>sys.__stdout__,'done' | |
|
260 | ||
|
261 | 257 | except KeyboardInterrupt: |
|
262 | #print >>sys.__stdout__,'got keyboard interrupt' | |
|
263 | 258 | wx.MutexGuiLeave() |
|
264 | #print >>sys.__stdout__,'interrupt unlock the GUI' | |
|
265 | 259 | raise KeyboardInterrupt |
|
266 | 260 | wx.MutexGuiLeave() |
|
267 | #print >>sys.__stdout__,'normal unlock the GUI' | |
|
268 | 261 | |
|
269 | 262 | |
|
270 | 263 | def write(self, text): |
@@ -565,13 +558,13 b' class IPShellWidget(wx.Panel):' | |||
|
565 | 558 | intro=welcome_text, |
|
566 | 559 | background_color=background_color) |
|
567 | 560 | |
|
568 | self.cout.write = self.text_ctrl.asyncWrite | |
|
569 | ||
|
570 | 561 | option_text = wx.StaticText(self, -1, "Options:") |
|
571 | 562 | self.completion_option = wx.CheckBox(self, -1, "Scintilla Completion") |
|
572 | 563 | #self.completion_option.SetValue(False) |
|
573 | 564 | self.background_option = wx.CheckBox(self, -1, "White Background") |
|
574 | 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 | 569 | self.options={'completion':{'value':'IPYTHON', |
|
577 | 570 | 'checkbox':self.completion_option,'STC':True,'IPYTHON':False, |
@@ -579,12 +572,20 b' class IPShellWidget(wx.Panel):' | |||
|
579 | 572 | 'background_color':{'value':'BLACK', |
|
580 | 573 | 'checkbox':self.background_option,'WHITE':True,'BLACK':False, |
|
581 | 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 | 583 | self.reloadOptions(self.options) |
|
584 | 584 | |
|
585 | 585 | self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress) |
|
586 | 586 | self.completion_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionCompletion) |
|
587 | 587 | self.background_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionBackgroundColor) |
|
588 | self.threading_option.Bind(wx.EVT_CHECKBOX, self.evtCheckOptionThreading) | |
|
588 | 589 | |
|
589 | 590 | ### making the layout of the panel ### |
|
590 | 591 | sizer = wx.BoxSizer(wx.VERTICAL) |
@@ -596,7 +597,9 b' class IPShellWidget(wx.Panel):' | |||
|
596 | 597 | (5, 5), |
|
597 | 598 | (self.completion_option, 0, wx.ALIGN_CENTER_VERTICAL), |
|
598 | 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 | 604 | self.SetAutoLayout(True) |
|
602 | 605 | sizer.Fit(self) |
@@ -802,7 +805,20 b' class IPShellWidget(wx.Panel):' | |||
|
802 | 805 | self.updateOptionTracker('background_color', |
|
803 | 806 | self.options['background_color']['value']) |
|
804 | 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 | 822 | def getOptions(self): |
|
807 | 823 | return self.options |
|
808 | 824 | |
@@ -813,7 +829,13 b' class IPShellWidget(wx.Panel):' | |||
|
813 | 829 | self.options[key]['checkbox'].SetValue(self.options[key][value]) |
|
814 | 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 | 839 | #------------------------ Hook Section ----------------------------------- |
|
818 | 840 | def updateOptionTracker(self,name,value): |
|
819 | 841 | ''' |
@@ -13,7 +13,7 b' from IPython.gui.wx.ipython_history import IPythonHistoryPanel' | |||
|
13 | 13 | #used to create options.conf file in user directory |
|
14 | 14 | from IPython.ipapi import get |
|
15 | 15 | |
|
16 |
__version__ = 0. |
|
|
16 | __version__ = 0.9 | |
|
17 | 17 | __author__ = "Laurent Dufrechou" |
|
18 | 18 | __email__ = "laurent.dufrechou _at_ gmail.com" |
|
19 | 19 | __license__ = "BSD" |
General Comments 0
You need to be logged in to leave comments.
Login now