##// END OF EJS Templates
Improve tooltip tringgering,make it configurable...
Improve tooltip tringgering,make it configurable As until now, when pressing tab and a white space was preceding the cursor The completion was triggerd with the whole namespace in it. Now if a whitespace or an opening bracket is just befor the cursor it will try to display a tooltip. The logic to find what object_info_request is send have been sightly changed to try to match the expression just before the last unmached openig bracket before the cursor (without considering what is after the cursor). example (_|_ represent the cursor): >>> his_|_<tab> # completion >>> hist(_|_<tab> # tooltip on hist >>> hist(rand(20),bins=range(_|_ <tab> #tooltip on range >>> hist(rand(20),bins=range(10), _|_ <tab> # tooltip on hist (whitespace before cursor) >>> hist(rand(20),bins=range(10),_|_ <tab> # completion as we dont care of what is after the cursor: >>> hist(rand(5000), bins=50, _|_orientaion='horizontal') # and tab, equivalent to >>> hist(rand(5000), bins=50, _|_<tab> # onte the space again >>> hist(_|_rand(5000), bins=50, orientaion='horizontal') # and tab, equivalent to >>> hist(_|_ the 4 give tooltip on hist note that you can get tooltip on things that aren't function by appending a '(' like >>> matplotlib(<tab> Which is kinda weird... so we might want to bound another shortcut for tooltip, but which matches without bracket... additionnaly I have added a "Config" pannel in the left pannel with a checkbox bind to wether or not activate this functionnality Note, (rebase and edited commit, might not work perfetly xwithout the following ones)

File last commit:

r5390:c82649ea
r5399:f73c6ce0
Show More
data.py
106 lines | 3.1 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""Utilities for working with data structures like lists, dicts and tuples.
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import types
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
def uniq_stable(elems):
"""uniq_stable(elems) -> list
Return from an iterable, a list of all the unique elements in the input,
but maintaining the order in which they first appear.
A naive solution to this problem which just makes a dictionary with the
elements as keys fails to respect the stability condition, since
dictionaries are unsorted by nature.
Note: All elements in the input must be valid dictionary keys for this
routine to work, as it internally uses a dictionary for efficiency
reasons."""
unique = []
unique_dict = {}
for nn in elems:
if nn not in unique_dict:
unique.append(nn)
unique_dict[nn] = None
return unique
def sort_compare(lst1, lst2, inplace=1):
"""Sort and compare two lists.
By default it does it in place, thus modifying the lists. Use inplace = 0
to avoid that (at the cost of temporary copy creation)."""
if not inplace:
lst1 = lst1[:]
lst2 = lst2[:]
lst1.sort(); lst2.sort()
return lst1 == lst2
def list2dict(lst):
"""Takes a list of (key,value) pairs and turns it into a dict."""
dic = {}
for k,v in lst: dic[k] = v
return dic
def list2dict2(lst, default=''):
"""Takes a list and turns it into a dict.
Much slower than list2dict, but more versatile. This version can take
lists with sublists of arbitrary length (including sclars)."""
dic = {}
for elem in lst:
if type(elem) in (types.ListType,types.TupleType):
size = len(elem)
if size == 0:
pass
elif size == 1:
dic[elem] = default
else:
k,v = elem[0], elem[1:]
if len(v) == 1: v = v[0]
dic[k] = v
else:
dic[elem] = default
return dic
def flatten(seq):
"""Flatten a list of lists (NOT recursive, only works for 2d lists)."""
return [x for subseq in seq for x in subseq]
def get_slice(seq, start=0, stop=None, step=1):
"""Get a slice of a sequence with variable step. Specify start,stop,step."""
if stop == None:
stop = len(seq)
item = lambda i: seq[i]
return map(item,xrange(start,stop,step))
def chop(seq, size):
"""Chop a sequence into chunks of the given size."""
chunk = lambda i: seq[i:i+size]
return map(chunk,xrange(0,len(seq),size))