當前位置: 首頁>>代碼示例>>Python>>正文


Python HyperParser.is_in_code方法代碼示例

本文整理匯總了Python中idlelib.HyperParser.HyperParser.is_in_code方法的典型用法代碼示例。如果您正苦於以下問題:Python HyperParser.is_in_code方法的具體用法?Python HyperParser.is_in_code怎麽用?Python HyperParser.is_in_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在idlelib.HyperParser.HyperParser的用法示例。


在下文中一共展示了HyperParser.is_in_code方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: open_completions

# 需要導入模塊: from idlelib.HyperParser import HyperParser [as 別名]
# 或者: from idlelib.HyperParser.HyperParser import is_in_code [as 別名]
    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)
開發者ID:ARK4579,項目名稱:cpython,代碼行數:60,代碼來源:AutoComplete.py

示例2: open_completions

# 需要導入模塊: from idlelib.HyperParser import HyperParser [as 別名]
# 或者: from idlelib.HyperParser.HyperParser import is_in_code [as 別名]
    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
開發者ID:2uller,項目名稱:LotF,代碼行數:56,代碼來源:AutoComplete.py

示例3: paren_closed_event

# 需要導入模塊: from idlelib.HyperParser import HyperParser [as 別名]
# 或者: from idlelib.HyperParser.HyperParser import is_in_code [as 別名]
 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()
開發者ID:dr4ke616,項目名稱:custom_python,代碼行數:17,代碼來源:ParenMatch.py

示例4: paren_closed_event

# 需要導入模塊: from idlelib.HyperParser import HyperParser [as 別名]
# 或者: from idlelib.HyperParser.HyperParser import is_in_code [as 別名]
 def paren_closed_event(self, event):
     closer = self.text.get('insert-1c')
     if closer not in _openers:
         return
     else:
         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()
         return
開發者ID:aevitas,項目名稱:wotsdk,代碼行數:18,代碼來源:idlelibparenmatch.py

示例5: open_completions

# 需要導入模塊: from idlelib.HyperParser import HyperParser [as 別名]
# 或者: from idlelib.HyperParser.HyperParser import is_in_code [as 別名]
    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
#.........這裏部分代碼省略.........
開發者ID:rsk0315,項目名稱:papyrus,代碼行數:103,代碼來源:AutoComplete.py


注:本文中的idlelib.HyperParser.HyperParser.is_in_code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。