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