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