Event handling in general...

Hey Everyone:

I've been given some great help on this directory listing stuff...but I
think I'm still missing something. And from my problems, I think it
must be something fundamental. I have totally simplified my directory
listing, and have included it it's own class. (See short code snip
below).

All I want to do is see some event happening when I click on the tree
item in my directory listing.

I know these GenericDirCtrl's have treeCtrls in them...is _that_ what
should be handing the events? If that's true, trying to give the
EVT_TREE_ITEM_ACTIVATED 'self' for the first parameter is way off eh?

If anyone can shed some light on this event stuff, in this context, I'd
appreciate it.

Matt

···

-------------------------------------------------

from wxPython.wx import *

DIRID = 50

class GpmDirList(wxPanel):
  def __init__(self, parent):
    wxPanel.__init__(self, parent, -1)

    dir = wxGenericDirCtrl(self, DIRID, size=(200, 200),
style=wxDIRCTRL_DIR_ONLY)
         
    EVT_TREE_ITEM_ACTIVATED(self, DIRID, self.testMe)

  def testMe():
    print("I Changed Directories")

Matt Graham wrote:

I know these GenericDirCtrl's have treeCtrls in them...is _that_ what
should be handing the events? If that's true, trying to give the
EVT_TREE_ITEM_ACTIVATED 'self' for the first parameter is way off eh?

I believe that this is the case. The wxGenericDirCtrl has a method GetTreeCtrl() to get a reference to the embedded tree control; IIRC, you should be able to use that in your EVT_* macros.

Jeff Shannon
Technician/Programmer
Credit International

Matt Graham wrote:

I know these GenericDirCtrl's have treeCtrls in them...is _that_ what
should be handing the events? If that's true, trying to give the
EVT_TREE_ITEM_ACTIVATED 'self' for the first parameter is way off eh?

If anyone can shed some light on this event stuff, in this context, I'd
appreciate it.

    dir = wxGenericDirCtrl(self, DIRID, size=(200, 200),
style=wxDIRCTRL_DIR_ONLY)
             EVT_TREE_ITEM_ACTIVATED(self, DIRID, self.testMe)

You have to give the ID of the control generating the event in order to catch it. Since the wxGenericDirCtrl has the wxTreeCtrl within it (not derived from it) then you need to use it's ID. So something like this:

     EVT_TREE_ITEM_ACTIVATED(self, dir.GetTreeCtrl().GetId(), self.testMe)

On the other hand, if this is the only wxTreeCtrl in the entire panel (children, grandchildren, etc.) then you can use -1 as a wildcard ID:

     EVT_TREE_ITEM_ACTIVATED(self, -1, self.testMe)

···

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

Hi,

I know these GenericDirCtrl's have treeCtrls in them...is _that_ what
should be handing the events? If that's true, trying to give the
EVT_TREE_ITEM_ACTIVATED 'self' for the first parameter is way off eh?

I'm still on the learning curve too but besides the GetTreeCtrl() method to
get the actual control, your event handling method is not bound to the
instance (which you've probably discovered by now). This works:

class GpmDirList(wxPanel):
def __init__(self, parent):
  wxPanel.__init__(self, parent, -1)

  dir = wxGenericDirCtrl(self, DIRID, size=(200,
200),style=wxDIRCTRL_DIR_ONLY)
  treeCtrl = dir.GetTreeCtrl()

  EVT_TREE_ITEM_ACTIVATED(self, treeCtrl.GetId(), self.testMe)

def testMe( self, evt ):
  print("I Changed Directories")

Man, I was really scratching my head on that one. I was fooling with
the GetTreeCtrl. What I was missing was the .GetId, in the EVT_.

That works great in my app.

Matt

···

On Mon, 2003-02-17 at 15:39, Rick King wrote:

Hi,
> I know these GenericDirCtrl's have treeCtrls in them...is _that_ what
> should be handing the events? If that's true, trying to give the
> EVT_TREE_ITEM_ACTIVATED 'self' for the first parameter is way off eh?
>

I'm still on the learning curve too but besides the GetTreeCtrl() method to
get the actual control, your event handling method is not bound to the
instance (which you've probably discovered by now). This works:

class GpmDirList(wxPanel):
def __init__(self, parent):
  wxPanel.__init__(self, parent, -1)

  dir = wxGenericDirCtrl(self, DIRID, size=(200,
200),style=wxDIRCTRL_DIR_ONLY)
  treeCtrl = dir.GetTreeCtrl()

  EVT_TREE_ITEM_ACTIVATED(self, treeCtrl.GetId(), self.testMe)

def testMe( self, evt ):
  print("I Changed Directories")

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org