28 from eric7.EricGui import EricPixmapCache |
29 from eric7.EricGui import EricPixmapCache |
29 from eric7.SystemUtilities import FileSystemUtilities |
30 from eric7.SystemUtilities import FileSystemUtilities |
30 from eric7.Utilities import ClassBrowsers |
31 from eric7.Utilities import ClassBrowsers |
31 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses |
32 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses |
32 |
33 |
33 # TODO: change this to enum.Enum |
34 |
34 BrowserItemRoot = 0 |
35 class BrowserItemType(enum.Enum): |
35 BrowserItemSimpleDirectory = 1 |
36 """ |
36 BrowserItemDirectory = 2 |
37 Class defining the various browser item types. |
37 BrowserItemSysPath = 3 |
38 """ |
38 BrowserItemFile = 4 |
39 |
39 BrowserItemClass = 5 |
40 # Base types used everywhere |
40 BrowserItemMethod = 6 |
41 Root = 0 |
41 BrowserItemAttributes = 7 |
42 SimpleDirectory = 1 |
42 BrowserItemAttribute = 8 |
43 Directory = 2 |
43 BrowserItemCoding = 9 |
44 SysPath = 3 |
44 BrowserItemImports = 10 |
45 File = 4 |
45 BrowserItemImport = 11 |
46 Class = 5 |
|
47 Method = 6 |
|
48 Attributes = 7 |
|
49 Attribute = 8 |
|
50 Coding = 9 |
|
51 Imports = 10 |
|
52 Import = 11 |
|
53 |
|
54 # Types used by the project browser model |
|
55 PbSimpleDirectory = 100 |
|
56 PbDirectory = 101 |
|
57 PbFile = 102 |
46 |
58 |
47 |
59 |
48 class BrowserModel(QAbstractItemModel): |
60 class BrowserModel(QAbstractItemModel): |
49 """ |
61 """ |
50 Class implementing the browser model. |
62 Class implementing the browser model. |
569 @param parentItem reference to the item to be populated |
581 @param parentItem reference to the item to be populated |
570 @type BrowserItem |
582 @type BrowserItem |
571 @param repopulate flag indicating a repopulation |
583 @param repopulate flag indicating a repopulation |
572 @type bool |
584 @type bool |
573 """ |
585 """ |
574 if parentItem.type() == BrowserItemDirectory: |
586 if parentItem.type() == BrowserItemType.Directory: |
575 self.populateDirectoryItem(parentItem, repopulate) |
587 self.populateDirectoryItem(parentItem, repopulate) |
576 elif parentItem.type() == BrowserItemSysPath: |
588 elif parentItem.type() == BrowserItemType.SysPath: |
577 self.populateSysPathItem(parentItem, repopulate) |
589 self.populateSysPathItem(parentItem, repopulate) |
578 elif parentItem.type() == BrowserItemFile: |
590 elif parentItem.type() == BrowserItemType.File: |
579 self.populateFileItem(parentItem, repopulate) |
591 self.populateFileItem(parentItem, repopulate) |
580 elif parentItem.type() == BrowserItemClass: |
592 elif parentItem.type() == BrowserItemType.Class: |
581 self.populateClassItem(parentItem, repopulate) |
593 self.populateClassItem(parentItem, repopulate) |
582 elif parentItem.type() == BrowserItemMethod: |
594 elif parentItem.type() == BrowserItemType.Method: |
583 self.populateMethodItem(parentItem, repopulate) |
595 self.populateMethodItem(parentItem, repopulate) |
584 elif parentItem.type() == BrowserItemAttributes: |
596 elif parentItem.type() == BrowserItemType.Attributes: |
585 self.populateClassAttributesItem(parentItem, repopulate) |
597 self.populateClassAttributesItem(parentItem, repopulate) |
586 |
598 |
587 def populateDirectoryItem(self, parentItem, repopulate=False): |
599 def populateDirectoryItem(self, parentItem, repopulate=False): |
588 """ |
600 """ |
589 Public method to populate a directory item's subtree. |
601 Public method to populate a directory item's subtree. |
762 if repopulate: |
774 if repopulate: |
763 self.endInsertRows() |
775 self.endInsertRows() |
764 |
776 |
765 parentItem._populated = True |
777 parentItem._populated = True |
766 if ( |
778 if ( |
767 parentItem.type_ == BrowserItemFile |
779 parentItem.type_ == BrowserItemType.File |
768 and fileName not in self.watchedFileItems |
780 and fileName not in self.watchedFileItems |
769 ): |
781 ): |
770 # watch the file only in the file browser not the project viewer |
782 # watch the file only in the file browser not the project viewer |
771 self.watcher.addPath(fileName) |
783 self.watcher.addPath(fileName) |
772 self.watchedFileItems[fileName] = parentItem |
784 self.watchedFileItems[fileName] = parentItem |
951 """ |
963 """ |
952 self.childItems = [] |
964 self.childItems = [] |
953 |
965 |
954 self.parentItem = parent |
966 self.parentItem = parent |
955 self.itemData = [data] |
967 self.itemData = [data] |
956 self.type_ = BrowserItemRoot |
968 self.type_ = BrowserItemType.Root |
957 self.icon = EricPixmapCache.getIcon("empty") |
969 self.icon = EricPixmapCache.getIcon("empty") |
958 self._populated = True |
970 self._populated = True |
959 self._lazyPopulation = False |
971 self._lazyPopulation = False |
960 self.symlink = False |
972 self.symlink = False |
961 |
973 |
1147 @param path path of the directory |
1158 @param path path of the directory |
1148 @type str |
1159 @type str |
1149 """ |
1160 """ |
1150 BrowserItem.__init__(self, parent, text) |
1161 BrowserItem.__init__(self, parent, text) |
1151 |
1162 |
1152 self.type_ = BrowserItemSimpleDirectory |
1163 self.type_ = BrowserItemType.SimpleDirectory |
1153 |
1164 |
1154 self._dirName = path |
1165 self._dirName = path |
1155 if not os.path.isdir(self._dirName): |
1166 if not os.path.isdir(self._dirName): |
1156 self._dirName = os.path.dirname(self._dirName) |
1167 self._dirName = os.path.dirname(self._dirName) |
1157 |
1168 |
1230 """ |
1241 """ |
1231 self._dirName = os.path.abspath(dinfo) |
1242 self._dirName = os.path.abspath(dinfo) |
1232 dn = self._dirName if full else os.path.basename(self._dirName) |
1243 dn = self._dirName if full else os.path.basename(self._dirName) |
1233 BrowserItem.__init__(self, parent, dn) |
1244 BrowserItem.__init__(self, parent, dn) |
1234 |
1245 |
1235 self.type_ = BrowserItemDirectory |
1246 self.type_ = BrowserItemType.Directory |
1236 if ( |
1247 if ( |
1237 not FileSystemUtilities.isDrive(self._dirName) |
1248 not FileSystemUtilities.isDrive(self._dirName) |
1238 and os.path.lexists(self._dirName) |
1249 and os.path.lexists(self._dirName) |
1239 and os.path.islink(self._dirName) |
1250 and os.path.islink(self._dirName) |
1240 ): |
1251 ): |
1309 @param parent parent item |
1320 @param parent parent item |
1310 @type BrowserItem |
1321 @type BrowserItem |
1311 """ |
1322 """ |
1312 BrowserItem.__init__(self, parent, "sys.path") |
1323 BrowserItem.__init__(self, parent, "sys.path") |
1313 |
1324 |
1314 self.type_ = BrowserItemSysPath |
1325 self.type_ = BrowserItemType.SysPath |
1315 self.icon = EricPixmapCache.getIcon("filePython") |
1326 self.icon = EricPixmapCache.getIcon("filePython") |
1316 self._populated = False |
1327 self._populated = False |
1317 self._lazyPopulation = True |
1328 self._lazyPopulation = True |
1318 |
1329 |
1319 def name(self): |
1330 def name(self): |
1344 @param sourceLanguage source code language of the project |
1355 @param sourceLanguage source code language of the project |
1345 @type str |
1356 @type str |
1346 """ |
1357 """ |
1347 BrowserItem.__init__(self, parent, os.path.basename(finfo)) |
1358 BrowserItem.__init__(self, parent, os.path.basename(finfo)) |
1348 |
1359 |
1349 self.type_ = BrowserItemFile |
1360 self.type_ = BrowserItemType.File |
1350 self.fileext = os.path.splitext(finfo)[1].lower() |
1361 self.fileext = os.path.splitext(finfo)[1].lower() |
1351 self._filename = os.path.abspath(finfo) |
1362 self._filename = os.path.abspath(finfo) |
1352 self._dirName = os.path.dirname(finfo) |
1363 self._dirName = os.path.dirname(finfo) |
1353 self.sourceLanguage = sourceLanguage |
1364 self.sourceLanguage = sourceLanguage |
1354 |
1365 |
1677 supers.append(sname) |
1688 supers.append(sname) |
1678 name += "({0})".format(", ".join(supers)) |
1689 name += "({0})".format(", ".join(supers)) |
1679 |
1690 |
1680 BrowserItem.__init__(self, parent, name) |
1691 BrowserItem.__init__(self, parent, name) |
1681 |
1692 |
1682 self.type_ = BrowserItemClass |
1693 self.type_ = BrowserItemType.Class |
1683 self._name = name |
1694 self._name = name |
1684 self._classObject = cl |
1695 self._classObject = cl |
1685 self._filename = filename |
1696 self._filename = filename |
1686 |
1697 |
1687 self.isfunction = isinstance(self._classObject, ClbrBaseClasses.Function) |
1698 self.isfunction = isinstance(self._classObject, ClbrBaseClasses.Function) |
1821 @type str |
1832 @type str |
1822 """ |
1833 """ |
1823 name = fn.name |
1834 name = fn.name |
1824 BrowserItem.__init__(self, parent, name) |
1835 BrowserItem.__init__(self, parent, name) |
1825 |
1836 |
1826 self.type_ = BrowserItemMethod |
1837 self.type_ = BrowserItemType.Method |
1827 self._name = name |
1838 self._name = name |
1828 self._functionObject = fn |
1839 self._functionObject = fn |
1829 self._filename = filename |
1840 self._filename = filename |
1830 if self._functionObject.modifier == ClbrBaseClasses.Function.Static: |
1841 if self._functionObject.modifier == ClbrBaseClasses.Function.Static: |
1831 self.icon = EricPixmapCache.getIcon("method_static") |
1842 self.icon = EricPixmapCache.getIcon("method_static") |
1958 @param isClass flag indicating class attributes |
1969 @param isClass flag indicating class attributes |
1959 @type bool |
1970 @type bool |
1960 """ |
1971 """ |
1961 BrowserItem.__init__(self, parent, text) |
1972 BrowserItem.__init__(self, parent, text) |
1962 |
1973 |
1963 self.type_ = BrowserItemAttributes |
1974 self.type_ = BrowserItemType.Attributes |
1964 self._attributes = attributes.copy() |
1975 self._attributes = attributes.copy() |
1965 self._populated = False |
1976 self._populated = False |
1966 self._lazyPopulation = True |
1977 self._lazyPopulation = True |
1967 if isClass: |
1978 if isClass: |
1968 self.icon = EricPixmapCache.getIcon("attributes_class") |
1979 self.icon = EricPixmapCache.getIcon("attributes_class") |
2034 @param isClass flag indicating a class attribute |
2045 @param isClass flag indicating a class attribute |
2035 @type bool |
2046 @type bool |
2036 """ |
2047 """ |
2037 BrowserItem.__init__(self, parent, attribute.name) |
2048 BrowserItem.__init__(self, parent, attribute.name) |
2038 |
2049 |
2039 self.type_ = BrowserItemAttribute |
2050 self.type_ = BrowserItemType.Attribute |
2040 self._attributeObject = attribute |
2051 self._attributeObject = attribute |
2041 self.__public = attribute.isPublic() |
2052 self.__public = attribute.isPublic() |
2042 if isClass: |
2053 if isClass: |
2043 self.icon = EricPixmapCache.getIcon("attribute_class") |
2054 self.icon = EricPixmapCache.getIcon("attribute_class") |
2044 elif attribute.isPrivate(): |
2055 elif attribute.isPrivate(): |
2150 @param linenumber line number of the coding line |
2161 @param linenumber line number of the coding line |
2151 @type int |
2162 @type int |
2152 """ |
2163 """ |
2153 BrowserItem.__init__(self, parent, text) |
2164 BrowserItem.__init__(self, parent, text) |
2154 |
2165 |
2155 self.type_ = BrowserItemCoding |
2166 self.type_ = BrowserItemType.Coding |
2156 self.icon = EricPixmapCache.getIcon("textencoding") |
2167 self.icon = EricPixmapCache.getIcon("textencoding") |
2157 |
2168 |
2158 self.__lineno = linenumber |
2169 self.__lineno = linenumber |
2159 |
2170 |
2160 def lineno(self): |
2171 def lineno(self): |
2202 @param text text to be shown by this item |
2213 @param text text to be shown by this item |
2203 @type str |
2214 @type str |
2204 """ |
2215 """ |
2205 BrowserItem.__init__(self, parent, text) |
2216 BrowserItem.__init__(self, parent, text) |
2206 |
2217 |
2207 self.type_ = BrowserItemImports |
2218 self.type_ = BrowserItemType.Imports |
2208 self.icon = EricPixmapCache.getIcon("imports") |
2219 self.icon = EricPixmapCache.getIcon("imports") |
2209 |
2220 |
2210 def lessThan(self, other, column, order): |
2221 def lessThan(self, other, column, order): |
2211 """ |
2222 """ |
2212 Public method to check, if the item is less than the other one. |
2223 Public method to check, if the item is less than the other one. |
2250 BrowserItem.__init__(self, parent, text) |
2261 BrowserItem.__init__(self, parent, text) |
2251 |
2262 |
2252 self.__filename = filename |
2263 self.__filename = filename |
2253 self.__linenos = lineNumbers[:] |
2264 self.__linenos = lineNumbers[:] |
2254 |
2265 |
2255 self.type_ = BrowserItemImport |
2266 self.type_ = BrowserItemType.Import |
2256 if isModule: |
2267 if isModule: |
2257 self.icon = EricPixmapCache.getIcon("importedModule") |
2268 self.icon = EricPixmapCache.getIcon("importedModule") |
2258 else: |
2269 else: |
2259 self.icon = EricPixmapCache.getIcon("importedName") |
2270 self.icon = EricPixmapCache.getIcon("importedName") |
2260 |
2271 |