how to detect mouse release outside of frame

I'm writing my own drag and drop functionality because the DnD
provided i Python is not suiting my needs.

I need to detect when the user releases the mouse in an invalid place,
any ideas?

What I may end up trying is to create a singleton class, which I will
empty and rewrite the drag object data to whenenver on mouse-down of a
dragable object. Then just handle mouse-up in valid containers and
check to see if the singleton has any data to be copied.

-Adam

Adam Fraser wrote:

I'm writing my own drag and drop functionality because the DnD
provided i Python is not suiting my needs.

I need to detect when the user releases the mouse in an invalid place,
any ideas?

What I may end up trying is to create a singleton class, which I will
empty and rewrite the drag object data to whenenver on mouse-down of a
dragable object. Then just handle mouse-up in valid containers and
check to see if the singleton has any data to be copied.

-Adam

If you're talking about DnD within your own program, you should be able to detect wherever your mouse is using GetPosition. If instead, you're talking about DnD outside of your own program, I think it's more of an OS-API thing. Either way, I don't know much about it. If you're on Windows, than you'd best ask on the PyWin32 user's group:

http://mail.python.org/mailman/listinfo/python-win32

They'll be able to tell you if it's possible and what you can and cannot do. I'm sure there are user groups for the other OS's as well...

Mike

Thanks mike,

The DnD is within the app so it's not too complicated.

My main concern is I want to change the cursor (or attach something to
it), but I'll need to know when to remove that. It's obvious on a
valid drop, but when dropping outside of the program, I want it to
reset itself.

···

On Mon, Oct 6, 2008 at 4:55 PM, Mike Driscoll <mike@pythonlibrary.org> wrote:

Adam Fraser wrote:

I'm writing my own drag and drop functionality because the DnD
provided i Python is not suiting my needs.

I need to detect when the user releases the mouse in an invalid place,
any ideas?

What I may end up trying is to create a singleton class, which I will
empty and rewrite the drag object data to whenenver on mouse-down of a
dragable object. Then just handle mouse-up in valid containers and
check to see if the singleton has any data to be copied.

-Adam

If you're talking about DnD within your own program, you should be able to
detect wherever your mouse is using GetPosition. If instead, you're talking
about DnD outside of your own program, I think it's more of an OS-API thing.
Either way, I don't know much about it. If you're on Windows, than you'd
best ask on the PyWin32 user's group:

python-win32 Info Page

They'll be able to tell you if it's possible and what you can and cannot do.
I'm sure there are user groups for the other OS's as well...

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

Adam Fraser wrote:

Thanks mike,

The DnD is within the app so it's not too complicated.

My main concern is I want to change the cursor (or attach something to
it), but I'll need to know when to remove that. It's obvious on a
valid drop, but when dropping outside of the program, I want it to
reset itself.
  
I know you can detect when the mouse has left the frame. I'm not sure if you can tell if one of the mouse buttons is depressed when the mouse comes back into your frame. If you can, then this should be easy. Something along the lines of "if btnDown: pass; else resetCursor". Maybe one of the other gurus here knows about that?

- Mike

···

On Mon, Oct 6, 2008 at 4:55 PM, Mike Driscoll <mike@pythonlibrary.org> wrote:
  

Adam Fraser wrote:
    

I'm writing my own drag and drop functionality because the DnD
provided i Python is not suiting my needs.

I need to detect when the user releases the mouse in an invalid place,
any ideas?

What I may end up trying is to create a singleton class, which I will
empty and rewrite the drag object data to whenenver on mouse-down of a
dragable object. Then just handle mouse-up in valid containers and
check to see if the singleton has any data to be copied.

-Adam
      

If you're talking about DnD within your own program, you should be able to
detect wherever your mouse is using GetPosition. If instead, you're talking
about DnD outside of your own program, I think it's more of an OS-API thing.
Either way, I don't know much about it. If you're on Windows, than you'd
best ask on the PyWin32 user's group:

python-win32 Info Page

They'll be able to tell you if it's possible and what you can and cannot do.
I'm sure there are user groups for the other OS's as well...

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

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

