Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

Attachment 'SconsTreeView-wx2.8.8.0.py'

Download

   1 from wx import *
   2 import os
   3 import sys
   4 
   5 ID_OPEN=102
   6 
   7 class SconsTreeView(wx.App):
   8   def OnInit(self):
   9     frame = wx.Frame(None, -1, 'Scons tree view')
  10     self.frame=frame
  11     frame.Show(True)
  12     self.SetTopWindow(frame)
  13 
  14     filemenu = wx.Menu()
  15     filemenu.Append(ID_OPEN, '&Open')
  16     menuBar = wx.MenuBar()
  17     menuBar.Append(filemenu, '&File')
  18     frame.SetMenuBar(menuBar)
  19     EVT_MENU(self, ID_OPEN, self.OnOpen)
  20 
  21     self.tree = wx.TreeCtrl(frame)
  22     sizer = wx.BoxSizer(wx.HORIZONTAL)
  23     sizer.Add(self.tree, 1, wx.EXPAND)
  24     frame.SetSizer(sizer)
  25     frame.SetAutoLayout(1)
  26     sizer.Fit(frame)
  27     if (len(sys.argv) > 1):
  28       f = open(sys.argv[1], 'r')
  29       print f
  30       self.Parse(f)
  31     return True
  32 
  33   def OnOpen(self, evt):
  34     dlg = wx.FileDialog(self.frame, "Choose a file", "", "", "*.*", wx.OPEN)
  35     if dlg.ShowModal() == wx.ID_OK:
  36       filename = dlg.GetFilename()
  37       dirname = dlg.GetDirectory()
  38       f = open(os.path.join(dirname, filename), 'r')
  39       self.Parse(f)
  40       f.close()
  41     dlg.Destroy()
  42 
  43   def Parse(self, f):
  44     t = self.tree
  45     t.DeleteAllItems()
  46     for line in f:
  47       if line.startswith('+') and line.find('-') != -1:
  48         lastdepth = line.index('-')/2
  49         nodes = [ t.AddRoot('.') ]
  50         break
  51 
  52     lastnode = nodes[-1]
  53     for line in f:
  54       if line.find('-') == -1:
  55         break
  56       depth=line.index('-')/2
  57       content = line[line.index('-')+1:]
  58       if depth > lastdepth:
  59         nodes.append(lastnode)
  60         lastnode = t.AppendItem(nodes[-1], content)
  61       elif depth < lastdepth:
  62         for i in range(depth, lastdepth):
  63           nodes.pop()
  64         lastnode = t.AppendItem(nodes[-1], content)
  65       else:
  66         lastnode = t.AppendItem(nodes[-1], content)
  67       lastdepth = depth
  68 
  69 app=SconsTreeView(0)
  70 app.MainLoop()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.