##// END OF EJS Templates
Fix tab-completion bug in threaded shells.x
fperez -
Show More
@@ -4,7 +4,7 b''
4 4 All the matplotlib support code was co-developed with John Hunter,
5 5 matplotlib's author.
6 6
7 $Id: Shell.py 958 2005-12-27 23:17:51Z fperez $"""
7 $Id: Shell.py 964 2005-12-28 21:03:01Z fperez $"""
8 8
9 9 #*****************************************************************************
10 10 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
@@ -47,10 +47,10 b' USE_TK = False'
47 47 class IPShell:
48 48 """Create an IPython instance."""
49 49
50 def __init__(self,argv=None,user_ns=None,debug=1,
51 shell_class=InteractiveShell):
52 self.IP = make_IPython(argv,user_ns=user_ns,debug=debug,
53 shell_class=shell_class)
50 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
51 debug=1,shell_class=InteractiveShell):
52 self.IP = make_IPython(argv,user_ns=user_ns,user_global_ns=user_global_ns,
53 debug=debug,shell_class=shell_class)
54 54
55 55 def mainloop(self,sys_exit=0,banner=None):
56 56 self.IP.mainloop(banner)
@@ -261,10 +261,11 b' class MTInteractiveShell(InteractiveShell):'
261 261 # from the pygtk mailing list, to avoid lockups with system calls.
262 262
263 263 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
264 user_ns = None, banner2='',**kw):
264 user_ns=None,user_global_ns=None,banner2='',**kw):
265 265 """Similar to the normal InteractiveShell, but with threading control"""
266 266
267 IPython.iplib.InteractiveShell.__init__(self,name,usage,rc,user_ns,banner2)
267 InteractiveShell.__init__(self,name,usage,rc,user_ns,
268 user_global_ns,banner2)
268 269
269 270 # Locking control variable
270 271 self.thread_ready = threading.Condition()
@@ -475,17 +476,19 b' class MatplotlibShell(MatplotlibShellBase,InteractiveShell):'
475 476 """Single-threaded shell with matplotlib support."""
476 477
477 478 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
478 user_ns = None, **kw):
479 user_ns=None,user_global_ns=None,**kw):
479 480 user_ns,b2 = self._matplotlib_config(name)
480 InteractiveShell.__init__(self,name,usage,rc,user_ns,banner2=b2,**kw)
481 InteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns,
482 banner2=b2,**kw)
481 483
482 484 class MatplotlibMTShell(MatplotlibShellBase,MTInteractiveShell):
483 485 """Multi-threaded shell with matplotlib support."""
484 486
485 487 def __init__(self,name,usage=None,rc=Struct(opts=None,args=None),
486 user_ns = None, **kw):
488 user_ns=None,user_global_ns=None, **kw):
487 489 user_ns,b2 = self._matplotlib_config(name)
488 MTInteractiveShell.__init__(self,name,usage,rc,user_ns,banner2=b2,**kw)
490 MTInteractiveShell.__init__(self,name,usage,rc,user_ns,user_global_ns,
491 banner2=b2,**kw)
489 492
490 493 #-----------------------------------------------------------------------------
491 494 # Utility functions for the different GUI enabled IPShell* classes.
@@ -581,8 +584,8 b' class IPShellGTK(threading.Thread):'
581 584
582 585 TIMEOUT = 100 # Millisecond interval between timeouts.
583 586
584 def __init__(self,argv=None,user_ns=None,debug=1,
585 shell_class=MTInteractiveShell):
587 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
588 debug=1,shell_class=MTInteractiveShell):
586 589
587 590 import gtk
588 591
@@ -595,7 +598,9 b' class IPShellGTK(threading.Thread):'
595 598 if gtk.pygtk_version >= (2,4,0): mainquit = self.gtk.main_quit
596 599 else: mainquit = self.gtk.mainquit
597 600
598 self.IP = make_IPython(argv,user_ns=user_ns,debug=debug,
601 self.IP = make_IPython(argv,user_ns=user_ns,
602 user_global_ns=user_global_ns,
603 debug=debug,
599 604 shell_class=shell_class,
600 605 on_kill=[mainquit])
601 606
@@ -656,8 +661,8 b' class IPShellWX(threading.Thread):'
656 661
657 662 TIMEOUT = 100 # Millisecond interval between timeouts.
658 663
659 def __init__(self,argv=None,user_ns=None,debug=1,
660 shell_class=MTInteractiveShell):
664 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
665 debug=1,shell_class=MTInteractiveShell):
661 666
662 667 import wxPython.wx as wx
663 668
@@ -668,7 +673,9 b' class IPShellWX(threading.Thread):'
668 673 # Allows us to use both Tk and GTK.
669 674 self.tk = get_tk()
670 675
671 self.IP = make_IPython(argv,user_ns=user_ns,debug=debug,
676 self.IP = make_IPython(argv,user_ns=user_ns,
677 user_global_ns=user_global_ns,
678 debug=debug,
672 679 shell_class=shell_class,
673 680 on_kill=[self.wxexit])
674 681 # HACK: slot for banner in self; it will be passed to the mainloop
@@ -738,8 +745,8 b' class IPShellQt(threading.Thread):'
738 745
739 746 TIMEOUT = 100 # Millisecond interval between timeouts.
740 747
741 def __init__(self,argv=None,user_ns=None,debug=0,
742 shell_class=MTInteractiveShell):
748 def __init__(self,argv=None,user_ns=None,user_global_ns=None,
749 debug=0,shell_class=MTInteractiveShell):
743 750
744 751 import qt
745 752
@@ -761,7 +768,9 b' class IPShellQt(threading.Thread):'
761 768 # Allows us to use both Tk and QT.
762 769 self.tk = get_tk()
763 770
764 self.IP = make_IPython(argv,user_ns=user_ns,debug=debug,
771 self.IP = make_IPython(argv,user_ns=user_ns,
772 user_global_ns=user_global_ns,
773 debug=debug,
765 774 shell_class=shell_class,
766 775 on_kill=[qt.qApp.exit])
767 776
@@ -809,32 +818,36 b' class IPShellMatplotlib(IPShell):'
809 818
810 819 Having this on a separate class simplifies the external driver code."""
811 820
812 def __init__(self,argv=None,user_ns=None,debug=1):
813 IPShell.__init__(self,argv,user_ns,debug,shell_class=MatplotlibShell)
821 def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
822 IPShell.__init__(self,argv,user_ns,user_global_ns,debug,
823 shell_class=MatplotlibShell)
814 824
815 825 class IPShellMatplotlibGTK(IPShellGTK):
816 826 """Subclass IPShellGTK with MatplotlibMTShell as the internal shell.
817 827
818 828 Multi-threaded class, meant for the GTK* backends."""
819 829
820 def __init__(self,argv=None,user_ns=None,debug=1):
821 IPShellGTK.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell)
830 def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
831 IPShellGTK.__init__(self,argv,user_ns,user_global_ns,debug,
832 shell_class=MatplotlibMTShell)
822 833
823 834 class IPShellMatplotlibWX(IPShellWX):
824 835 """Subclass IPShellWX with MatplotlibMTShell as the internal shell.
825 836
826 837 Multi-threaded class, meant for the WX* backends."""
827 838
828 def __init__(self,argv=None,user_ns=None,debug=1):
829 IPShellWX.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell)
839 def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
840 IPShellWX.__init__(self,argv,user_ns,user_global_ns,debug,
841 shell_class=MatplotlibMTShell)
830 842
831 843 class IPShellMatplotlibQt(IPShellQt):
832 844 """Subclass IPShellQt with MatplotlibMTShell as the internal shell.
833 845
834 846 Multi-threaded class, meant for the Qt* backends."""
835 847
836 def __init__(self,argv=None,user_ns=None,debug=1):
837 IPShellQt.__init__(self,argv,user_ns,debug,shell_class=MatplotlibMTShell)
848 def __init__(self,argv=None,user_ns=None,user_global_ns=None,debug=1):
849 IPShellQt.__init__(self,argv,user_ns,user_global_ns,debug,
850 shell_class=MatplotlibMTShell)
838 851
839 852 #-----------------------------------------------------------------------------
840 853 # Factory functions to actually start the proper thread-aware shell
@@ -103,12 +103,13 b' class Completer:'
103 103
104 104 readline.set_completer(Completer(my_namespace).complete)
105 105 """
106
107 if namespace and type(namespace) != types.DictType:
108 raise TypeError,'namespace must be a dictionary'
109 106
110 if global_namespace and type(global_namespace) != types.DictType:
111 raise TypeError,'global_namespace must be a dictionary'
107 # some minimal strict typechecks. For some core data structures, I
108 # want actual basic python types, not just anything that looks like
109 # one. This is especially true for namespaces.
110 for ns in (namespace,global_namespace):
111 if ns is not None and type(ns) != types.DictType:
112 raise TypeError,'namespace must be a dictionary'
112 113
113 114 # Don't bind to namespace quite yet, but flag whether the user wants a
114 115 # specific namespace or to use __main__.__dict__. This will allow us
@@ -518,6 +519,8 b' class IPCompleter(Completer):'
518 519 except IndexError:
519 520 return None
520 521 except:
521 #import traceback; traceback.print_exc() # dbg
522 #from IPython.ultraTB import AutoFormattedTB; # dbg
523 #tb=AutoFormattedTB('Verbose');tb() #dbg
524
522 525 # If completion fails, don't annoy the user.
523 526 return None
@@ -6,7 +6,7 b' Requires Python 2.1 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 963 2005-12-28 19:21:29Z fperez $
9 $Id: iplib.py 964 2005-12-28 21:03:01Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -236,6 +236,13 b' class InteractiveShell(Logger, Magic):'
236 236 user_ns = None,user_global_ns=None,banner2='',
237 237 custom_exceptions=((),None),embedded=False):
238 238
239 # some minimal strict typechecks. For some core data structures, I
240 # want actual basic python types, not just anything that looks like
241 # one. This is especially true for namespaces.
242 for ns in (user_ns,user_global_ns):
243 if ns is not None and type(ns) != types.DictType:
244 raise TypeError,'namespace must be a dictionary'
245
239 246 # Put a reference to self in builtins so that any form of embedded or
240 247 # imported code can test for being inside IPython.
241 248 __builtin__.__IPYTHON__ = self
@@ -6,7 +6,7 b' Requires Python 2.1 or better.'
6 6
7 7 This file contains the main make_IPython() starter function.
8 8
9 $Id: ipmaker.py 963 2005-12-28 19:21:29Z fperez $"""
9 $Id: ipmaker.py 964 2005-12-28 21:03:01Z fperez $"""
10 10
11 11 #*****************************************************************************
12 12 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -55,8 +55,9 b' from IPython.Prompts import CachedOutput'
55 55 from IPython.genutils import *
56 56
57 57 #-----------------------------------------------------------------------------
58 def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None,
59 shell_class=InteractiveShell,embedded=False,**kw):
58 def make_IPython(argv=None,user_ns=None,user_global_ns=None,debug=1,
59 rc_override=None,shell_class=InteractiveShell,
60 embedded=False,**kw):
60 61 """This is a dump of IPython into a single function.
61 62
62 63 Later it will have to be broken up in a sensible manner.
@@ -86,7 +87,8 b' def make_IPython(argv=None,user_ns=None,debug=1,rc_override=None,'
86 87 # __IP.name. We set its name via the first parameter passed to
87 88 # InteractiveShell:
88 89
89 IP = shell_class('__IP',user_ns=user_ns,embedded=embedded,**kw)
90 IP = shell_class('__IP',user_ns=user_ns,user_global_ns=user_global_ns,
91 embedded=embedded,**kw)
90 92
91 93 # Put 'help' in the user namespace
92 94 from site import _Helper
@@ -5,6 +5,7 b''
5 5 questions part 2 - \/ characters revisited' on the iypthon user
6 6 list:
7 7 http://scipy.net/pipermail/ipython-user/2005-June/000907.html
8 (InteractiveShell.__init__): fix tab-completion bug in threaded shells.
8 9
9 10 * IPython/ipmaker.py (make_IPython): make the autoedit_syntax flag
10 11 true by default, and add it to the shipped ipythonrc file. Since
General Comments 0
You need to be logged in to leave comments. Login now