示例#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()
        self.autocompletewindow.show_window(comp_lists,
                                            "insert-%dc" % len(comp_start),
                                            complete, mode, userWantsWin)
        return True
示例#2
0
文件: DocViewer.py 项目: CWade3051/Py
    def calltip_event(self, event=None):
        window = self.docWindow.window
        if window is None:
            return

        if not window.update_calltip.get():
            # don't process calltip event
            return

        # get calltip
        # code borrows from CallTips.py::open_calltip
        evalfuncs = False
        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets('(')
        if not sur_paren:
            return
        hp.set_index(sur_paren[0])
        name = hp.get_expression()
        if not name or (not evalfuncs and name.find('(') != -1):
            return

        w = window
        w.entry.delete("0", "end")
        w.entry.insert("insert", name)
        w.get_doc()
示例#3
0
    def calltip_event(self, event=None):
        window = self.docWindow.window
        if window is None:
            return

        if not window.update_calltip.get():
            # don't process calltip event
            return

        # get calltip
        # code borrows from CallTips.py::open_calltip
        evalfuncs = False
        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets('(')
        if not sur_paren:
            return
        hp.set_index(sur_paren[0])
        name = hp.get_expression()
        if not name or (not evalfuncs and name.find('(') != -1):
            return

        w = window
        w.entry.delete("0", "end")
        w.entry.insert("insert", name)
        w.get_doc()
示例#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):
            # 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)
示例#5
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 + 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

        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
    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 + 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

        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
示例#7
0
 def open_calltip(self, evalfuncs):
     self._remove_calltip_window()
     hp = HyperParser(self.editwin, 'insert')
     sur_paren = hp.get_surrounding_brackets('(')
     if not sur_paren:
         return
     hp.set_index(sur_paren[0])
     expression = hp.get_expression()
     if not expression or not evalfuncs and expression.find('(') != -1:
         return
     arg_text = self.fetch_tip(expression)
     if not arg_text:
         return
     self.calltip = self._make_calltip_window()
     self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
示例#8
0
 def open_calltip(self, evalfuncs):
     self._remove_calltip_window()
     hp = HyperParser(self.editwin, 'insert')
     sur_paren = hp.get_surrounding_brackets('(')
     if not sur_paren:
         return
     hp.set_index(sur_paren[0])
     expression = hp.get_expression()
     if not expression or not evalfuncs and expression.find('(') != -1:
         return
     arg_text = self.fetch_tip(expression)
     if not arg_text:
         return
     self.calltip = self._make_calltip_window()
     self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
示例#9
0
    def open_calltip(self, evalfuncs):
        self._remove_calltip_window()

        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets("(")
        if not sur_paren:
            return
        hp.set_index(sur_paren[0])
        name = hp.get_expression()
        if not name or (not evalfuncs and name.find("(") != -1):
            return
        arg_text = self.fetch_tip(name)
        if not arg_text:
            return
        self.calltip = self._make_calltip_window()
        self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
示例#10
0
    def open_completions(self, evalfuncs, complete, userWantsWin, mode=None):
        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 + 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
        if complete and not comp_what and not comp_start:
            return
        else:
            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)
示例#11
0
    def open_calltip(self, evalfuncs):
        self._remove_calltip_window()

        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets('(')
        if not sur_paren:
            return
        hp.set_index(sur_paren[0])
        expression = hp.get_expression()
        if not expression:
            return
        if not evalfuncs and (expression.find('(') != -1):
            return
        argspec = self.fetch_tip(expression)
        if not argspec:
            return
        self.active_calltip = self._calltip_window()
        self.active_calltip.showtip(argspec, sur_paren[0], sur_paren[1])
示例#12
0
    def open_calltip(self, evalfuncs):
        self._remove_calltip_window()

        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets("(")
        if not sur_paren:
            return
        hp.set_index(sur_paren[0])
        expression = hp.get_expression()
        if not expression:
            return
        if not evalfuncs and (expression.find("(") != -1):
            return
        argspec = self.fetch_tip(expression)
        if not argspec:
            return
        self.active_calltip = self._calltip_window()
        self.active_calltip.showtip(argspec, sur_paren[0], sur_paren[1])
示例#13
0
    def open_calltip(self, evalfuncs):
        self._remove_calltip_window()

        # - 2016 9 28 --
        lt = self.text.get('insert linestart', 'insert')
        m = re.search(r'(\w+)<[^>]*', lt)

        if m:
            from idlelib.languages import _cppclassref
            if m.group(1) in _cppclassref.CPP_CLASSREF:
                arg_text = _cppclassref.CPP_CLASSREF[m.group(1)]
                if not arg_text:
                    return

                self.calltip = self._make_calltip_window()
