Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
idlelib.AutoComplete.AutoComplete Class Reference

List of all members.

Public Member Functions

def __init__
def force_open_completions_event
def try_open_completions_event
def autocomplete_event
def open_completions
def fetch_completions
def get_entity

Public Attributes

 editwin
 text
 autocompletewindow

Static Public Attributes

list menudefs
tuple popupwait

Private Member Functions

def _make_autocomplete_window
def _remove_autocomplete_window
def _open_completions_later
def _delayed_open_completions

Private Attributes

 _delayed_completion_id
 _delayed_completion_index

Detailed Description

Definition at line 30 of file AutoComplete.py.


Constructor & Destructor Documentation

def idlelib.AutoComplete.AutoComplete.__init__ (   self,
  editwin = None 
)

Definition at line 41 of file AutoComplete.py.

00041 
00042     def __init__(self, editwin=None):
00043         self.editwin = editwin
00044         if editwin is None:  # subprocess and test
00045             return
00046         self.text = editwin.text
00047         self.autocompletewindow = None
00048 
00049         # id of delayed call, and the index of the text insert when the delayed
00050         # call was issued. If _delayed_completion_id is None, there is no
00051         # delayed call.
00052         self._delayed_completion_id = None
00053         self._delayed_completion_index = None

Here is the caller graph for this function:


Member Function Documentation

Definition at line 105 of file AutoComplete.py.

00105 
00106     def _delayed_open_completions(self, *args):
00107         self._delayed_completion_id = None
00108         if self.text.index("insert") != self._delayed_completion_index:
00109             return
00110         self.open_completions(*args)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 54 of file AutoComplete.py.

Here is the caller graph for this function:

def idlelib.AutoComplete.AutoComplete._open_completions_later (   self,
  args 
) [private]

Definition at line 97 of file AutoComplete.py.

00097 
00098     def _open_completions_later(self, *args):
00099         self._delayed_completion_index = self.text.index("insert")
00100         if self._delayed_completion_id is not None:
00101             self.text.after_cancel(self._delayed_completion_id)
00102         self._delayed_completion_id = \
00103             self.text.after(self.popupwait, self._delayed_open_completions,
00104                             *args)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.AutoComplete.AutoComplete._remove_autocomplete_window (   self,
  event = None 
) [private]

Definition at line 57 of file AutoComplete.py.

00057 
00058     def _remove_autocomplete_window(self, event=None):
00059         if self.autocompletewindow:
00060             self.autocompletewindow.hide_window()
00061             self.autocompletewindow = None

Here is the caller graph for this function:

Happens when the user wants to complete his word, and if necessary,
open a completion list after that (if there is more than one
completion)

Definition at line 81 of file AutoComplete.py.

00081 
00082     def autocomplete_event(self, event):
00083         """Happens when the user wants to complete his word, and if necessary,
00084         open a completion list after that (if there is more than one
00085         completion)
00086         """
00087         if hasattr(event, "mc_state") and event.mc_state:
00088             # A modifier was pressed along with the tab, continue as usual.
00089             return
00090         if self.autocompletewindow and self.autocompletewindow.is_active():
00091             self.autocompletewindow.complete()
00092             return "break"
00093         else:
00094             opened = self.open_completions(False, True, True)
00095             if opened:
00096                 return "break"

Here is the call graph for this function:

def idlelib.AutoComplete.AutoComplete.fetch_completions (   self,
  what,
  mode 
)
Return a pair of lists of completions for something. The first list
is a sublist of the second. Both are sorted.

If there is a Python subprocess, get the comp. list there.  Otherwise,
either fetch_completions() is running in the subprocess itself or it
was called in an IDLE EditorWindow before any script had been run.

The subprocess environment is that of the most recently run script.  If
two unrelated modules are being edited some calltips in the current
module may be inoperative if the module was not the last to run.

Definition at line 166 of file AutoComplete.py.

00166 
00167     def fetch_completions(self, what, mode):
00168         """Return a pair of lists of completions for something. The first list
00169         is a sublist of the second. Both are sorted.
00170 
00171         If there is a Python subprocess, get the comp. list there.  Otherwise,
00172         either fetch_completions() is running in the subprocess itself or it
00173         was called in an IDLE EditorWindow before any script had been run.
00174 
00175         The subprocess environment is that of the most recently run script.  If
00176         two unrelated modules are being edited some calltips in the current
00177         module may be inoperative if the module was not the last to run.
00178         """
00179         try:
00180             rpcclt = self.editwin.flist.pyshell.interp.rpcclt
00181         except:
00182             rpcclt = None
00183         if rpcclt:
00184             return rpcclt.remotecall("exec", "get_the_completion_list",
00185                                      (what, mode), {})
00186         else:
00187             if mode == COMPLETE_ATTRIBUTES:
00188                 if what == "":
00189                     namespace = __main__.__dict__.copy()
00190                     namespace.update(__main__.__builtins__.__dict__)
00191                     bigl = eval("dir()", namespace)
00192                     bigl.sort()
00193                     if "__all__" in bigl:
00194                         smalll = eval("__all__", namespace)
00195                         smalll.sort()
00196                     else:
00197                         smalll = [s for s in bigl if s[:1] != '_']
00198                 else:
00199                     try:
00200                         entity = self.get_entity(what)
00201                         bigl = dir(entity)
00202                         bigl.sort()
00203                         if "__all__" in bigl:
00204                             smalll = entity.__all__
00205                             smalll.sort()
00206                         else:
00207                             smalll = [s for s in bigl if s[:1] != '_']
00208                     except:
00209                         return [], []
00210 
00211             elif mode == COMPLETE_FILES:
00212                 if what == "":
00213                     what = "."
00214                 try:
00215                     expandedpath = os.path.expanduser(what)
00216                     bigl = os.listdir(expandedpath)
00217                     bigl.sort()
00218                     smalll = [s for s in bigl if s[:1] != '.']
00219                 except OSError:
00220                     return [], []
00221 
00222             if not smalll:
00223                 smalll = bigl
00224             return smalll, bigl

