コード例 #1
0
    def 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.
        """
        # Cancel another delayed call, if it exists.
        if self._delayed_completion_id is not None:
            self.text.after_cancel(self._delayed_completion_id)
            self._delayed_completion_id = None

        hp = HyperParser(self.editwin, "insert")
        curline = self.text.get("insert linestart", "insert")
        i = j = len(curline)
        if hp.is_in_string() and (not mode or mode == COMPLETE_FILES):
            # Find the beginning of the string
            # fetch_completions will look at the file system to determine whether the
            # string value constitutes an actual file name
            # XXX could consider raw strings here and unescape the string value if it's
            # not raw.
            self._remove_autocomplete_window()
            mode = COMPLETE_FILES
            # Find last separator or string start
            while i and curline[i - 1] not in "'\"" + SEPS:
                i -= 1
            comp_start = curline[i:j]
            j = i
            # Find string start
            while i and curline[i - 1] not in "'\"":
                i -= 1
            comp_what = curline[i:j]
        elif hp.is_in_code() and (not mode or mode == COMPLETE_ATTRIBUTES):
            self._remove_autocomplete_window()
            mode = COMPLETE_ATTRIBUTES
            while i and (curline[i - 1] in ID_CHARS
                         or ord(curline[i - 1]) > 127):
                i -= 1
            comp_start = curline[i:j]
            if i and curline[i - 1] == '.':
                hp.set_index("insert-%dc" % (len(curline) - (i - 1)))
                comp_what = hp.get_expression()
                if not comp_what or \
                   (not evalfuncs and comp_what.find('(') != -1):
                    return
            else:
                comp_what = ""
        else:
            return

        if complete and not comp_what and not comp_start:
            return
        comp_lists = self.fetch_completions(comp_what, mode)
        if not comp_lists[0]:
            return
        self.autocompletewindow = self._make_autocomplete_window()
        return not self.autocompletewindow.show_window(
            comp_lists, "insert-%dc" % len(comp_start), complete, mode,
            userWantsWin)
コード例 #2
0
    def 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.
        """
        # Cancel another delayed call, if it exists.
        if self._delayed_completion_id is not None:
            self.text.after_cancel(self._delayed_completion_id)
            self._delayed_completion_id = None

        hp = HyperParser(self.editwin, "insert")
        curline = self.text.get("insert linestart", "insert")
        i = j = len(curline)
        if hp.is_in_string() and (not mode or mode==COMPLETE_FILES):
            # Find the beginning of the string
            # fetch_completions will look at the file system to determine whether the
            # string value constitutes an actual file name
            # XXX could consider raw strings here and unescape the string value if it's
            # not raw.
            self._remove_autocomplete_window()
            mode = COMPLETE_FILES
            # Find last separator or string start
            while i and curline[i-1] not in "'\"" + SEPS:
                i -= 1
            comp_start = curline[i:j]
            j = i
            # Find string start
            while i and curline[i-1] not in "'\"":
                i -= 1
            comp_what = curline[i:j]
        elif hp.is_in_code() and (not mode or mode==COMPLETE_ATTRIBUTES):
            self._remove_autocomplete_window()
            mode = COMPLETE_ATTRIBUTES
            while i and (curline[i-1] in ID_CHARS or ord(curline[i-1]) > 127):
                i -= 1
            comp_start = curline[i:j]
            if i and curline[i-1] == '.':
                hp.set_index("insert-%dc" % (len(curline)-(i-1)))
                comp_what = hp.get_expression()
                if not comp_what or \
                   (not evalfuncs and comp_what.find('(') != -1):
                    return
            else:
                comp_what = ""
        else:
            return

        if complete and not comp_what and not comp_start:
            return
        comp_lists = self.fetch_completions(comp_what, mode)
        if not comp_lists[0]:
            return
        self.autocompletewindow = self._make_autocomplete_window()
        return not self.autocompletewindow.show_window(
                comp_lists, "insert-%dc" % len(comp_start),
                complete, mode, userWantsWin)
