##// END OF EJS Templates
cleanup and linted a bit :)
Laurent Dufréchou -
Show More
@@ -21,15 +21,13 b' import re'
21 21 import sys
22 22 import os
23 23 import locale
24 import time
25 import pydoc,__builtin__,site
26 24 from thread_ex import ThreadEx
27 from StringIO import StringIO
28 25
29 26 try:
30 27 import IPython
31 28 except Exception,e:
32 raise "Error importing IPython (%s)" % str(e)
29 print "Error importing IPython (%s)" % str(e)
30 raise Exception, e
33 31
34 32 ##############################################################################
35 33 class _Helper(object):
@@ -46,10 +44,12 b' class _Helper(object):'
46 44
47 45 def __call__(self, *args, **kwds):
48 46 class DummyWriter(object):
47 '''Dumy class to handle help output'''
49 48 def __init__(self,pager):
50 49 self._pager = pager
51 50
52 51 def write(self,data):
52 '''hook to fill self._pager'''
53 53 self._pager(data)
54 54
55 55 import pydoc
@@ -61,13 +61,14 b' class _Helper(object):'
61 61
62 62 ##############################################################################
63 63 class _CodeExecutor(ThreadEx):
64
64 ''' Thread that execute ipython code '''
65 65 def __init__(self, instance, after):
66 66 ThreadEx.__init__(self)
67 67 self.instance = instance
68 68 self._afterExecute=after
69 69
70 70 def run(self):
71 '''Thread main loop'''
71 72 try:
72 73 self.instance._doc_text = None
73 74 self.instance._help_text = None
@@ -112,6 +113,8 b' class NonBlockingIPShell(object):'
112 113 @type int
113 114 '''
114 115 #ipython0 initialisation
116 self._IP = None
117 self._term = None
115 118 self.initIpython0(argv, user_ns, user_global_ns,
116 119 cin, cout, cerr,
117 120 ask_exit_handler)
@@ -134,6 +137,8 b' class NonBlockingIPShell(object):'
134 137 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
135 138 cin=None, cout=None, cerr=None,
136 139 ask_exit_handler=None):
140 ''' Initialize an ithon0 instance '''
141
137 142 #first we redefine in/out/error functions of IPython
138 143 if cin:
139 144 IPython.Shell.Term.cin = cin
@@ -190,8 +195,8 b' class NonBlockingIPShell(object):'
190 195
191 196 self._line_to_execute = line
192 197 #we launch the ipython line execution in a thread to make it interruptible
193 self.ce = _CodeExecutor(self,self._afterExecute)
194 self.ce.start()
198 ce = _CodeExecutor(self, self._afterExecute)
199 ce.start()
195 200
196 201 #----------------------- IPython management section ----------------------
197 202 def getDocText(self):
@@ -321,7 +326,8 b' class NonBlockingIPShell(object):'
321 326 '''
322 327 history = ''
323 328 #the below while loop is used to suppress empty history lines
324 while((history == '' or history == '\n') and self._history_level <= self._getHistoryMaxIndex()):
329 while((history == '' or history == '\n') \
330 and self._history_level <= self._getHistoryMaxIndex()):
325 331 if self._history_level < self._getHistoryMaxIndex():
326 332 self._history_level += 1
327 333 history = self._getHistory()
@@ -375,8 +381,8 b' class NonBlockingIPShell(object):'
375 381 '''
376 382 This function is used as a callback replacment to IPython help pager function
377 383
378 It puts the 'text' value inside the self._help_text string that can be retrived via getHelpText
379 function.
384 It puts the 'text' value inside the self._help_text string that can be retrived via
385 getHelpText function.
380 386 '''
381 387 if self._help_text == None:
382 388 self._help_text = text
@@ -387,8 +393,8 b' class NonBlockingIPShell(object):'
387 393 '''
388 394 This function is used as a callback replacment to IPython pager function
389 395
390 It puts the 'text' value inside the self._doc_text string that can be retrived via getDocText
391 function.
396 It puts the 'text' value inside the self._doc_text string that can be retrived via
397 getDocText function.
392 398 '''
393 399 self._doc_text = text
394 400
@@ -429,8 +435,7 b' class NonBlockingIPShell(object):'
429 435 self._IP.showtraceback()
430 436 else:
431 437 self._iter_more = self._IP.push(line)
432 if (self._IP.SyntaxTB.last_syntax_error and
433 self._IP.rc.autoedit_syntax):
438 if (self._IP.SyntaxTB.last_syntax_error and self._IP.rc.autoedit_syntax):
434 439 self._IP.edit_syntax_error()
435 440 if self._iter_more:
436 441 self._prompt = str(self._IP.outputcache.prompt2).strip()
@@ -452,8 +457,8 b' class NonBlockingIPShell(object):'
452 457 '''
453 458 stdin, stdout = os.popen4(cmd)
454 459 result = stdout.read().decode('cp437').encode(locale.getpreferredencoding())
455 #we use print command because the shell command is called inside IPython instance and thus is
456 #redirected to thread cout
460 #we use print command because the shell command is called
461 #inside IPython instance and thus is redirected to thread cout
457 462 #"\x01\x1b[1;36m\x02" <-- add colour to the text...
458 463 print "\x01\x1b[1;36m\x02"+result
459 464 stdout.close()
@@ -28,13 +28,7 b' import wx'
28 28 import wx.stc as stc
29 29
30 30 import re
31 import sys
32 import locale
33 31 from StringIO import StringIO
34 try:
35 import IPython
36 except Exception,e:
37 raise "Error importing IPython (%s)" % str(e)
38 32
39 33 from ipshell_nonblocking import NonBlockingIPShell
40 34
@@ -387,9 +381,7 b' class WxConsoleView(stc.StyledTextCtrl):'
387 381 max_symbol =' '*max_len
388 382
389 383 #now we check how much symbol we can put on a line...
390 cursor_pos = self.getCursorPos()
391 384 test_buffer = max_symbol + ' '*4
392 current_lines = self.GetLineCount()
393 385
394 386 allowed_symbols = 80/len(test_buffer)
395 387 if allowed_symbols == 0:
@@ -462,7 +454,8 b' class WxConsoleView(stc.StyledTextCtrl):'
462 454 return True
463 455
464 456 if skip:
465 if event.GetKeyCode() not in [wx.WXK_PAGEUP,wx.WXK_PAGEDOWN] and event.Modifiers == wx.MOD_NONE:
457 if event.GetKeyCode() not in [wx.WXK_PAGEUP, wx.WXK_PAGEDOWN]\
458 and event.Modifiers == wx.MOD_NONE:
466 459 self.moveCursorOnNewValidKey()
467 460
468 461 event.Skip()
General Comments 0
You need to be logged in to leave comments. Login now