[wxPython] MVCTree and clicking events.

Which version of wxPython are you using? I reported a problem I have using
ver 2.2.5 (with Python 2.0) where it takes a double-right-click (rather than
single right-click) to get the menu to appear. I don't remember which
version the fix was going to be in, though.
You may also want to consider catching the event on RIGHT_UP rather than
RIGHT_DOWN. Using RIGHT_UP allows the user to change their mind, move the
mouse away, and not have a menu pop up every time they click in the tree.

-Ron

···

-----Original Message-----
From: Gareth Walters [mailto:garethw@syd.microforte.com.au]
Sent: Wednesday, October 10, 2001 9:26 PM
To: wxpython-users@lists.wxwindows.org
Subject: [wxPython] MVCTree and clicking events.

G'day all,

I am in the process of switching a wxPython app of mine from
using wxTreeCtrl to MVCTree and I have hit a bit of a stumbling block.

I have a module that contains the data that the MVCTree is representing and
a
TreeModel thats working to some extent.
What I would like to do is associate a pop up menu with each of the nodes
based on some of the methods in the classes represented by each of the
nodes, however I cannot work out how to get the right click event processed
correctly.

I tried creating a tree class of my own (derived from MVCTree) with an
EVT_RIGHT_DOWN handler
but this event is never caught by this handler.

I really don't have any idea where this should go, did I do the right thing
and just stuff it up
or have I got this all wrong?

This is the code fragment......

class MyTree( wxMVCTree ):
def __init__( self,parent ):
  wxMVCTree.__init__( self,parent, -1 )
  EVT_RIGHT_DOWN(self, self.onRightClick)

def onRightClick(self, event):
  print "got a Right CLICK"
  node = self.GetSelection()
  popmenu = wxMenu("")
    for method in node.publicMethods:
        print "adding->", method.__name__
        reuseId = addMenu(popmenu,method.__name__,method.__name__,method)
        self.PopupMenu(popmenu,event.GetPosition())

TIA

----Gareth Walters

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Which version of wxPython are you using? I reported a problem I have using
ver 2.2.5 (with Python 2.0) where it takes a double-right-click (rather

than

single right-click) to get the menu to appear. I don't remember which
version the fix was going to be in, though.

wxPython 2.3.1 on Python 2.1 on LINUX and WIN2k

You may also want to consider catching the event on RIGHT_UP rather than
RIGHT_DOWN. Using RIGHT_UP allows the user to change their mind, move the
mouse away, and not have a menu pop up every time they click in the tree.

Good idea, thanks.

The problem is not in the way the mouse events are handled, I just don't
seem to be able to
to catch and event or know wher I should (conseptually or practically) be
trying to do this.

---Gareth Walters

···

----- Original Message -----
From: "CLARKE,RON (HP-Vancouver,ex1)" <ron_clarke@hp.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, October 12, 2001 12:42 AM
Subject: RE: [wxPython] MVCTree and clicking events.

The problem is not in the way the mouse events are handled, I just don't
seem to be able to
to catch and event or know wher I should (conseptually or practically) be
trying to do this.

I'm not that familiar with the MVCTree so I may be off in left field, but
after a quick peek it looks like all mouse events are caught by
wxMVCTree.OnMouse which hands them off to the Painter's OnMouse. That gives
you a couple places to intercept them in a derived class and preprocess
before the tree's default behaviour does it's thing.

···

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

I'm not that familiar with the MVCTree so I may be off in left field, but
after a quick peek it looks like all mouse events are caught by
wxMVCTree.OnMouse which hands them off to the Painter's OnMouse. That

gives

you a couple places to intercept them in a derived class and preprocess
before the tree's default behaviour does it's thing.

Thanks Robin,thats what I suspected but, how precisely do I do this, I tried
the following

class myTree( wxMVCTree ):
    def __init__( self,parent ):
        #wxMVCTree.__init__( self,parent, -1)
          EVT_RIGHT_UP( self, self.onRightClick )
          wxMVCTree.__init__(
self,parent, -1,None,None,None,myPainter(self) )

def onRightClick(self, event):
    print "got a Right CLICK"

and got the following error

  File "sccam.py", line 86, in __init__
    EVT_RIGHT_UP( self, self.onRightClick )
  File "d:\program files\python21\wxPython\wx.py", line 997, in EVT_RIGHT_UP
    win.Connect(-1, -1, wxEVT_RIGHT_UP, func)
  File "d:\program files\python21\wxPython\windows.py", line 52, in Connect
    val = apply(windowsc.wxEvtHandler_Connect,(self,) + _args, _kwargs)
TypeError: Type error in argument 1 of wxEvtHandler_Connect. Expected
_wxEvtHandler_p.

What am I doing wrong?

---Gareth Walter

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, October 12, 2001 9:21 AM
Subject: Re: [wxPython] MVCTree and clicking events.

Thanks Robin,thats what I suspected but, how precisely do I do this, I

tried

the following

class myTree( wxMVCTree ):
    def __init__( self,parent ):
        #wxMVCTree.__init__( self,parent, -1)
          EVT_RIGHT_UP( self, self.onRightClick )
          wxMVCTree.__init__(
self,parent, -1,None,None,None,myPainter(self) )

You'll want to do this last line BEFORE the call to any EVT_* functions. It
looks like you tried that already though, did it not work?

Another approach in this case is that since wxMVCTree is already hooking all
mouse events you could just override it's OnMouse method, something like
this:

    def OnMouse(self, evt):
        if evt.ButtonUp(3):
            print "got a Right CLICK"
        else:
            wxMVCTree.OnMouse(self, evt)

···

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

You'll want to do this last line BEFORE the call to any EVT_* functions.

It

looks like you tried that already though, did it not work?

Correct.

Another approach in this case is that since wxMVCTree is already hooking

all

mouse events you could just override it's OnMouse method, something like
this:

    def OnMouse(self, evt):
        if evt.ButtonUp(3):
            print "got a Right CLICK"
        else:
            wxMVCTree.OnMouse(self, evt)

Ahhhhhh.... :slight_smile:

Thanks again Robin, got it working now.

----G

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, October 12, 2001 1:04 PM
Subject: Re: [wxPython] MVCTree and clicking events.

I take it back (the "I got it working" bit not the thanks :slight_smile:

The problem now is that, the EVT_MENU (methodWrapper)
handler seems to be called when the items are appended
to the menu and NOT when the item is selected from the menu.
What have I done wrong? I have never seen this happen before.

TIA

----Gareth Walters

here is the offending bit of code.

···

______________________
class myTree( wxMVCTree ):
    def __init__( self,parent ):
        wxMVCTree.__init__( self,parent, -1,None,None,None,myPainter(self) )
    def OnMouse(self, event):
        if event.ButtonUp(3):
        print "Got a right Click"
        node = self.GetSelection()[0]

        if not hasattr(node,"popmenu"):
            node.popmenu = wxMenu(node.name)
            for method in node.publicMethods:
            print "adding method->", method.__name__
            node.popmenu.Append(wxNewId(), method.__name__,
                            method.__name__)
            EVT_MENU( node.popmenu, newitem,
                            self.methodWrapper(method))

        self.PopupMenu(node.popmenu,event.GetPosition())
       else:
           self.painter.OnMouse(event)

def methodWrapper( self, method ):
  print method.__name__
___________________________