QScintilla/Editor.py

changeset 2643
e870fc2b4819
parent 2640
dedcd4f987e0
child 2659
7f46c5a7ed73
equal deleted inserted replaced
2642:c9f965bd21d2 2643:e870fc2b4819
1682 """ 1682 """
1683 if self.filetype in ["Python", "Python2"]: 1683 if self.filetype in ["Python", "Python2"]:
1684 return True 1684 return True
1685 1685
1686 if self.filetype == "": 1686 if self.filetype == "":
1687 # 1) Determine by first line
1687 line0 = self.text(0) 1688 line0 = self.text(0)
1688 if line0.startswith("#!") and \ 1689 if line0.startswith("#!") and \
1689 ("python2" in line0 or \ 1690 ("python2" in line0 or \
1690 ("python" in line0 and not "python3" in line0)): 1691 ("python" in line0 and not "python3" in line0)):
1691 self.filetype = "Python2" 1692 self.filetype = "Python2"
1692 return True 1693 return True
1693 1694
1694 if self.fileName is not None: 1695 if self.fileName is not None:
1695 ext = os.path.splitext(self.fileName)[1] 1696 ext = os.path.splitext(self.fileName)[1]
1696 if ext in [".py", ".pyw"] and \ 1697 if ext in [".py", ".pyw"]:
1697 Preferences.getProject("DeterminePyFromProject") and \ 1698 # 2) .py and .pyw are ambiguous; determine from project
1698 self.project.isOpen() and \ 1699 if Preferences.getProject("DeterminePyFromProject") and \
1699 self.project.isProjectFile(self.fileName): 1700 self.project.isOpen() and \
1700 isProjectPy2 = \ 1701 self.project.isProjectFile(self.fileName):
1701 self.project.getProjectLanguage() in ["Python", "Python2"] 1702 isProjectPy2 = \
1702 if isProjectPy2: 1703 self.project.getProjectLanguage() in ["Python", "Python2"]
1703 self.filetype = "Python2" 1704 if isProjectPy2:
1704 return isProjectPy2 1705 self.filetype = "Python2"
1706 return isProjectPy2
1707 else:
1708 # 3) determine by compiling the sources
1709 syntaxError = Utilities.py2compile(self.fileName,
1710 checkFlakes=False)[0]
1711 if not syntaxError:
1712 self.filetype = "Python2"
1713 return True
1705 1714
1706 if ext in self.dbs.getExtensions('Python2'): 1715 if ext in self.dbs.getExtensions('Python2'):
1707 self.filetype = "Python2" 1716 self.filetype = "Python2"
1708 return True 1717 return True
1709 1718
1717 """ 1726 """
1718 if self.filetype in ["Python3"]: 1727 if self.filetype in ["Python3"]:
1719 return True 1728 return True
1720 1729
1721 if self.filetype == "": 1730 if self.filetype == "":
1731 # 1) Determine by first line
1722 line0 = self.text(0) 1732 line0 = self.text(0)
1723 if line0.startswith("#!") and \ 1733 if line0.startswith("#!") and \
1724 "python3" in line0: 1734 "python3" in line0:
1725 self.filetype = "Python3" 1735 self.filetype = "Python3"
1726 return True 1736 return True
1727 1737
1728 if self.fileName is not None: 1738 if self.fileName is not None:
1729 ext = os.path.splitext(self.fileName)[1] 1739 ext = os.path.splitext(self.fileName)[1]
1730 if ext in [".py", ".pyw"] and \ 1740 if ext in [".py", ".pyw"]:
1731 Preferences.getProject("DeterminePyFromProject") and \ 1741 # 2) .py and .pyw are ambiguous; determine from project
1732 self.project.isOpen() and \ 1742 if Preferences.getProject("DeterminePyFromProject") and \
1733 self.project.isProjectFile(self.fileName): 1743 self.project.isOpen() and \
1734 isProjectPy3 = self.project.getProjectLanguage() in ["Python3"] 1744 self.project.isProjectFile(self.fileName):
1735 if isProjectPy3: 1745 isProjectPy3 = self.project.getProjectLanguage() in ["Python3"]
1736 self.filetype = "Python3" 1746 if isProjectPy3:
1737 return isProjectPy3 1747 self.filetype = "Python3"
1748 return isProjectPy3
1749 else:
1750 # 3) determine by compiling the sources
1751 syntaxError = Utilities.compile(self.fileName, self.text())
1752 if not syntaxError:
1753 self.filetype = "Python3"
1754 return True
1738 1755
1739 if ext in self.dbs.getExtensions('Python3'): 1756 if ext in self.dbs.getExtensions('Python3'):
1740 self.filetype = "Python3" 1757 self.filetype = "Python3"
1741 return True 1758 return True
1742 1759

eric ide

mercurial