##// END OF EJS Templates
Merge from upstream
Fernando Perez -
r1156:75a534f3 merge
parent child Browse files
Show More
@@ -12,6 +12,7 b' import IPython.ipapi'
12 import glob,os,shlex,sys
12 import glob,os,shlex,sys
13 import inspect
13 import inspect
14 from time import time
14 from time import time
15 from zipimport import zipimporter
15 ip = IPython.ipapi.get()
16 ip = IPython.ipapi.get()
16
17
17 try:
18 try:
@@ -86,6 +87,11 b' def moduleList(path):'
86
87
87 if os.path.isdir(path):
88 if os.path.isdir(path):
88 folder_list = os.listdir(path)
89 folder_list = os.listdir(path)
90 elif path.endswith('.egg'):
91 try:
92 folder_list = [f for f in zipimporter(path)._files]
93 except:
94 folder_list = []
89 else:
95 else:
90 folder_list = []
96 folder_list = []
91 #folder_list = glob.glob(os.path.join(path,'*'))
97 #folder_list = glob.glob(os.path.join(path,'*'))
@@ -1052,25 +1052,40 b' class SList(list):'
1052
1052
1053 p = paths = property(get_paths)
1053 p = paths = property(get_paths)
1054
1054
1055 def grep(self, pattern, prune = False):
1055 def grep(self, pattern, prune = False, field = None):
1056 """ Return all strings matching 'pattern' (a regex or callable)
1056 """ Return all strings matching 'pattern' (a regex or callable)
1057
1057
1058 This is case-insensitive. If prune is true, return all items
1058 This is case-insensitive. If prune is true, return all items
1059 NOT matching the pattern.
1059 NOT matching the pattern.
1060
1060
1061 If field is specified, the match must occur in the specified
1062 whitespace-separated field.
1063
1061 Examples::
1064 Examples::
1062
1065
1063 a.grep( lambda x: x.startswith('C') )
1066 a.grep( lambda x: x.startswith('C') )
1064 a.grep('Cha.*log', prune=1)
1067 a.grep('Cha.*log', prune=1)
1068 a.grep('chm', field=-1)
1065 """
1069 """
1070
1071 def match_target(s):
1072 if field is None:
1073 return s
1074 parts = s.split()
1075 try:
1076 tgt = parts[field]
1077 return tgt
1078 except IndexError:
1079 return ""
1080
1066 if isinstance(pattern, basestring):
1081 if isinstance(pattern, basestring):
1067 pred = lambda x : re.search(pattern, x, re.IGNORECASE)
1082 pred = lambda x : re.search(pattern, x, re.IGNORECASE)
1068 else:
1083 else:
1069 pred = pattern
1084 pred = pattern
1070 if not prune:
1085 if not prune:
1071 return SList([el for el in self if pred(el)])
1086 return SList([el for el in self if pred(match_target(el))])
1072 else:
1087 else:
1073 return SList([el for el in self if not pred(el)])
1088 return SList([el for el in self if not pred(match_target(el))])
1074 def fields(self, *fields):
1089 def fields(self, *fields):
1075 """ Collect whitespace-separated fields from string list
1090 """ Collect whitespace-separated fields from string list
1076
1091
@@ -1083,6 +1098,7 b' class SList(list):'
1083 a.fields(0) is ['-rwxrwxrwx', 'drwxrwxrwx+']
1098 a.fields(0) is ['-rwxrwxrwx', 'drwxrwxrwx+']
1084 a.fields(1,0) is ['1 -rwxrwxrwx', '6 drwxrwxrwx+']
1099 a.fields(1,0) is ['1 -rwxrwxrwx', '6 drwxrwxrwx+']
1085 (note the joining by space).
1100 (note the joining by space).
1101 a.fields(-1) is ['ChangeLog', 'IPython']
1086
1102
1087 IndexErrors are ignored.
1103 IndexErrors are ignored.
1088
1104
@@ -92,7 +92,7 b' class NonBlockingIPShell(object):'
92
92
93 def __init__(self,argv=[],user_ns={},user_global_ns=None,
93 def __init__(self,argv=[],user_ns={},user_global_ns=None,
94 cin=None, cout=None, cerr=None,
94 cin=None, cout=None, cerr=None,
95 ask_exit_handler=None, rawinput=None):
95 ask_exit_handler=None):
96 '''
96 '''
97 @param argv: Command line options for IPython
97 @param argv: Command line options for IPython
98 @type argv: list
98 @type argv: list
@@ -114,7 +114,7 b' class NonBlockingIPShell(object):'
114 #ipython0 initialisation
114 #ipython0 initialisation
115 self.initIpython0(argv, user_ns, user_global_ns,
115 self.initIpython0(argv, user_ns, user_global_ns,
116 cin, cout, cerr,
116 cin, cout, cerr,
117 ask_exit_handler, rawinput)
117 ask_exit_handler)
118
118
119 #vars used by _execute
119 #vars used by _execute
120 self._iter_more = 0
120 self._iter_more = 0
@@ -133,7 +133,7 b' class NonBlockingIPShell(object):'
133
133
134 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
134 def initIpython0(self, argv=[], user_ns={}, user_global_ns=None,
135 cin=None, cout=None, cerr=None,
135 cin=None, cout=None, cerr=None,
136 ask_exit_handler=None, rawinput=None):
136 ask_exit_handler=None):
137 #first we redefine in/out/error functions of IPython
137 #first we redefine in/out/error functions of IPython
138 if cin:
138 if cin:
139 IPython.Shell.Term.cin = cin
139 IPython.Shell.Term.cin = cin
@@ -167,13 +167,19 b' class NonBlockingIPShell(object):'
167 self._IP.set_hook('shell_hook',self._shell)
167 self._IP.set_hook('shell_hook',self._shell)
168
168
169 #we replace the ipython default input command caller by our method
169 #we replace the ipython default input command caller by our method
170 IPython.iplib.raw_input_original = rawinput
170 IPython.iplib.raw_input_original = self._raw_input
171
172 #we replace the ipython default exit command by our method
171 #we replace the ipython default exit command by our method
173 self._IP.exit = ask_exit_handler
172 self._IP.exit = ask_exit_handler
174 #we replace the help command
173 #we replace the help command
175 self._IP.user_ns['help'] = _Helper(self._pager_help)
174 self._IP.user_ns['help'] = _Helper(self._pager_help)
176
175
176 #we disable cpase magic... until we found a way to use it properly.
177 #import IPython.ipapi
178 ip = IPython.ipapi.get()
179 def bypassMagic(self, arg):
180 print '%this magic is currently disabled.'
181 ip.expose_magic('cpaste', bypassMagic)
182
177 sys.excepthook = excepthook
183 sys.excepthook = excepthook
178
184
179 #----------------------- Thread management section ----------------------
185 #----------------------- Thread management section ----------------------
@@ -340,6 +346,12 b' class NonBlockingIPShell(object):'
340 '''
346 '''
341 pass
347 pass
342
348
349 #def _askExit(self):
350 # '''
351 # Can be redefined to generate post event to exit the Ipython shell
352 # '''
353 # pass
354
343 def _getHistoryMaxIndex(self):
355 def _getHistoryMaxIndex(self):
344 '''
356 '''
345 returns the max length of the history buffer
357 returns the max length of the history buffer
@@ -380,6 +392,18 b' class NonBlockingIPShell(object):'
380 '''
392 '''
381 self._doc_text = text
393 self._doc_text = text
382
394
395 def _raw_input(self, prompt=''):
396 '''
397 Custom raw_input() replacement. Get's current line from console buffer.
398
399 @param prompt: Prompt to print. Here for compatability as replacement.
400 @type prompt: string
401
402 @return: The current command line text.
403 @rtype: string
404 '''
405 return self._line_to_execute
406
383 def _execute(self):
407 def _execute(self):
384 '''
408 '''
385 Executes the current line provided by the shell object.
409 Executes the current line provided by the shell object.
@@ -47,12 +47,11 b' class WxNonBlockingIPShell(NonBlockingIPShell):'
47 def __init__(self, parent,
47 def __init__(self, parent,
48 argv=[],user_ns={},user_global_ns=None,
48 argv=[],user_ns={},user_global_ns=None,
49 cin=None, cout=None, cerr=None,
49 cin=None, cout=None, cerr=None,
50 ask_exit_handler=None, rawinput=None):
50 ask_exit_handler=None):
51
51
52 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
52 NonBlockingIPShell.__init__(self,argv,user_ns,user_global_ns,
53 cin, cout, cerr,
53 cin, cout, cerr,
54 ask_exit_handler,
54 ask_exit_handler)
55 rawinput)
56
55
57 self.parent = parent
56 self.parent = parent
58
57
@@ -216,6 +215,31 b' class WxConsoleView(stc.StyledTextCtrl):'
216
215
217 self.Bind(wx.EVT_KEY_DOWN, self._onKeypress, self)
216 self.Bind(wx.EVT_KEY_DOWN, self._onKeypress, self)
218
217
218 def asyncWrite(self, text):
219 '''
220 Write given text to buffer in an asynchroneous way.
221 It is used from another thread to be able to acces the GUI.
222 @param text: Text to append
223 @type text: string
224 '''
225 try:
226 #print >>sys.__stdout__,'entering'
227 wx.MutexGuiEnter()
228 #print >>sys.__stdout__,'locking the GUI'
229
230 #be sure not to be interrutpted before the MutexGuiLeave!
231 self.write(text)
232 #print >>sys.__stdout__,'done'
233
234 except KeyboardInterrupt:
235 #print >>sys.__stdout__,'got keyboard interrupt'
236 wx.MutexGuiLeave()
237 #print >>sys.__stdout__,'interrupt unlock the GUI'
238 raise KeyboardInterrupt
239 wx.MutexGuiLeave()
240 #print >>sys.__stdout__,'normal unlock the GUI'
241
242
219 def write(self, text):
243 def write(self, text):
220 '''
244 '''
221 Write given text to buffer.
245 Write given text to buffer.
@@ -453,7 +477,7 b' class IPShellWidget(wx.Panel):'
453
477
454 def __init__(self, parent, intro=None,
478 def __init__(self, parent, intro=None,
455 background_color="BLACK", add_button_handler=None,
479 background_color="BLACK", add_button_handler=None,
456 wx_ip_shell=None,
480 wx_ip_shell=None, user_ns={},user_global_ns=None,
457 ):
481 ):
458 '''
482 '''
459 Initialize.
483 Initialize.
@@ -472,8 +496,7 b' class IPShellWidget(wx.Panel):'
472 else:
496 else:
473 self.IP = WxNonBlockingIPShell(self,
497 self.IP = WxNonBlockingIPShell(self,
474 cout = self.cout, cerr = self.cout,
498 cout = self.cout, cerr = self.cout,
475 ask_exit_handler = self.askExitCallback,
499 ask_exit_handler = self.askExitCallback)
476 rawinput = self.rawInput)
477
500
478 ### IPython wx console view instanciation ###
501 ### IPython wx console view instanciation ###
479 #If user didn't defined an intro text, we create one for him
502 #If user didn't defined an intro text, we create one for him
@@ -492,7 +515,7 b' class IPShellWidget(wx.Panel):'
492 intro=welcome_text,
515 intro=welcome_text,
493 background_color=background_color)
516 background_color=background_color)
494
517
495 self.cout.write = self.text_ctrl.write
518 self.cout.write = self.text_ctrl.asyncWrite
496
519
497 self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress, self.text_ctrl)
520 self.text_ctrl.Bind(wx.EVT_KEY_DOWN, self.keyPress, self.text_ctrl)
498
521
@@ -509,18 +532,19 b' class IPShellWidget(wx.Panel):'
509 #widget state management (for key handling different cases)
532 #widget state management (for key handling different cases)
510 self.setCurrentState('IDLE')
533 self.setCurrentState('IDLE')
511 self.pager_state = 'DONE'
534 self.pager_state = 'DONE'
535 self.raw_input_current_line = 0
512
536
513 def askExitCallback(self, event):
537 def askExitCallback(self, event):
514 self.askExitHandler(event)
538 self.askExitHandler(event)
515
539
516 #---------------------- IPython Thread Management ------------------------
540 #---------------------- IPython Thread Management ------------------------
517 def stateDoExecuteLine(self):
541 def stateDoExecuteLine(self):
518 #print >>sys.__stdout__,"command:",self.getCurrentLine()
519 lines=self.text_ctrl.getCurrentLine()
542 lines=self.text_ctrl.getCurrentLine()
520 self.text_ctrl.write('\n')
543 self.text_ctrl.write('\n')
521 for line in lines.split('\n'):
544 lines_to_execute = lines.replace('\t',' '*4)
522 self.IP.doExecute((line.replace('\t',' '*4)).encode('cp1252'))
545 lines_to_execute = lines_to_execute.replace('\r\n','\n')
523 self.updateHistoryTracker(self.text_ctrl.getCurrentLine())
546 self.IP.doExecute(lines.encode('cp1252'))
547 self.updateHistoryTracker(lines)
524 self.setCurrentState('WAIT_END_OF_EXECUTION')
548 self.setCurrentState('WAIT_END_OF_EXECUTION')
525
549
526 def evtStateExecuteDone(self,evt):
550 def evtStateExecuteDone(self,evt):
@@ -551,16 +575,7 b' class IPShellWidget(wx.Panel):'
551 def setCurrentState(self, state):
575 def setCurrentState(self, state):
552 self.cur_state = state
576 self.cur_state = state
553 self.updateStatusTracker(self.cur_state)
577 self.updateStatusTracker(self.cur_state)
554 #---------------------------- Ipython raw_input -----------------------------------
555 def rawInput(self, prompt=''):
556 self.setCurrentState('WAITING_USER_INPUT')
557 while self.cur_state != 'WAIT_END_OF_EXECUTION':
558 pass
559 line = self.text_ctrl.getCurrentLine()
560 line = line.split('\n')
561 return line[-2]
562
578
563 #---------------------------- IPython pager ---------------------------------------
564 def pager(self,text):
579 def pager(self,text):
565
580
566 if self.pager_state == 'INIT':
581 if self.pager_state == 'INIT':
@@ -1,3 +1,10 b''
1 2008-04-15 Ville Vainio <vivainio@gmail.com>
2
3 * genutils.py: SList.grep supports 'field' argument
4
5 * ipy_completers.py: module completer looks inside
6 .egg zip files (patch by mc). Close #196.
7
1 2008-04-09 Ville Vainio <vivainio@gmail.com>
8 2008-04-09 Ville Vainio <vivainio@gmail.com>
2
9
3 * deep_reload.py: do not crash on from __future__ import
10 * deep_reload.py: do not crash on from __future__ import
General Comments 0
You need to be logged in to leave comments. Login now