genericDirCtrl

I am hopeing to use genericDirCtrl in my program but I am coming up with a couple of problems. One is that I was hopeing to start where I want to start and I don’t understand what these two lines do (SetPath and SetDefaultPath)

tree.SetPath = “”“c:\dex_tracker”""
tree.SetDefaultPath = “”“c:\dex_tracker”""

The other problem I have is that I have managed to bind a click to it (with an example in a prior post) but I have no idea how to get the filename back out of it so that I can use it… Any help or even additional examples (i.e open source that uses it) would be helpfull… thanks in advance

import wx

def create(parent):
return Frame6(parent)

[wxID_FRAME6, wxID_FRAME6GENERICDIRCTRL1,
] = [wx.NewId() for _init_ctrls in range(2)]

class Frame6(wx.Frame):
def _init_ctrls(self, prnt):
# generated method, don’t edit
wx.Frame.init(self, id=wxID_FRAME6, name=’’, parent=prnt,
pos=wx.Point(572, 281), size=wx.Size(400, 485),
style=wx.DEFAULT_FRAME_STYLE, title=‘Load Instrument’)
self.SetClientSize(wx.Size(392, 451))
self.Bind(wx.EVT_RIGHT_DCLICK, self.OnFrame6RightDclick)

self.genericDirCtrl1 = wx.GenericDirCtrl(defaultFilter=0,
dir=‘dex tracker’, filter=’*.orc’,
id=wxID_FRAME6GENERICDIRCTRL1, name=‘genericDirCtrl1’,
parent=self, pos=wx.Point(0, 0), size=wx.Size(392, 451),
style=wx.DIRCTRL_SELECT_FIRST | wx.DIRCTRL_3D_INTERNAL | wx.SUNKEN_BORDER)
self.genericDirCtrl1.Bind(wx.EVT_LEFT_DCLICK,
self.OnGenericDirCtrl1LeftDclick)
self.genericDirCtrl1.Bind(wx.EVT_RIGHT_DCLICK,
self.OnGenericDirCtrl1RightDclick)

    tree = self.genericDirCtrl1.GetTreeCtrl()
    tree.Bind(wx.EVT_RIGHT_DCLICK,
          self.OnGenericDirCtrl1LeftDclick)
    tree.SetPath = """c:\dex_tracker"""
    tree.SetDefaultPath = """c:\dex_tracker"""

def init(self, parent):
self._init_ctrls(parent)

def OnGenericDirCtrl1LeftDclick(self, event):
#event.Skip()
print(‘was dbl clicked’)

def OnFrame6RightDclick(self, event):
event.Skip()

def OnGenericDirCtrl1RightDclick(self, event):
#event.Skip()
print(‘right dbl click’

eric_dexter@netzero.com wrote:

I am hopeing to use genericDirCtrl in my program but I am coming up with a couple of problems. One is that I was hopeing to start where I want to start and I don't understand what these two lines do (SetPath and SetDefaultPath)

tree.SetPath = """c:\dex_tracker"""
        tree.SetDefaultPath = """c:\dex_tracker"""

You probably want to use self.genericDirCtrl1.SetPath(r"c:\dex_tracker") and self.genericDirCtrl1.SetDefaultPath(r"c:\dex_tracker") otherwise you are just creating new (unused) attributes on the tree object.

The other problem I have is that I have managed to bind a click to it (with an example in a prior post) but I have no idea how to get the filename back out of it so that I can use it.. Any help or even additional examples (i.e open source that uses it) would be helpfull.. thanks in advance

You can use the self.genericDirCtrl1.GetPath() method to get the path for the currently selected item. If you want to do something with an item other than the currently selected one then you can use the treectrl items. IOW, get the text from the leaf item, get it's parent, get the text from that item and join it with that you already have, then get it's parent item, and so on until you get to the root.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!