New to wxPython, mouse down event goes to wrong panel

I create two panels (A & B) in a frame. Each panel has
a txtControl in the upper left corner. The Panels aorigin is set so that they
overlap. I create panel A first, then B – so in the display it appears
that B is on top of A. Each panel binds to the evt_mouse_down, but call its
own event handler. For the test, which ever panel was clicked write the mouse
position in its tectbox. For debug purposes I also print the message that says
which panel was clicked.

When I run this, if I click on the part of Panel B which overlaps
panel A, panel A handlers responds, and writes the mouse position in its text
box, with respects to its origin. The only way I can get panel B to grab the
event is to click on a part of panel B that does not overlap panel A.

As an aside, on Panel A, if I position the mouse in panel A’s
text box it the cursor changes to text, as it should. But if I position over
the text box in panel B, the cursor remains an arrow.

I am running this on windows XP. IS this normal behavior.
If not, what am I doing wrong???

Here’s the code:

···

import wx

class frame(wx.Frame):

def __init__(self):

    wx.Frame.__init__(self, None, title="test

move",size=(400,400))

    self.panelA =

wx.Panel(self,pos=(20,20),size=(200,200),style=wx.DOUBLE_BORDER)

    self.panelA.Bind(wx.EVT_LEFT_DOWN,

self.OnLeftClickA)

    self.panelA.t1A = wx.TextCtrl(self.panelA, -1,

“panel A”, size=(125, -1))

    self.panelB =

wx.Panel(self,pos=(60,60),size=(200,200),style=wx.DOUBLE_BORDER)

    self.panelB.Bind(wx.EVT_LEFT_DOWN,

self.OnLeftClickB)

    self.panelB.t1B = wx.TextCtrl(self.panelB, -1,

"panel B ", size=(125, -1))

def OnLeftClickA(self, event):

    print "leftclick A"

self.panelA.t1A.SetValue(“A”+str(event.GetPosition()))

def OnLeftClickB(self, event):

    print "Left Click B"

self.panelB.t1B.SetValue(“B”+str(event.GetPosition()))

class App(wx.App):

def OnInit(self):

    myframe = frame()

    myframe.Show()

    return True

if name == ‘main’:

app = App()

app.MainLoop()

Norm

I believe the behavior of overlapping controls is generally undefined.
Is there any particular reason why you are trying to make your controls
overlap? Note that there are numerous sizer classes that can help to
lay out widgets in vari row-based, column-based, row and column based,
wrapping, etc., orientations. If you tell us what you ultimately want
(that isn't dependent on overlapping controls), we could probably help.

- Josiah

···

"Normand Frenette" <frenint@verizon.net> wrote:

I create two panels (A & B) in a frame. Each panel has a txtControl in the
upper left corner. The Panels aorigin is set so that they overlap. I
create panel A first, then B - so in the display it appears that B is on top
of A. Each panel binds to the evt_mouse_down, but call its own event
handler. For the test, which ever panel was clicked write the mouse
position in its tectbox. For debug purposes I also print the message that
says which panel was clicked.

1) Thanks Josiah, do you know of any docs on the subject?

2) I actually am moving from .NET world. I want to port to Python an app
that builds PERT Chart graphically (looks like a flow chart). Each task is
represented by a panel containing various text controls/buttons. The user
can grab and move these task panels around on the "canvas" while the
interconnections move with the task panel and get redrawn. While doing so,
he will often cross over other task panels. I actually had a python
prototype written where I moved the panels (using the mouse motion event and
repositioning the panel by tracking the mouse). When two panels crossed,
sometimes, the mouse events would stop being reported to the task panel that
was moving and start going to the other task panel (that was being crossed
over). (That, I can fix using a hack which would track the ID of what I was
moving).

But if the user stopped dragging a panel that partly covered one other
panel, and then wanted to start the drag again, I would get the funny
behavior described below. If the underlying panel was created first, it
would get the mouse event instead of the panel positioned on top, even when
clicking on the top panel.

While building the little app I originally posted for you to look at, I also
noticed that a text box on the second panel overlapping the first did not
get the focus in the part of the text box that overlapped the first panel.

- Norm

"Normand Frenette" wrote:

I create two panels (A & B) in a frame. Each panel has a txtControl in

the

upper left corner. The Panels aorigin is set so that they overlap. I
create panel A first, then B - so in the display it appears that B is on

top

of A. Each panel binds to the evt_mouse_down, but call its own event
handler. For the test, which ever panel was clicked write the mouse
position in its tectbox. For debug purposes I also print the message that
says which panel was clicked.

I believe the behavior of overlapping controls is generally undefined.
Is there any particular reason why you are trying to make your controls
overlap? Note that there are numerous sizer classes that can help to
lay out widgets in vari row-based, column-based, row and column based,
wrapping, etc., orientations. If you tell us what you ultimately want
(that isn't dependent on overlapping controls), we could probably help.

- Josiah

1) Thanks Josiah, do you know of any docs on the subject?

wx officially does not support overlapping windows, period. Undefined
behavior results when you do so, don't do it.

2) I actually am moving from .NET world. I want to port to Python an app
that builds PERT Chart graphically (looks like a flow chart). Each task is
represented by a panel containing various text controls/buttons. The user
can grab and move these task panels around on the "canvas" while the
interconnections move with the task panel and get redrawn. While doing so,
he will often cross over other task panels. I actually had a python
prototype written where I moved the panels (using the mouse motion event and
repositioning the panel by tracking the mouse). When two panels crossed,
sometimes, the mouse events would stop being reported to the task panel that
was moving and start going to the other task panel (that was being crossed
over). (That, I can fix using a hack which would track the ID of what I was
moving).

The .NET control is almost certainly not implemented using native
windows, but with custom drawing and hittesting using some sort of
canvas class. Take a look at wx.lib.ogl and wx.lib.floatcanvas, you
can see them in in action in the wxPython demo.

If you feel adventurous, writing your own from scratch using
wx.GraphicsContext may be fun.

But if the user stopped dragging a panel that partly covered one other
panel, and then wanted to start the drag again, I would get the funny
behavior described below. If the underlying panel was created first, it
would get the mouse event instead of the panel positioned on top, even when
clicking on the top panel.

While building the little app I originally posted for you to look at, I also
noticed that a text box on the second panel overlapping the first did not
get the focus in the part of the text box that overlapped the first panel.

- Norm

<rest snipped>

···

On 1/15/07, Normand Frenette <frenint@verizon.net> wrote: