QScintilla/Editor.py

changeset 991
5ec5e707dfa5
parent 989
42b69a254eda
child 994
8ed60a191a3a
equal deleted inserted replaced
990:93253de2ae77 991:5ec5e707dfa5
493 elif "python2" in line0: 493 elif "python2" in line0:
494 bindName = "dummy.py" 494 bindName = "dummy.py"
495 self.filetype = "Python2" 495 self.filetype = "Python2"
496 elif "python" in line0: 496 elif "python" in line0:
497 bindName = "dummy.py" 497 bindName = "dummy.py"
498 self.filetype = "Python" 498 self.filetype = "Python2"
499 elif ("/bash" in line0 or "/sh" in line0): 499 elif ("/bash" in line0 or "/sh" in line0):
500 bindName = "dummy.sh" 500 bindName = "dummy.sh"
501 elif "ruby" in line0: 501 elif "ruby" in line0:
502 bindName = "dummy.rb" 502 bindName = "dummy.rb"
503 self.filetype = "Ruby" 503 self.filetype = "Ruby"
1576 if self.filetypeByFlag: 1576 if self.filetypeByFlag:
1577 return self.filetype 1577 return self.filetype
1578 else: 1578 else:
1579 return "" 1579 return ""
1580 1580
1581 def determineFileType(self):
1582 """
1583 Public method to determine the file type using various tests.
1584
1585 @return type of the displayed file or an empty string (string)
1586 """
1587 ftype = self.filetype
1588 if not ftype:
1589 ftype = self.getFileTypeByFlag()
1590 if not ftype:
1591 if self.isPy2File():
1592 ftype = "Python2"
1593 elif self.isPy3File():
1594 ftype = "Python3"
1595 elif self.isRubyFile():
1596 ftype = "Ruby"
1597 else:
1598 ftype = ""
1599
1600 return ftype
1601
1581 def getEncoding(self): 1602 def getEncoding(self):
1582 """ 1603 """
1583 Public method to return the current encoding. 1604 Public method to return the current encoding.
1584 1605
1585 @return current encoding (string) 1606 @return current encoding (string)
1593 @return flag indicating a Python file (boolean) 1614 @return flag indicating a Python file (boolean)
1594 """ 1615 """
1595 if self.filetype in ["Python", "Python2"]: 1616 if self.filetype in ["Python", "Python2"]:
1596 return True 1617 return True
1597 1618
1598 if self.filetype == "" and self.fileName is not None: 1619 if self.filetype == "":
1599 ext = os.path.splitext(self.fileName)[1] 1620 line0 = self.text(0)
1600 if ext in [".py", ".pyw"] and \ 1621 if line0.startswith("#!") and \
1601 Preferences.getProject("DeterminePyFromProject") and \ 1622 ("python2" in line0 or \
1602 self.project.isOpen() and \ 1623 ("python" in line0 and not "python3" in line0)):
1603 self.project.isProjectFile(self.fileName): 1624 return True
1604 return self.project.getProjectLanguage() in ["Python", "Python2"] 1625
1626 if self.fileName is not None:
1627 ext = os.path.splitext(self.fileName)[1]
1628 if ext in [".py", ".pyw"] and \
1629 Preferences.getProject("DeterminePyFromProject") and \
1630 self.project.isOpen() and \
1631 self.project.isProjectFile(self.fileName):
1632 return self.project.getProjectLanguage() in ["Python", "Python2"]
1605 1633
1606 if ext in self.dbs.getExtensions('Python2'): 1634 if ext in self.dbs.getExtensions('Python2'):
1607 return True 1635 return True
1608 1636
1609 return False 1637 return False
1615 @return flag indicating a Python3 file (boolean) 1643 @return flag indicating a Python3 file (boolean)
1616 """ 1644 """
1617 if self.filetype in ["Python3"]: 1645 if self.filetype in ["Python3"]:
1618 return True 1646 return True
1619 1647
1620 if self.filetype == "" and self.fileName is not None: 1648 if self.filetype == "":
1621 ext = os.path.splitext(self.fileName)[1] 1649 line0 = self.text(0)
1622 if ext in [".py", ".pyw"] and \ 1650 if line0.startswith("#!") and \
1623 Preferences.getProject("DeterminePyFromProject") and \ 1651 "python3" in line0:
1624 self.project.isOpen() and \ 1652 return True
1625 self.project.isProjectFile(self.fileName): 1653
1626 return self.project.getProjectLanguage() in ["Python3"] 1654 if self.fileName is not None:
1655 ext = os.path.splitext(self.fileName)[1]
1656 if ext in [".py", ".pyw"] and \
1657 Preferences.getProject("DeterminePyFromProject") and \
1658 self.project.isOpen() and \
1659 self.project.isProjectFile(self.fileName):
1660 return self.project.getProjectLanguage() in ["Python3"]
1627 1661
1628 if ext in self.dbs.getExtensions('Python3'): 1662 if ext in self.dbs.getExtensions('Python3'):
1629 return True 1663 return True
1630 1664
1631 return False 1665 return False
1634 """ 1668 """
1635 Public method to return a flag indicating a Ruby file. 1669 Public method to return a flag indicating a Ruby file.
1636 1670
1637 @return flag indicating a Ruby file (boolean) 1671 @return flag indicating a Ruby file (boolean)
1638 """ 1672 """
1639 return self.filetype == "Ruby" or \ 1673 if self.filetype == "Ruby":
1640 (self.filetype == "" and \ 1674 return True
1641 self.fileName is not None and \ 1675
1642 os.path.splitext(self.fileName)[1] in self.dbs.getExtensions('Ruby')) 1676 if self.filetype == "":
1677 line0 = self.text(0)
1678 if line0.startswith("#!") and \
1679 "ruby" in line0:
1680 return True
1681
1682 if self.fileName is not None and \
1683 os.path.splitext(self.fileName)[1] in self.dbs.getExtensions('Ruby'):
1684 return True
1685
1686 return False
1643 1687
1644 def highlightVisible(self): 1688 def highlightVisible(self):
1645 """ 1689 """
1646 Public method to make sure that the highlight is visible. 1690 Public method to make sure that the highlight is visible.
1647 """ 1691 """

eric ide

mercurial