22 QCoreApplication, |
22 QCoreApplication, |
23 ) |
23 ) |
24 from PyQt6.QtGui import QImageReader, QFont |
24 from PyQt6.QtGui import QImageReader, QFont |
25 from PyQt6.QtWidgets import QApplication |
25 from PyQt6.QtWidgets import QApplication |
26 |
26 |
27 import UI.PixmapCache |
27 from eric7.EricGui import EricPixmapCache |
28 import Preferences |
28 from eric7 import Preferences, Utilities |
29 import Utilities |
|
30 |
29 |
31 BrowserItemRoot = 0 |
30 BrowserItemRoot = 0 |
32 BrowserItemDirectory = 1 |
31 BrowserItemDirectory = 1 |
33 BrowserItemSysPath = 2 |
32 BrowserItemSysPath = 2 |
34 BrowserItemFile = 3 |
33 BrowserItemFile = 3 |
624 Public method to populate a file item's subtree. |
623 Public method to populate a file item's subtree. |
625 |
624 |
626 @param parentItem reference to the file item to be populated |
625 @param parentItem reference to the file item to be populated |
627 @param repopulate flag indicating a repopulation (boolean) |
626 @param repopulate flag indicating a repopulation (boolean) |
628 """ |
627 """ |
629 import Utilities.ClassBrowsers |
628 from eric7.Utilities import ClassBrowsers |
630 |
629 |
631 moduleName = parentItem.moduleName() |
630 moduleName = parentItem.moduleName() |
632 fileName = parentItem.fileName() |
631 fileName = parentItem.fileName() |
633 try: |
632 try: |
634 dictionary = Utilities.ClassBrowsers.readmodule( |
633 dictionary = ClassBrowsers.readmodule( |
635 moduleName, |
634 moduleName, |
636 [parentItem.dirName()], |
635 [parentItem.dirName()], |
637 parentItem.isPython3File() or parentItem.isCythonFile(), |
636 parentItem.isPython3File() or parentItem.isCythonFile(), |
638 ) |
637 ) |
639 except ImportError: |
638 except ImportError: |
884 self.childItems = [] |
883 self.childItems = [] |
885 |
884 |
886 self.parentItem = parent |
885 self.parentItem = parent |
887 self.itemData = [data] |
886 self.itemData = [data] |
888 self.type_ = BrowserItemRoot |
887 self.type_ = BrowserItemRoot |
889 self.icon = UI.PixmapCache.getIcon("empty") |
888 self.icon = EricPixmapCache.getIcon("empty") |
890 self._populated = True |
889 self._populated = True |
891 self._lazyPopulation = False |
890 self._lazyPopulation = False |
892 self.symlink = False |
891 self.symlink = False |
893 |
892 |
894 def appendChild(self, child): |
893 def appendChild(self, child): |
1063 not Utilities.isDrive(self._dirName) |
1062 not Utilities.isDrive(self._dirName) |
1064 and os.path.lexists(self._dirName) |
1063 and os.path.lexists(self._dirName) |
1065 and os.path.islink(self._dirName) |
1064 and os.path.islink(self._dirName) |
1066 ): |
1065 ): |
1067 self.symlink = True |
1066 self.symlink = True |
1068 self.icon = UI.PixmapCache.getSymlinkIcon("dirClosed") |
1067 self.icon = EricPixmapCache.getSymlinkIcon("dirClosed") |
1069 else: |
1068 else: |
1070 self.icon = UI.PixmapCache.getIcon("dirClosed") |
1069 self.icon = EricPixmapCache.getIcon("dirClosed") |
1071 self._populated = False |
1070 self._populated = False |
1072 self._lazyPopulation = True |
1071 self._lazyPopulation = True |
1073 |
1072 |
1074 def setName(self, dinfo, full=True): |
1073 def setName(self, dinfo, full=True): |
1075 """ |
1074 """ |
1127 @param parent parent item |
1126 @param parent parent item |
1128 """ |
1127 """ |
1129 BrowserItem.__init__(self, parent, "sys.path") |
1128 BrowserItem.__init__(self, parent, "sys.path") |
1130 |
1129 |
1131 self.type_ = BrowserItemSysPath |
1130 self.type_ = BrowserItemSysPath |
1132 self.icon = UI.PixmapCache.getIcon("filePython") |
1131 self.icon = EricPixmapCache.getIcon("filePython") |
1133 self._populated = False |
1132 self._populated = False |
1134 self._lazyPopulation = True |
1133 self._lazyPopulation = True |
1135 |
1134 |
1136 def name(self): |
1135 def name(self): |
1137 """ |
1136 """ |
1221 else: |
1220 else: |
1222 pixName = "fileMisc" |
1221 pixName = "fileMisc" |
1223 |
1222 |
1224 if os.path.lexists(self._filename) and os.path.islink(self._filename): |
1223 if os.path.lexists(self._filename) and os.path.islink(self._filename): |
1225 self.symlink = True |
1224 self.symlink = True |
1226 self.icon = UI.PixmapCache.getSymlinkIcon(pixName) |
1225 self.icon = EricPixmapCache.getSymlinkIcon(pixName) |
1227 else: |
1226 else: |
1228 self.icon = UI.PixmapCache.getIcon(pixName) |
1227 self.icon = EricPixmapCache.getIcon(pixName) |
1229 |
1228 |
1230 def setName(self, finfo, full=True): |
1229 def setName(self, finfo, full=True): |
1231 """ |
1230 """ |
1232 Public method to set the directory name. |
1231 Public method to set the directory name. |
1233 |
1232 |
1483 self.type_ = BrowserItemClass |
1482 self.type_ = BrowserItemClass |
1484 self._name = name |
1483 self._name = name |
1485 self._classObject = cl |
1484 self._classObject = cl |
1486 self._filename = filename |
1485 self._filename = filename |
1487 |
1486 |
1488 import Utilities.ClassBrowsers.ClbrBaseClasses |
1487 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses |
1489 |
1488 |
1490 self.isfunction = isinstance( |
1489 self.isfunction = isinstance(self._classObject, ClbrBaseClasses.Function) |
1491 self._classObject, Utilities.ClassBrowsers.ClbrBaseClasses.Function |
1490 self.ismodule = isinstance(self._classObject, ClbrBaseClasses.Module) |
1492 ) |
1491 self.isenum = isinstance(self._classObject, ClbrBaseClasses.Enum) |
1493 self.ismodule = isinstance( |
|
1494 self._classObject, Utilities.ClassBrowsers.ClbrBaseClasses.Module |
|
1495 ) |
|
1496 self.isenum = isinstance( |
|
1497 self._classObject, Utilities.ClassBrowsers.ClbrBaseClasses.Enum |
|
1498 ) |
|
1499 if self.isfunction: |
1492 if self.isfunction: |
1500 if cl.isPrivate(): |
1493 if cl.isPrivate(): |
1501 self.icon = UI.PixmapCache.getIcon("method_private") |
1494 self.icon = EricPixmapCache.getIcon("method_private") |
1502 elif cl.isProtected(): |
1495 elif cl.isProtected(): |
1503 self.icon = UI.PixmapCache.getIcon("method_protected") |
1496 self.icon = EricPixmapCache.getIcon("method_protected") |
1504 else: |
1497 else: |
1505 self.icon = UI.PixmapCache.getIcon("method") |
1498 self.icon = EricPixmapCache.getIcon("method") |
1506 self.itemData[0] = "{0}({1})".format( |
1499 self.itemData[0] = "{0}({1})".format( |
1507 name, ", ".join(self._classObject.parameters) |
1500 name, ", ".join(self._classObject.parameters) |
1508 ) |
1501 ) |
1509 if self._classObject.annotation: |
1502 if self._classObject.annotation: |
1510 self.itemData[0] = "{0} {1}".format( |
1503 self.itemData[0] = "{0} {1}".format( |
1513 # - if no defaults are wanted |
1506 # - if no defaults are wanted |
1514 # - ....format(name, |
1507 # - ....format(name, |
1515 # - ", ".join([e.split('=')[0].strip() |
1508 # - ", ".join([e.split('=')[0].strip() |
1516 # - for e in self._classObject.parameters])) |
1509 # - for e in self._classObject.parameters])) |
1517 elif self.ismodule: |
1510 elif self.ismodule: |
1518 self.icon = UI.PixmapCache.getIcon("module") |
1511 self.icon = EricPixmapCache.getIcon("module") |
1519 elif self.isenum: |
1512 elif self.isenum: |
1520 self.icon = UI.PixmapCache.getIcon("attribute") |
1513 self.icon = EricPixmapCache.getIcon("attribute") |
1521 else: |
1514 else: |
1522 if cl.isPrivate(): |
1515 if cl.isPrivate(): |
1523 self.icon = UI.PixmapCache.getIcon("class_private") |
1516 self.icon = EricPixmapCache.getIcon("class_private") |
1524 elif cl.isProtected(): |
1517 elif cl.isProtected(): |
1525 self.icon = UI.PixmapCache.getIcon("class_protected") |
1518 self.icon = EricPixmapCache.getIcon("class_protected") |
1526 else: |
1519 else: |
1527 self.icon = UI.PixmapCache.getIcon("class") |
1520 self.icon = EricPixmapCache.getIcon("class") |
1528 if self._classObject and ( |
1521 if self._classObject and ( |
1529 self._classObject.methods |
1522 self._classObject.methods |
1530 or self._classObject.classes |
1523 or self._classObject.classes |
1531 or self._classObject.attributes |
1524 or self._classObject.attributes |
1532 or self._classObject.globals |
1525 or self._classObject.globals |
1617 @param filename filename of the file defining this class (string) |
1610 @param filename filename of the file defining this class (string) |
1618 """ |
1611 """ |
1619 name = fn.name |
1612 name = fn.name |
1620 BrowserItem.__init__(self, parent, name) |
1613 BrowserItem.__init__(self, parent, name) |
1621 |
1614 |
1622 import Utilities.ClassBrowsers.ClbrBaseClasses |
1615 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses |
1623 |
1616 |
1624 self.type_ = BrowserItemMethod |
1617 self.type_ = BrowserItemMethod |
1625 self._name = name |
1618 self._name = name |
1626 self._functionObject = fn |
1619 self._functionObject = fn |
1627 self._filename = filename |
1620 self._filename = filename |
1628 if ( |
1621 if self._functionObject.modifier == ClbrBaseClasses.Function.Static: |
1629 self._functionObject.modifier |
1622 self.icon = EricPixmapCache.getIcon("method_static") |
1630 == Utilities.ClassBrowsers.ClbrBaseClasses.Function.Static |
1623 elif self._functionObject.modifier == ClbrBaseClasses.Function.Class: |
1631 ): |
1624 self.icon = EricPixmapCache.getIcon("method_class") |
1632 self.icon = UI.PixmapCache.getIcon("method_static") |
|
1633 elif ( |
|
1634 self._functionObject.modifier |
|
1635 == Utilities.ClassBrowsers.ClbrBaseClasses.Function.Class |
|
1636 ): |
|
1637 self.icon = UI.PixmapCache.getIcon("method_class") |
|
1638 elif self._functionObject.isPrivate(): |
1625 elif self._functionObject.isPrivate(): |
1639 self.icon = UI.PixmapCache.getIcon("method_private") |
1626 self.icon = EricPixmapCache.getIcon("method_private") |
1640 elif self._functionObject.isProtected(): |
1627 elif self._functionObject.isProtected(): |
1641 self.icon = UI.PixmapCache.getIcon("method_protected") |
1628 self.icon = EricPixmapCache.getIcon("method_protected") |
1642 else: |
1629 else: |
1643 self.icon = UI.PixmapCache.getIcon("method") |
1630 self.icon = EricPixmapCache.getIcon("method") |
1644 self.itemData[0] = "{0}({1})".format( |
1631 self.itemData[0] = "{0}({1})".format( |
1645 name, ", ".join(self._functionObject.parameters) |
1632 name, ", ".join(self._functionObject.parameters) |
1646 ) |
1633 ) |
1647 if self._functionObject.annotation: |
1634 if self._functionObject.annotation: |
1648 self.itemData[0] = "{0} {1}".format( |
1635 self.itemData[0] = "{0} {1}".format( |
1751 self.type_ = BrowserItemAttributes |
1738 self.type_ = BrowserItemAttributes |
1752 self._attributes = attributes.copy() |
1739 self._attributes = attributes.copy() |
1753 self._populated = False |
1740 self._populated = False |
1754 self._lazyPopulation = True |
1741 self._lazyPopulation = True |
1755 if isClass: |
1742 if isClass: |
1756 self.icon = UI.PixmapCache.getIcon("attributes_class") |
1743 self.icon = EricPixmapCache.getIcon("attributes_class") |
1757 else: |
1744 else: |
1758 self.icon = UI.PixmapCache.getIcon("attributes") |
1745 self.icon = EricPixmapCache.getIcon("attributes") |
1759 self.__isClass = isClass |
1746 self.__isClass = isClass |
1760 |
1747 |
1761 def name(self): |
1748 def name(self): |
1762 """ |
1749 """ |
1763 Public method to return the name of the item. |
1750 Public method to return the name of the item. |
1816 |
1803 |
1817 self.type_ = BrowserItemAttribute |
1804 self.type_ = BrowserItemAttribute |
1818 self._attributeObject = attribute |
1805 self._attributeObject = attribute |
1819 self.__public = attribute.isPublic() |
1806 self.__public = attribute.isPublic() |
1820 if isClass: |
1807 if isClass: |
1821 self.icon = UI.PixmapCache.getIcon("attribute_class") |
1808 self.icon = EricPixmapCache.getIcon("attribute_class") |
1822 elif attribute.isPrivate(): |
1809 elif attribute.isPrivate(): |
1823 self.icon = UI.PixmapCache.getIcon("attribute_private") |
1810 self.icon = EricPixmapCache.getIcon("attribute_private") |
1824 elif attribute.isProtected(): |
1811 elif attribute.isProtected(): |
1825 self.icon = UI.PixmapCache.getIcon("attribute_protected") |
1812 self.icon = EricPixmapCache.getIcon("attribute_protected") |
1826 else: |
1813 else: |
1827 self.icon = UI.PixmapCache.getIcon("attribute") |
1814 self.icon = EricPixmapCache.getIcon("attribute") |
1828 |
1815 |
1829 def isPublic(self): |
1816 def isPublic(self): |
1830 """ |
1817 """ |
1831 Public method returning the public visibility status. |
1818 Public method returning the public visibility status. |
1832 |
1819 |
1963 @param text text to be shown by this item (string) |
1950 @param text text to be shown by this item (string) |
1964 """ |
1951 """ |
1965 BrowserItem.__init__(self, parent, text) |
1952 BrowserItem.__init__(self, parent, text) |
1966 |
1953 |
1967 self.type_ = BrowserItemImports |
1954 self.type_ = BrowserItemImports |
1968 self.icon = UI.PixmapCache.getIcon("imports") |
1955 self.icon = EricPixmapCache.getIcon("imports") |
1969 |
1956 |
1970 def lessThan(self, other, column, order): |
1957 def lessThan(self, other, column, order): |
1971 """ |
1958 """ |
1972 Public method to check, if the item is less than the other one. |
1959 Public method to check, if the item is less than the other one. |
1973 |
1960 |
2004 self.__filename = filename |
1991 self.__filename = filename |
2005 self.__linenos = lineNumbers[:] |
1992 self.__linenos = lineNumbers[:] |
2006 |
1993 |
2007 self.type_ = BrowserItemImport |
1994 self.type_ = BrowserItemImport |
2008 if isModule: |
1995 if isModule: |
2009 self.icon = UI.PixmapCache.getIcon("importedModule") |
1996 self.icon = EricPixmapCache.getIcon("importedModule") |
2010 else: |
1997 else: |
2011 self.icon = UI.PixmapCache.getIcon("importedName") |
1998 self.icon = EricPixmapCache.getIcon("importedName") |
2012 |
1999 |
2013 def fileName(self): |
2000 def fileName(self): |
2014 """ |
2001 """ |
2015 Public method returning the filename. |
2002 Public method returning the filename. |
2016 |
2003 |