here's a snippet of wxTreeCtrl with list-based populator
(just a portion of the code, to give you some of my idea).
In this case, I have tuple of data and text value (ie:
'dlgSampleDialogXrc','Normal dialog with XRC') as leaf item.
the data portion, is hidden from view, and used internally
to display assigned icon (assigned from wxImageList -- not
shown), and proper action when double-clicked (ie, for www,
the rest of the string is considered a URL, which when
clicked, open up web browser).
nav = [
['fld','Samples',
[
['wwwhttp://www.Google.com','Link to website'],
['dlgSampleDialogXrc','Normal dialog with XRC'],
['dlgSampleDialog','Normal dialog without XRC'],
['frmSampleFrameXrc','Normal frame with XRC'],
['frmSampleFrame','Normal frame without XRC'],
]
],
['fld','Basic Services',
[
['tbwMp3','Mp3 Client'],
['frmIsoCode','ISO Code Definition'],
['tbwSysSequences','Sys Sequences'],
['frmSysSequences','Sys Sequences'],
['tbwCurrencyAll','Currency (All)'],
['tbwCompanyParam','Application Parameters'],
]
],
]
class MyTreeCtrl(wx.TreeCtrl):
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.TR_HAS_BUTTONS | wx.TR_SINGLE):
wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
self.stack = []
def populate(self,navtree):
self._plant_tree(self.stack,navtree)
self.Expand(self.stack[-1])
def _plant_tree(self,parent,tree):
"""internal funtion to recursively parse _tree module into wxtree's item
"""
for element in tree:
# item type depend on first 3 letters
type = element[0][0:3]
if type == 'fld': #folder!
# create parent
parent.append(self.AppendItem(parent[-1], element[1]))
self.SetItemImage(parent[-1], self.icons['folder'], wx.TreeItemIcon_Normal)
self.SetItemImage(parent[-1], self.icons['folder_open'], wx.TreeItemIcon_Expanded)
children = element[2]
self._plant_tree(parent,children)
parent.pop()
else:
mapdict = dict(frm='frame',tbw='table',www='www',dlg='dialog',rpt='report')
icon = self.icons[mapdict.get(type,'generic')]
data = wx.TreeItemData(element[0]); #set filename as data for this tree item
child = self.AppendItem(parent[-1], element[1], icon, -1, data)
···
--
Best regards,
dody mailto:dody.wijaya2@asp.co.id