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

[82ddff]: plugins / codetree.py Maximize Restore History

Download this file

codetree.py    110 lines (94 with data), 3.8 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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
import wx
import sys
icons = 1
colors = 1
newroot = sys.platform != 'win32'
blue = wx.Colour(0, 0, 200)
red = wx.Colour(200, 0, 0)
green = wx.Colour(0, 200, 0)
D = {'cl':blue,
'de':red,
'cd':green,
'\\l':red,
'\\s':blue,
'#d':green}
class TreeCtrl(wx.TreeCtrl):
def __init__(self, parent, st):
wx.TreeCtrl.__init__(self, parent, -1, style=wx.TR_DEFAULT_STYLE|wx.TR_HAS_BUTTONS|wx.TR_HIDE_ROOT)
if icons:
isz = (16,16)
il = wx.ImageList(isz[0], isz[1])
self.images = [wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz),
wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz),
wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)]
for i in self.images:
il.Add(i)
self.SetImageList(il)
self.il = il
self.SORTTREE = st
self.root = self.AddRoot("Unseen Root")
def OnCompareItems(self, item1, item2):
if self.SORTTREE:
return cmp(self.GetItemData(item1).GetData(),\
self.GetItemData(item2).GetData())
else:
return cmp(self.GetItemData(item1).GetData()[1],\
self.GetItemData(item2).GetData()[1])
class hierCodeTreePanel(wx.Panel):
def __init__(self, root, parent, st):
# Use the WANTS_CHARS style so the panel doesn't eat the Return key.
wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
self.parent = parent
self.root = root
tID = wx.NewId()
self.tree = TreeCtrl(self, st)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.tree, 1, wx.EXPAND)
self.SetSizer(sizer)
#self.tree.Expand(self.root)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate)
def new_hierarchy(self, hier):
self.tree.DeleteAllItems()
if newroot:
#on GTK/Linux, tree.DeleteAllItems() kills the unseen root,
#not so on Windows.
self.tree.root = self.tree.AddRoot("Unseen Root")
root = [self.tree.root]
stk = [hier[:]]
while stk:
cur = stk.pop()
while cur:
name, line_no, leading, children = cur.pop()
item_no = self.tree.AppendItem(root[-1], name)
self.tree.SetPyData(item_no, line_no)
if colors: self.tree.SetItemTextColour(item_no, D.get(name[:2], blue))
if children:
if icons:
self.tree.SetItemImage(item_no, 0, wx.TreeItemIcon_Normal)
self.tree.SetItemImage(item_no, 1, wx.TreeItemIcon_Expanded)
stk.append(cur)
root.append(item_no)
cur = children[:]
elif icons:
self.tree.SetItemImage(item_no, 2, wx.TreeItemIcon_Normal)
self.tree.SetItemImage(item_no, 2, wx.TreeItemIcon_Selected)
self.tree.SortChildren(root[-1])
root.pop()
def OnLeftDClick(self, event):
#pity this doesn't do what it should.
num, win = self.root.getNumWin(event)
win.SetFocus()
def OnActivate(self, event):
num, win = self.root.getNumWin(event)
dat = self.tree.GetItemData(event.GetItem()).GetData()
if dat == None:
return event.Skip()
ln = dat[1]-1
#print ln
#print dir(win)
linepos = win.GetLineEndPosition(ln)
win.EnsureVisible(ln)
win.SetSelection(linepos-len(win.GetLine(ln))+len(win.format), linepos)
win.ScrollToColumn(0)
win.SetFocus()