55 PbSimpleDirectory = 100 |
55 PbSimpleDirectory = 100 |
56 PbDirectory = 101 |
56 PbDirectory = 101 |
57 PbFile = 102 |
57 PbFile = 102 |
58 |
58 |
59 |
59 |
|
60 class BrowserModelType(enum.Enum): |
|
61 """ |
|
62 Class defining the various browser model types. |
|
63 """ |
|
64 |
|
65 Generic = 0 |
|
66 Project = 1 |
|
67 EditorOutline = 2 |
|
68 |
|
69 |
60 class BrowserModel(QAbstractItemModel): |
70 class BrowserModel(QAbstractItemModel): |
61 """ |
71 """ |
62 Class implementing the browser model. |
72 Class implementing the browser model. |
63 """ |
73 """ |
64 |
74 |
65 def __init__(self, parent=None, nopopulate=False, fsInterface=None): |
75 def __init__( |
|
76 self, |
|
77 parent=None, |
|
78 nopopulate=False, |
|
79 fsInterface=None, |
|
80 modelType=BrowserModelType.Generic, |
|
81 ): |
66 """ |
82 """ |
67 Constructor |
83 Constructor |
68 |
84 |
69 @param parent reference to parent object (defaults to None) |
85 @param parent reference to parent object (defaults to None) |
70 @type QObject (optional) |
86 @type QObject (optional) |
71 @param nopopulate flag indicating to not populate the model (defaults to False) |
87 @param nopopulate flag indicating to not populate the model (defaults to False) |
72 @type bool (optional) |
88 @type bool (optional) |
73 @param fsInterface reference to the 'eric-ide' server interface object |
89 @param fsInterface reference to the 'eric-ide' server interface object |
74 (defaults to None) |
90 (defaults to None) |
75 @type EricServerFileSystemInterface (optional) |
91 @type EricServerFileSystemInterface (optional) |
|
92 @param modelType type of the browser model (defaults to |
|
93 BrowserModelType.Generic) |
|
94 @type BrowserModelType (optional) |
76 """ |
95 """ |
77 super().__init__(parent) |
96 super().__init__(parent) |
78 |
97 |
79 self.progDir = None |
98 self.progDir = None |
80 |
99 |
81 self.__sysPathInterpreter = "" |
100 self.__sysPathInterpreter = "" |
82 self.__sysPathItem = None |
101 self.__sysPathItem = None |
83 |
102 |
84 self.__remotefsInterface = fsInterface |
103 self.__remotefsInterface = fsInterface |
|
104 self._modelType = modelType |
85 |
105 |
86 if not nopopulate: |
106 if not nopopulate: |
87 self.watchedDirItems = {} |
107 self.watchedDirItems = {} |
88 self.watchedFileItems = {} |
108 self.watchedFileItems = {} |
89 watcher = EricFileSystemWatcher.instance() |
109 watcher = EricFileSystemWatcher.instance() |
767 with contextlib.suppress(AttributeError): |
787 with contextlib.suppress(AttributeError): |
768 if cl.module == moduleName: |
788 if cl.module == moduleName: |
769 if isinstance( |
789 if isinstance( |
770 cl, (ClbrBaseClasses.Class, ClbrBaseClasses.Module) |
790 cl, (ClbrBaseClasses.Class, ClbrBaseClasses.Module) |
771 ): |
791 ): |
772 node = BrowserClassItem(parentItem, cl, fileName) |
792 node = BrowserClassItem( |
|
793 parentItem, cl, fileName, modelType=self._modelType |
|
794 ) |
773 elif isinstance(cl, ClbrBaseClasses.Function): |
795 elif isinstance(cl, ClbrBaseClasses.Function): |
774 node = BrowserMethodItem(parentItem, cl, fileName) |
796 node = BrowserMethodItem( |
|
797 parentItem, cl, fileName, modelType=self._modelType |
|
798 ) |
775 else: |
799 else: |
776 node = None |
800 node = None |
777 if node: |
801 if node: |
778 self._addItem(node, parentItem) |
802 self._addItem(node, parentItem) |
779 if "@@Coding@@" in dictionary and Preferences.getUI("BrowserShowCoding"): |
803 if "@@Coding@@" in dictionary and Preferences.getUI("BrowserShowCoding"): |
804 m_node = BrowserImportItem( |
828 m_node = BrowserImportItem( |
805 node, |
829 node, |
806 importedModule.importedModuleName, |
830 importedModule.importedModuleName, |
807 importedModule.file, |
831 importedModule.file, |
808 importedModule.linenos, |
832 importedModule.linenos, |
|
833 modelType=self._modelType, |
809 ) |
834 ) |
810 self._addItem(m_node, node) |
835 self._addItem(m_node, node) |
811 for ( |
836 for ( |
812 importedName, |
837 importedName, |
813 linenos, |
838 linenos, |
921 self.beginInsertRows( |
947 self.beginInsertRows( |
922 self.createIndex(parentItem.row(), 0, parentItem), 0, len(keys) - 1 |
948 self.createIndex(parentItem.row(), 0, parentItem), 0, len(keys) - 1 |
923 ) |
949 ) |
924 for key, kind in keys: |
950 for key, kind in keys: |
925 if kind == "c": |
951 if kind == "c": |
926 node = BrowserClassItem(parentItem, cl.classes[key], file_) |
952 node = BrowserClassItem( |
|
953 parentItem, cl.classes[key], file_, modelType=self._modelType |
|
954 ) |
927 elif kind == "m": |
955 elif kind == "m": |
928 node = BrowserMethodItem(parentItem, cl.methods[key], file_) |
956 node = BrowserMethodItem( |
|
957 parentItem, cl.methods[key], file_, modelType=self._modelType |
|
958 ) |
929 self._addItem(node, parentItem) |
959 self._addItem(node, parentItem) |
930 if repopulate: |
960 if repopulate: |
931 self.endInsertRows() |
961 self.endInsertRows() |
932 |
962 |
933 def populateMethodItem(self, parentItem, repopulate=False): |
963 def populateMethodItem(self, parentItem, repopulate=False): |
959 self.beginInsertRows( |
989 self.beginInsertRows( |
960 self.createIndex(parentItem.row(), 0, parentItem), 0, len(keys) - 1 |
990 self.createIndex(parentItem.row(), 0, parentItem), 0, len(keys) - 1 |
961 ) |
991 ) |
962 for key, kind in keys: |
992 for key, kind in keys: |
963 if kind == "c": |
993 if kind == "c": |
964 node = BrowserClassItem(parentItem, fn.classes[key], file_) |
994 node = BrowserClassItem( |
|
995 parentItem, fn.classes[key], file_, modelType=self._modelType |
|
996 ) |
965 elif kind == "m": |
997 elif kind == "m": |
966 node = BrowserMethodItem(parentItem, fn.methods[key], file_) |
998 node = BrowserMethodItem( |
|
999 parentItem, fn.methods[key], file_, modelType=self._modelType |
|
1000 ) |
967 elif kind == "a": |
1001 elif kind == "a": |
968 node = BrowserClassAttributeItem(parentItem, fn.attributes[key]) |
1002 node = BrowserClassAttributeItem( |
|
1003 parentItem, fn.attributes[key], modelType=self._modelType |
|
1004 ) |
969 self._addItem(node, parentItem) |
1005 self._addItem(node, parentItem) |
970 if repopulate: |
1006 if repopulate: |
971 self.endInsertRows() |
1007 self.endInsertRows() |
972 |
1008 |
973 def populateClassAttributesItem(self, parentItem, repopulate=False): |
1009 def populateClassAttributesItem(self, parentItem, repopulate=False): |
991 self.beginInsertRows( |
1027 self.beginInsertRows( |
992 self.createIndex(parentItem.row(), 0, parentItem), 0, len(keys) - 1 |
1028 self.createIndex(parentItem.row(), 0, parentItem), 0, len(keys) - 1 |
993 ) |
1029 ) |
994 for key in keys: |
1030 for key in keys: |
995 node = BrowserClassAttributeItem( |
1031 node = BrowserClassAttributeItem( |
996 parentItem, attributes[key], classAttributes |
1032 parentItem, |
|
1033 attributes[key], |
|
1034 classAttributes, |
|
1035 modelType=self._modelType, |
997 ) |
1036 ) |
998 self._addItem(node, parentItem) |
1037 self._addItem(node, parentItem) |
999 if repopulate: |
1038 if repopulate: |
1000 self.endInsertRows() |
1039 self.endInsertRows() |
1001 |
1040 |
1805 class BrowserClassItem(BrowserItem): |
1844 class BrowserClassItem(BrowserItem): |
1806 """ |
1845 """ |
1807 Class implementing the data structure for browser class items. |
1846 Class implementing the data structure for browser class items. |
1808 """ |
1847 """ |
1809 |
1848 |
1810 def __init__(self, parent, cl, filename): |
1849 def __init__(self, parent, cl, filename, modelType=BrowserModelType.Generic): |
1811 """ |
1850 """ |
1812 Constructor |
1851 Constructor |
1813 |
1852 |
1814 @param parent parent item |
1853 @param parent parent item |
1815 @type BrowserItem |
1854 @type BrowserItem |
1816 @param cl Class object to be shown |
1855 @param cl Class object to be shown |
1817 @type Class |
1856 @type Class |
1818 @param filename file name of the file defining this class |
1857 @param filename file name of the file defining this class |
1819 @type str |
1858 @type str |
|
1859 @param modelType type of the browser model (defaults to |
|
1860 BrowserModelType.Generic) |
|
1861 @type BrowserModelType (optional) |
1820 """ |
1862 """ |
1821 name = cl.name |
1863 name = cl.name |
1822 if hasattr(cl, "super") and cl.super: |
1864 if hasattr(cl, "super") and cl.super: |
1823 supers = [] |
1865 supers = [] |
1824 for sup in cl.super: |
1866 for sup in cl.super: |
1831 supers.append(sname) |
1873 supers.append(sname) |
1832 name += "({0})".format(", ".join(supers)) |
1874 name += "({0})".format(", ".join(supers)) |
1833 |
1875 |
1834 super().__init__(parent, name) |
1876 super().__init__(parent, name) |
1835 |
1877 |
|
1878 self._modelType = modelType |
1836 self.type_ = BrowserItemType.Class |
1879 self.type_ = BrowserItemType.Class |
1837 self._name = name |
1880 self._name = name |
1838 self._classObject = cl |
1881 self._classObject = cl |
1839 self._filename = filename |
1882 self._filename = filename |
1840 |
1883 |
1947 @rtype bool |
1990 @rtype bool |
1948 """ |
1991 """ |
1949 if issubclass(other.__class__, (BrowserCodingItem, BrowserClassAttributesItem)): |
1992 if issubclass(other.__class__, (BrowserCodingItem, BrowserClassAttributesItem)): |
1950 return order == Qt.SortOrder.DescendingOrder |
1993 return order == Qt.SortOrder.DescendingOrder |
1951 |
1994 |
1952 if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: |
1995 if column == 0 and ( |
|
1996 ( |
|
1997 self._modelType == BrowserModelType.EditorOutline |
|
1998 and Preferences.getEditor("SourceOutlineListContentsByOccurrence") |
|
1999 ) |
|
2000 or ( |
|
2001 self._modelType != BrowserModelType.EditorOutline |
|
2002 and Preferences.getUI("BrowsersListContentsByOccurrence") |
|
2003 ) |
|
2004 ): |
1953 if order == Qt.SortOrder.AscendingOrder: |
2005 if order == Qt.SortOrder.AscendingOrder: |
1954 return self.lineno() < other.lineno() |
2006 return self.lineno() < other.lineno() |
1955 else: |
2007 else: |
1956 return self.lineno() > other.lineno() |
2008 return self.lineno() > other.lineno() |
1957 |
2009 |
1970 class BrowserMethodItem(BrowserItem): |
2022 class BrowserMethodItem(BrowserItem): |
1971 """ |
2023 """ |
1972 Class implementing the data structure for browser method items. |
2024 Class implementing the data structure for browser method items. |
1973 """ |
2025 """ |
1974 |
2026 |
1975 def __init__(self, parent, fn, filename): |
2027 def __init__(self, parent, fn, filename, modelType=BrowserModelType.Generic): |
1976 """ |
2028 """ |
1977 Constructor |
2029 Constructor |
1978 |
2030 |
1979 @param parent parent item |
2031 @param parent parent item |
1980 @type BrowserItem |
2032 @type BrowserItem |
1981 @param fn Function object to be shown |
2033 @param fn Function object to be shown |
1982 @type Function |
2034 @type Function |
1983 @param filename filename of the file defining this class |
2035 @param filename filename of the file defining this class |
1984 @type str |
2036 @type str |
|
2037 @param modelType type of the browser model (defaults to |
|
2038 BrowserModelType.Generic) |
|
2039 @type BrowserModelType (optional) |
1985 """ |
2040 """ |
1986 name = fn.name |
2041 name = fn.name |
1987 super().__init__(parent, name) |
2042 super().__init__(parent, name) |
1988 |
2043 |
|
2044 self._modelType = modelType |
1989 self.type_ = BrowserItemType.Method |
2045 self.type_ = BrowserItemType.Method |
1990 self._name = name |
2046 self._name = name |
1991 self._functionObject = fn |
2047 self._functionObject = fn |
1992 self._filename = filename |
2048 self._filename = filename |
1993 if self._functionObject.modifier == ClbrBaseClasses.Function.Static: |
2049 if self._functionObject.modifier == ClbrBaseClasses.Function.Static: |
2092 if other._name.startswith("__init__"): |
2148 if other._name.startswith("__init__"): |
2093 return order == Qt.SortOrder.DescendingOrder |
2149 return order == Qt.SortOrder.DescendingOrder |
2094 elif issubclass(other.__class__, BrowserClassAttributesItem): |
2150 elif issubclass(other.__class__, BrowserClassAttributesItem): |
2095 return order == Qt.SortOrder.DescendingOrder |
2151 return order == Qt.SortOrder.DescendingOrder |
2096 |
2152 |
2097 if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: |
2153 if column == 0 and ( |
|
2154 ( |
|
2155 self._modelType == BrowserModelType.EditorOutline |
|
2156 and Preferences.getEditor("SourceOutlineListContentsByOccurrence") |
|
2157 ) |
|
2158 or ( |
|
2159 self._modelType != BrowserModelType.EditorOutline |
|
2160 and Preferences.getUI("BrowsersListContentsByOccurrence") |
|
2161 ) |
|
2162 ): |
2098 if order == Qt.SortOrder.AscendingOrder: |
2163 if order == Qt.SortOrder.AscendingOrder: |
2099 return self.lineno() < other.lineno() |
2164 return self.lineno() < other.lineno() |
2100 else: |
2165 else: |
2101 return self.lineno() > other.lineno() |
2166 return self.lineno() > other.lineno() |
2102 |
2167 |
2193 class BrowserClassAttributeItem(BrowserItem): |
2258 class BrowserClassAttributeItem(BrowserItem): |
2194 """ |
2259 """ |
2195 Class implementing the data structure for browser class attribute items. |
2260 Class implementing the data structure for browser class attribute items. |
2196 """ |
2261 """ |
2197 |
2262 |
2198 def __init__(self, parent, attribute, isClass=False): |
2263 def __init__( |
|
2264 self, parent, attribute, isClass=False, modelType=BrowserModelType.Generic |
|
2265 ): |
2199 """ |
2266 """ |
2200 Constructor |
2267 Constructor |
2201 |
2268 |
2202 @param parent parent item |
2269 @param parent parent item |
2203 @type BrowserItem |
2270 @type BrowserItem |
2204 @param attribute reference to the attribute object |
2271 @param attribute reference to the attribute object |
2205 @type Attribute |
2272 @type Attribute |
2206 @param isClass flag indicating a class attribute |
2273 @param isClass flag indicating a class attribute (defaults to False) |
2207 @type bool |
2274 @type bool (optional) |
|
2275 @param modelType type of the browser model (defaults to |
|
2276 BrowserModelType.Generic) |
|
2277 @type BrowserModelType (optional) |
2208 """ |
2278 """ |
2209 super().__init__(parent, attribute.name) |
2279 super().__init__(parent, attribute.name) |
2210 |
2280 |
|
2281 self._modelType = modelType |
2211 self.type_ = BrowserItemType.Attribute |
2282 self.type_ = BrowserItemType.Attribute |
2212 self._attributeObject = attribute |
2283 self._attributeObject = attribute |
2213 self.__public = attribute.isPublic() |
2284 self.__public = attribute.isPublic() |
2214 if isClass: |
2285 if isClass: |
2215 self.icon = EricPixmapCache.getIcon("attribute_class") |
2286 self.icon = EricPixmapCache.getIcon("attribute_class") |
2285 @param order sort order (for special sorting) |
2356 @param order sort order (for special sorting) |
2286 @type Qt.SortOrder |
2357 @type Qt.SortOrder |
2287 @return true, if this item is less than other |
2358 @return true, if this item is less than other |
2288 @rtype bool |
2359 @rtype bool |
2289 """ |
2360 """ |
2290 if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: |
2361 if column == 0 and ( |
|
2362 ( |
|
2363 self._modelType == BrowserModelType.EditorOutline |
|
2364 and Preferences.getEditor("SourceOutlineListContentsByOccurrence") |
|
2365 ) |
|
2366 or ( |
|
2367 self._modelType != BrowserModelType.EditorOutline |
|
2368 and Preferences.getUI("BrowsersListContentsByOccurrence") |
|
2369 ) |
|
2370 ): |
2291 if order == Qt.SortOrder.AscendingOrder: |
2371 if order == Qt.SortOrder.AscendingOrder: |
2292 return self.lineno() < other.lineno() |
2372 return self.lineno() < other.lineno() |
2293 else: |
2373 else: |
2294 return self.lineno() > other.lineno() |
2374 return self.lineno() > other.lineno() |
2295 |
2375 |
2411 """ |
2491 """ |
2412 Class implementing the data structure for browser imported module and |
2492 Class implementing the data structure for browser imported module and |
2413 imported names items. |
2493 imported names items. |
2414 """ |
2494 """ |
2415 |
2495 |
2416 def __init__(self, parent, text, filename, lineNumbers, isModule=True): |
2496 def __init__( |
|
2497 self, |
|
2498 parent, |
|
2499 text, |
|
2500 filename, |
|
2501 lineNumbers, |
|
2502 isModule=True, |
|
2503 modelType=BrowserModelType.Generic, |
|
2504 ): |
2417 """ |
2505 """ |
2418 Constructor |
2506 Constructor |
2419 |
2507 |
2420 @param parent parent item |
2508 @param parent parent item |
2421 @type BrowserItem |
2509 @type BrowserItem |
2423 @type str |
2511 @type str |
2424 @param filename name of the file |
2512 @param filename name of the file |
2425 @type str |
2513 @type str |
2426 @param lineNumbers list of line numbers of the import statement |
2514 @param lineNumbers list of line numbers of the import statement |
2427 @type list of int |
2515 @type list of int |
2428 @param isModule flag indicating a module item entry |
2516 @param isModule flag indicating a module item entry (defaults to True) |
2429 @type bool |
2517 @type bool (optional) |
|
2518 @param modelType type of the browser model (defaults to |
|
2519 BrowserModelType.Generic) |
|
2520 @type BrowserModelType (optional) |
2430 """ |
2521 """ |
2431 super().__init__(parent, text) |
2522 super().__init__(parent, text) |
2432 |
2523 |
2433 self.__filename = filename |
2524 self.__filename = filename |
2434 self.__linenos = lineNumbers[:] |
2525 self.__linenos = lineNumbers[:] |
2435 |
2526 |
|
2527 self._modelType = modelType |
2436 self.type_ = BrowserItemType.Import |
2528 self.type_ = BrowserItemType.Import |
2437 if isModule: |
2529 if isModule: |
2438 self.icon = EricPixmapCache.getIcon("importedModule") |
2530 self.icon = EricPixmapCache.getIcon("importedModule") |
2439 else: |
2531 else: |
2440 self.icon = EricPixmapCache.getIcon("importedName") |
2532 self.icon = EricPixmapCache.getIcon("importedName") |
2477 @param order sort order (for special sorting) |
2569 @param order sort order (for special sorting) |
2478 @type Qt.SortOrder |
2570 @type Qt.SortOrder |
2479 @return true, if this item is less than other |
2571 @return true, if this item is less than other |
2480 @rtype bool |
2572 @rtype bool |
2481 """ |
2573 """ |
2482 if Preferences.getUI("BrowsersListContentsByOccurrence") and column == 0: |
2574 if column == 0 and ( |
|
2575 ( |
|
2576 self._modelType == BrowserModelType.EditorOutline |
|
2577 and Preferences.getEditor("SourceOutlineListContentsByOccurrence") |
|
2578 ) |
|
2579 or ( |
|
2580 self._modelType != BrowserModelType.EditorOutline |
|
2581 and Preferences.getUI("BrowsersListContentsByOccurrence") |
|
2582 ) |
|
2583 ): |
2483 if order == Qt.SortOrder.AscendingOrder: |
2584 if order == Qt.SortOrder.AscendingOrder: |
2484 return self.lineno() < other.lineno() |
2585 return self.lineno() < other.lineno() |
2485 else: |
2586 else: |
2486 return self.lineno() > other.lineno() |
2587 return self.lineno() > other.lineno() |
2487 |
2588 |