Discussion:
[fc] Bind LEFT_CLICK DOWN and LEFT_CLICK_DOWN_MOTION
Nouvelle Collection
11 years ago
Permalink
Hello,

I would like to bind to a Button the fact of :
1) left-clicking-down (this is done successfully with
mybtn.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.OnClick) )
2) but also : motion/hover over the button when the mouse left button is
still clicked down

(Thus, the user can enable 10 buttons quickly by clicking just once on the
first, and then motion over the 9 other buttons while mouse is still
clicked down.... This is faster than clicking 10 times on each button, and
it would be useful for my app).

Do you know how to do 2) with FloatCanvas ?

Best regards, J
Chris Barker
11 years ago
Permalink
On Tue, Feb 18, 2014 at 12:51 AM, Nouvelle Collection <
...
On the left click on your objects, set a flag to True

Bind the left up event on the Canvas:

FC.EVT_LEFT_UP(Canvas, self.OnUp)

in that, set the flag to False

on the object, bind the enter event:

rect.Bind(FC.EVT_FC_ENTER_OBJECT, self.OnEnter)

if the flag is True -- you can set that as a selected object.

See enclosed example ;-)

-Chris
Post by Nouvelle Collection
Best regards, J
_______________________________________________
FloatCanvas mailing list
http://mailman.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas
--
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-***@public.gmane.org
Nouvelle Collection
11 years ago
Permalink
Thanks Chris for answer and example !
Indeed, it works great like this (except if we release the mouse button up
*outside* of the main Frame window : then self.InSelectMode remains "True")

Best regards, J
...
Chris Barker
11 years ago
Permalink
On Wed, Feb 19, 2014 at 3:51 PM, Nouvelle Collection <
Post by Nouvelle Collection
Thanks Chris for answer and example !
Indeed, it works great like this (except if we release the mouse button up
*outside* of the main Frame window : then self.InSelectMode remains "True")
yup, I thought of that later on -- you could:

Use wx.Window.CaptureMouse() to get that event. then you'll want to call
ReleaseMouse() in the Left up event. See:

http://www.wxpython.org/docs/api/wx.Window-class.html#CaptureMouse

-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-***@public.gmane.org
Nouvelle Collection
11 years ago
Permalink
Hi Chris, Thanks for your answer. With your MultiHitDemo.py, I tried to
modify like this :

def OnDown(self, obj):
self.InSelectMode = True
self.CatpureMouse()

but a wx.Frame has no CaptureMouse().

Do you think I should rebuild the whole thing around a wx.Window instead of
a wx.Frame ?

(Then there are some methods that are available for wx.Frame but not
anymore for wx.Window...)

Do you have an idea on this ?

Best, J
...
Chris Barker - NOAA Federal
11 years ago
Permalink
On Feb 20, 2014, at 7:09 AM, Nouvelle Collection <
nouvellecollection-***@public.gmane.org> wrote:

Hi Chris, Thanks for your answer. With your MultiHitDemo.py, I tried to
modify like this :

def OnDown(self, obj):
self.InSelectMode = True
self.CatpureMouse()

Try self.Canvas.CaptureMouse()


but a wx.Frame has no CaptureMouse().

Do you think I should rebuild the whole thing around a wx.Window instead of
a wx.Frame ?

Well, a Frame IS a Window...

But anyway, a FloatCanvas is a Window also...

-Chris




(Then there are some methods that are available for wx.Frame but not
anymore for wx.Window...)

Do you have an idea on this ?

Best, J
...
Nouvelle Collection
11 years ago
Permalink
Hello Chris,

Thank you for your answer.


Try self.Canvas.CaptureMouse()
It works, indeed ! (see attachment)