コード例 #3
0
    def 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.
        """
        # Cancel another delayed call, if it exists.
        if self._delayed_completion_id is not None:
            self.text.after_cancel(self._delayed_completion_id)
            self._delayed_completion_id = None

        hp = HyperParser(self.editwin, "insert")
        curline = self.text.get("insert linestart", "insert")
        i = j = len(curline)
        if hp.is_in_string() and (not mode or mode==COMPLETE_FILES):
            self._remove_autocomplete_window()
            mode = COMPLETE_FILES
            while i and curline[i-1] in FILENAME_CHARS:
                i -= 1
            comp_start = curline[i:j]
            j = i
            while i and curline[i-1] in FILENAME_CHARS+os.sep:
                i -= 1
            comp_what = curline[i:j]
        elif hp.is_in_code() and (not mode or mode==COMPLETE_ATTRIBUTES):
            self._remove_autocomplete_window()
            mode = COMPLETE_ATTRIBUTES
            while i and curline[i-1] in ID_CHARS:
                i -= 1
            comp_start = curline[i:j]
            if i and curline[i-1] == '.':
                hp.set_index("insert-%dc" % (len(curline)-(i-1)))
                comp_what = hp.get_expression()
                if not comp_what or \
                   (not evalfuncs and comp_what.find('(') != -1):
                    return
            else:
                comp_what = ""
        else:
            return

        if complete and not comp_what and not comp_start:
            return
        comp_lists = self.fetch_completions(comp_what, mode)
        if not comp_lists[0]:
            return
        self.autocompletewindow = self._make_autocomplete_window()
        self.autocompletewindow.show_window(comp_lists,
                                            "insert-%dc" % len(comp_start),
                                            complete,
                                            mode,
                                            userWantsWin)
        return True
コード例 #4
0
    def 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.
        """
        # Cancel another delayed call, if it exists.
        if self._delayed_completion_id is not None:
            self.text.after_cancel(self._delayed_completion_id)
            self._delayed_completion_id = None

        hp = HyperParser(self.editwin, "insert")
        curline = self.text.get("insert linestart", "insert")
        i = j = len(curline)
        if hp.is_in_string() and (not mode or mode==COMPLETE_FILES):
            self._remove_autocomplete_window()
            mode = COMPLETE_FILES
            while i and curline[i-1] in FILENAME_CHARS:
                i -= 1
            comp_start = curline[i:j]
            j = i
            while i and curline[i-1] in FILENAME_CHARS+os.sep:
                i -= 1
            comp_what = curline[i:j]
        elif hp.is_in_code() and (not mode or mode==COMPLETE_ATTRIBUTES):
            self._remove_autocomplete_window()
            mode = COMPLETE_ATTRIBUTES
            while i and curline[i-1] in ID_CHARS:
                i -= 1
            comp_start = curline[i:j]
            if i and curline[i-1] == '.':
                hp.set_index("insert-%dc" % (len(curline)-(i-1)))
                comp_what = hp.get_expression()
                if not comp_what or \
                   (not evalfuncs and comp_what.find('(') != -1):
                    return
            else:
                comp_what = ""
        else:
            return

        if complete and not comp_what and not comp_start:
            return
        comp_lists = self.fetch_completions(comp_what, mode)
        if not comp_lists[0]:
            return
        self.autocompletewindow = self._make_autocomplete_window()
        self.autocompletewindow.show_window(comp_lists,
                                            "insert-%dc" % len(comp_start),
                                            complete,
                                            mode,
                                            userWantsWin)
        return True
コード例 #5
0
 def paren_closed_event(self, event):
     # If it was a shortcut and not really a closing paren, quit.
     closer = self.text.get("insert-1c")
     if closer not in _openers:
         return
     hp = HyperParser(self.editwin, "insert-1c")
     if not hp.is_in_code():
         return
     indices = hp.get_surrounding_brackets(_openers[closer], True)
     if indices is None:
         self.warn_mismatched()
         return
     self.activate_restore()
     self.create_tag(indices)
     self.set_timeout()
コード例 #6
0
ファイル: ParenMatch.py プロジェクト: belzner/idle-errors-uap
 def paren_closed_event(self, event):
     # If it was a shortcut and not really a closing paren, quit.
     closer = self.text.get("insert-1c")
     if closer not in _openers:
         return
     hp = HyperParser(self.editwin, "insert-1c")
     if not hp.is_in_code():
         return
     indices = hp.get_surrounding_brackets(_openers[closer], True)
     if indices is None:
         self.warn_mismatched()
         return
     self.activate_restore()
     self.create_tag(indices)
     self.set_timeout()
