;ò
ÎÑAHc           @   s  d  Z  d k l Z d k l Z l Z d k l	 Z	 y e
 Wn d k l Z
 n Xd a e
 e	 e i ƒ  ƒ ƒ e
 e	 e ƒ  ƒ ƒ Z d „  Z t d „ Z e d j oÖ e e ƒ Z e i ƒ  d	 e i f d
 „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z e ƒ  Z e e _ e ƒ  Z e ƒ  i Z d k Z d e _ e i d ƒ g  j p t  ‚ e i d ƒ Z! e! d d g j p t  ‚ d GHn d S(   sn  Traits-aware tab completion.

This module provides a custom tab-completer that intelligently hides the names
that the enthought.traits library (http://code.enthought.com/traits)
automatically adds to all objects that inherit from its base HasTraits class.


Activation
==========

To use this, put in your ~/.ipython/ipy_user_conf.py file:

    from ipy_traits_completer import activate
    activate([complete_threshold])

The optional complete_threshold argument is the minimal length of text you need
to type for tab-completion to list names that are automatically generated by
traits.  The default value is 3.  Note that at runtime, you can change this
value simply by doing:

    import ipy_traits_completer
    ipy_traits_completer.COMPLETE_THRESHOLD = 4


Usage
=====

The system works as follows.  If t is an empty object that HasTraits, then
(assuming the threshold is at the default value of 3):

In [7]: t.ed<TAB>

doesn't show anything at all, but:

In [7]: t.edi<TAB>
t.edit_traits      t.editable_traits

shows these two names that come from traits.  This allows you to complete on
the traits-specific names by typing at least 3 letters from them (or whatever
you set your threshold to), but to otherwise not see them in normal completion.


Notes
=====

  - This requires Python 2.4 to work (I use sets).  I don't think anyone is
  using traits with 2.3 anyway, so that's OK.
(   s   api(   s   TryNexts   get(   s   dir2(   s   Seti   c         C   sá  | i i d ƒ } d i | d  ƒ }	 |  i |	 ƒ } | d o
 t	 ‚ n | d } t | t i ƒ o
 t	 ‚ n t | ƒ } | d } | o? g  i } | D]$ }
 |
 i | ƒ o | |
 ƒ q q ~ } n t ƒ  i i } | d j o@ g  i } | D]% }
 |
 i d ƒ o | |
 ƒ qø qø ~ } nN | d j o@ g  i } | D]% }
 |
 i d ƒ o | |
 ƒ qEqE~ } n t | ƒ t j  o t t | ƒ t ƒ } n |	 d } g  i } | D] }
 | | |
 ƒ q¼~ } | Sd	 S(
   sÐ   A custom IPython tab-completer that is traits-aware.

    It tries to hide the internal traits attributes, and reveal them only when
    it can reasonably guess that the user really is after one of them.
    s   .iÿÿÿÿs   founds   obji   s   __i   s   _N(    s   events   symbols   splits   symbol_partss   joins   bases   selfs   _ofinds   oinfos   TryNexts   objs
   isinstances   Ts	   HasTraitss   dir2s   attrss
   attr_starts   appends   _[1]s   as
   startswiths   ipgets   optionss   readline_omit__namess   omit__namess   lens   COMPLETE_THRESHOLDs   lists   sets   TRAIT_NAMESs   bdots   tcomp(   s   selfs   events   oinfos   attrss
   attr_starts   tcomps   symbol_partss   omit__namess   bdots   bases   as   objs   _[1](    (    sX   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_traits_completer.pys   trait_completerN   s.     



?@@
+c         C   sa   t  |  t ƒ o
 |  d j o d |  } t | ƒ ‚ n |  a t ƒ  } | i d t	 d d ƒd S(   sÈ   Activate the Traits completer.

    :Keywords:
      complete_threshold : int
        The minimum number of letters that a user must type in order to
      activate completion of traits-private names.i    s5   complete_threshold must be a positive integer, not %rs   complete_commands   re_keys   .*N(
   s
   isinstances   complete_thresholds   ints   es
   ValueErrors   COMPLETE_THRESHOLDs   ipgets   ips   set_hooks   trait_completer(   s   complete_thresholds   es   ip(    (    sX   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_traits_completer.pys   activate~   s     
 	s   __main__s   TCleanc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sX   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_traits_completer.pys   TCleanž   s    s   Bunchc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sX   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_traits_completer.pys   BunchŸ   s    Ns   t.eds   t.edis   t.edit_traitss   t.editable_traitss   Tests OK("   s   __doc__s   enthought.traitss   apis   Ts   IPython.ipapis   TryNexts   gets   ipgets   IPython.genutilss   dir2s   sets   setss   Sets   COMPLETE_THRESHOLDs	   HasTraitss   objects   TRAIT_NAMESs   trait_completers   activates   __name__s   lists   TNLs   sorts   TCleans   Bunchs   ts   fs   os   IPs   ips   ipy_traits_completers   completes   AssertionErrors   ta(   s   ips   dir2s   Bunchs   sets   fs   TCleans   ipy_traits_completers   os   ts   tas   TRAIT_NAMESs   trait_completers   ipgets   Ts   TNLs   TryNexts   activate(    (    sX   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/Extensions/ipy_traits_completer.pys   ?0   s6   	+	0
						