QScintilla/Editor.py

branch
BgService
changeset 3173
1fb284abe46e
parent 3145
a9de05d4a22f
child 3177
5af61402d74d
equal deleted inserted replaced
3172:c0f78e9d0971 3173:1fb284abe46e
310 310
311 # set the text display 311 # set the text display
312 self.__setTextDisplay() 312 self.__setTextDisplay()
313 313
314 # initialize the online syntax check timer 314 # initialize the online syntax check timer
315 self.internalServices = e5App().getObject('InternalServices')
316 self.internalServices.syntaxChecked.connect(self.__processResult)
315 self.__initOnlineSyntaxCheck() 317 self.__initOnlineSyntaxCheck()
316 318
317 self.isResourcesFile = False 319 self.isResourcesFile = False
318 if editor is None: 320 if editor is None:
319 if self.fileName is not None: 321 if self.fileName is not None:
1761 self.project.getProjectLanguage() in ["Python", 1763 self.project.getProjectLanguage() in ["Python",
1762 "Python2"] 1764 "Python2"]
1763 if isProjectPy2: 1765 if isProjectPy2:
1764 self.filetype = "Python2" 1766 self.filetype = "Python2"
1765 return isProjectPy2 1767 return isProjectPy2
1766 else: 1768 # else:
1767 # 3) determine by compiling the sources 1769 # # 3) determine by compiling the sources
1768 syntaxError = Utilities.compile( 1770 # syntaxError = Utilities.compile(
1769 self.fileName, self.text(), True)[0] 1771 # self.fileName, self.text(), True)[0]
1770 if not syntaxError: 1772 # if not syntaxError:
1771 self.filetype = "Python2" 1773 # self.filetype = "Python2"
1772 return True 1774 # return True
1773 1775
1774 if ext in self.dbs.getExtensions('Python2'): 1776 if ext in self.dbs.getExtensions('Python2'):
1775 self.filetype = "Python2" 1777 self.filetype = "Python2"
1776 return True 1778 return True
1777 1779
1804 isProjectPy3 = \ 1806 isProjectPy3 = \
1805 self.project.getProjectLanguage() in ["Python3"] 1807 self.project.getProjectLanguage() in ["Python3"]
1806 if isProjectPy3: 1808 if isProjectPy3:
1807 self.filetype = "Python3" 1809 self.filetype = "Python3"
1808 return isProjectPy3 1810 return isProjectPy3
1809 else: 1811 # else:
1810 # 3) determine by compiling the sources 1812 # # 3) determine by compiling the sources
1811 syntaxError = Utilities.compile( 1813 # syntaxError = Utilities.compile(
1812 self.fileName, self.text(), False)[0] 1814 # self.fileName, self.text(), False)[0]
1813 if not syntaxError: 1815 # if not syntaxError:
1814 self.filetype = "Python3" 1816 # self.filetype = "Python3"
1815 return True 1817 # return True
1816 1818
1817 if ext in self.dbs.getExtensions('Python3'): 1819 if ext in self.dbs.getExtensions('Python3'):
1818 self.filetype = "Python3" 1820 self.filetype = "Python3"
1819 return True 1821 return True
1820 1822
4958 4960
4959 def __autoSyntaxCheck(self): 4961 def __autoSyntaxCheck(self):
4960 """ 4962 """
4961 Private method to perform an automatic syntax check of the file. 4963 Private method to perform an automatic syntax check of the file.
4962 """ 4964 """
4963 isPy2 = self.isPy2File() 4965 if (self.isPy2File() or self.isPy3File()) is False:
4964 if (isPy2 or self.isPy3File()) is False:
4965 return 4966 return
4966 4967
4967 if Preferences.getEditor("AutoCheckSyntax"): 4968 if Preferences.getEditor("AutoCheckSyntax"):
4968 if Preferences.getEditor("OnlineSyntaxCheck"): 4969 if Preferences.getEditor("OnlineSyntaxCheck"):
4969 self.__onlineSyntaxCheckTimer.stop() 4970 self.__onlineSyntaxCheckTimer.stop()
4970 self.clearSyntaxError() 4971
4971 self.clearFlakesWarnings() 4972 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck")
4973 ignoreStarImportWarnings = Preferences.getFlakes(
4974 "IgnoreStarImportWarnings")
4975
4976 self.internalServices.syntaxCheck(
4977 self.fileName or "(Unnamed)", self.text(), checkFlakes,
4978 ignoreStarImportWarnings, editor=self)
4972 4979
4973 syntaxError, _fn, errorline, errorindex, _code, _error, warnings =\ 4980 def __processResult(
4974 Utilities.compile( 4981 self, fn, nok, fname, line, index, code, error, warnings):
4975 self.fileName or "(Unnamed)", self.text(), isPy2) 4982 """
4976 if syntaxError: 4983 Slot to report the resulting messages.
4977 self.toggleSyntaxError(errorline, errorindex, True, _error) 4984
4978 else: 4985 If checkFlakes is True, warnings contains a list of strings containing
4979 for warning in warnings: 4986 the warnings (marker, file name, line number, message)
4980 self.toggleWarning( 4987 The values are only valid, if nok is False.
4981 warning[2], True, warning[3]) 4988
4989 @param fn filename of the checked file (str)
4990 @param nok flag if an error in the source was found (boolean)
4991 @param fname filename of the checked file (str) # TODO: remove dubl.
4992 @param line number where the error occured (int)
4993 @param index the column where the error occured (int)
4994 @param code the part of the code where the error occured (str)
4995 @param error the name of the error (str)
4996 @param warnings a list of strings containing the warnings
4997 (marker, file name, line number, message)
4998 """
4999 # Check if it's the requested file, otherwise ignore signal
5000 if fn != self.fileName and (
5001 self.fileName is not None or fn != "(Unnamed)"):
5002 return
5003
5004 self.clearSyntaxError()
5005 self.clearFlakesWarnings()
5006
5007 if nok:
5008 self.toggleSyntaxError(line, index, True, error)
5009 else:
5010 for warning in warnings:
5011 self.toggleWarning(warning[2], True, warning[3])
4982 5012
4983 def __initOnlineSyntaxCheck(self): 5013 def __initOnlineSyntaxCheck(self):
4984 """ 5014 """
4985 Private slot to initialize the online syntax check. 5015 Private slot to initialize the online syntax check.
4986 """ 5016 """
5852 self.__breakPointDataAboutToBeChanged) 5882 self.__breakPointDataAboutToBeChanged)
5853 self.breakpointModel.dataChanged.disconnect( 5883 self.breakpointModel.dataChanged.disconnect(
5854 self.__changeBreakPoints) 5884 self.__changeBreakPoints)
5855 self.breakpointModel.rowsInserted.disconnect( 5885 self.breakpointModel.rowsInserted.disconnect(
5856 self.__addBreakPoints) 5886 self.__addBreakPoints)
5887
5888 self.internalServices.syntaxChecked.disconnect(self.__processResult)
5857 5889
5858 if self.spell: 5890 if self.spell:
5859 self.spell.stopIncrementalCheck() 5891 self.spell.stopIncrementalCheck()
5860 5892
5861 try: 5893 try:

eric ide

mercurial