コード例 #7
0
ファイル: AutoComplete.py プロジェクト: idlespork/idlespork
    def 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.
        """
        # Cancel another delayed call, if it exists.
        if self._delayed_completion_id is not None:
            self.text.after_cancel(self._delayed_completion_id)
            self._delayed_completion_id = None

        # If the window is already open, show the big list of completions.
        # This means that a double Ctrl-space opens the big list every time, which is nice.
        if self.autocompletewindow is not None and self.autocompletewindow.autocompletewindow is not None:
            showbig = True
        else:
            showbig = False

        hp = HyperParser(self.editwin, "insert")
        curline = self.text.get("insert linestart", "insert")
        i = j = len(curline)

        # Check if it's an import statement.
        # This is seperated from the rest since the pattern check is in ModuleCompletion.
        imports = self.get_module_completion(curline)
        if imports:
            if imports == ([], []):
                return
            comp_lists = imports
            while i and curline[i - 1] in ID_CHARS:
                i -= 1
            comp_start = curline[i:j]
        elif self.dictkeys and hp.is_in_dict() and (not mode or mode==COMPLETE_KEYS) and evalfuncs:
            self._remove_autocomplete_window()
            mode = COMPLETE_KEYS
            while i and curline[i - 1] in ID_CHARS + '"' + "'":
                i -= 1
            comp_start = curline[i:j]
            if curline[i - 1:i] == "[":
                hp.set_index("insert-%dc" % (len(curline) - (i - 1)))
                comp_what = hp.get_expression()
            else:
                comp_what = ""
        elif (hp.is_in_string() or hp.is_in_command()) \
            and (not mode or mode==COMPLETE_FILES):
            self._remove_autocomplete_window()
            mode = COMPLETE_FILES
            while i and curline[i-1] in FILENAME_CHARS:
                i -= 1
            comp_start = curline[i:j]
            j = i
            while i and curline[i-1] in FILENAME_CHARS + SEPS:
                i -= 1
            comp_what = curline[i:j]
        elif hp.is_in_code() and (not mode or mode==COMPLETE_ATTRIBUTES):
            self._remove_autocomplete_window()
            mode = COMPLETE_ATTRIBUTES

            while i and curline[i-1] in ID_CHARS:
                i -= 1
            comp_start = curline[i:j]
            if i and curline[i-1] == '.':
                hp.set_index("insert-%dc" % (len(curline)-(i-1)))
                comp_what = hp.get_expression()

                if not comp_what or \
                   (not evalfuncs and comp_what.find('(') != -1):
                    return
            else:
                comp_what = ""
        else:
            return

        # For everything but imports, call fetch_completions
        if not imports:
            if complete and not comp_what and not comp_start:
                return
            comp_lists = self.fetch_completions(comp_what, mode)
            if not comp_lists[0]:
                return

        # It's nice to be able to see the length of a tuple/list (but not anything more complicated)
        if comp_lists[0] == SHOWCALLTIP:
            parenleft = self.text.index('insert-1c')
            CallTip(self.text).showtip(comp_lists[1], parenleft, parenleft.split('.')[0] + '.end')
            return

        if mode == COMPLETE_ATTRIBUTES and not imports:
            calltips = self.editwin.extensions.get('CallTips')
            if calltips:
                args = calltips.arg_names(evalfuncs)
                if args:
                    args = [a + '=' for a in args]
                    comp_lists = sorted(comp_lists[0] + args), sorted(comp_lists[1] + args)

        # Check if we want to show only completion containing typed word.
        if self.onlycontaining:
            # Small optimization
            comp_lower = comp_start.lower()
            # Find such completions.
            comp_lists = [name for name in comp_lists[0] if comp_lower in name.lower()], comp_lists[1]
            # If none were found, look in big list.
            if not comp_lists[0]:
                comp_lists = [name for name in comp_lists[1] if comp_lower in name.lower()], comp_lists[1]
            # If still none were found, just return the big list - which is the default anyway.
            if not comp_lists[0]:
                comp_lists = comp_lists[1], comp_lists[1]

        if showbig:
            comp_lists = comp_lists[1], []

        self.autocompletewindow = self._make_autocomplete_window()
        return not self.autocompletewindow.show_window(
                comp_lists, "insert-%dc" % len(comp_start),
                complete, mode, userWantsWin, onlycontaining=self.onlycontaining)
コード例 #8
0
    def 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.
        """
        # Cancel another delayed call, if it exists.
        if self._delayed_completion_id is not None:
            self.text.after_cancel(self._delayed_completion_id)
            self._delayed_completion_id = None

        # If the window is already open, show the big list of completions.
        # This means that a double Ctrl-space opens the big list every time, which is nice.
        if self.autocompletewindow is not None and self.autocompletewindow.autocompletewindow is not None:
            showbig = True
        else:
            showbig = False

        hp = HyperParser(self.editwin, "insert")
        curline = self.text.get("insert linestart", "insert")
        i = j = len(curline)

        # Check if it's an import statement.
        # This is seperated from the rest since the pattern check is in ModuleCompletion.
        imports = self.get_module_completion(curline)
        if imports:
            if imports == ([], []):
                return
            comp_lists = imports
            while i and curline[i - 1] in ID_CHARS:
                i -= 1
            comp_start = curline[i:j]
        elif self.dictkeys and hp.is_in_dict() and (
                not mode or mode == COMPLETE_KEYS) and evalfuncs:
            self._remove_autocomplete_window()
            mode = COMPLETE_KEYS
            while i and curline[i - 1] in ID_CHARS + '"' + "'":
                i -= 1
            comp_start = curline[i:j]
            if curline[i - 1:i] == "[":
                hp.set_index("insert-%dc" % (len(curline) - (i - 1)))
                comp_what = hp.get_expression()
            else:
                comp_what = ""
        elif (hp.is_in_string() or hp.is_in_command()) \
            and (not mode or mode==COMPLETE_FILES):
            self._remove_autocomplete_window()
            mode = COMPLETE_FILES
            while i and curline[i - 1] in FILENAME_CHARS:
                i -= 1
            comp_start = curline[i:j]
            j = i
            while i and curline[i - 1] in FILENAME_CHARS + SEPS:
                i -= 1
            comp_what = curline[i:j]
        elif hp.is_in_code() and (not mode or mode == COMPLETE_ATTRIBUTES):
            self._remove_autocomplete_window()
            mode = COMPLETE_ATTRIBUTES

            while i and curline[i - 1] in ID_CHARS:
                i -= 1
            comp_start = curline[i:j]
            if i and curline[i - 1] == '.':
                hp.set_index("insert-%dc" % (len(curline) - (i - 1)))
                comp_what = hp.get_expression()

                if not comp_what or \
                   (not evalfuncs and comp_what.find('(') != -1):
                    return
            else:
                comp_what = ""
        else:
            return

        # For everything but imports, call fetch_completions
        if not imports:
            if complete and not comp_what and not comp_start:
                return
            comp_lists = self.fetch_completions(comp_what, mode)
            if not comp_lists[0]:
                return

        # It's nice to be able to see the length of a tuple/list (but not anything more complicated)
        if comp_lists[0] == SHOWCALLTIP:
            parenleft = self.text.index('insert-1c')
            CallTip(self.text).showtip(comp_lists[1], parenleft,
                                       parenleft.split('.')[0] + '.end')
            return

        if mode == COMPLETE_ATTRIBUTES and not imports:
            calltips = self.editwin.extensions.get('CallTips')
            if calltips:
                args = calltips.arg_names(evalfuncs)
                if args:
                    args = [a + '=' for a in args]
                    comp_lists = sorted(comp_lists[0] +
                                        args), sorted(comp_lists[1] + args)

        # Check if we want to show only completion containing typed word.
        if self.onlycontaining:
            # Small optimization
            comp_lower = comp_start.lower()
            # Find such completions.
            comp_lists = [
                name for name in comp_lists[0] if comp_lower in name.lower()
            ], comp_lists[1]
            # If none were found, look in big list.
            if not comp_lists[0]:
                comp_lists = [
                    name for name in comp_lists[1]
                    if comp_lower in name.lower()
                ], comp_lists[1]
            # If still none were found, just return the big list - which is the default anyway.
            if not comp_lists[0]:
                comp_lists = comp_lists[1], comp_lists[1]

        if showbig:
            comp_lists = comp_lists[1], []

        self.autocompletewindow = self._make_autocomplete_window()
        return not self.autocompletewindow.show_window(
            comp_lists,
            "insert-%dc" % len(comp_start),
            complete,
            mode,
            userWantsWin,
            onlycontaining=self.onlycontaining)