Hi All,

···

On Tue, Oct 7, 2008 at 4:12 PM, Mike Driscoll wrote:

Adam Fraser wrote:

Thanks mike,

The DnD is within the app so it's not too complicated.

My main concern is I want to change the cursor (or attach something to
it), but I'll need to know when to remove that. It's obvious on a
valid drop, but when dropping outside of the program, I want it to
reset itself.

I know you can detect when the mouse has left the frame. I'm not sure if you
can tell if one of the mouse buttons is depressed when the mouse comes back
into your frame. If you can, then this should be easy. Something along the
lines of "if btnDown: pass; else resetCursor". Maybe one of the other gurus
here knows about that?

You might try something like this:

wx.GetMouseState().LeftDown()

To check for the mouse state.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Thanks so much! Hopefully that'll cover me for DnD.
-Adam

···

On Tue, Oct 7, 2008 at 11:18 AM, Andrea Gavana <andrea.gavana@gmail.com> wrote:

Hi All,

On Tue, Oct 7, 2008 at 4:12 PM, Mike Driscoll wrote:

Adam Fraser wrote:

Thanks mike,

The DnD is within the app so it's not too complicated.

My main concern is I want to change the cursor (or attach something to
it), but I'll need to know when to remove that. It's obvious on a
valid drop, but when dropping outside of the program, I want it to
reset itself.

I know you can detect when the mouse has left the frame. I'm not sure if you
can tell if one of the mouse buttons is depressed when the mouse comes back
into your frame. If you can, then this should be easy. Something along the
lines of "if btnDown: pass; else resetCursor". Maybe one of the other gurus
here knows about that?

You might try something like this:

wx.GetMouseState().LeftDown()

To check for the mouse state.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Adam Fraser wrote:

I know you can detect when the mouse has left the frame. I'm not

sure if you

can tell if one of the mouse buttons is depressed when the mouse

comes back

into your frame.

You might want to try doing a wx.Window.CaptureMouse() at the start of
your drag, and a ReleaseMouse() on the up event at the "drop"

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Using wx.Window.CaptureMouse() was a good suggestion. I capture the
mouse on LEFT_DOWN on a draggable object, and release it on LEFT_UP.
This solves the problem of not being able to detect when the mouse is
released outside of a valid drop target.

However, now I can't capture drop (LEFT_UP) events on the drop targets
because the dragged object catches it.

Using evt.Skip on the LEFT_UP handler for the drag object (the object
the captured the mouse), doesn't work to propagate the event to the
target it is being dropped in.

Suppose I capture the mouse instead with the base frame. How could I
then check if LEFT_UP events occur within a particular container
(panel)?

-Adam

···

On Tue, Oct 7, 2008 at 12:32 PM, Christopher Barker <Chris.Barker@noaa.gov> wrote:

Adam Fraser wrote:

I know you can detect when the mouse has left the frame. I'm not

sure if you

can tell if one of the mouse buttons is depressed when the mouse

comes back

into your frame.

You might want to try doing a wx.Window.CaptureMouse() at the start of
your drag, and a ReleaseMouse() on the up event at the "drop"

-Chris
--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Adam Fraser wrote:

Using wx.Window.CaptureMouse() was a good suggestion. I capture the
mouse on LEFT_DOWN on a draggable object, and release it on LEFT_UP.
This solves the problem of not being able to detect when the mouse is
released outside of a valid drop target.

However, now I can't capture drop (LEFT_UP) events on the drop targets
because the dragged object catches it.

Using evt.Skip on the LEFT_UP handler for the drag object (the object
the captured the mouse), doesn't work to propagate the event to the
target it is being dropped in.

Suppose I capture the mouse instead with the base frame. How could I
then check if LEFT_UP events occur within a particular container
(panel)?

Convert the position from coordinates relative to the frame into coordinates relative to the panel, and see if it is within the width and height of the panel. If you have more than one panel then check them all and see which (if any) it is within. The ClientToScreen and ScreenToClient methods will help.

···

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