Show More
@@ -29,35 +29,35 b' import IPython.ipapi' | |||||
29 | ip = IPython.ipapi.get() |
|
29 | ip = IPython.ipapi.get() | |
30 |
|
30 | |||
31 | def ankka_f(self, arg): |
|
31 | def ankka_f(self, arg): | |
32 |
print |
|
32 | print 'Ankka',self,'says uppercase:',arg.upper() | |
33 |
|
33 | |||
34 |
ip.expose_magic( |
|
34 | ip.expose_magic('ankka',ankka_f) | |
35 |
|
35 | |||
36 | ip.magic('alias sayhi echo "Testing, hi ok"') |
|
36 | ip.magic('alias sayhi echo "Testing, hi ok"') | |
37 | ip.magic('alias helloworld echo "Hello world"') |
|
37 | ip.magic('alias helloworld echo "Hello world"') | |
38 | ip.system('pwd') |
|
38 | ip.system('pwd') | |
39 |
|
39 | |||
40 | ip.ex('import re') |
|
40 | ip.ex('import re') | |
41 |
ip.ex( |
|
41 | ip.ex(''' | |
42 | def funcci(a,b): |
|
42 | def funcci(a,b): | |
43 | print a+b |
|
43 | print a+b | |
44 | print funcci(3,4) |
|
44 | print funcci(3,4) | |
45 | """) |
|
45 | ''') | |
46 |
ip.ex( |
|
46 | ip.ex('funcci(348,9)') | |
47 |
|
47 | |||
48 | def jed_editor(self,filename, linenum=None): |
|
48 | def jed_editor(self,filename, linenum=None): | |
49 |
print |
|
49 | print 'Calling my own editor, jed ... via hook!' | |
50 | import os |
|
50 | import os | |
51 | if linenum is None: linenum = 0 |
|
51 | if linenum is None: linenum = 0 | |
52 | os.system('jed +%d %s' % (linenum, filename)) |
|
52 | os.system('jed +%d %s' % (linenum, filename)) | |
53 |
print |
|
53 | print 'exiting jed' | |
54 |
|
54 | |||
55 | ip.set_hook('editor',jed_editor) |
|
55 | ip.set_hook('editor',jed_editor) | |
56 |
|
56 | |||
57 | o = ip.options |
|
57 | o = ip.options | |
58 | o.autocall = 2 # FULL autocall mode |
|
58 | o.autocall = 2 # FULL autocall mode | |
59 |
|
59 | |||
60 |
print |
|
60 | print 'done!' | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | #----------------------------------------------------------------------------- |
|
63 | #----------------------------------------------------------------------------- | |
@@ -86,6 +86,7 b' class TryNext(Exception):' | |||||
86 | self.args = args |
|
86 | self.args = args | |
87 | self.kwargs = kwargs |
|
87 | self.kwargs = kwargs | |
88 |
|
88 | |||
|
89 | ||||
89 | class UsageError(Exception): |
|
90 | class UsageError(Exception): | |
90 | """ Error in magic function arguments, etc. |
|
91 | """ Error in magic function arguments, etc. | |
91 |
|
92 | |||
@@ -93,6 +94,7 b' class UsageError(Exception):' | |||||
93 | nevertheless interrupt a macro / batch file. |
|
94 | nevertheless interrupt a macro / batch file. | |
94 | """ |
|
95 | """ | |
95 |
|
96 | |||
|
97 | ||||
96 | class IPyAutocall: |
|
98 | class IPyAutocall: | |
97 | """ Instances of this class are always autocalled |
|
99 | """ Instances of this class are always autocalled | |
98 |
|
100 | |||
@@ -109,7 +111,6 b' class IPyAutocall:' | |||||
109 | self._ip = ip |
|
111 | self._ip = ip | |
110 |
|
112 | |||
111 |
|
113 | |||
112 |
|
||||
113 | class IPythonNotRunning: |
|
114 | class IPythonNotRunning: | |
114 | """Dummy do-nothing class. |
|
115 | """Dummy do-nothing class. | |
115 |
|
116 | |||
@@ -161,7 +162,8 b' def get(allow_dummy=False,dummy_warn=True):' | |||||
161 | _RECENT_IP = IPythonNotRunning(dummy_warn) |
|
162 | _RECENT_IP = IPythonNotRunning(dummy_warn) | |
162 | return _RECENT_IP |
|
163 | return _RECENT_IP | |
163 |
|
164 | |||
164 | class IPApi: |
|
165 | ||
|
166 | class IPApi(object): | |||
165 | """ The actual API class for configuring IPython |
|
167 | """ The actual API class for configuring IPython | |
166 |
|
168 | |||
167 | You should do all of the IPython configuration by getting an IPApi object |
|
169 | You should do all of the IPython configuration by getting an IPApi object | |
@@ -225,22 +227,23 b' class IPApi:' | |||||
225 | options = property(get_options,None,None,get_options.__doc__) |
|
227 | options = property(get_options,None,None,get_options.__doc__) | |
226 |
|
228 | |||
227 | def expose_magic(self,magicname, func): |
|
229 | def expose_magic(self,magicname, func): | |
228 |
|
|
230 | """Expose own function as magic function for ipython | |
229 |
|
231 | |||
230 | def foo_impl(self,parameter_s=''): |
|
232 | def foo_impl(self,parameter_s=''): | |
231 |
|
|
233 | 'My very own magic!. (Use docstrings, IPython reads them).' | |
232 |
print 'Magic function. Passed parameter is between < >: |
|
234 | print 'Magic function. Passed parameter is between < >:' | |
|
235 | print '<%s>' % parameter_s | |||
233 | print 'The self object is:',self |
|
236 | print 'The self object is:',self | |
234 |
|
237 | |||
235 |
ipapi.expose_magic( |
|
238 | ipapi.expose_magic('foo',foo_impl) | |
236 |
|
|
239 | """ | |
237 |
|
|
240 | ||
238 | import new |
|
241 | import new | |
239 | im = new.instancemethod(func,self.IP, self.IP.__class__) |
|
242 | im = new.instancemethod(func,self.IP, self.IP.__class__) | |
240 | old = getattr(self.IP, "magic_" + magicname, None) |
|
243 | old = getattr(self.IP, "magic_" + magicname, None) | |
241 | if old: |
|
244 | if old: | |
242 |
self.dbg.debug_stack("Magic redefinition '%s', old %s" % |
|
245 | self.dbg.debug_stack("Magic redefinition '%s', old %s" % | |
243 | old)) |
|
246 | (magicname,old) ) | |
244 |
|
247 | |||
245 | setattr(self.IP, "magic_" + magicname, im) |
|
248 | setattr(self.IP, "magic_" + magicname, im) | |
246 |
|
249 |
General Comments 0
You need to be logged in to leave comments.
Login now