Here is the call graph for this function:

Here is the caller graph for this function:

Happens when the user really wants to open a completion list, even
if a function call is needed.

Definition at line 62 of file AutoComplete.py.

00062 
00063     def force_open_completions_event(self, event):
00064         """Happens when the user really wants to open a completion list, even
00065         if a function call is needed.
00066         """
00067         self.open_completions(True, False, True)

Here is the call graph for this function:

Lookup name in a namespace spanning sys.modules and __main.dict__

Definition at line 225 of file AutoComplete.py.

00225 
00226     def get_entity(self, name):
00227         """Lookup name in a namespace spanning sys.modules and __main.dict__"""
00228         namespace = sys.modules.copy()
00229         namespace.update(__main__.__dict__)
00230         return eval(name, namespace)

Here is the caller graph for this function:

def idlelib.AutoComplete.AutoComplete.open_completions (   self,
  evalfuncs,
  complete,
  userWantsWin,
  mode = None 
)
Find the completions and create the AutoCompleteWindow.
Return True if successful (no syntax error or so found).
if complete is True, then if there's nothing to complete and no
start of completion, won't open completions and return False.
If mode is given, will open a completion list only in this mode.

Definition at line 111 of file AutoComplete.py.

00111 
00112     def open_completions(self, evalfuncs, complete, userWantsWin, mode=None):
00113         """Find the completions and create the AutoCompleteWindow.
00114         Return True if successful (no syntax error or so found).
00115         if complete is True, then if there's nothing to complete and no
00116         start of completion, won't open completions and return False.
00117         If mode is given, will open a completion list only in this mode.
00118         """
00119         # Cancel another delayed call, if it exists.
00120         if self._delayed_completion_id is not None:
00121             self.text.after_cancel(self._delayed_completion_id)
00122             self._delayed_completion_id = None
00123 
00124         hp = HyperParser(self.editwin, "insert")
00125         curline = self.text.get("insert linestart", "insert")
00126         i = j = len(curline)
00127         if hp.is_in_string() and (not mode or mode==COMPLETE_FILES):
00128             self._remove_autocomplete_window()
00129             mode = COMPLETE_FILES
00130             while i and curline[i-1] in FILENAME_CHARS:
00131                 i -= 1
00132             comp_start = curline[i:j]
00133             j = i
00134             while i and curline[i-1] in FILENAME_CHARS + SEPS:
00135                 i -= 1
00136             comp_what = curline[i:j]
00137         elif hp.is_in_code() and (not mode or mode==COMPLETE_ATTRIBUTES):
00138             self._remove_autocomplete_window()
00139             mode = COMPLETE_ATTRIBUTES
00140             while i and curline[i-1] in ID_CHARS:
00141                 i -= 1
00142             comp_start = curline[i:j]
00143             if i and curline[i-1] == '.':
00144                 hp.set_index("insert-%dc" % (len(curline)-(i-1)))
00145                 comp_what = hp.get_expression()
00146                 if not comp_what or \
00147                    (not evalfuncs and comp_what.find('(') != -1):
00148                     return
00149             else:
00150                 comp_what = ""
00151         else:
00152             return
00153 
00154         if complete and not comp_what and not comp_start:
00155             return
00156         comp_lists = self.fetch_completions(comp_what, mode)
00157         if not comp_lists[0]:
00158             return
00159         self.autocompletewindow = self._make_autocomplete_window()
00160         self.autocompletewindow.show_window(comp_lists,
00161                                             "insert-%dc" % len(comp_start),
00162                                             complete,
00163                                             mode,
00164                                             userWantsWin)
00165         return True

Here is the call graph for this function:

Here is the caller graph for this function:

Happens when it would be nice to open a completion list, but not
really necessary, for example after an dot, so function
calls won't be made.

Definition at line 68 of file AutoComplete.py.

00068 
00069     def try_open_completions_event(self, event):
00070         """Happens when it would be nice to open a completion list, but not
00071         really necessary, for example after an dot, so function
00072         calls won't be made.
00073         """
00074         lastchar = self.text.get("insert-1c")
00075         if lastchar == ".":
00076             self._open_completions_later(False, False, False,
00077                                          COMPLETE_ATTRIBUTES)
00078         elif lastchar in SEPS:
00079             self._open_completions_later(False, False, False,
00080                                          COMPLETE_FILES)

Here is the call graph for this function:


Member Data Documentation

Definition at line 51 of file AutoComplete.py.

Definition at line 52 of file AutoComplete.py.

Definition at line 46 of file AutoComplete.py.

Definition at line 42 of file AutoComplete.py.

Initial value:
[
        ('edit', [
            ("Show Completions", "<<force-open-completions>>"),
        ])
    ]

Definition at line 32 of file AutoComplete.py.

Initial value:
idleConf.GetOption("extensions", "AutoComplete",
                                   "popupwait", type="int", default=0)

Definition at line 38 of file AutoComplete.py.

Definition at line 45 of file AutoComplete.py.


The documentation for this class was generated from the following file: