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