Hi,
I have a wxPython newbie question. I am trying to show a wx.TreeCtrl
while using mixin.mixins.VirtualTree to connect the gui to some model.
I have a separate class for the tree model which is populated with
some items when the wx application is started.
I derive the MyTree class from VirtualTree and wx.TreeCtrl and
overwrite the OnGetChildrenCount and OnGetItemText methods. I have
debugged them and they return the correct values. However, no tree
control shows up on the screen. I suppose I am not calling the
__init__ functions correctly since the OnGet... methods in MyTree are
never called. When I call the wx.TreeCtrl.__init__ method in the
MyTree class the program crashes (PyDeadObject). Here is my wx code:
···
-----------------------------------------------------------------------------------------
import wx
from wx.lib.mixins.treemixin import VirtualTree
class TreeFrame(wx.Frame):
def __init__(self, model):
wx.Frame.__init__(self, None, title='wxTree Test Program')
self.model = model
pa_main = wx.Panel(self)
self.tree = MyTree(pa_main, treemodel=model)
self.tree.SetMinSize((150, 300))
szr = wx.BoxSizer(wx.VERTICAL)
szr.Add(self.tree, 1, wx.ALIGN_CENTER)
pa_main.SetSizer(szr)
pa_main.Fit()
szr.SetSizeHints(self)
class MyTree(VirtualTree, wx.TreeCtrl):
def __init__(self, *args, **kwargs):
kwargs['style'] = wx.TR_HIDE_ROOT
self.model = kwargs.pop('treemodel')
super(MyTree, self).__init__(*args, **kwargs)
#wx.TreeCtrl.__init__(self, *args, **kwargs)
def OnGetItemText(self, index):
return self.model.OnGetItemText(index)
def OnGetChildrenCount(self, index):
return self.model.OnGetChildrenCount(index)
class TreeApp(wx.App):
def OnInit(self):
self.model = create_model()
self.view = TreeFrame(self.model)
self.view.Show()
return True
if __name__ == '__main__':
app = TreeApp()
app.MainLoop()
--------------------------------------------------------------------------------------
Has someone an idea of what goes wrong here and can point me in the
right direction?
Thanks in advance
Daniel