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): | |
|
95 | ask_exit_handler=None, rawinput=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) | |
|
117 | ask_exit_handler, rawinput) | |
|
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): | |
|
136 | ask_exit_handler=None, rawinput=None): | |
|
137 | 137 | #first we redefine in/out/error functions of IPython |
|
138 | 138 | if cin: |
|
139 | 139 | IPython.Shell.Term.cin = cin |
@@ -167,7 +167,8 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 = |
|
|
170 | IPython.iplib.raw_input_original = rawinput | |
|
171 | ||
|
171 | 172 | #we replace the ipython default exit command by our method |
|
172 | 173 | self._IP.exit = ask_exit_handler |
|
173 | 174 | #we replace the help command |
@@ -339,12 +340,6 b' class NonBlockingIPShell(object):' | |||
|
339 | 340 | ''' |
|
340 | 341 | pass |
|
341 | 342 | |
|
342 | #def _askExit(self): | |
|
343 | # ''' | |
|
344 | # Can be redefined to generate post event to exit the Ipython shell | |
|
345 | # ''' | |
|
346 | # pass | |
|
347 | ||
|
348 | 343 | def _getHistoryMaxIndex(self): |
|
349 | 344 | ''' |
|
350 | 345 | returns the max length of the history buffer |
@@ -385,18 +380,6 b' class NonBlockingIPShell(object):' | |||
|
385 | 380 | ''' |
|
386 | 381 | self._doc_text = text |
|
387 | 382 | |
|
388 | def _raw_input(self, prompt=''): | |
|
389 | ''' | |
|
390 | Custom raw_input() replacement. Get's current line from console buffer. | |
|
391 | ||
|
392 | @param prompt: Prompt to print. Here for compatability as replacement. | |
|
393 | @type prompt: string | |
|
394 | ||
|
395 | @return: The current command line text. | |
|
396 | @rtype: string | |
|
397 | ''' | |
|
398 | return self._line_to_execute | |
|
399 | ||
|
400 | 383 | def _execute(self): |
|
401 | 384 | ''' |
|
402 | 385 | Executes the current line provided by the shell object. |
@@ -47,11 +47,12 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): | |
|
50 | ask_exit_handler=None, rawinput=None): | |
|
51 | 51 | |
|
52 | 52 | NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns, |
|
53 | 53 | cin, cout, cerr, |
|
54 |
ask_exit_handler |
|
|
54 | ask_exit_handler, | |
|
55 | rawinput) | |
|
55 | 56 | |
|
56 | 57 | self.parent = parent |
|
57 | 58 | |
@@ -394,7 +395,7 b' class WxConsoleView(stc.StyledTextCtrl):' | |||
|
394 | 395 | elif event.GetKeyCode() == wx.WXK_BACK: |
|
395 | 396 | self.moveCursorOnNewValidKey() |
|
396 | 397 | if self.getCursorPos() > self.getCurrentPromptStart(): |
|
397 | self.removeFromTo(self.getCursorPos()-1,self.getCursorPos()) | |
|
398 | event.Skip() | |
|
398 | 399 | return True |
|
399 | 400 | |
|
400 | 401 | if skip: |
@@ -470,8 +471,9 b' class IPShellWidget(wx.Panel):' | |||
|
470 | 471 | self.IP = wx_ip_shell |
|
471 | 472 | else: |
|
472 | 473 | self.IP = WxNonBlockingIPShell(self, |
|
473 | cout = self.cout,cerr = self.cout, | |
|
474 |
ask_exit_handler = self.askExitCallback |
|
|
474 | cout = self.cout, cerr = self.cout, | |
|
475 | ask_exit_handler = self.askExitCallback, | |
|
476 | rawinput = self.rawInput) | |
|
475 | 477 | |
|
476 | 478 | ### IPython wx console view instanciation ### |
|
477 | 479 | #If user didn't defined an intro text, we create one for him |
@@ -548,9 +550,17 b' class IPShellWidget(wx.Panel):' | |||
|
548 | 550 | def setCurrentState(self, state): |
|
549 | 551 | self.cur_state = state |
|
550 | 552 | self.updateStatusTracker(self.cur_state) |
|
551 | ||
|
553 | #---------------------------- Ipython raw_input ----------------------------------- | |
|
554 | def rawInput(self, prompt=''): | |
|
555 | self.setCurrentState('WAITING_USER_INPUT') | |
|
556 | while self.cur_state != 'WAIT_END_OF_EXECUTION': | |
|
557 | pass | |
|
558 | line = self.text_ctrl.getCurrentLine() | |
|
559 | line = line.split('\n') | |
|
560 | return line[-2] | |
|
561 | ||
|
552 | 562 | #---------------------------- IPython pager --------------------------------------- |
|
553 | def pager(self,text):#,start=0,screen_lines=0,pager_cmd = None): | |
|
563 | def pager(self,text): | |
|
554 | 564 | |
|
555 | 565 | if self.pager_state == 'INIT': |
|
556 | 566 | #print >>sys.__stdout__,"PAGER state:",self.pager_state |
@@ -623,15 +633,20 b' class IPShellWidget(wx.Panel):' | |||
|
623 | 633 | self.pager(self.doc) |
|
624 | 634 | return |
|
625 | 635 | |
|
636 | if self.cur_state == 'WAITING_USER_INPUT': | |
|
637 | line=self.text_ctrl.getCurrentLine() | |
|
638 | self.text_ctrl.write('\n') | |
|
639 | self.setCurrentState('WAIT_END_OF_EXECUTION') | |
|
640 | return | |
|
641 | ||
|
626 | 642 | if event.GetKeyCode() in [ord('q'),ord('Q')]: |
|
627 | 643 | if self.pager_state == 'WAITING': |
|
628 | 644 | self.pager_state = 'DONE' |
|
629 | 645 | self.stateShowPrompt() |
|
630 | 646 | return |
|
631 | 647 | |
|
632 |
|
|
|
633 | # print self.cur_state | |
|
634 | # self.text_ctrl.write('.') | |
|
648 | if self.cur_state == 'WAITING_USER_INPUT': | |
|
649 | event.Skip() | |
|
635 | 650 | |
|
636 | 651 | if self.cur_state == 'IDLE': |
|
637 | 652 | if event.KeyCode == wx.WXK_UP: |
@@ -121,6 +121,7 b' class MyFrame(wx.Frame):' | |||
|
121 | 121 | states = {'IDLE':'Idle', |
|
122 | 122 | 'DO_EXECUTE_LINE':'Send command', |
|
123 | 123 | 'WAIT_END_OF_EXECUTION':'Running command', |
|
124 | 'WAITING_USER_INPUT':'Waiting user input', | |
|
124 | 125 | 'SHOW_DOC':'Showing doc', |
|
125 | 126 | 'SHOW_PROMPT':'Showing prompt'} |
|
126 | 127 | self.statusbar.SetStatusText(states[text], 0) |
General Comments 0
You need to be logged in to leave comments.
Login now