Show More
@@ -1,55 +1,54 b'' | |||||
1 | from IPython.ipapi import TryNext |
|
1 | ''' 'Generic' functions for extending IPython. | |
2 | from IPython.external.simplegeneric import generic |
|
|||
3 |
|
|
2 | ||
4 | ''' 'Generic' functions for extending IPython |
|
3 | See http://cheeseshop.python.org/pypi/simplegeneric. | |
5 |
|
4 | |||
6 | See http://cheeseshop.python.org/pypi/simplegeneric |
|
5 | Here is an example from genutils.py: | |
7 |
|
||||
8 | Here's an example from genutils.py: |
|
|||
9 |
|
6 | |||
10 | def print_lsstring(arg): |
|
7 | def print_lsstring(arg): | |
11 |
" |
|
8 | "Prettier (non-repr-like) and more informative printer for LSString" | |
12 | print "LSString (.p, .n, .l, .s available). Value:" |
|
9 | print "LSString (.p, .n, .l, .s available). Value:" | |
13 | print arg |
|
10 | print arg | |
14 |
|
11 | |||
15 | print_lsstring = result_display.when_type(LSString)(print_lsstring) |
|
12 | print_lsstring = result_display.when_type(LSString)(print_lsstring) | |
16 |
|
13 | |||
17 | (Yes, the nasty syntax is for python 2.3 compatibility. Your own extensions |
|
14 | (Yes, the nasty syntax is for python 2.3 compatibility. Your own extensions | |
18 | can use the niftier decorator syntax) |
|
15 | can use the niftier decorator syntax introduced in Python 2.4). | |
19 |
|
||||
20 | ''' |
|
16 | ''' | |
21 |
|
17 | |||
|
18 | from IPython.ipapi import TryNext | |||
|
19 | from IPython.external.simplegeneric import generic | |||
|
20 | ||||
22 | def result_display(result): |
|
21 | def result_display(result): | |
23 | """ print the result of computation """ |
|
22 | """ print the result of computation """ | |
24 | raise TryNext |
|
23 | raise TryNext | |
25 |
|
24 | |||
26 | result_display = generic(result_display) |
|
25 | result_display = generic(result_display) | |
27 |
|
26 | |||
28 | def inspect_object(obj): |
|
27 | def inspect_object(obj): | |
29 | """ Called when you do obj? """ |
|
28 | """ Called when you do obj? """ | |
30 | raise TryNext |
|
29 | raise TryNext | |
31 | inspect_object = generic(inspect_object) |
|
30 | inspect_object = generic(inspect_object) | |
32 |
|
31 | |||
33 | def complete_object(obj, prev_completions): |
|
32 | def complete_object(obj, prev_completions): | |
34 | """ Custom completer dispatching for python objects |
|
33 | """ Custom completer dispatching for python objects | |
35 |
|
34 | |||
36 | obj is the object itself. |
|
35 | obj is the object itself. | |
37 | prev_completions is the list of attributes discovered so far. |
|
36 | prev_completions is the list of attributes discovered so far. | |
38 |
|
37 | |||
39 | This should return the list of attributes in obj. If you only wish to |
|
38 | This should return the list of attributes in obj. If you only wish to | |
40 | add to the attributes already discovered normally, return |
|
39 | add to the attributes already discovered normally, return | |
41 | own_attrs + prev_completions. |
|
40 | own_attrs + prev_completions. | |
42 | """ |
|
41 | """ | |
43 |
|
42 | |||
44 | raise TryNext |
|
43 | raise TryNext | |
45 | complete_object = generic(complete_object) |
|
44 | complete_object = generic(complete_object) | |
46 |
|
45 | |||
47 | #import os |
|
46 | #import os | |
48 | #def my_demo_complete_object(obj, prev_completions): |
|
47 | #def my_demo_complete_object(obj, prev_completions): | |
49 | # """ Demo completer that adds 'foobar' to the completions suggested |
|
48 | # """ Demo completer that adds 'foobar' to the completions suggested | |
50 | # for any object that has attribute (path), e.g. 'os'""" |
|
49 | # for any object that has attribute (path), e.g. 'os'""" | |
51 | # if hasattr(obj,'path'): |
|
50 | # if hasattr(obj,'path'): | |
52 | # return prev_completions + ['foobar'] |
|
51 | # return prev_completions + ['foobar'] | |
53 | # raise TryNext |
|
52 | # raise TryNext | |
54 | # |
|
53 | # | |
55 | #my_demo_complete_object = complete_object.when_type(type(os))(my_demo_complete_object) |
|
54 | #my_demo_complete_object = complete_object.when_type(type(os))(my_demo_complete_object) |
General Comments 0
You need to be logged in to leave comments.
Login now