##// END OF EJS Templates
-revised code to correct ehaviour under linux....
ldufrechou -
Show More
@@ -92,7 +92,7 b' class NonBlockingIPShell(object):'
92
92
93 def __init__(self,argv=[],user_ns={},user_global_ns=None,
93 def __init__(self,argv=[],user_ns={},user_global_ns=None,
94 cin=None, cout=None, cerr=None,
94 cin=None, cout=None, cerr=None,
95 ask_exit_handler=None, rawinput=None):
95 ask_exit_handler=None):
96 '''
96 '''
97 @param argv: Command line options for IPython
97 @param argv: Command line options for IPython
98 @type argv: list
98 @type argv: list
@@ -114,7 +114,7 b' class NonBlockingIPShell(object):'
114 #ipython0 initialisation
114 #ipython0 initialisation
115 self.initIpython0(argv, user_ns, user_global_ns,
115 self.initIpython0(argv, user_ns, user_global_ns,
116 cin, cout, cerr,
116 cin, cout, cerr,
117 ask_exit_handler, rawinput)
117 ask_exit_handler)
118
118
119 #vars used by _execute
119 #vars used by _execute
120 self._iter_more = 0
120 self._iter_more = 0
@@ -133,7 +133,7 b' class NonBlockingIPShell(object):'
133
133
134 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
134 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
135 cin=None, cout=None, cerr=None,
135 cin=None, cout=None, cerr=None,
136 ask_exit_handler=None, rawinput=None):
136 ask_exit_handler=None):
137 #first we redefine in/out/error functions of IPython
137 #first we redefine in/out/error functions of IPython
138 if cin:
138 if cin:
139 IPython.Shell.Term.cin = cin
139 IPython.Shell.Term.cin = cin
@@ -167,12 +167,18 b' class NonBlockingIPShell(object):'
167 self._IP.set_hook('shell_hook',self._shell)
167 self._IP.set_hook('shell_hook',self._shell)
168
168
169 #we replace the ipython default input command caller by our method
169 #we replace the ipython default input command caller by our method
170 IPython.iplib.raw_input_original = rawinput
170 IPython.iplib.raw_input_original = self._raw_input
171
172 #we replace the ipython default exit command by our method
171 #we replace the ipython default exit command by our method
173 self._IP.exit = ask_exit_handler
172 self._IP.exit = ask_exit_handler
174 #we replace the help command
173 #we replace the help command
175 self._IP.user_ns['help'] = _Helper(self._pager_help)
174 self._IP.user_ns['help'] = _Helper(self._pager_help)
175
176 #we disable cpase magic... until we found a way to use it properly.
177 #import IPython.ipapi
178 ip = IPython.ipapi.get()
179 def bypassMagic(self, arg):
180 print '%this magic is currently disabled.'
181 ip.expose_magic('cpaste', bypassMagic)
176
182
177 sys.excepthook = excepthook
183 sys.excepthook = excepthook
178
184
@@ -340,6 +346,12 b' class NonBlockingIPShell(object):'
340 '''
346 '''
341 pass
347 pass
342
348
349 #def _askExit(self):
350 # '''
351 # Can be redefined to generate post event to exit the Ipython shell
352 # '''
353 # pass
354
343 def _getHistoryMaxIndex(self):
355 def _getHistoryMaxIndex(self):
344 '''
356 '''
345 returns the max length of the history buffer
357 returns the max length of the history buffer
@@ -380,6 +392,18 b' class NonBlockingIPShell(object):'
380 '''
392 '''
381 self._doc_text = text
393 self._doc_text = text
382
394
395 def _raw_input(self, prompt=''):
396 '''
397 Custom raw_input() replacement. Get's current line from console buffer.
398
399 @param prompt: Prompt to print. Here for compatability as replacement.
400 @type prompt: string
401
402 @return: The current command line text.
403 @rtype: string
404 '''
405 return self._line_to_execute
406
383 def _execute(self):
407 def _execute(self):
384 '''
408 '''
385 Executes the current line provided by the shell object.
409 Executes the current line provided by the shell object.
@@ -47,12 +47,11 b' class WxNonBlockingIPShell(NonBlockingIPShell):'
47 def __init__(self, parent,
47 def __init__(self, parent,
48 argv=[],user_ns={},user_global_ns=None,
48 argv=[],user_ns={},user_global_ns=None,
49 cin=None, cout=None, cerr=None,
49 cin=None, cout=None, cerr=None,
50 ask_exit_handler=None, rawinput=None):
50 ask_exit_handler=None):
51
51
52 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
52 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
53 cin, cout, cerr,
53 cin, cout, cerr,
54 ask_exit_handler,
54 ask_exit_handler)
55 rawinput)
56
55
57 self.parent = parent
56 self.parent = parent
58
57
@@ -216,6 +215,31 b' class WxConsoleView(stc.StyledTextCtrl):'
216
215
217 self.Bind(wx.EVT_KEY_DOWN, self._onKeypress, self)
216 self.Bind(wx.EVT_KEY_DOWN, self._onKeypress, self)
218
217
218 def asyncWrite(self, text):
219 '''
220 Write given text to buffer in an asynchroneous way.
221 It is used from another thread to be able to acces the GUI.
222 @param text: Text to append
223 @type text: string
224 '''
225 try:
226 #print >>sys.__stdout__,'entering'
227 wx.MutexGuiEnter()
228 #print >>sys.__stdout__,'locking the GUI'
229
230 #be sure not to be interrutpted before the MutexGuiLeave!
231 self.write(text)
232 #print >>sys.__stdout__,'done'
233
234 except KeyboardInterrupt:
235 #print >>sys.__stdout__,'got keyboard interrupt'
236 wx.MutexGuiLeave()
237 #print >>sys.__stdout__,'interrupt unlock the GUI'
238 raise KeyboardInterrupt
239 wx.MutexGuiLeave()
240 #print >>sys.__stdout__,'normal unlock the GUI'
241
242
219 def write(self, text):
243 def write(self, text):
220 '''
244 '''
221 Write given text to buffer.
245 Write given text to buffer.
@@ -472,8 +496,7 b' class IPShellWidget(wx.Panel):'
472 else:
496 else:
473 self.IP = WxNonBlockingIPShell(self,
497 self.IP = WxNonBlockingIPShell(self,
474 cout = self.cout, cerr = self.cout,
498 cout = self.cout, cerr = self.cout,
475 ask_exit_handler = self.askExitCallback,
499 ask_exit_handler = self.askExitCallback)
476 rawinput = self.rawInput)
477
500
478 ### IPython wx console view instanciation ###
501 ### IPython wx console view instanciation ###
479 #If user didn't defined an intro text, we create one for him
502 #If user didn't defined an intro text, we create one for him
@@ -492,7 +515,7 b' class IPShellWidget(wx.Panel):'
492 intro=welcome_text,
515 intro=welcome_text,
493 background_color=background_color)
516 background_color=background_color)
494
517
495 self.cout.write = self.text_ctrl.write
518 self.cout.write = self.text_ctrl.asyncWrite
496
519
497 self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress, self.text_ctrl)
520 self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress, self.text_ctrl)
498
521
@@ -509,18 +532,19 b' class IPShellWidget(wx.Panel):'
509 #widget state management (for key handling different cases)
532 #widget state management (for key handling different cases)
510 self.setCurrentState('IDLE')
533 self.setCurrentState('IDLE')
511 self.pager_state = 'DONE'
534 self.pager_state = 'DONE'
535 self.raw_input_current_line = 0
512
536
513 def askExitCallback(self, event):
537 def askExitCallback(self, event):
514 self.askExitHandler(event)
538 self.askExitHandler(event)
515
539
516 #---------------------- IPython Thread Management ------------------------
540 #---------------------- IPython Thread Management ------------------------
517 def stateDoExecuteLine(self):
541 def stateDoExecuteLine(self):
518 #print >>sys.__stdout__,"command:",self.getCurrentLine()
519 lines=self.text_ctrl.getCurrentLine()
542 lines=self.text_ctrl.getCurrentLine()
520 self.text_ctrl.write('\n')
543 self.text_ctrl.write('\n')
521 for line in lines.split('\n'):
544 lines_to_execute = lines.replace('\t',' '*4)
522 self.IP.doExecute((line.replace('\t',' '*4)).encode('cp1252'))
545 lines_to_execute = lines_to_execute.replace('\r\n','\n')
523 self.updateHistoryTracker(self.text_ctrl.getCurrentLine())
546 self.IP.doExecute(lines.encode('cp1252'))
547 self.updateHistoryTracker(lines)
524 self.setCurrentState('WAIT_END_OF_EXECUTION')
548 self.setCurrentState('WAIT_END_OF_EXECUTION')
525
549
526 def evtStateExecuteDone(self,evt):
550 def evtStateExecuteDone(self,evt):
@@ -551,16 +575,7 b' class IPShellWidget(wx.Panel):'
551 def setCurrentState(self, state):
575 def setCurrentState(self, state):
552 self.cur_state = state
576 self.cur_state = state
553 self.updateStatusTracker(self.cur_state)
577 self.updateStatusTracker(self.cur_state)
554 #---------------------------- Ipython raw_input -----------------------------------
578
555 def rawInput(self, prompt=''):
556 self.setCurrentState('WAITING_USER_INPUT')
557 while self.cur_state != 'WAIT_END_OF_EXECUTION':
558 pass
559 line = self.text_ctrl.getCurrentLine()
560 line = line.split('\n')
561 return line[-2]
562
563 #---------------------------- IPython pager ---------------------------------------
564 def pager(self,text):
579 def pager(self,text):
565
580
566 if self.pager_state == 'INIT':
581 if self.pager_state == 'INIT':
General Comments 0
You need to be logged in to leave comments. Login now