home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1764 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.6 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from enthought.traits import api as T
  5. from IPython.ipapi import TryNext, get as ipget
  6. from IPython.genutils import dir2
  7.  
  8. try:
  9.     set
  10. except:
  11.     from sets import Set as set
  12.  
  13. COMPLETE_THRESHOLD = 3
  14. TRAIT_NAMES = set(dir2(T.HasTraits())) - set(dir2(object()))
  15.  
  16. def trait_completer(self, event):
  17.     symbol_parts = event.symbol.split('.')
  18.     base = '.'.join(symbol_parts[:-1])
  19.     oinfo = self._ofind(base)
  20.     if not oinfo['found']:
  21.         raise TryNext
  22.     oinfo['found']
  23.     obj = oinfo['obj']
  24.     if not isinstance(obj, T.HasTraits):
  25.         raise TryNext
  26.     isinstance(obj, T.HasTraits)
  27.     attrs = dir2(obj)
  28.     attr_start = symbol_parts[-1]
  29.     omit__names = ipget().options.readline_omit__names
  30.     if omit__names == 1:
  31.         attrs = _[2]
  32.     elif omit__names == 2:
  33.         attrs = _[3]
  34.     
  35.     bdot = base + '.'
  36.     tcomp = [ bdot + a for a in attrs ]
  37.     return tcomp
  38.  
  39.  
  40. def activate(complete_threshold = COMPLETE_THRESHOLD):
  41.     global COMPLETE_THRESHOLD
  42.     if not isinstance(complete_threshold, int) and complete_threshold > 0:
  43.         e = 'complete_threshold must be a positive integer, not %r' % complete_threshold
  44.         raise ValueError(e)
  45.     complete_threshold > 0
  46.     COMPLETE_THRESHOLD = complete_threshold
  47.     ip = ipget()
  48.     ip.set_hook('complete_command', trait_completer, re_key = '.*')
  49.  
  50. if __name__ == '__main__':
  51.     TNL = list(TRAIT_NAMES)
  52.     TNL.sort()
  53.     
  54.     class TClean(T.HasTraits):
  55.         pass
  56.  
  57.     
  58.     class Bunch(object):
  59.         pass
  60.  
  61.     t = TClean()
  62.     f = Bunch()
  63.     f.t = t
  64.     o = object()
  65.     ip = ipget().IP
  66.     import ipy_traits_completer
  67.     ipy_traits_completer.COMPLETE_THRESHOLD = 3
  68.     ta = ip.complete('t.edi')
  69.     print 'Tests OK'
  70.  
  71.