views:

11

answers:

1

Hi, I'm using this control but I can't to handle control click (and others events). This is my code:

class BoExplorerPanel(wx.Panel):
  def __init__(self, parent):
     wx.Panel.__init__(self, parent, wx.ID_ANY)

     self.initComponents() # initialize Window components

  def initComponents(self):
     print "Inizializzo i controlli"
     # controls
     resizeBox = wx.BoxSizer(wx.VERTICAL)

     self.dirBrowser = wx.GenericDirCtrl(self, wx.ID_ANY, style = wx.DIRCTRL_DIR_ONLY)

     resizeBox.Add(self.dirBrowser, 1, wx.EXPAND | wx.ALL)

     self.SetSizerAndFit(resizeBox)

     # events
     self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.dirBrowser_OnItemSelected,   self.dirBrowser)
     self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.dirBrowser_OnRightClick, self.dirBrowser)
     self.Bind(wx.EVT_TREE_SEL_CHANGED, self.dirBrowser_OnSelectionChanged, self.dirBrowser)

     # panel's properties

  def dirBrowser_OnItemSelected(self, event):
     print "CLicked"

  def dirBrowser_OnRightClick(self, event):
     print "Right Click"

  def dirBrowser_OnSelectionChanged(self, event):
     print "Selection Changed"
+1  A: 

You need to bind to the TreeCtrl of the directory class, not that class itself.

Fixed code below. Note the call to event.Skip() in the event handlers (comment it out to see its effect)

#!/usr/bin/python
import wx

class BoExplorerPanel(wx.Frame):
  def __init__(self):
     wx.Frame.__init__(self, None)

     self.initComponents() # initialize Window components

  def initComponents(self):
     print "Inizializzo i controlli"
     # controls
     resizeBox = wx.BoxSizer(wx.VERTICAL)

     self.dirBrowser = wx.GenericDirCtrl(self, wx.ID_ANY, style = wx.DIRCTRL_DIR_ONLY)

     resizeBox.Add(self.dirBrowser, 1, wx.EXPAND | wx.ALL)

     self.SetSizerAndFit(resizeBox)

     # events
     tree = self.dirBrowser.GetTreeCtrl()
     self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.dirBrowser_OnItemSelected, tree)
     self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.dirBrowser_OnRightClick, tree)
     self.Bind(wx.EVT_TREE_SEL_CHANGED, self.dirBrowser_OnSelectionChanged, tree)

     # panel's properties

  def dirBrowser_OnItemSelected(self, event):
     print "CLicked"
     event.Skip()

  def dirBrowser_OnRightClick(self, event):
     print "Right Click"
     event.Skip()

  def dirBrowser_OnSelectionChanged(self, event):
     print "Selection Changed"
     event.Skip()


app = wx.App(False)
f = BoExplorerPanel()
f.Show()
app.MainLoop
Steven Sproat
Ohhhh Thanks :) I have tryed in all manner....thanks.
pyCoder
PS: I can't to vote yet :(
pyCoder