QScintilla/EditorAssembly.py

Mon, 03 Oct 2011 18:52:38 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 03 Oct 2011 18:52:38 +0200
changeset 1358
c1622c708cd9
child 1421
8fead6686d1c
permissions
-rw-r--r--

Added source navigation function for Python 2, Python 3 and Ruby sources.

1358
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de>
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the editor assembly widget containing the navigation combos and
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 the editor widget.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtCore import QTimer
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt4.QtGui import QWidget, QGridLayout, QComboBox
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from .Editor import Editor
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from Utilities.ModuleParser import Module, Function, getTypeFromTypeName
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import UI.PixmapCache
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class EditorAssembly(QWidget):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing the editor assembly widget containing the navigation combos and
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 the editor widget.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def __init__(self, dbs, fn=None, vm=None, filetype="", editor=None, tv=None):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param dbs reference to the debug server object
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @param fn name of the file to be opened (string). If it is None,
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 a new (empty) editor is opened
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @param vm reference to the view manager object (ViewManager.ViewManager)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param filetype type of the source file (string)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @param editor reference to an Editor object, if this is a cloned view
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param tv reference to the task viewer object
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 super().__init__()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__layout = QGridLayout(self)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__layout.setContentsMargins(0, 0, 0, 0)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.__layout.setSpacing(1)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__globalsCombo = QComboBox()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.__membersCombo = QComboBox()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.__editor = Editor(dbs, fn, vm, filetype, editor, tv)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__layout.addWidget(self.__globalsCombo, 0, 0)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.__layout.addWidget(self.__membersCombo, 0, 1)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.__layout.addWidget(self.__editor, 1, 0, 1, -1)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__module = None
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__globalsCombo.activated[int].connect(self.__globalsActivated)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__membersCombo.activated[int].connect(self.__membersActivated)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__parseTimer = QTimer(self)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__parseTimer.setSingleShot(True)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__parseTimer.setInterval(5 * 1000)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__parseTimer.timeout.connect(self.__parseEditor)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.__editor.textChanged.connect(self.__resetParseTimer)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 QTimer.singleShot(0, self.__parseEditor)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def getEditor(self):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Public method to get the reference to the editor widget.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @return reference to the editor widget (Editor)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return self.__editor
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def __globalsActivated(self, index):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Private method to jump to the line of the selected global entry and to populate
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 the members combo box.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 @param index index of the selected entry (integer)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 # step 1: go to the line of the selected entry
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 lineno = self.__globalsCombo.itemData(index)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 txt = self.__editor.text(lineno - 1).rstrip()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 pos = len(txt.replace(txt.strip(), ""))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.__editor.gotoLine(lineno, pos if pos == 0 else pos +1)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__editor.setFocus()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 # step 2: populate the members combo, if the entry is a class
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.__membersCombo.clear()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 entryName = self.__globalsCombo.itemText(index)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if self.__module and entryName in self.__module.classes:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 cl = self.__module.classes[entryName]
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 # step 2.1: add class methods
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 items = []
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 for meth in cl.methods.values():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 if meth.modifier == Function.Static:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 icon = UI.PixmapCache.getIcon("method_static.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 elif meth.modifier == Function.Class:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 icon = UI.PixmapCache.getIcon("method_class.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 elif meth.isPrivate():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 icon = UI.PixmapCache.getIcon("method_private.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 elif meth.isProtected():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 icon = UI.PixmapCache.getIcon("method_protected.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 else:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 icon = UI.PixmapCache.getIcon("method.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 items.append((meth.name, icon, meth.lineno))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 for itm in sorted(items):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.__membersCombo.addItem(itm[1], itm[0], itm[2])
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 # step 2.2: add class instance attributes
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 items = []
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 for attr in cl.attributes.values():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 if attr.isPrivate():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 icon = UI.PixmapCache.getIcon("attribute_private.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 elif attr.isProtected():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 icon = UI.PixmapCache.getIcon("attribute_protected.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 else:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 icon = UI.PixmapCache.getIcon("attribute.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 items.append((attr.name, icon, attr.lineno))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 for itm in sorted(items):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.__membersCombo.addItem(itm[1], itm[0], itm[2])
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 # step 2.3: add class attributes
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 items = []
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 icon = UI.PixmapCache.getIcon("attribute_class.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 for glob in cl.globals.values():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 items.append((glob.name, icon, glob.lineno))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 for itm in sorted(items):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 self.__membersCombo.addItem(itm[1], itm[0], itm[2])
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 def __membersActivated(self, index):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 Private method to jump to the line of the selected members entry.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @param index index of the selected entry (integer)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 lineno = self.__membersCombo.itemData(index)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 txt = self.__editor.text(lineno - 1).rstrip()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 pos = len(txt.replace(txt.strip(), ""))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.__editor.gotoLine(lineno, pos if pos == 0 else pos +1)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.__editor.setFocus()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 def __resetParseTimer(self):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 Private slot to reset the parse timer.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 self.__parseTimer.stop()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.__parseTimer.start()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 def __parseEditor(self):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 Private method to parse the editor source and repopulate the globals combo.
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self.__module = None
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 sourceType = getTypeFromTypeName(self.__editor.determineFileType())
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 if sourceType != -1:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 src = self.__editor.text()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 if src:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 fn = self.__editor.getFileName()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 if fn is None:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 fn = ""
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.__module = Module("", fn, sourceType)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self.__module.scan(src)
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.__globalsCombo.clear()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__membersCombo.clear()
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self.__globalsCombo.addItem("")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 # step 1: add classes
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 items = []
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 for cl in self.__module.classes.values():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 if cl.isPrivate():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 icon = UI.PixmapCache.getIcon("class_private.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 elif cl.isProtected():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 icon = UI.PixmapCache.getIcon("class_protected.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 else:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 icon = UI.PixmapCache.getIcon("class.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 items.append((cl.name, icon, cl.lineno))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 for itm in sorted(items):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__globalsCombo.addItem(itm[1], itm[0], itm[2])
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 # step 2: add functions
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 items = []
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 for func in self.__module.functions.values():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 if func.isPrivate():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 icon = UI.PixmapCache.getIcon("method_private.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 elif func.isProtected():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 icon = UI.PixmapCache.getIcon("method_protected.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 else:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 icon = UI.PixmapCache.getIcon("method.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 items.append((func.name, icon, func.lineno))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 for itm in sorted(items):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 self.__globalsCombo.addItem(itm[1], itm[0], itm[2])
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 # step 3: add attributes
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 items = []
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 for glob in self.__module.globals.values():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 if glob.isPrivate():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 icon = UI.PixmapCache.getIcon("attribute_private.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 elif glob.isProtected():
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 icon = UI.PixmapCache.getIcon("attribute_protected.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 else:
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 icon = UI.PixmapCache.getIcon("attribute.png")
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 items.append((glob.name, icon, glob.lineno))
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 for itm in sorted(items):
c1622c708cd9 Added source navigation function for Python 2, Python 3 and Ruby sources.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 self.__globalsCombo.addItem(itm[1], itm[0], itm[2])

eric ide

mercurial