(I also get Traceback like this :, but maybe this is not very important?,
it works anyway...

Traceback (most recent call last):
File "C:\Users\Silk\Desktop\MultiHitDemo(1).py", line 76, in OnUp
self.Canvas.ReleaseMouse()
File "C:\ProgramData\Anaconda\lib\site-packages\wx-3.0-msw\wx\_core.py",
line 10649, in ReleaseMouse
return _core_.Window_ReleaseMouse(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "!wxMouseCapture::stack.empty()"
failed at ..\..\src\common\wincmn.cpp(3319) in
wxWindowBase::ReleaseMouse(): Releasing mouse capture but capture stack
empty?
)
Post by Chris Barker - NOAA Federal
Well, a Frame IS a Window...
But anyway, a FloatCanvas is a Window also...
That's right, I forgot all these things ! Now everything is clear...

Best regards, J
Chris Barker
11 years ago
Permalink
On Tue, Feb 25, 2014 at 7:04 AM, Nouvelle Collection <
Post by Nouvelle Collection
Post by Chris Barker - NOAA Federal
Try self.Canvas.CaptureMouse()
It works, indeed ! (see attachment)
good to know.
...
well, it works because wxPython drops exceptions in event handlers. But the
"right" thing to do is to check if the Window has the mouse Captured first:

if self.Canvas.HasCapture():
self.Canvas.ReleaseMouse()

kind of klunky. it might be worth writing a little method:
ReleaseIfCaptured()

or something....

-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-***@public.gmane.org
Nouvelle Collection
11 years ago
Permalink
Hello Chris,

Thanks for your answer.
Post by Nouvelle Collection
self.Canvas.ReleaseMouse()
...I get a crash of my application when the mouse is captured, and the
mouse goes *outside* the app.

Have you ever experienced this too?

I'm sure not if I should use wx.MouseCaptureLostEvent, and if so, do you
have an example showing how to use it ? I already read
http://www.wxpython.org/docs/api/wx.MouseCaptureLostEvent-class.html, but
I'm not sure how to implement it.

Best regards, Jo
Nouvelle Collection
11 years ago
Permalink
Sorry for this mail : I finally solved it by capuring mouse *to the parent
panel* :
with self.CaptureMouse() instead of self.Canvas.CaptureMouse(), I don't
get this crash anymore.

Problem closed :)

Jo
Post by Nouvelle Collection
Hello Chris,
Thanks for your answer.
Post by Nouvelle Collection
self.Canvas.ReleaseMouse()
...I get a crash of my application when the mouse is captured, and the
mouse goes *outside* the app.
Have you ever experienced this too?
I'm sure not if I should use wx.MouseCaptureLostEvent, and if so, do you
have an example showing how to use it ? I already read
http://www.wxpython.org/docs/api/wx.MouseCaptureLostEvent-class.html, but
I'm not sure how to implement it.
Best regards, Jo
Chris Barker
11 years ago
Permalink
On Tue, Mar 4, 2014 at 9:00 AM, Nouvelle Collection <
Post by Nouvelle Collection
Post by Nouvelle Collection
self.Canvas.ReleaseMouse()
...I get a crash of my application when the mouse is captured, and the
mouse goes *outside* the app.
Have you ever experienced this too?
no -- this is odd, but I"d guess it is something being out of sync with
Mouse events and Capturing..
Post by Nouvelle Collection
I'm sure not if I should use wx.MouseCaptureLostEvent, and if so, do you
have an example showing how to use it ? I already read
http://www.wxpython.org/docs/api/wx.MouseCaptureLostEvent-class.html, but
I'm not sure how to implement it.
Yes, that does sound like what you need -- but no, I don't have an example.
I don't think that existed back when I was first working with this stuff. I
may take a look, but in the meantime, I'd try making a
simple-as-possible example, and see if it crashes, and if so, and you can't
figure out wx.MouseCaptureLostEvent, post a question to the wxPython list.
I don't think this is FloatCanvas specific.

-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-***@public.gmane.org
Nouvelle Collection
11 years ago
Permalink
Thanks! I'll investigate on this.
...