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): |
|
95 | ask_exit_handler=None, rawinput=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) |
|
117 | ask_exit_handler, rawinput) | |
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): |
|
136 | ask_exit_handler=None, rawinput=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,7 +167,8 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 = |
|
170 | IPython.iplib.raw_input_original = rawinput | |
|
171 | ||||
171 | #we replace the ipython default exit command by our method |
|
172 | #we replace the ipython default exit command by our method | |
172 | self._IP.exit = ask_exit_handler |
|
173 | self._IP.exit = ask_exit_handler | |
173 | #we replace the help command |
|
174 | #we replace the help command | |
@@ -339,12 +340,6 b' class NonBlockingIPShell(object):' | |||||
339 | ''' |
|
340 | ''' | |
340 | pass |
|
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 | def _getHistoryMaxIndex(self): |
|
343 | def _getHistoryMaxIndex(self): | |
349 | ''' |
|
344 | ''' | |
350 | returns the max length of the history buffer |
|
345 | returns the max length of the history buffer | |
@@ -385,18 +380,6 b' class NonBlockingIPShell(object):' | |||||
385 | ''' |
|
380 | ''' | |
386 | self._doc_text = text |
|
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 | def _execute(self): |
|
383 | def _execute(self): | |
401 | ''' |
|
384 | ''' | |
402 | Executes the current line provided by the shell object. |
|
385 | Executes the current line provided by the shell object. |
@@ -47,11 +47,12 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): |
|
50 | ask_exit_handler=None, rawinput=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) | |||
55 |
|
56 | |||
56 | self.parent = parent |
|
57 | self.parent = parent | |
57 |
|
58 | |||
@@ -394,7 +395,7 b' class WxConsoleView(stc.StyledTextCtrl):' | |||||
394 | elif event.GetKeyCode() == wx.WXK_BACK: |
|
395 | elif event.GetKeyCode() == wx.WXK_BACK: | |
395 | self.moveCursorOnNewValidKey() |
|
396 | self.moveCursorOnNewValidKey() | |
396 | if self.getCursorPos() > self.getCurrentPromptStart(): |
|
397 | if self.getCursorPos() > self.getCurrentPromptStart(): | |
397 | self.removeFromTo(self.getCursorPos()-1,self.getCursorPos()) |
|
398 | event.Skip() | |
398 | return True |
|
399 | return True | |
399 |
|
400 | |||
400 | if skip: |
|
401 | if skip: | |
@@ -470,8 +471,9 b' class IPShellWidget(wx.Panel):' | |||||
470 | self.IP = wx_ip_shell |
|
471 | self.IP = wx_ip_shell | |
471 | else: |
|
472 | else: | |
472 | self.IP = WxNonBlockingIPShell(self, |
|
473 | self.IP = WxNonBlockingIPShell(self, | |
473 | cout = self.cout,cerr = self.cout, |
|
474 | cout = self.cout, cerr = self.cout, | |
474 |
ask_exit_handler = self.askExitCallback |
|
475 | ask_exit_handler = self.askExitCallback, | |
|
476 | rawinput = self.rawInput) | |||
475 |
|
477 | |||
476 | ### IPython wx console view instanciation ### |
|
478 | ### IPython wx console view instanciation ### | |
477 | #If user didn't defined an intro text, we create one for him |
|
479 | #If user didn't defined an intro text, we create one for him | |
@@ -548,9 +550,17 b' class IPShellWidget(wx.Panel):' | |||||
548 | def setCurrentState(self, state): |
|
550 | def setCurrentState(self, state): | |
549 | self.cur_state = state |
|
551 | self.cur_state = state | |
550 | self.updateStatusTracker(self.cur_state) |
|
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 | #---------------------------- IPython pager --------------------------------------- |
|
562 | #---------------------------- IPython pager --------------------------------------- | |
553 | def pager(self,text):#,start=0,screen_lines=0,pager_cmd = None): |
|
563 | def pager(self,text): | |
554 |
|
564 | |||
555 | if self.pager_state == 'INIT': |
|
565 | if self.pager_state == 'INIT': | |
556 | #print >>sys.__stdout__,"PAGER state:",self.pager_state |
|
566 | #print >>sys.__stdout__,"PAGER state:",self.pager_state | |
@@ -623,15 +633,20 b' class IPShellWidget(wx.Panel):' | |||||
623 | self.pager(self.doc) |
|
633 | self.pager(self.doc) | |
624 | return |
|
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 | if event.GetKeyCode() in [ord('q'),ord('Q')]: |
|
642 | if event.GetKeyCode() in [ord('q'),ord('Q')]: | |
627 | if self.pager_state == 'WAITING': |
|
643 | if self.pager_state == 'WAITING': | |
628 | self.pager_state = 'DONE' |
|
644 | self.pager_state = 'DONE' | |
629 | self.stateShowPrompt() |
|
645 | self.stateShowPrompt() | |
630 | return |
|
646 | return | |
631 |
|
647 | |||
632 |
|
|
648 | if self.cur_state == 'WAITING_USER_INPUT': | |
633 | # print self.cur_state |
|
649 | event.Skip() | |
634 | # self.text_ctrl.write('.') |
|
|||
635 |
|
650 | |||
636 | if self.cur_state == 'IDLE': |
|
651 | if self.cur_state == 'IDLE': | |
637 | if event.KeyCode == wx.WXK_UP: |
|
652 | if event.KeyCode == wx.WXK_UP: |
@@ -121,6 +121,7 b' class MyFrame(wx.Frame):' | |||||
121 | states = {'IDLE':'Idle', |
|
121 | states = {'IDLE':'Idle', | |
122 | 'DO_EXECUTE_LINE':'Send command', |
|
122 | 'DO_EXECUTE_LINE':'Send command', | |
123 | 'WAIT_END_OF_EXECUTION':'Running command', |
|
123 | 'WAIT_END_OF_EXECUTION':'Running command', | |
|
124 | 'WAITING_USER_INPUT':'Waiting user input', | |||
124 | 'SHOW_DOC':'Showing doc', |
|
125 | 'SHOW_DOC':'Showing doc', | |
125 | 'SHOW_PROMPT':'Showing prompt'} |
|
126 | 'SHOW_PROMPT':'Showing prompt'} | |
126 | self.statusbar.SetStatusText(states[text], 0) |
|
127 | self.statusbar.SetStatusText(states[text], 0) |
General Comments 0
You need to be logged in to leave comments.
Login now