##// END OF EJS Templates
Merge with upstream
Fernando Perez -
r1483:3d01fd53 merge
parent child Browse files
Show More
@@ -174,23 +174,15 b' class LeoNode(object, UserDict.DictMixin):'
174
174
175 def __get_h(self): return self.p.headString()
175 def __get_h(self): return self.p.headString()
176 def __set_h(self,val):
176 def __set_h(self,val):
177 print "set head",val
177 c.setHeadString(self.p,val)
178 c.beginUpdate()
178 c.redraw()
179 try:
180 c.setHeadString(self.p,val)
181 finally:
182 c.endUpdate()
183
179
184 h = property( __get_h, __set_h, doc = "Node headline string")
180 h = property( __get_h, __set_h, doc = "Node headline string")
185
181
186 def __get_b(self): return self.p.bodyString()
182 def __get_b(self): return self.p.bodyString()
187 def __set_b(self,val):
183 def __set_b(self,val):
188 print "set body",val
184 c.setBodyString(self.p, val)
189 c.beginUpdate()
185 c.redraw()
190 try:
191 c.setBodyString(self.p, val)
192 finally:
193 c.endUpdate()
194
186
195 b = property(__get_b, __set_b, doc = "Nody body string")
187 b = property(__get_b, __set_b, doc = "Nody body string")
196
188
@@ -265,11 +257,8 b' class LeoNode(object, UserDict.DictMixin):'
265
257
266 def go(self):
258 def go(self):
267 """ Set node as current node (to quickly see it in Outline) """
259 """ Set node as current node (to quickly see it in Outline) """
268 c.beginUpdate()
260 c.setCurrentPosition(self.p)
269 try:
261 c.redraw()
270 c.setCurrentPosition(self.p)
271 finally:
272 c.endUpdate()
273
262
274 def script(self):
263 def script(self):
275 """ Method to get the 'tangled' contents of the node
264 """ Method to get the 'tangled' contents of the node
@@ -337,7 +326,6 b' def workbook_complete(obj, prev):'
337
326
338
327
339 def add_var(varname):
328 def add_var(varname):
340 c.beginUpdate()
341 r = rootnode()
329 r = rootnode()
342 try:
330 try:
343 if r is None:
331 if r is None:
@@ -356,7 +344,7 b' def add_var(varname):'
356 c.setHeadString(p2,varname)
344 c.setHeadString(p2,varname)
357 return LeoNode(p2)
345 return LeoNode(p2)
358 finally:
346 finally:
359 c.endUpdate()
347 c.redraw()
360
348
361 def add_file(self,fname):
349 def add_file(self,fname):
362 p2 = c.currentPosition().insertAfter()
350 p2 = c.currentPosition().insertAfter()
@@ -368,7 +356,6 b' def expose_ileo_push(f, prio = 0):'
368
356
369 def push_ipython_script(node):
357 def push_ipython_script(node):
370 """ Execute the node body in IPython, as if it was entered in interactive prompt """
358 """ Execute the node body in IPython, as if it was entered in interactive prompt """
371 c.beginUpdate()
372 try:
359 try:
373 ohist = ip.IP.output_hist
360 ohist = ip.IP.output_hist
374 hstart = len(ip.IP.input_hist)
361 hstart = len(ip.IP.input_hist)
@@ -393,7 +380,7 b' def push_ipython_script(node):'
393 if not has_output:
380 if not has_output:
394 es('ipy run: %s (%d LL)' %( node.h,len(script)))
381 es('ipy run: %s (%d LL)' %( node.h,len(script)))
395 finally:
382 finally:
396 c.endUpdate()
383 c.redraw()
397
384
398
385
399 def eval_body(body):
386 def eval_body(body):
@@ -495,7 +482,6 b' def lee_f(self,s):'
495 """
482 """
496 import os
483 import os
497
484
498 c.beginUpdate()
499 try:
485 try:
500 if s == 'hist':
486 if s == 'hist':
501 wb.ipython_history.b = get_history()
487 wb.ipython_history.b = get_history()
@@ -533,7 +519,7 b' def lee_f(self,s):'
533 c.selectPosition(p)
519 c.selectPosition(p)
534 print "Editing file(s), press ctrl+shift+w in Leo to write @auto nodes"
520 print "Editing file(s), press ctrl+shift+w in Leo to write @auto nodes"
535 finally:
521 finally:
536 c.endUpdate()
522 c.redraw()
537
523
538
524
539
525
@@ -510,7 +510,7 b' class MatplotlibShellBase:'
510 Given Python's MRO, this should be used as the FIRST class in the
510 Given Python's MRO, this should be used as the FIRST class in the
511 inheritance hierarchy, so that it overrides the relevant methods."""
511 inheritance hierarchy, so that it overrides the relevant methods."""
512
512
513 def _matplotlib_config(self,name,user_ns):
513 def _matplotlib_config(self,name,user_ns,user_global_ns=None):
514 """Return items needed to setup the user's shell with matplotlib"""
514 """Return items needed to setup the user's shell with matplotlib"""
515
515
516 # Initialize matplotlib to interactive mode always
516 # Initialize matplotlib to interactive mode always
@@ -564,7 +564,8 b' class MatplotlibShellBase:'
564 self.pylab.draw_if_interactive = flag_calls(self.pylab.draw_if_interactive)
564 self.pylab.draw_if_interactive = flag_calls(self.pylab.draw_if_interactive)
565
565
566 # Build a user namespace initialized with matplotlib/matlab features.
566 # Build a user namespace initialized with matplotlib/matlab features.
567 user_ns = IPython.ipapi.make_user_ns(user_ns)
567 user_ns, user_global_ns = IPython.ipapi.make_user_namespaces(user_ns,
568 user_global_ns)
568
569
569 # Import numpy as np/pyplot as plt are conventions we're trying to
570 # Import numpy as np/pyplot as plt are conventions we're trying to
570 # somewhat standardize on. Making them available to users by default
571 # somewhat standardize on. Making them available to users by default
@@ -584,7 +585,7 b' class MatplotlibShellBase:'
584 Welcome to pylab, a matplotlib-based Python environment.
585 Welcome to pylab, a matplotlib-based Python environment.
585 For more information, type 'help(pylab)'.
586 For more information, type 'help(pylab)'.
586 """
587 """
587 return user_ns,b
588 return user_ns,user_global_ns,b
588
589
589 def mplot_exec(self,fname,*where,**kw):
590 def mplot_exec(self,fname,*where,**kw):
590 """Execute a matplotlib script.
591 """Execute a matplotlib script.
@@ -624,7 +625,7 b' class MatplotlibShell(MatplotlibShellBase,InteractiveShell):'
624
625
625 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
626 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
626 user_ns=None,user_global_ns=None,**kw):
627 user_ns=None,user_global_ns=None,**kw):
627 user_ns,b2 = self._matplotlib_config(name,user_ns)
628 user_ns,user_global_ns,b2 = self._matplotlib_config(name,user_ns,user_global_ns)
628 InteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns,
629 InteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns,
629 banner2=b2,**kw)
630 banner2=b2,**kw)
630
631
@@ -567,17 +567,7 b' def make_user_ns(user_ns = None):'
567 classes in ipython.
567 classes in ipython.
568 """
568 """
569
569
570 if user_ns is None:
570 raise NotImplementedError
571 # Set __name__ to __main__ to better match the behavior of the
572 # normal interpreter.
573 user_ns = {'__name__' :'__main__',
574 '__builtins__' : __builtin__,
575 }
576 else:
577 user_ns.setdefault('__name__','__main__')
578 user_ns.setdefault('__builtins__',__builtin__)
579
580 return user_ns
581
571
582
572
583 def make_user_global_ns(ns = None):
573 def make_user_global_ns(ns = None):
@@ -587,8 +577,56 b' def make_user_global_ns(ns = None):'
587 embedded applications, where there is a distinction between the user's
577 embedded applications, where there is a distinction between the user's
588 interactive namespace and the global one where ipython is running."""
578 interactive namespace and the global one where ipython is running."""
589
579
590 if ns is None: ns = {}
580 raise NotImplementedError
591 return ns
581
582 # Record the true objects in order to be able to test if the user has overridden
583 # these API functions.
584 _make_user_ns = make_user_ns
585 _make_user_global_ns = make_user_global_ns
586
587
588 def make_user_namespaces(user_ns = None,user_global_ns = None):
589 """Return a valid local and global user interactive namespaces.
590
591 This builds a dict with the minimal information needed to operate as a
592 valid IPython user namespace, which you can pass to the various embedding
593 classes in ipython. The default implementation returns the same dict for
594 both the locals and the globals to allow functions to refer to variables in
595 the namespace. Customized implementations can return different dicts. The
596 locals dictionary can actually be anything following the basic mapping
597 protocol of a dict, but the globals dict must be a true dict, not even
598 a subclass. It is recommended that any custom object for the locals
599 namespace synchronize with the globals dict somehow.
600
601 Raises TypeError if the provided globals namespace is not a true dict.
602 """
603
604 if user_ns is None:
605 if make_user_ns is not _make_user_ns:
606 # Old API overridden.
607 # FIXME: Issue DeprecationWarning, or just let the old API live on?
608 user_ns = make_user_ns(user_ns)
609 else:
610 # Set __name__ to __main__ to better match the behavior of the
611 # normal interpreter.
612 user_ns = {'__name__' :'__main__',
613 '__builtins__' : __builtin__,
614 }
615 else:
616 user_ns.setdefault('__name__','__main__')
617 user_ns.setdefault('__builtins__',__builtin__)
618
619 if user_global_ns is None:
620 if make_user_global_ns is not _make_user_global_ns:
621 # Old API overridden.
622 user_global_ns = make_user_global_ns(user_global_ns)
623 else:
624 user_global_ns = user_ns
625 if type(user_global_ns) is not dict:
626 raise TypeError("user_global_ns must be a true dict; got %r"
627 % type(user_global_ns))
628
629 return user_ns, user_global_ns
592
630
593
631
594 def make_session(user_ns = None, shellclass = None):
632 def make_session(user_ns = None, shellclass = None):
@@ -207,7 +207,7 b' class InteractiveShell(object,Magic):'
207 isthreaded = False
207 isthreaded = False
208
208
209 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
209 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
210 user_ns = None,user_global_ns=None,banner2='',
210 user_ns=None,user_global_ns=None,banner2='',
211 custom_exceptions=((),None),embedded=False):
211 custom_exceptions=((),None),embedded=False):
212
212
213 # log system
213 # log system
@@ -254,7 +254,8 b' class InteractiveShell(object,Magic):'
254 # the locals argument. But we do carry a user_global_ns namespace
254 # the locals argument. But we do carry a user_global_ns namespace
255 # given as the exec 'globals' argument, This is useful in embedding
255 # given as the exec 'globals' argument, This is useful in embedding
256 # situations where the ipython shell opens in a context where the
256 # situations where the ipython shell opens in a context where the
257 # distinction between locals and globals is meaningful.
257 # distinction between locals and globals is meaningful. For
258 # non-embedded contexts, it is just the same object as the user_ns dict.
258
259
259 # FIXME. For some strange reason, __builtins__ is showing up at user
260 # FIXME. For some strange reason, __builtins__ is showing up at user
260 # level as a dict instead of a module. This is a manual fix, but I
261 # level as a dict instead of a module. This is a manual fix, but I
@@ -284,14 +285,12 b' class InteractiveShell(object,Magic):'
284 # These routines return properly built dicts as needed by the rest of
285 # These routines return properly built dicts as needed by the rest of
285 # the code, and can also be used by extension writers to generate
286 # the code, and can also be used by extension writers to generate
286 # properly initialized namespaces.
287 # properly initialized namespaces.
287 user_ns = IPython.ipapi.make_user_ns(user_ns)
288 user_ns, user_global_ns = IPython.ipapi.make_user_namespaces(user_ns,
288 user_global_ns = IPython.ipapi.make_user_global_ns(user_global_ns)
289 user_global_ns)
289
290
290 # Assign namespaces
291 # Assign namespaces
291 # This is the namespace where all normal user variables live
292 # This is the namespace where all normal user variables live
292 self.user_ns = user_ns
293 self.user_ns = user_ns
293 # Embedded instances require a separate namespace for globals.
294 # Normally this one is unused by non-embedded instances.
295 self.user_global_ns = user_global_ns
294 self.user_global_ns = user_global_ns
296 # A namespace to keep track of internal data structures to prevent
295 # A namespace to keep track of internal data structures to prevent
297 # them from cluttering user-visible stuff. Will be updated later
296 # them from cluttering user-visible stuff. Will be updated later
@@ -2070,16 +2069,7 b' want to merge them back into the new files.""" % locals()'
2070 try:
2069 try:
2071 try:
2070 try:
2072 self.hooks.pre_runcode_hook()
2071 self.hooks.pre_runcode_hook()
2073 # Embedded instances require separate global/local namespaces
2072 exec code_obj in self.user_global_ns, self.user_ns
2074 # so they can see both the surrounding (local) namespace and
2075 # the module-level globals when called inside another function.
2076 if self.embedded:
2077 exec code_obj in self.user_global_ns, self.user_ns
2078 # Normal (non-embedded) instances should only have a single
2079 # namespace for user code execution, otherwise functions won't
2080 # see interactive top-level globals.
2081 else:
2082 exec code_obj in self.user_ns
2083 finally:
2073 finally:
2084 # Reset our crash handler in place
2074 # Reset our crash handler in place
2085 sys.excepthook = old_excepthook
2075 sys.excepthook = old_excepthook
General Comments 0
You need to be logged in to leave comments. Login now