QScintilla/Editor.py

changeset 5932
af9aa23e12ec
parent 5919
d0de2b378b24
child 5935
1fac1b80b440
equal deleted inserted replaced
5928:a3809f75ca07 5932:af9aa23e12ec
386 386
387 # set the auto-completion function 387 # set the auto-completion function
388 self.__acContext = True 388 self.__acContext = True
389 self.__acText = "" 389 self.__acText = ""
390 self.__acCompletions = set() 390 self.__acCompletions = set()
391 self.__acCompletionsFinished = 0
391 self.__acCache = E5Cache( 392 self.__acCache = E5Cache(
392 size=Preferences.getEditor("AutoCompletionCacheSize")) 393 size=Preferences.getEditor("AutoCompletionCacheSize"))
393 self.__acCache.setMaximumCacheTime( 394 self.__acCache.setMaximumCacheTime(
394 Preferences.getEditor("AutoCompletionCacheTime")) 395 Preferences.getEditor("AutoCompletionCacheTime"))
395 self.__acTimer = QTimer(self) 396 self.__acTimer = QTimer(self)
396 self.__acTimer.setSingleShot(True) 397 self.__acTimer.setSingleShot(True)
397 self.__acTimer.setInterval( 398 self.__acTimer.setInterval(
398 Preferences.getEditor("AutoCompletionTimeout")) 399 Preferences.getEditor("AutoCompletionTimeout"))
399 self.__acTimer.timeout.connect(self.__autoComplete) 400 self.__acTimer.timeout.connect(self.__autoComplete)
401
402 self.__acWatchdog = QTimer(self)
403 self.__acWatchdog.setSingleShot(True)
404 self.__acWatchdog.setInterval(
405 Preferences.getEditor("AutoCompletionWatchdogTime"))
406 self.__acWatchdog.timeout.connect(self.autoCompleteQScintilla)
400 407
401 self.__completionListHookFunctions = {} 408 self.__completionListHookFunctions = {}
402 self.__completionListAsyncHookFunctions = {} 409 self.__completionListAsyncHookFunctions = {}
403 self.__setAutoCompletion() 410 self.__setAutoCompletion()
404 411
4454 4461
4455 def autoCompleteQScintilla(self): 4462 def autoCompleteQScintilla(self):
4456 """ 4463 """
4457 Public method to perform an autocompletion using QScintilla methods. 4464 Public method to perform an autocompletion using QScintilla methods.
4458 """ 4465 """
4466 self.__acText = ' ' # Prevent long running ACs to add results
4467 self.__acWatchdog.stop()
4468 if self.__acCompletions:
4469 return
4470
4459 acs = Preferences.getEditor("AutoCompletionSource") 4471 acs = Preferences.getEditor("AutoCompletionSource")
4460 if acs == QsciScintilla.AcsDocument: 4472 if acs == QsciScintilla.AcsDocument:
4461 self.autoCompleteFromDocument() 4473 self.autoCompleteFromDocument()
4462 elif acs == QsciScintilla.AcsAPIs: 4474 elif acs == QsciScintilla.AcsAPIs:
4463 self.autoCompleteFromAPIs() 4475 self.autoCompleteFromAPIs()
4671 if self.__isStartChar(text[col - 1]): 4683 if self.__isStartChar(text[col - 1]):
4672 self.__acText = self.getWordLeft(line, col - 1) + text[col - 1] 4684 self.__acText = self.getWordLeft(line, col - 1) + text[col - 1]
4673 else: 4685 else:
4674 self.__acText = self.getWordLeft(line, col) 4686 self.__acText = self.getWordLeft(line, col)
4675 self.__acCompletions.clear() 4687 self.__acCompletions.clear()
4688 self.__acCompletionsFinished = 0
4676 4689
4677 # Suppress empty completions 4690 # Suppress empty completions
4678 if auto and self.__acText == '': 4691 if auto and self.__acText == '':
4679 return 4692 return
4680 4693
4695 4708
4696 for key in self.__completionListHookFunctions: 4709 for key in self.__completionListHookFunctions:
4697 completions = self.__completionListHookFunctions[key]( 4710 completions = self.__completionListHookFunctions[key](
4698 self, context) 4711 self, context)
4699 self.completionsListReady(completions, self.__acText) 4712 self.completionsListReady(completions, self.__acText)
4713
4714 if Preferences.getEditor("AutoCompletionScintillaOnFail"):
4715 self.__acWatchdog.start()
4700 4716
4701 # TODO: document this hook in chapter 6.2 of plug-in document 4717 # TODO: document this hook in chapter 6.2 of plug-in document
4702 def completionsListReady(self, completions, acText): 4718 def completionsListReady(self, completions, acText):
4703 """ 4719 """
4704 Public method to show the completions determined by a completions 4720 Public method to show the completions determined by a completions
4710 @type str 4726 @type str
4711 """ 4727 """
4712 if acText == self.__acText and bool(completions): 4728 if acText == self.__acText and bool(completions):
4713 # process the list only, if not already obsolete or completions 4729 # process the list only, if not already obsolete or completions
4714 # are not empty 4730 # are not empty
4731 self.__acCompletions.update(set(completions))
4732
4733 self.__acCompletionsFinished += 1
4734 # Got all results from auto completer?
4735 if self.__acCompletionsFinished >= len(
4736 self.__completionListAsyncHookFunctions):
4737 self.__acWatchdog.stop()
4738
4739 # Autocomplete with QScintilla if no results present
4740 if (Preferences.getEditor("AutoCompletionScintillaOnFail")
4741 and not self.__acCompletions):
4742 self.autoCompleteQScintilla()
4743 return
4715 if self.isListActive(): 4744 if self.isListActive():
4716 self.cancelList() 4745 self.cancelList()
4717 4746
4718 self.__acCompletions.update(set(completions))
4719 if self.__acCompletions: 4747 if self.__acCompletions:
4720 self.__acCache.add(acText, set(self.__acCompletions)) 4748 self.__acCache.add(acText, set(self.__acCompletions))
4721 self.__showCompletionsList(self.__acCompletions) 4749 self.__showCompletionsList(self.__acCompletions)
4722 4750
4723 def __showCompletionsList(self, completions): 4751 def __showCompletionsList(self, completions):

eric ide

mercurial