##                print `self.text.index('insert-1c')`, `self.text.index('insert').split('.')[0]+'.end'`
                self.calltip.showtip(
                    arg_text,
                    self.text.index('insert-1c'),
                    self.text.index('insert').split('.')[0]+'.end',
                )
                return
        # ---

        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets('(')
        if not sur_paren:
            return

        hp.set_index(sur_paren[0])
        expression = hp.get_expression()
        if not expression or (not evalfuncs and expression.find('(') != -1):
            return
        arg_text = self.fetch_tip(expression)
        # - 2016 9 27 --
        if hasattr(self.editwin, 'ftype') and self.editwin.ftype.get() in ('C++/l',):
            e = ''
            if not arg_text:
                # treat as constructor
                lt = self.text.get('insert linestart', 'insert lineend')
##                print `lt`, 1
                if re.match(r'^[ \t]', lt, flags=re.MULTILINE):
                    e = lt.lstrip().split()[0]
                    if e == 'string':
                        e = 'basic_string'
                    arg_text = self.fetch_tip(e)

            if not arg_text:
                e = e.split('<')[0]
                if e == 'string':
                    e = 'basic_string'
                arg_text = self.fetch_tip(e)

            if not arg_text:
                # treat as member function
                if expression.count('.') != 1:
                    return # gives up

                name = expression.split('.')[0]
                func = expression.split('.')[1]
                # queue<int> q;  < hit this
                # q.push(1);     < skip this
                # q.front();     < when call here
                ln = int(sur_paren[0].split('.')[0])-1
                pat = re.compile(
                    (
                        r'\b{n}(?!\.)'
                    ).format(n=name)
                )
                lt = self.text.get('{}.0'.format(ln), '{}.end'.format(ln))
                m = pat.search(lt)
                while ln > 0 and not m:
                    lt = self.text.get('{}.0'.format(ln), '{}.end'.format(ln))
                    m = pat.search(lt)
                    ln -= 1

                if m:
                    pat = re.compile(
                        (
                            r'((?:{w}::)*{w}(?:<[^<>]*(?:<[^>]*>)*[^<>]*>)?)\s*'
                            r'{n}'
                        ).format(
                            n=name,
                            w=r'(?:[_A-Za-z]\w*)',
                        )
                    )
                    m2 = pat.search(lt)
                    if m2:
                        e = m2.group(1)
                        if e == 'string':
                            e = 'basic_string'
                        arg_text = self.fetch_tip('{}::{}'.format(e, func))

                    if not arg_text:
                        e = lt.lstrip().split()[0]
                        if e == 'string':
                            e = 'basic_string'
                        arg_text = self.fetch_tip(
                            '{}::{}'.format(e, func)
                        )
                    if not arg_text:
                        e = e.split('<')[0]
                        if e == 'string':
                            e = 'basic_string'
                        arg_text = self.fetch_tip(
                            '{}::{}'.format(e, func)
                        )

##            print `e`
        # ---
        if not arg_text:
            return
        self.calltip = self._make_calltip_window()
        self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
示例#14
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 + 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:
            # todo ---
            tail = self.text.get('insert linestart', 'insert').rstrip(ID_CHARS+' \t')

            if re.search(r'^[ \t]*#include[ \t]*<?', curline, flags=re.M):
                if re.search(r'^[ \t]*#include[ \t]*$', curline, flags=re.M):
                    self.text.insert('insert', '<')
##                    curline = self.text.get('insert linestart', 'insert')
                    curline += '<'
##                    i += 1
                    j += 1
                else:
                    i -= 1

                charset = INCLUDE_CHARS
                mode = COMPLETE_HEADERS
##            elif '::' in self.text.get('insert linestart', 'insert'):
##                charset = NAMESPACE_CHARS
##                mode = COMPLETE_NAMESPACE
##                comp_what = ''
##            else:
##                charset = ID_CHARS
            elif tail.endswith(':') or tail.endswith('>'):
                charset = NAMESPACE_CHARS
                mode = COMPLETE_NAMESPACE
                comp_what = ''
            else:
                charset = ID_CHARS

##            print `curline[i:]`, 1
            while i and curline[i-1] in charset:
            # ---
                if mode == COMPLETE_HEADERS and curline[i] == '<':
                    break

                i -= 1
                if mode == COMPLETE_HEADERS and curline[i] == '<':
                    break
                elif mode == COMPLETE_NAMESPACE:
                    if curline[:i+1].endswith('::'):
                        i += 1

                        ## comp_what = curline[:i].split()[-1]
                        ## hack: foo<T, U>
                        ##     : foo < T >

                        comp_what = re.split(r'\w?[ \t=<(]+(?=[_A-Za-z])', curline[:i])[-1]
                        break

##            print mode, COMPLETE_HEADERS
##            print `curline[i:]`, 2

            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:
                if mode not in (COMPLETE_NAMESPACE,):
                    comp_what = ""
        else:
            return

##        print `comp_start, comp_what`

        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)
