Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[a37b2b]: plugins / sourcetags.py Maximize Restore History

Download this file

sourcetags.py    95 lines (77 with data), 3.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'''
This software is licensed under the GPL (GNU General Public License) version 2
as it appears here: http://www.gnu.org/copyleft/gpl.html
It is also included with this archive as `gpl.txt <gpl.txt>`_.
'''
import wx
import todo
columns = ((0, "definiton", 100, 0),)
class SourceTags(wx.Panel):
def __init__(self, parent, stc):
wx.Panel.__init__(self, parent)
self.parent = parent
self.stc = stc
#child control definition
self.taglist = wx.CheckListBox(self, -1, style=wx.LB_SINGLE)
self.results = todo.vTodo(self, columns)
#event binding definition
self.taglist.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckToggle, self.taglist)
self.results.Bind(wx.EVT_LIST_ITEM_SELECTED, self.FindDefinition, self.results)
self.results.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.FindDefinition, self.results)
#layout definition
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.taglist, 1, wx.ALL|wx.EXPAND, 3)
sizer.Add(self.results, 1, wx.ALL|wx.EXPAND, 3)
self.SetSizer(sizer)
#data
self.tags = {}
self.last_tags = []
#tags[name] -> {line:defn, line:defn, ...}
#last_tags -> [name, name, name, ...]
def _sortfcn(self, a, b):
#reversed ordering of number of tags
return cmp(len(self.tags[b]), len(self.tags[a]))
def OnCheckToggle(self, event):
tags = []
for i in xrange(self.taglist.GetCount()):
if self.taglist.IsChecked(i):
tags.append(self.taglist.GetString(i))
tags.sort(self._sortfcn)
self.last_tags = tags[:]
if tags:
results = self.tags[tags.pop()]
while tags:
_results = {}
next = self.tags[tags.pop()]
for i,j in results.iteritems():
if i in next:
_results[i] = j
results = _results
else:
results = self.tags['']
data = [(j,i) for i,j in results.iteritems()]
self.results.setData(data, copy=0)
self.results.SortItems()
def FindDefinition(self, event):
win = self.stc
selected = self.results.GetFirstSelected()
if selected == -1:
return
sel = self.results.data[selected][1]
win.GotoLineS(sel)
def newTags(self, tags):
self.Freeze()
for i in xrange(self.taglist.GetCount()-1, -1, -1):
self.taglist.Delete(i)
self.tags = tags
self.last_tags = [i for i in self.last_tags if i in tags]
checkable = tags.keys()
checkable.sort()
for j in checkable:
if not j:
continue
posn = self.taglist.Append(j)
if j in self.last_tags:
self.taglist.Check(posn, 1)
self.OnCheckToggle(None)
self.Thaw()