##// END OF EJS Templates
cleaner way to handle raw_input, done with a TextEntryDialog + __builtin__ overload as suggested by Ville....
laurent.dufrechou@gmail.com -
Show More
@@ -176,7 +176,7 b' class NonBlockingIPShell(object):'
176 self._IP.set_hook('shell_hook', self._shell)
176 self._IP.set_hook('shell_hook', self._shell)
177
177
178 #we replace the ipython default input command caller by our method
178 #we replace the ipython default input command caller by our method
179 IPython.iplib.raw_input_original = self._raw_input
179 IPython.iplib.raw_input_original = self._raw_input_original
180 #we replace the ipython default exit command by our method
180 #we replace the ipython default exit command by our method
181 self._IP.exit = ask_exit_handler
181 self._IP.exit = ask_exit_handler
182 #we replace the help command
182 #we replace the help command
@@ -189,26 +189,9 b' class NonBlockingIPShell(object):'
189 print '%this magic is currently disabled.'
189 print '%this magic is currently disabled.'
190 ip.expose_magic('cpaste', bypass_magic)
190 ip.expose_magic('cpaste', bypass_magic)
191
191
192 def reset_magic(self, arg):
192 import __builtin__
193 """Resets the namespace by removing all names defined by the user.
193 __builtin__.raw_input = self._raw_input
194
194
195 Input/Output history are left around in case you need them."""
196
197 ans = True ##todo find away to ask the user...
198 ##seems hard to do it cleanly...
199 if not ans:
200 print 'Nothing done.'
201 return
202 user_ns = self.shell.user_ns
203 for i in self.magic_who_ls():
204 del(user_ns[i])
205
206 # Also flush the private list of module references kept for script
207 # execution protection
208 self.shell._user_main_modules[:] = []
209
210 ip.expose_magic('reset', reset_magic)
211
212 sys.excepthook = excepthook
195 sys.excepthook = excepthook
213
196
214 #----------------------- Thread management section ----------------------
197 #----------------------- Thread management section ----------------------
@@ -416,11 +399,11 b' class NonBlockingIPShell(object):'
416 '''
399 '''
417 pass
400 pass
418
401
419 #def _ask_exit(self):
402 def _ask_exit(self):
420 # '''
403 '''
421 # Can be redefined to generate post event to exit the Ipython shell
404 Can be redefined to generate post event to exit the Ipython shell
422 # '''
405 '''
423 # pass
406 pass
424
407
425 def _get_history_max_index(self):
408 def _get_history_max_index(self):
426 '''
409 '''
@@ -462,7 +445,7 b' class NonBlockingIPShell(object):'
462 '''
445 '''
463 self._doc_text = text
446 self._doc_text = text
464
447
465 def _raw_input(self, prompt=''):
448 def _raw_input_original(self, prompt=''):
466 '''
449 '''
467 Custom raw_input() replacement. Get's current line from console buffer.
450 Custom raw_input() replacement. Get's current line from console buffer.
468
451
@@ -474,6 +457,11 b' class NonBlockingIPShell(object):'
474 '''
457 '''
475 return self._line_to_execute
458 return self._line_to_execute
476
459
460 def _raw_input(self, prompt=''):
461 """ A replacement from python's raw_input.
462 """
463 raise NotImplementedError
464
477 def _execute(self):
465 def _execute(self):
478 '''
466 '''
479 Executes the current line provided by the shell object.
467 Executes the current line provided by the shell object.
@@ -70,6 +70,29 b' class WxNonBlockingIPShell(NonBlockingIPShell):'
70 button_info={ 'text':text,
70 button_info={ 'text':text,
71 'func':self.parent.doExecuteLine(func)})
71 'func':self.parent.doExecuteLine(func)})
72
72
73 def _raw_input(self, prompt=''):
74 """ A replacement from python's raw_input.
75 """
76 self.answer = None
77 wx.CallAfter(self._yesNoBox, prompt)
78 while self.answer is None:
79 wx.Yield()
80 return self.answer
81
82 def _yesNoBox(self, prompt):
83 """ yes/no box managed with wx.CallAfter jsut in case caler is executed in a thread"""
84 dlg = wx.TextEntryDialog(
85 self.parent, prompt,
86 'Input requested', 'Python')
87 dlg.SetValue("")
88
89 answer = ''
90 if dlg.ShowModal() == wx.ID_OK:
91 answer = dlg.GetValue()
92
93 dlg.Destroy()
94 self.answer = answer
95
73 def _ask_exit(self):
96 def _ask_exit(self):
74 wx.CallAfter(self.ask_exit_callback, ())
97 wx.CallAfter(self.ask_exit_callback, ())
75
98
@@ -432,7 +455,6 b' class WxConsoleView(stc.StyledTextCtrl):'
432 @return: Return True if event as been catched.
455 @return: Return True if event as been catched.
433 @rtype: boolean
456 @rtype: boolean
434 '''
457 '''
435
436 if not self.AutoCompActive():
458 if not self.AutoCompActive():
437 if event.GetKeyCode() == wx.WXK_HOME:
459 if event.GetKeyCode() == wx.WXK_HOME:
438 if event.Modifiers == wx.MOD_NONE:
460 if event.Modifiers == wx.MOD_NONE:
General Comments 0
You need to be logged in to leave comments. Login now