示例#15
0
    def open_calltip(self, evalfuncs):
        self._remove_calltip_window()

        # - 2016 9 28 --
        lt = self.text.get('insert linestart', 'insert')
        m = re.search(r'(\w+)<[^>]*', lt)

        if m:
            from idlelib.languages import _cppclassref
            if m.group(1) in _cppclassref.CPP_CLASSREF:
                arg_text = _cppclassref.CPP_CLASSREF[m.group(1)]
                if not arg_text:
                    return

                self.calltip = self._make_calltip_window()
                ##                print `self.text.index('insert-1c')`, `self.text.index('insert').split('.')[0]+'.end'`
                self.calltip.showtip(
                    arg_text,
                    self.text.index('insert-1c'),
                    self.text.index('insert').split('.')[0] + '.end',
                )
                return
        # ---

        hp = HyperParser(self.editwin, "insert")
        sur_paren = hp.get_surrounding_brackets('(')
        if not sur_paren:
            return

        hp.set_index(sur_paren[0])
        expression = hp.get_expression()
        if not expression or (not evalfuncs and expression.find('(') != -1):
            return
        arg_text = self.fetch_tip(expression)
        # - 2016 9 27 --
        if hasattr(self.editwin,
                   'ftype') and self.editwin.ftype.get() in ('C++/l', ):
            e = ''
            if not arg_text:
                # treat as constructor
                lt = self.text.get('insert linestart', 'insert lineend')
                ##                print `lt`, 1
                if re.match(r'^[ \t]', lt, flags=re.MULTILINE):
                    e = lt.lstrip().split()[0]
                    if e == 'string':
                        e = 'basic_string'
                    arg_text = self.fetch_tip(e)

            if not arg_text:
                e = e.split('<')[0]
                if e == 'string':
                    e = 'basic_string'
                arg_text = self.fetch_tip(e)

            if not arg_text:
                # treat as member function
                if expression.count('.') != 1:
                    return  # gives up

                name = expression.split('.')[0]
                func = expression.split('.')[1]
                # queue<int> q;  < hit this
                # q.push(1);     < skip this
                # q.front();     < when call here
                ln = int(sur_paren[0].split('.')[0]) - 1
                pat = re.compile((r'\b{n}(?!\.)').format(n=name))
                lt = self.text.get('{}.0'.format(ln), '{}.end'.format(ln))
                m = pat.search(lt)
                while ln > 0 and not m:
                    lt = self.text.get('{}.0'.format(ln), '{}.end'.format(ln))
                    m = pat.search(lt)
                    ln -= 1

                if m:
                    pat = re.compile(
                        (r'((?:{w}::)*{w}(?:<[^<>]*(?:<[^>]*>)*[^<>]*>)?)\s*'
                         r'{n}').format(
                             n=name,
                             w=r'(?:[_A-Za-z]\w*)',
                         ))
                    m2 = pat.search(lt)
                    if m2:
                        e = m2.group(1)
                        if e == 'string':
                            e = 'basic_string'
                        arg_text = self.fetch_tip('{}::{}'.format(e, func))

                    if not arg_text:
                        e = lt.lstrip().split()[0]
                        if e == 'string':
                            e = 'basic_string'
                        arg_text = self.fetch_tip('{}::{}'.format(e, func))
                    if not arg_text:
                        e = e.split('<')[0]
                        if e == 'string':
                            e = 'basic_string'
                        arg_text = self.fetch_tip('{}::{}'.format(e, func))


##            print `e`
# ---
        if not arg_text:
            return
        self.calltip = self._make_calltip_window()
        self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
示例#16
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 + 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:
            # todo ---
            tail = self.text.get('insert linestart',
                                 'insert').rstrip(ID_CHARS + ' \t')

            if re.search(r'^[ \t]*#include[ \t]*<?', curline, flags=re.M):
                if re.search(r'^[ \t]*#include[ \t]*$', curline, flags=re.M):
                    self.text.insert('insert', '<')
                    ##                    curline = self.text.get('insert linestart', 'insert')
                    curline += '<'
                    ##                    i += 1
                    j += 1
                else:
                    i -= 1

                charset = INCLUDE_CHARS
                mode = COMPLETE_HEADERS
##            elif '::' in self.text.get('insert linestart', 'insert'):
##                charset = NAMESPACE_CHARS
##                mode = COMPLETE_NAMESPACE
##                comp_what = ''
##            else:
##                charset = ID_CHARS
            elif tail.endswith(':') or tail.endswith('>'):
                charset = NAMESPACE_CHARS
                mode = COMPLETE_NAMESPACE
                comp_what = ''
            else:
                charset = ID_CHARS

##            print `curline[i:]`, 1
            while i and curline[i - 1] in charset:
                # ---
                if mode == COMPLETE_HEADERS and curline[i] == '<':
                    break

                i -= 1
                if mode == COMPLETE_HEADERS and curline[i] == '<':
                    break
                elif mode == COMPLETE_NAMESPACE:
                    if curline[:i + 1].endswith('::'):
                        i += 1

                        ## comp_what = curline[:i].split()[-1]
                        ## hack: foo<T, U>
                        ##     : foo < T >

                        comp_what = re.split(r'\w?[ \t=<(]+(?=[_A-Za-z])',
                                             curline[:i])[-1]
                        break

##            print mode, COMPLETE_HEADERS
##            print `curline[i:]`, 2

            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:
                if mode not in (COMPLETE_NAMESPACE, ):
                    comp_what = ""
        else:
            return

##        print `comp_start, comp_what`

        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)