##// 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 93 def __init__(self,argv=[],user_ns={},user_global_ns=None,
94 94 cin=None, cout=None, cerr=None,
95 ask_exit_handler=None, rawinput=None):
95 ask_exit_handler=None):
96 96 '''
97 97 @param argv: Command line options for IPython
98 98 @type argv: list
@@ -114,7 +114,7 b' class NonBlockingIPShell(object):'
114 114 #ipython0 initialisation
115 115 self.initIpython0(argv, user_ns, user_global_ns,
116 116 cin, cout, cerr,
117 ask_exit_handler, rawinput)
117 ask_exit_handler)
118 118
119 119 #vars used by _execute
120 120 self._iter_more = 0
@@ -133,7 +133,7 b' class NonBlockingIPShell(object):'
133 133
134 134 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
135 135 cin=None, cout=None, cerr=None,
136 ask_exit_handler=None, rawinput=None):
136 ask_exit_handler=None):
137 137 #first we redefine in/out/error functions of IPython
138 138 if cin:
139 139 IPython.Shell.Term.cin = cin
@@ -167,12 +167,18 b' class NonBlockingIPShell(object):'
167 167 self._IP.set_hook('shell_hook',self._shell)
168 168
169 169 #we replace the ipython default input command caller by our method
170 IPython.iplib.raw_input_original = rawinput
171
170 IPython.iplib.raw_input_original = self._raw_input
172 171 #we replace the ipython default exit command by our method
173 172 self._IP.exit = ask_exit_handler
174 173 #we replace the help command
175 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 183 sys.excepthook = excepthook
178 184
@@ -340,6 +346,12 b' class NonBlockingIPShell(object):'
340 346 '''
341 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 355 def _getHistoryMaxIndex(self):
344 356 '''
345 357 returns the max length of the history buffer
@@ -380,6 +392,18 b' class NonBlockingIPShell(object):'
380 392 '''
381 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 407 def _execute(self):
384 408 '''
385 409 Executes the current line provided by the shell object.
@@ -47,12 +47,11 b' class WxNonBlockingIPShell(NonBlockingIPShell):'
47 47 def __init__(self, parent,
48 48 argv=[],user_ns={},user_global_ns=None,
49 49 cin=None, cout=None, cerr=None,
50 ask_exit_handler=None, rawinput=None):
50 ask_exit_handler=None):
51 51
52 52 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
53 53 cin, cout, cerr,
54 ask_exit_handler,
55 rawinput)
54 ask_exit_handler)
56 55
57 56 self.parent = parent
58 57
@@ -216,6 +215,31 b' class WxConsoleView(stc.StyledTextCtrl):'
216 215
217 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 243 def write(self, text):
220 244 '''
221 245 Write given text to buffer.
@@ -472,8 +496,7 b' class IPShellWidget(wx.Panel):'
472 496 else:
473 497 self.IP = WxNonBlockingIPShell(self,
474 498 cout = self.cout, cerr = self.cout,
475 ask_exit_handler = self.askExitCallback,
476 rawinput = self.rawInput)
499 ask_exit_handler = self.askExitCallback)
477 500
478 501 ### IPython wx console view instanciation ###
479 502 #If user didn't defined an intro text, we create one for him
@@ -492,7 +515,7 b' class IPShellWidget(wx.Panel):'
492 515 intro=welcome_text,
493 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 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 532 #widget state management (for key handling different cases)
510 533 self.setCurrentState('IDLE')
511 534 self.pager_state = 'DONE'
535 self.raw_input_current_line = 0
512 536
513 537 def askExitCallback(self, event):
514 538 self.askExitHandler(event)
515 539
516 540 #---------------------- IPython Thread Management ------------------------
517 541 def stateDoExecuteLine(self):
518 #print >>sys.__stdout__,"command:",self.getCurrentLine()
519 542 lines=self.text_ctrl.getCurrentLine()
520 543 self.text_ctrl.write('\n')
521 for line in lines.split('\n'):
522 self.IP.doExecute((line.replace('\t',' '*4)).encode('cp1252'))
523 self.updateHistoryTracker(self.text_ctrl.getCurrentLine())
544 lines_to_execute = lines.replace('\t',' '*4)
545 lines_to_execute = lines_to_execute.replace('\r\n','\n')
546 self.IP.doExecute(lines.encode('cp1252'))
547 self.updateHistoryTracker(lines)
524 548 self.setCurrentState('WAIT_END_OF_EXECUTION')
525 549
526 550 def evtStateExecuteDone(self,evt):
@@ -551,16 +575,7 b' class IPShellWidget(wx.Panel):'
551 575 def setCurrentState(self, state):
552 576 self.cur_state = state
553 577 self.updateStatusTracker(self.cur_state)
554 #---------------------------- Ipython raw_input -----------------------------------
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 ---------------------------------------
578
564 579 def pager(self,text):
565 580
566 581 if self.pager_state == 'INIT':
General Comments 0
You need to be logged in to leave comments. Login now