QScintilla/EditorAssembly.py

changeset 2768
eab35f6e709f
parent 2409
df3820f08247
child 2791
a9577f248f04
child 3011
18292228c724
equal deleted inserted replaced
2766:c413e9eeaf95 2768:eab35f6e709f
48 48
49 self.__module = None 49 self.__module = None
50 50
51 self.__globalsCombo.activated[int].connect(self.__globalsActivated) 51 self.__globalsCombo.activated[int].connect(self.__globalsActivated)
52 self.__membersCombo.activated[int].connect(self.__membersActivated) 52 self.__membersCombo.activated[int].connect(self.__membersActivated)
53 self.__editor.cursorLineChanged.connect(self.__editorCursorLineChanged)
53 54
54 self.__parseTimer = QTimer(self) 55 self.__parseTimer = QTimer(self)
55 self.__parseTimer.setSingleShot(True) 56 self.__parseTimer.setSingleShot(True)
56 self.__parseTimer.setInterval(5 * 1000) 57 self.__parseTimer.setInterval(5 * 1000)
57 self.__parseTimer.timeout.connect(self.__parseEditor) 58 self.__parseTimer.timeout.connect(self.__parseEditor)
58 self.__editor.textChanged.connect(self.__resetParseTimer) 59 self.__editor.textChanged.connect(self.__resetParseTimer)
59 self.__editor.refreshed.connect(self.__resetParseTimer) 60 self.__editor.refreshed.connect(self.__resetParseTimer)
60 61
61 self.__selectedGlobal = "" 62 self.__selectedGlobal = ""
62 self.__selectedMember = "" 63 self.__selectedMember = ""
64 self.__globalsBoundaries = {}
65 self.__membersBoundaries = {}
63 66
64 QTimer.singleShot(0, self.__parseEditor) 67 QTimer.singleShot(0, self.__parseEditor)
65 68
66 def shutdownTimer(self): 69 def shutdownTimer(self):
67 """ 70 """
97 self.__editor.gotoLine(lineno, pos if pos == 0 else pos + 1, True) 100 self.__editor.gotoLine(lineno, pos if pos == 0 else pos + 1, True)
98 self.__editor.setFocus() 101 self.__editor.setFocus()
99 102
100 # step 2: populate the members combo, if the entry is a class 103 # step 2: populate the members combo, if the entry is a class
101 self.__membersCombo.clear() 104 self.__membersCombo.clear()
105 self.__membersBoundaries = {}
106 self.__membersCombo.addItem("")
107 memberIndex = 0
102 entryName = self.__globalsCombo.itemText(index) 108 entryName = self.__globalsCombo.itemText(index)
103 if self.__module: 109 if self.__module:
104 if entryName in self.__module.classes: 110 if entryName in self.__module.classes:
105 entry = self.__module.classes[entryName] 111 entry = self.__module.classes[entryName]
106 elif entryName in self.__module.modules: 112 elif entryName in self.__module.modules:
112 icon = UI.PixmapCache.getIcon("class_private.png") 118 icon = UI.PixmapCache.getIcon("class_private.png")
113 elif cl.isProtected(): 119 elif cl.isProtected():
114 icon = UI.PixmapCache.getIcon("class_protected.png") 120 icon = UI.PixmapCache.getIcon("class_protected.png")
115 else: 121 else:
116 icon = UI.PixmapCache.getIcon("class.png") 122 icon = UI.PixmapCache.getIcon("class.png")
117 items[cl.name] = (icon, cl.lineno) 123 items[cl.name] = (icon, cl.lineno, cl.endlineno)
118 for key in sorted(items.keys()): 124 for key in sorted(items.keys()):
119 itm = items[key] 125 itm = items[key]
120 self.__membersCombo.addItem(itm[0], key, itm[1]) 126 self.__membersCombo.addItem(itm[0], key, itm[1])
127 memberIndex += 1
128 self.__membersBoundaries[(itm[1], itm[2])] = memberIndex
121 else: 129 else:
122 return 130 return
123 131
124 # step 2.1: add class methods 132 # step 2.1: add class methods
125 from Utilities.ModuleParser import Function 133 from Utilities.ModuleParser import Function
133 icon = UI.PixmapCache.getIcon("method_private.png") 141 icon = UI.PixmapCache.getIcon("method_private.png")
134 elif meth.isProtected(): 142 elif meth.isProtected():
135 icon = UI.PixmapCache.getIcon("method_protected.png") 143 icon = UI.PixmapCache.getIcon("method_protected.png")
136 else: 144 else:
137 icon = UI.PixmapCache.getIcon("method.png") 145 icon = UI.PixmapCache.getIcon("method.png")
138 items[meth.name] = (icon, meth.lineno) 146 items[meth.name] = (icon, meth.lineno, meth.endlineno)
139 for key in sorted(items.keys()): 147 for key in sorted(items.keys()):
140 itm = items[key] 148 itm = items[key]
141 self.__membersCombo.addItem(itm[0], key, itm[1]) 149 self.__membersCombo.addItem(itm[0], key, itm[1])
150 memberIndex += 1
151 self.__membersBoundaries[(itm[1], itm[2])] = memberIndex
142 152
143 # step 2.2: add class instance attributes 153 # step 2.2: add class instance attributes
144 items = {} 154 items = {}
145 for attr in entry.attributes.values(): 155 for attr in entry.attributes.values():
146 if attr.isPrivate(): 156 if attr.isPrivate():
205 self.__selectedGlobal = self.__globalsCombo.currentText() 215 self.__selectedGlobal = self.__globalsCombo.currentText()
206 self.__selectedMember = self.__membersCombo.currentText() 216 self.__selectedMember = self.__membersCombo.currentText()
207 217
208 self.__globalsCombo.clear() 218 self.__globalsCombo.clear()
209 self.__membersCombo.clear() 219 self.__membersCombo.clear()
220 self.__globalsBoundaries = {}
221 self.__membersBoundaries = {}
210 222
211 self.__globalsCombo.addItem("") 223 self.__globalsCombo.addItem("")
224 index = 0
212 225
213 # step 1: add modules 226 # step 1: add modules
214 items = {} 227 items = {}
215 for module in self.__module.modules.values(): 228 for module in self.__module.modules.values():
216 items[module.name] = (UI.PixmapCache.getIcon("module.png"), 229 items[module.name] = (UI.PixmapCache.getIcon("module.png"),
217 module.lineno) 230 module.lineno, module.endlineno)
218 for key in sorted(items.keys()): 231 for key in sorted(items.keys()):
219 itm = items[key] 232 itm = items[key]
220 self.__globalsCombo.addItem(itm[0], key, itm[1]) 233 self.__globalsCombo.addItem(itm[0], key, itm[1])
234 index += 1
235 self.__globalsBoundaries[(itm[1], itm[2])] = index
221 236
222 # step 2: add classes 237 # step 2: add classes
223 items = {} 238 items = {}
224 for cl in self.__module.classes.values(): 239 for cl in self.__module.classes.values():
225 if cl.isPrivate(): 240 if cl.isPrivate():
226 icon = UI.PixmapCache.getIcon("class_private.png") 241 icon = UI.PixmapCache.getIcon("class_private.png")
227 elif cl.isProtected(): 242 elif cl.isProtected():
228 icon = UI.PixmapCache.getIcon("class_protected.png") 243 icon = UI.PixmapCache.getIcon("class_protected.png")
229 else: 244 else:
230 icon = UI.PixmapCache.getIcon("class.png") 245 icon = UI.PixmapCache.getIcon("class.png")
231 items[cl.name] = (icon, cl.lineno) 246 items[cl.name] = (icon, cl.lineno, cl.endlineno)
232 for key in sorted(items.keys()): 247 for key in sorted(items.keys()):
233 itm = items[key] 248 itm = items[key]
234 self.__globalsCombo.addItem(itm[0], key, itm[1]) 249 self.__globalsCombo.addItem(itm[0], key, itm[1])
250 index += 1
251 self.__globalsBoundaries[(itm[1], itm[2])] = index
235 252
236 # step 3: add functions 253 # step 3: add functions
237 items = {} 254 items = {}
238 for func in self.__module.functions.values(): 255 for func in self.__module.functions.values():
239 if func.isPrivate(): 256 if func.isPrivate():
240 icon = UI.PixmapCache.getIcon("method_private.png") 257 icon = UI.PixmapCache.getIcon("method_private.png")
241 elif func.isProtected(): 258 elif func.isProtected():
242 icon = UI.PixmapCache.getIcon("method_protected.png") 259 icon = UI.PixmapCache.getIcon("method_protected.png")
243 else: 260 else:
244 icon = UI.PixmapCache.getIcon("method.png") 261 icon = UI.PixmapCache.getIcon("method.png")
245 items[func.name] = (icon, func.lineno) 262 items[func.name] = (icon, func.lineno, func.endlineno)
246 for key in sorted(items.keys()): 263 for key in sorted(items.keys()):
247 itm = items[key] 264 itm = items[key]
248 self.__globalsCombo.addItem(itm[0], key, itm[1]) 265 self.__globalsCombo.addItem(itm[0], key, itm[1])
266 index += 1
267 self.__globalsBoundaries[(itm[1], itm[2])] = index
249 268
250 # step 4: add attributes 269 # step 4: add attributes
251 items = {} 270 items = {}
252 for glob in self.__module.globals.values(): 271 for glob in self.__module.globals.values():
253 if glob.isPrivate(): 272 if glob.isPrivate():
268 self.__globalsActivated(index, moveCursor=False) 287 self.__globalsActivated(index, moveCursor=False)
269 index = self.__membersCombo.findText(self.__selectedMember) 288 index = self.__membersCombo.findText(self.__selectedMember)
270 if index != -1: 289 if index != -1:
271 self.__membersCombo.setCurrentIndex(index) 290 self.__membersCombo.setCurrentIndex(index)
272 self.__membersActivated(index, moveCursor=False) 291 self.__membersActivated(index, moveCursor=False)
292
293 def __editorCursorLineChanged(self, lineno):
294 """
295 Private slot handling a line change of the cursor of the editor.
296
297 @param lineno line number of the cursor (integer)
298 """
299 lineno += 1 # cursor position is zero based, code info one based
300
301 # step 1: search in the globals
302 for (lower, upper), index in self.__globalsBoundaries.items():
303 if upper == -1:
304 upper = 1000000 # it is the last line
305 if lower <= lineno <= upper:
306 break
307 else:
308 index = 0
309 self.__globalsCombo.setCurrentIndex(index)
310 self.__globalsActivated(index, moveCursor=False)
311
312 # step 2: search in members
313 for (lower, upper), index in self.__membersBoundaries.items():
314 if upper == -1:
315 upper = 1000000 # it is the last line
316 if lower <= lineno <= upper:
317 break
318 else:
319 index = 0
320 self.__membersCombo.setCurrentIndex(index)
321 self.__membersActivated(index, moveCursor=False)

eric ide

mercurial