QScintilla/EditorAssembly.py

changeset 3011
18292228c724
parent 2768
eab35f6e709f
child 3057
10516539f238
child 3160
209a07d7e401
equal deleted inserted replaced
3010:befeff46ec0f 3011:18292228c724
2 2
3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de> 3 # Copyright (c) 2011 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
4 # 4 #
5 5
6 """ 6 """
7 Module implementing the editor assembly widget containing the navigation combos and 7 Module implementing the editor assembly widget containing the navigation
8 the editor widget. 8 combos and the editor widget.
9 """ 9 """
10 10
11 from PyQt4.QtCore import QTimer 11 from PyQt4.QtCore import QTimer
12 from PyQt4.QtGui import QWidget, QGridLayout, QComboBox 12 from PyQt4.QtGui import QWidget, QGridLayout, QComboBox
13 13
14 import UI.PixmapCache 14 import UI.PixmapCache
15 15
16 16
17 class EditorAssembly(QWidget): 17 class EditorAssembly(QWidget):
18 """ 18 """
19 Class implementing the editor assembly widget containing the navigation combos and 19 Class implementing the editor assembly widget containing the navigation
20 the editor widget. 20 combos and the editor widget.
21 """ 21 """
22 def __init__(self, dbs, fn=None, vm=None, filetype="", editor=None, tv=None): 22 def __init__(self, dbs, fn=None, vm=None, filetype="", editor=None,
23 tv=None):
23 """ 24 """
24 Constructor 25 Constructor
25 26
26 @param dbs reference to the debug server object 27 @param dbs reference to the debug server object
27 @param fn name of the file to be opened (string). If it is None, 28 @param fn name of the file to be opened (string). If it is None,
28 a new (empty) editor is opened 29 a new (empty) editor is opened
29 @param vm reference to the view manager object (ViewManager.ViewManager) 30 @param vm reference to the view manager object
31 (ViewManager.ViewManager)
30 @param filetype type of the source file (string) 32 @param filetype type of the source file (string)
31 @param editor reference to an Editor object, if this is a cloned view 33 @param editor reference to an Editor object, if this is a cloned view
32 @param tv reference to the task viewer object 34 @param tv reference to the task viewer object
33 """ 35 """
34 super().__init__() 36 super().__init__()
83 """ 85 """
84 return self.__editor 86 return self.__editor
85 87
86 def __globalsActivated(self, index, moveCursor=True): 88 def __globalsActivated(self, index, moveCursor=True):
87 """ 89 """
88 Private method to jump to the line of the selected global entry and to populate 90 Private method to jump to the line of the selected global entry and to
89 the members combo box. 91 populate the members combo box.
90 92
91 @param index index of the selected entry (integer) 93 @param index index of the selected entry (integer)
92 @keyparam moveCursor flag indicating to move the editor cursor (boolean) 94 @keyparam moveCursor flag indicating to move the editor cursor
95 (boolean)
93 """ 96 """
94 # step 1: go to the line of the selected entry 97 # step 1: go to the line of the selected entry
95 lineno = self.__globalsCombo.itemData(index) 98 lineno = self.__globalsCombo.itemData(index)
96 if lineno is not None: 99 if lineno is not None:
97 if moveCursor: 100 if moveCursor:
98 txt = self.__editor.text(lineno - 1).rstrip() 101 txt = self.__editor.text(lineno - 1).rstrip()
99 pos = len(txt.replace(txt.strip(), "")) 102 pos = len(txt.replace(txt.strip(), ""))
100 self.__editor.gotoLine(lineno, pos if pos == 0 else pos + 1, True) 103 self.__editor.gotoLine(
104 lineno, pos if pos == 0 else pos + 1, True)
101 self.__editor.setFocus() 105 self.__editor.setFocus()
102 106
103 # step 2: populate the members combo, if the entry is a class 107 # step 2: populate the members combo, if the entry is a class
104 self.__membersCombo.clear() 108 self.__membersCombo.clear()
105 self.__membersBoundaries = {} 109 self.__membersBoundaries = {}
115 items = {} 119 items = {}
116 for cl in entry.classes.values(): 120 for cl in entry.classes.values():
117 if cl.isPrivate(): 121 if cl.isPrivate():
118 icon = UI.PixmapCache.getIcon("class_private.png") 122 icon = UI.PixmapCache.getIcon("class_private.png")
119 elif cl.isProtected(): 123 elif cl.isProtected():
120 icon = UI.PixmapCache.getIcon("class_protected.png") 124 icon = UI.PixmapCache.getIcon(
125 "class_protected.png")
121 else: 126 else:
122 icon = UI.PixmapCache.getIcon("class.png") 127 icon = UI.PixmapCache.getIcon("class.png")
123 items[cl.name] = (icon, cl.lineno, cl.endlineno) 128 items[cl.name] = (icon, cl.lineno, cl.endlineno)
124 for key in sorted(items.keys()): 129 for key in sorted(items.keys()):
125 itm = items[key] 130 itm = items[key]
126 self.__membersCombo.addItem(itm[0], key, itm[1]) 131 self.__membersCombo.addItem(itm[0], key, itm[1])
127 memberIndex += 1 132 memberIndex += 1
128 self.__membersBoundaries[(itm[1], itm[2])] = memberIndex 133 self.__membersBoundaries[(itm[1], itm[2])] = \
134 memberIndex
129 else: 135 else:
130 return 136 return
131 137
132 # step 2.1: add class methods 138 # step 2.1: add class methods
133 from Utilities.ModuleParser import Function 139 from Utilities.ModuleParser import Function
154 items = {} 160 items = {}
155 for attr in entry.attributes.values(): 161 for attr in entry.attributes.values():
156 if attr.isPrivate(): 162 if attr.isPrivate():
157 icon = UI.PixmapCache.getIcon("attribute_private.png") 163 icon = UI.PixmapCache.getIcon("attribute_private.png")
158 elif attr.isProtected(): 164 elif attr.isProtected():
159 icon = UI.PixmapCache.getIcon("attribute_protected.png") 165 icon = UI.PixmapCache.getIcon(
166 "attribute_protected.png")
160 else: 167 else:
161 icon = UI.PixmapCache.getIcon("attribute.png") 168 icon = UI.PixmapCache.getIcon("attribute.png")
162 items[attr.name] = (icon, attr.lineno) 169 items[attr.name] = (icon, attr.lineno)
163 for key in sorted(items.keys()): 170 for key in sorted(items.keys()):
164 itm = items[key] 171 itm = items[key]
176 def __membersActivated(self, index, moveCursor=True): 183 def __membersActivated(self, index, moveCursor=True):
177 """ 184 """
178 Private method to jump to the line of the selected members entry. 185 Private method to jump to the line of the selected members entry.
179 186
180 @param index index of the selected entry (integer) 187 @param index index of the selected entry (integer)
181 @keyparam moveCursor flag indicating to move the editor cursor (boolean) 188 @keyparam moveCursor flag indicating to move the editor cursor
189 (boolean)
182 """ 190 """
183 lineno = self.__membersCombo.itemData(index) 191 lineno = self.__membersCombo.itemData(index)
184 if lineno is not None and moveCursor: 192 if lineno is not None and moveCursor:
185 txt = self.__editor.text(lineno - 1).rstrip() 193 txt = self.__editor.text(lineno - 1).rstrip()
186 pos = len(txt.replace(txt.strip(), "")) 194 pos = len(txt.replace(txt.strip(), ""))
194 self.__parseTimer.stop() 202 self.__parseTimer.stop()
195 self.__parseTimer.start() 203 self.__parseTimer.start()
196 204
197 def __parseEditor(self): 205 def __parseEditor(self):
198 """ 206 """
199 Private method to parse the editor source and repopulate the globals combo. 207 Private method to parse the editor source and repopulate the globals
208 combo.
200 """ 209 """
201 from Utilities.ModuleParser import Module, getTypeFromTypeName 210 from Utilities.ModuleParser import Module, getTypeFromTypeName
202 211
203 self.__module = None 212 self.__module = None
204 sourceType = getTypeFromTypeName(self.__editor.determineFileType()) 213 sourceType = getTypeFromTypeName(self.__editor.determineFileType())
270 items = {} 279 items = {}
271 for glob in self.__module.globals.values(): 280 for glob in self.__module.globals.values():
272 if glob.isPrivate(): 281 if glob.isPrivate():
273 icon = UI.PixmapCache.getIcon("attribute_private.png") 282 icon = UI.PixmapCache.getIcon("attribute_private.png")
274 elif glob.isProtected(): 283 elif glob.isProtected():
275 icon = UI.PixmapCache.getIcon("attribute_protected.png") 284 icon = UI.PixmapCache.getIcon(
285 "attribute_protected.png")
276 else: 286 else:
277 icon = UI.PixmapCache.getIcon("attribute.png") 287 icon = UI.PixmapCache.getIcon("attribute.png")
278 items[glob.name] = (icon, glob.lineno) 288 items[glob.name] = (icon, glob.lineno)
279 for key in sorted(items.keys()): 289 for key in sorted(items.keys()):
280 itm = items[key] 290 itm = items[key]
281 self.__globalsCombo.addItem(itm[0], key, itm[1]) 291 self.__globalsCombo.addItem(itm[0], key, itm[1])
282 292
283 # reset the currently selected entries without moving the text cursor 293 # reset the currently selected entries without moving the
294 # text cursor
284 index = self.__globalsCombo.findText(self.__selectedGlobal) 295 index = self.__globalsCombo.findText(self.__selectedGlobal)
285 if index != -1: 296 if index != -1:
286 self.__globalsCombo.setCurrentIndex(index) 297 self.__globalsCombo.setCurrentIndex(index)
287 self.__globalsActivated(index, moveCursor=False) 298 self.__globalsActivated(index, moveCursor=False)
288 index = self.__membersCombo.findText(self.__selectedMember) 299 index = self.__membersCombo.findText(self.__selectedMember)

eric ide

mercurial