##// END OF EJS Templates
Code refactoring to be pep8 complaint with functions names.
laurent.dufrechou@gmail.com -
Show More
@@ -73,7 +73,7 b' class _CodeExecutor(ThreadEx):'
73 self.instance._help_text = None
73 self.instance._help_text = None
74 self.instance._execute()
74 self.instance._execute()
75 # used for uper class to generate event after execution
75 # used for uper class to generate event after execution
76 self.instance._afterExecute()
76 self.instance._after_execute()
77
77
78 except KeyboardInterrupt:
78 except KeyboardInterrupt:
79 pass
79 pass
@@ -113,7 +113,7 b' class NonBlockingIPShell(object):'
113 '''
113 '''
114 #ipython0 initialisation
114 #ipython0 initialisation
115 self._IP = None
115 self._IP = None
116 self.initIpython0(argv, user_ns, user_global_ns,
116 self.init_ipython0(argv, user_ns, user_global_ns,
117 cin, cout, cerr,
117 cin, cout, cerr,
118 ask_exit_handler)
118 ask_exit_handler)
119
119
@@ -133,7 +133,7 b' class NonBlockingIPShell(object):'
133 self._help_text = None
133 self._help_text = None
134 self._add_button = None
134 self._add_button = None
135
135
136 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
136 def init_ipython0(self, argv=[], user_ns={}, user_global_ns=None,
137 cin=None, cout=None, cerr=None,
137 cin=None, cout=None, cerr=None,
138 ask_exit_handler=None):
138 ask_exit_handler=None):
139 ''' Initialize an ipython0 instance '''
139 ''' Initialize an ipython0 instance '''
@@ -184,11 +184,11 b' class NonBlockingIPShell(object):'
184 #we disable cpase magic... until we found a way to use it properly.
184 #we disable cpase magic... until we found a way to use it properly.
185 #import IPython.ipapi
185 #import IPython.ipapi
186 ip = IPython.ipapi.get()
186 ip = IPython.ipapi.get()
187 def bypassMagic(self, arg):
187 def bypass_magic(self, arg):
188 print '%this magic is currently disabled.'
188 print '%this magic is currently disabled.'
189 ip.expose_magic('cpaste', bypassMagic)
189 ip.expose_magic('cpaste', bypass_magic)
190
190
191 def resetMagic(self, arg):
191 def reset_magic(self, arg):
192 """Resets the namespace by removing all names defined by the user.
192 """Resets the namespace by removing all names defined by the user.
193
193
194 Input/Output history are left around in case you need them."""
194 Input/Output history are left around in case you need them."""
@@ -206,12 +206,12 b' class NonBlockingIPShell(object):'
206 # execution protection
206 # execution protection
207 self.shell._user_main_modules[:] = []
207 self.shell._user_main_modules[:] = []
208
208
209 ip.expose_magic('reset', resetMagic)
209 ip.expose_magic('reset', reset_magic)
210
210
211 sys.excepthook = excepthook
211 sys.excepthook = excepthook
212
212
213 #----------------------- Thread management section ----------------------
213 #----------------------- Thread management section ----------------------
214 def doExecute(self, line):
214 def do_execute(self, line):
215 """
215 """
216 Tell the thread to process the 'line' command
216 Tell the thread to process the 'line' command
217 """
217 """
@@ -229,13 +229,13 b' class NonBlockingIPShell(object):'
229 self._help_text = None
229 self._help_text = None
230 self._execute()
230 self._execute()
231 # used for uper class to generate event after execution
231 # used for uper class to generate event after execution
232 self._afterExecute()
232 self._after_execute()
233
233
234 except KeyboardInterrupt:
234 except KeyboardInterrupt:
235 pass
235 pass
236
236
237 #----------------------- IPython management section ----------------------
237 #----------------------- IPython management section ----------------------
238 def getThreading(self):
238 def get_threading(self):
239 """
239 """
240 Returns threading status, is set to True, then each command sent to
240 Returns threading status, is set to True, then each command sent to
241 the interpreter will be executed in a separated thread allowing,
241 the interpreter will be executed in a separated thread allowing,
@@ -248,7 +248,7 b' class NonBlockingIPShell(object):'
248 """
248 """
249 return self._threading
249 return self._threading
250
250
251 def setThreading(self, state):
251 def set_threading(self, state):
252 """
252 """
253 Sets threading state, if set to True, then each command sent to
253 Sets threading state, if set to True, then each command sent to
254 the interpreter will be executed in a separated thread allowing,
254 the interpreter will be executed in a separated thread allowing,
@@ -261,7 +261,7 b' class NonBlockingIPShell(object):'
261 """
261 """
262 self._threading = state
262 self._threading = state
263
263
264 def getDocText(self):
264 def get_doc_text(self):
265 """
265 """
266 Returns the output of the processing that need to be paged (if any)
266 Returns the output of the processing that need to be paged (if any)
267
267
@@ -270,7 +270,7 b' class NonBlockingIPShell(object):'
270 """
270 """
271 return self._doc_text
271 return self._doc_text
272
272
273 def getHelpText(self):
273 def get_help_text(self):
274 """
274 """
275 Returns the output of the processing that need to be paged via help pager(if any)
275 Returns the output of the processing that need to be paged via help pager(if any)
276
276
@@ -279,7 +279,7 b' class NonBlockingIPShell(object):'
279 """
279 """
280 return self._help_text
280 return self._help_text
281
281
282 def getBanner(self):
282 def get_banner(self):
283 """
283 """
284 Returns the IPython banner for useful info on IPython instance
284 Returns the IPython banner for useful info on IPython instance
285
285
@@ -288,7 +288,7 b' class NonBlockingIPShell(object):'
288 """
288 """
289 return self._IP.BANNER
289 return self._IP.BANNER
290
290
291 def getPromptCount(self):
291 def get_prompt_count(self):
292 """
292 """
293 Returns the prompt number.
293 Returns the prompt number.
294 Each time a user execute a line in the IPython shell the prompt count is increased
294 Each time a user execute a line in the IPython shell the prompt count is increased
@@ -298,7 +298,7 b' class NonBlockingIPShell(object):'
298 """
298 """
299 return self._IP.outputcache.prompt_count
299 return self._IP.outputcache.prompt_count
300
300
301 def getPrompt(self):
301 def get_prompt(self):
302 """
302 """
303 Returns current prompt inside IPython instance
303 Returns current prompt inside IPython instance
304 (Can be In [...]: ot ...:)
304 (Can be In [...]: ot ...:)
@@ -308,7 +308,7 b' class NonBlockingIPShell(object):'
308 """
308 """
309 return self._prompt
309 return self._prompt
310
310
311 def getIndentation(self):
311 def get_indentation(self):
312 """
312 """
313 Returns the current indentation level
313 Returns the current indentation level
314 Usefull to put the caret at the good start position if we want to do autoindentation.
314 Usefull to put the caret at the good start position if we want to do autoindentation.
@@ -318,7 +318,7 b' class NonBlockingIPShell(object):'
318 """
318 """
319 return self._IP.indent_current_nsp
319 return self._IP.indent_current_nsp
320
320
321 def updateNamespace(self, ns_dict):
321 def update_namespace(self, ns_dict):
322 '''
322 '''
323 Add the current dictionary to the shell namespace.
323 Add the current dictionary to the shell namespace.
324
324
@@ -342,7 +342,7 b' class NonBlockingIPShell(object):'
342 possibilities = self._IP.complete(split_line[-1])
342 possibilities = self._IP.complete(split_line[-1])
343 if possibilities:
343 if possibilities:
344
344
345 def _commonPrefix(str1, str2):
345 def _common_prefix(str1, str2):
346 '''
346 '''
347 Reduction function. returns common prefix of two given strings.
347 Reduction function. returns common prefix of two given strings.
348
348
@@ -358,13 +358,13 b' class NonBlockingIPShell(object):'
358 if not str2.startswith(str1[:i+1]):
358 if not str2.startswith(str1[:i+1]):
359 return str1[:i]
359 return str1[:i]
360 return str1
360 return str1
361 common_prefix = reduce(_commonPrefix, possibilities)
361 common_prefix = reduce(_common_prefix, possibilities)
362 completed = line[:-len(split_line[-1])]+common_prefix
362 completed = line[:-len(split_line[-1])]+common_prefix
363 else:
363 else:
364 completed = line
364 completed = line
365 return completed, possibilities
365 return completed, possibilities
366
366
367 def historyBack(self):
367 def history_back(self):
368 '''
368 '''
369 Provides one history command back.
369 Provides one history command back.
370
370
@@ -376,10 +376,10 b' class NonBlockingIPShell(object):'
376 while((history == '' or history == '\n') and self._history_level >0):
376 while((history == '' or history == '\n') and self._history_level >0):
377 if self._history_level >= 1:
377 if self._history_level >= 1:
378 self._history_level -= 1
378 self._history_level -= 1
379 history = self._getHistory()
379 history = self._get_history()
380 return history
380 return history
381
381
382 def historyForward(self):
382 def history_forward(self):
383 '''
383 '''
384 Provides one history command forward.
384 Provides one history command forward.
385
385
@@ -389,38 +389,38 b' class NonBlockingIPShell(object):'
389 history = ''
389 history = ''
390 #the below while loop is used to suppress empty history lines
390 #the below while loop is used to suppress empty history lines
391 while((history == '' or history == '\n') \
391 while((history == '' or history == '\n') \
392 and self._history_level <= self._getHistoryMaxIndex()):
392 and self._history_level <= self._get_history_max_index()):
393 if self._history_level < self._getHistoryMaxIndex():
393 if self._history_level < self._get_history_max_index():
394 self._history_level += 1
394 self._history_level += 1
395 history = self._getHistory()
395 history = self._get_history()
396 else:
396 else:
397 if self._history_level == self._getHistoryMaxIndex():
397 if self._history_level == self._get_history_max_index():
398 history = self._getHistory()
398 history = self._get_history()
399 self._history_level += 1
399 self._history_level += 1
400 else:
400 else:
401 history = ''
401 history = ''
402 return history
402 return history
403
403
404 def initHistoryIndex(self):
404 def init_history_index(self):
405 '''
405 '''
406 set history to last command entered
406 set history to last command entered
407 '''
407 '''
408 self._history_level = self._getHistoryMaxIndex()+1
408 self._history_level = self._get_history_max_index()+1
409
409
410 #----------------------- IPython PRIVATE management section --------------
410 #----------------------- IPython PRIVATE management section --------------
411 def _afterExecute(self):
411 def _after_execute(self):
412 '''
412 '''
413 Can be redefined to generate post event after excution is done
413 Can be redefined to generate post event after excution is done
414 '''
414 '''
415 pass
415 pass
416
416
417 #def _askExit(self):
417 #def _ask_exit(self):
418 # '''
418 # '''
419 # Can be redefined to generate post event to exit the Ipython shell
419 # Can be redefined to generate post event to exit the Ipython shell
420 # '''
420 # '''
421 # pass
421 # pass
422
422
423 def _getHistoryMaxIndex(self):
423 def _get_history_max_index(self):
424 '''
424 '''
425 returns the max length of the history buffer
425 returns the max length of the history buffer
426
426
@@ -429,7 +429,7 b' class NonBlockingIPShell(object):'
429 '''
429 '''
430 return len(self._IP.input_hist_raw)-1
430 return len(self._IP.input_hist_raw)-1
431
431
432 def _getHistory(self):
432 def _get_history(self):
433 '''
433 '''
434 Get's the command string of the current history level.
434 Get's the command string of the current history level.
435
435
@@ -444,7 +444,7 b' class NonBlockingIPShell(object):'
444 This function is used as a callback replacment to IPython help pager function
444 This function is used as a callback replacment to IPython help pager function
445
445
446 It puts the 'text' value inside the self._help_text string that can be retrived via
446 It puts the 'text' value inside the self._help_text string that can be retrived via
447 getHelpText function.
447 get_help_text function.
448 '''
448 '''
449 if self._help_text == None:
449 if self._help_text == None:
450 self._help_text = text
450 self._help_text = text
@@ -456,7 +456,7 b' class NonBlockingIPShell(object):'
456 This function is used as a callback replacment to IPython pager function
456 This function is used as a callback replacment to IPython pager function
457
457
458 It puts the 'text' value inside the self._doc_text string that can be retrived via
458 It puts the 'text' value inside the self._doc_text string that can be retrived via
459 getDocText function.
459 get_doc_text function.
460 '''
460 '''
461 self._doc_text = text
461 self._doc_text = text
462
462
@@ -63,17 +63,17 b' class WxNonBlockingIPShell(NonBlockingIPShell):'
63 self.parent = parent
63 self.parent = parent
64
64
65 self.ask_exit_callback = ask_exit_handler
65 self.ask_exit_callback = ask_exit_handler
66 self._IP.exit = self._askExit
66 self._IP.exit = self._ask_exit
67
67
68 def addGUIShortcut(self, text, func):
68 def addGUIShortcut(self, text, func):
69 wx.CallAfter(self.parent.add_button_handler,
69 wx.CallAfter(self.parent.add_button_handler,
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 _askExit(self):
73 def _ask_exit(self):
74 wx.CallAfter(self.ask_exit_callback, ())
74 wx.CallAfter(self.ask_exit_callback, ())
75
75
76 def _afterExecute(self):
76 def _after_execute(self):
77 wx.CallAfter(self.parent.evtStateExecuteDone, ())
77 wx.CallAfter(self.parent.evtStateExecuteDone, ())
78
78
79
79
@@ -547,14 +547,14 b' class IPShellWidget(wx.Panel):'
547 #with intro=''
547 #with intro=''
548 if intro is None:
548 if intro is None:
549 welcome_text = "Welcome to WxIPython Shell.\n\n"
549 welcome_text = "Welcome to WxIPython Shell.\n\n"
550 welcome_text+= self.IP.getBanner()
550 welcome_text+= self.IP.get_banner()
551 welcome_text+= "!command -> Execute command in shell\n"
551 welcome_text+= "!command -> Execute command in shell\n"
552 welcome_text+= "TAB -> Autocompletion\n"
552 welcome_text+= "TAB -> Autocompletion\n"
553 else:
553 else:
554 welcome_text = intro
554 welcome_text = intro
555
555
556 self.text_ctrl = WxConsoleView(self,
556 self.text_ctrl = WxConsoleView(self,
557 self.IP.getPrompt(),
557 self.IP.get_prompt(),
558 intro=welcome_text,
558 intro=welcome_text,
559 background_color=background_color)
559 background_color=background_color)
560
560
@@ -580,7 +580,7 b' class IPShellWidget(wx.Panel):'
580 'setfunc':self.text_ctrl.setBackgroundColor},
580 'setfunc':self.text_ctrl.setBackgroundColor},
581 'threading':{'value':'True',
581 'threading':{'value':'True',
582 'checkbox':self.threading_option,'True':True,'False':False,
582 'checkbox':self.threading_option,'True':True,'False':False,
583 'setfunc':self.IP.setThreading},
583 'setfunc':self.IP.set_threading},
584 }
584 }
585
585
586 #self.cout.write dEfault option is asynchroneous because default sate is threading ON
586 #self.cout.write dEfault option is asynchroneous because default sate is threading ON
@@ -628,15 +628,15 b' class IPShellWidget(wx.Panel):'
628 self.text_ctrl.write('\n')
628 self.text_ctrl.write('\n')
629 lines_to_execute = lines.replace('\t',' '*4)
629 lines_to_execute = lines.replace('\t',' '*4)
630 lines_to_execute = lines_to_execute.replace('\r','')
630 lines_to_execute = lines_to_execute.replace('\r','')
631 self.IP.doExecute(lines_to_execute.encode(ENCODING))
631 self.IP.do_execute(lines_to_execute.encode(ENCODING))
632 self.updateHistoryTracker(lines)
632 self.updateHistoryTracker(lines)
633 if(self.text_ctrl.getCursorPos()!=0):
634 self.text_ctrl.removeCurrentLine()
635 self.setCurrentState('WAIT_END_OF_EXECUTION')
633 self.setCurrentState('WAIT_END_OF_EXECUTION')
636
634
637 def evtStateExecuteDone(self,evt):
635 def evtStateExecuteDone(self,evt):
638 self.doc = self.IP.getDocText()
636 if(self.text_ctrl.getCursorPos()!=0):
639 self.help = self.IP.getHelpText()
637 self.text_ctrl.removeCurrentLine()
638 self.doc = self.IP.get_doc_text()
639 self.help = self.IP.get_help_text()
640 if self.doc:
640 if self.doc:
641 self.pager_lines = self.doc[7:].split('\n')
641 self.pager_lines = self.doc[7:].split('\n')
642 self.pager_state = 'INIT'
642 self.pager_state = 'INIT'
@@ -652,11 +652,11 b' class IPShellWidget(wx.Panel):'
652
652
653 def stateShowPrompt(self):
653 def stateShowPrompt(self):
654 self.setCurrentState('SHOW_PROMPT')
654 self.setCurrentState('SHOW_PROMPT')
655 self.text_ctrl.setPrompt(self.IP.getPrompt())
655 self.text_ctrl.setPrompt(self.IP.get_prompt())
656 self.text_ctrl.setIndentation(self.IP.getIndentation())
656 self.text_ctrl.setIndentation(self.IP.get_indentation())
657 self.text_ctrl.setPromptCount(self.IP.getPromptCount())
657 self.text_ctrl.setPromptCount(self.IP.get_prompt_count())
658 self.text_ctrl.showPrompt()
658 self.text_ctrl.showPrompt()
659 self.IP.initHistoryIndex()
659 self.IP.init_history_index()
660 self.setCurrentState('IDLE')
660 self.setCurrentState('IDLE')
661
661
662 def setCurrentState(self, state):
662 def setCurrentState(self, state):
@@ -762,11 +762,11 b' class IPShellWidget(wx.Panel):'
762
762
763 if self.cur_state == 'IDLE':
763 if self.cur_state == 'IDLE':
764 if event.KeyCode == wx.WXK_UP:
764 if event.KeyCode == wx.WXK_UP:
765 history = self.IP.historyBack()
765 history = self.IP.history_back()
766 self.text_ctrl.writeHistory(history)
766 self.text_ctrl.writeHistory(history)
767 return
767 return
768 if event.KeyCode == wx.WXK_DOWN:
768 if event.KeyCode == wx.WXK_DOWN:
769 history = self.IP.historyForward()
769 history = self.IP.history_forward()
770 self.text_ctrl.writeHistory(history)
770 self.text_ctrl.writeHistory(history)
771 return
771 return
772 if event.KeyCode == wx.WXK_TAB:
772 if event.KeyCode == wx.WXK_TAB:
@@ -817,11 +817,11 b' class IPShellWidget(wx.Panel):'
817 def evtCheckOptionThreading(self, event):
817 def evtCheckOptionThreading(self, event):
818 if event.IsChecked():
818 if event.IsChecked():
819 self.options['threading']['value']='True'
819 self.options['threading']['value']='True'
820 self.IP.setThreading(True)
820 self.IP.set_threading(True)
821 self.cout.write = self.text_ctrl.asyncWrite
821 self.cout.write = self.text_ctrl.asyncWrite
822 else:
822 else:
823 self.options['threading']['value']='False'
823 self.options['threading']['value']='False'
824 self.IP.setThreading(False)
824 self.IP.set_threading(False)
825 self.cout.write = self.text_ctrl.write
825 self.cout.write = self.text_ctrl.write
826 self.updateOptionTracker('threading',
826 self.updateOptionTracker('threading',
827 self.options['threading']['value'])
827 self.options['threading']['value'])
@@ -838,10 +838,10 b' class IPShellWidget(wx.Panel):'
838 self.options[key]['setfunc'](value)
838 self.options[key]['setfunc'](value)
839
839
840 if self.options['threading']['value']=='True':
840 if self.options['threading']['value']=='True':
841 self.IP.setThreading(True)
841 self.IP.set_threading(True)
842 self.cout.write = self.text_ctrl.asyncWrite
842 self.cout.write = self.text_ctrl.asyncWrite
843 else:
843 else:
844 self.IP.setThreading(False)
844 self.IP.set_threading(False)
845 self.cout.write = self.text_ctrl.write
845 self.cout.write = self.text_ctrl.write
846
846
847 #------------------------ Hook Section -----------------------------------
847 #------------------------ Hook Section -----------------------------------
General Comments 0
You need to be logged in to leave comments. Login now