Hi all,
Is there any sample implementation or docs on wxGenericDirCtrl, I am building a file browser and want to add some basic events like double click and right click menu items.
thanks
Deez
wxGenericDirCtrl and events
wxGenericDirCtrl mouse events not working
I am using wxPython version of GenericDirCtrl and dont appear to be getting the events mentioned below, is there something special that I have to do to make it work??
"""
self.dirTree = wx.GenericDirCtrl(defaultFilter=0, dir='.',
filter='All files (*.*)|*.*|SConstruct files|SConstruct;SConscript|Make files|Makefile|Source files (*.cpp;*.c)|*.cpp;*.c|Header Files (*.hpp;*.h) |*.hpp;*.h',
id=wxID_MAINFRAMEDIRTREE, name='dirTree',
parent=self.spltTreeText, pos=wx.Point(0, 0), size=wx.Size(200,
650), style=wx.DIRCTRL_SHOW_FILTERS | wx.DIRCTRL_3D_INTERNAL)
self.dirTree.Bind(wx.EVT_LEFT_DCLICK, self.OnDirTreeLeftDclick)
self.dirTree.Bind(wx.EVT_RIGHT_DOWN, self.OnDirTreeRightDown)
"""
"""
self.dirTree = wx.GenericDirCtrl(defaultFilter=0, dir='.',
filter='All files (*.*)|*.*|SConstruct files|SConstruct;SConscript|Make files|Makefile|Source files (*.cpp;*.c)|*.cpp;*.c|Header Files (*.hpp;*.h) |*.hpp;*.h',
id=wxID_MAINFRAMEDIRTREE, name='dirTree',
parent=self.spltTreeText, pos=wx.Point(0, 0), size=wx.Size(200,
650), style=wx.DIRCTRL_SHOW_FILTERS | wx.DIRCTRL_3D_INTERNAL)
self.dirTree.Bind(wx.EVT_LEFT_DCLICK, self.OnDirTreeLeftDclick)
self.dirTree.Bind(wx.EVT_RIGHT_DOWN, self.OnDirTreeRightDown)
"""
Hi,
wxGenericDirCtrl is a composite control: there's a wxTreeCtrl buried inside it. Because mouse events don't propagate they never arrive at the wxGenericDirCtrl, so you can't get at treectrl mouse events in the usual way.
There are three possible solutions:
1) I've not tried it, but you can probably use the "Connect" method of grabbing events. I'd suggest trying this if there are only 1 or 2 events that you want to grab, and otherwise you are just using the wxGenericDirCtrl straight.
2) You should be able to push a new derived wxEvtHandler onto the treectrl, and use this to process or redirect as many events as you like.
3) If you are planning on doing lots of clever things to the wxGenericDirCtrl, you will probably want to subclass the treectrl anyway. This is now easy in wx2.6.2 as there is a new protected member function, wxGenericDirCtrl::CreateTreeCtrl(), that allows you to recreate the tree as you wish. So you subclass wxGenericDirCtrl (to allow you to use CreateTreeCtrl()) and replace the old tree with your own, subclassed version MyTreeCtrl. Within MyTreeCtrl you can use an event table to process events as usual.
BTW, I don't know wxPython, so it's just possible that some things may be different there.
HTH,
David
wxGenericDirCtrl is a composite control: there's a wxTreeCtrl buried inside it. Because mouse events don't propagate they never arrive at the wxGenericDirCtrl, so you can't get at treectrl mouse events in the usual way.
There are three possible solutions:
1) I've not tried it, but you can probably use the "Connect" method of grabbing events. I'd suggest trying this if there are only 1 or 2 events that you want to grab, and otherwise you are just using the wxGenericDirCtrl straight.
2) You should be able to push a new derived wxEvtHandler onto the treectrl, and use this to process or redirect as many events as you like.
3) If you are planning on doing lots of clever things to the wxGenericDirCtrl, you will probably want to subclass the treectrl anyway. This is now easy in wx2.6.2 as there is a new protected member function, wxGenericDirCtrl::CreateTreeCtrl(), that allows you to recreate the tree as you wish. So you subclass wxGenericDirCtrl (to allow you to use CreateTreeCtrl()) and replace the old tree with your own, subclassed version MyTreeCtrl. Within MyTreeCtrl you can use an event table to process events as usual.
BTW, I don't know wxPython, so it's just possible that some things may be different there.
HTH,
David