Drawing a rectangle on a panel, then drag it to adjacent panel

Hi,

I have a main panel, which contains a splitter window. Split contains 2 horizontally splitted panels.

I draw a rectangle on the upper panel, with help of wx.WindowDC. Then I try to drag it to the lower panel.

I bind EVT_MOTION event to the upper panel, as user clicks the rectangle on upper panel and keeps left button down, with each movement of mouse, the rectangle is redrawn on the point where mouse is. So this creates a dragging effect.

The problem is: when mouse leaves upper panel and enters lower panel, the rectangle cannot be drawn on the lower panel (although the arrow is on the lower panel). The lowest point where the rectangle can be drawn is the lowest area of upper panel.

I think this is because the EVT_MOTION is binded to upper panel, so it cannot calculate the x and y positions of the lower panel.

Do you have any idea how to make the rectangle be drawn outside upper panel?

I draw a rectangle on the upper panel, with help of wx.WindowDC. Then I
try to drag it to the lower panel.

I bind EVT_MOTION event to the upper panel, as user clicks the rectangle
on upper panel and keeps left button down, with each movement of mouse, the
rectangle is redrawn on the point where mouse is. So this creates a
dragging effect.

The problem is: when mouse leaves upper panel and enters lower panel, the
rectangle cannot be drawn on the lower panel (although the arrow is on the
lower panel). The lowest point where the rectangle can be drawn is the
lowest area of upper panel.

I think this is because the EVT_MOTION is binded to upper panel, so it
cannot calculate the x and y positions of the lower panel

you need to use CaptureMouse() so that mouse events will continue to be
sent to the original Window.

then you'll need to figure out how to draw the rect in the lower panel.

You can only draw to one Window with a DC, so you'll need to "pass off" the
drawing to the new Panel.

Or maybe catch teh EVT_ENTER in the second panel, and then use some shared
state to start drawing the rect in the new panel.

Essentially, you'll need to draw two rects -- one in each panel, each one
will only show the part that is in its own panel.

However, this seems like a pretty ugly way to do it.

Is there a way you can keep the rect all in one Panel? I suspect you may be
using two wxPanels when you really could use one, and do some custom
drawing to make it look like two.

Maybe a full description of what you are trying to achieve and we could
help you figure out an easier architecture.

BTW, if you download:

there is a lot in there that might give you ideas.

-Chris

···

On Tue, Oct 25, 2016 at 11:26 AM, steve <oslocourse@gmail.com> wrote:

Do you have any idea how to make the rectangle be drawn outside upper
panel?

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

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

One trick that works quite well is to overlay the entire window with a
single panel containing a bitmap with a screen shot of the entire window
- much simpler than two elastic bands (rectangles) at a time. This can
be extended to allow elastic banding the entire screen if desired.

···

On 25/10/2016 22:22, Chris Barker wrote:

On Tue, Oct 25, 2016 at 11:26 AM, steve <oslocourse@gmail.com > <mailto:oslocourse@gmail.com>> wrote:

    I draw a rectangle on the upper panel, with help of wx.WindowDC.
    Then I try to drag it to the lower panel.
     
    I bind EVT_MOTION event to the upper panel, as user clicks the
    rectangle on upper panel and keeps left button down, with each
    movement of mouse, the rectangle is redrawn on the point where mouse
    is. So this creates a dragging effect.
     
    The problem is: when mouse leaves upper panel and enters lower
    panel, the rectangle cannot be drawn on the lower panel (although
    the arrow is on the lower panel). The lowest point where the
    rectangle can be drawn is the lowest area of upper panel.
     
    I think this is because the EVT_MOTION is binded to upper panel, so
    it cannot calculate the x and y positions of the lower panel

you need to use CaptureMouse() so that mouse events will continue to be
sent to the original Window.

then you'll need to figure out how to draw the rect in the lower panel.

You can only draw to one Window with a DC, so you'll need to "pass off"
the drawing to the new Panel.

Or maybe catch teh EVT_ENTER in the second panel, and then use some
shared state to start drawing the rect in the new panel.

Essentially, you'll need to draw two rects -- one in each panel, each
one will only show the part that is in its own panel.

However, this seems like a pretty ugly way to do it.

Is there a way you can keep the rect all in one Panel? I suspect you may
be using two wxPanels when you really could use one, and do some custom
drawing to make it look like two.

Maybe a full description of what you are trying to achieve and we could
help you figure out an easier architecture.

BTW, if you download:

GitHub - PythonCHB/wxPythonDemos: wxPython Demos: Various small demos of wxPython features -- dveloped over years of discussion on the wxPython-users mailinglist

there is a lot in there that might give you ideas.

-Chris

    Do you have any idea how to make the rectangle be drawn outside
    upper panel?

    --
    You received this message because you are subscribed to the Google
    Groups "wxPython-users" group.
    To unsubscribe from this group and stop receiving emails from it,
    send an email to wxpython-users+unsubscribe@googlegroups.com
    <mailto:wxpython-users+unsubscribe@googlegroups.com>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout&gt;\.

--

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 <mailto:Chris.Barker@noaa.gov>

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-users+unsubscribe@googlegroups.com
<mailto:wxpython-users+unsubscribe@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.

Hi Chris,

I don’t know how to use CaptureMouse(). Will this bind EVT_MOTION event to lower panel ? Could you please be more specific?

Best Regards

···

On Wednesday, October 26, 2016 at 12:23:04 AM UTC+3, Chris Barker wrote:

On Tue, Oct 25, 2016 at 11:26 AM, steve osloc...@gmail.com wrote:

I draw a rectangle on the upper panel, with help of wx.WindowDC. Then I try to drag it to the lower panel.

I bind EVT_MOTION event to the upper panel, as user clicks the rectangle on upper panel and keeps left button down, with each movement of mouse, the rectangle is redrawn on the point where mouse is. So this creates a dragging effect.

The problem is: when mouse leaves upper panel and enters lower panel, the rectangle cannot be drawn on the lower panel (although the arrow is on the lower panel). The lowest point where the rectangle can be drawn is the lowest area of upper panel.

I think this is because the EVT_MOTION is binded to upper panel, so it cannot calculate the x and y positions of the lower panel

you need to use CaptureMouse() so that mouse events will continue to be sent to the original Window.

then you’ll need to figure out how to draw the rect in the lower panel.

You can only draw to one Window with a DC, so you’ll need to “pass off” the drawing to the new Panel.

Or maybe catch teh EVT_ENTER in the second panel, and then use some shared state to start drawing the rect in the new panel.

Essentially, you’ll need to draw two rects – one in each panel, each one will only show the part that is in its own panel.

However, this seems like a pretty ugly way to do it.

Is there a way you can keep the rect all in one Panel? I suspect you may be using two wxPanels when you really could use one, and do some custom drawing to make it look like two.

Maybe a full description of what you are trying to achieve and we could help you figure out an easier architecture.

BTW, if you download:

https://github.com/PythonCHB/wxPythonDemos

there is a lot in there that might give you ideas.

-Chris

Do you have any idea how to make the rectangle be drawn outside upper panel?

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

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....@noaa.gov

Hi Chris,

I don't know how to use CaptureMouse(). Will this bind EVT_MOTION event to
lower panel ? Could you please be more specific?

no -- it will allow the top panel (or whichever you call it on) to continue
to get mouse messages after teh mouse leaves the Window.

BUt that's not going to help as much as I thought (now that I"ve thought a
bit more). I really think there is probably a better way to accomplish what
you want, but we don't know what your goals are.

However, if you realyl need to do it, I think I"d do it this way:

In BOTH of your Windows, bind the ouse movement events.

when the user starts to draw a rect (mouse down, or???) set some state
shared bewteen the two panels:

self.rect_start_pos (or whatever)

on teh mouse movement events (in both panels): update the shared state:

self.current_mouse_position

draw the rect in both panels.

(note that you are going to need to do some coordinate transformation to
get the coords right in both panels.

when the rect is overlapping the panels -- each panel will draw its half of
the rect, so it will look like one rect. AT least if you get the coordinate
mapping right :slight_smile:

-CHB

···

On Wed, Oct 26, 2016 at 4:32 AM, steve <oslocourse@gmail.com> wrote:

Best Regards

On Wednesday, October 26, 2016 at 12:23:04 AM UTC+3, Chris Barker wrote:

On Tue, Oct 25, 2016 at 11:26 AM, steve <osloc...@gmail.com> wrote:

I draw a rectangle on the upper panel, with help of wx.WindowDC. Then I
try to drag it to the lower panel.

I bind EVT_MOTION event to the upper panel, as user clicks the rectangle
on upper panel and keeps left button down, with each movement of mouse, the
rectangle is redrawn on the point where mouse is. So this creates a
dragging effect.

The problem is: when mouse leaves upper panel and enters lower panel,
the rectangle cannot be drawn on the lower panel (although the arrow is on
the lower panel). The lowest point where the rectangle can be drawn is the
lowest area of upper panel.

I think this is because the EVT_MOTION is binded to upper panel, so it
cannot calculate the x and y positions of the lower panel

you need to use CaptureMouse() so that mouse events will continue to be
sent to the original Window.

then you'll need to figure out how to draw the rect in the lower panel.

You can only draw to one Window with a DC, so you'll need to "pass off"
the drawing to the new Panel.

Or maybe catch teh EVT_ENTER in the second panel, and then use some
shared state to start drawing the rect in the new panel.

Essentially, you'll need to draw two rects -- one in each panel, each one
will only show the part that is in its own panel.

However, this seems like a pretty ugly way to do it.

Is there a way you can keep the rect all in one Panel? I suspect you may
be using two wxPanels when you really could use one, and do some custom
drawing to make it look like two.

Maybe a full description of what you are trying to achieve and we could
help you figure out an easier architecture.

BTW, if you download:

GitHub - PythonCHB/wxPythonDemos: wxPython Demos: Various small demos of wxPython features -- dveloped over years of discussion on the wxPython-users mailinglist

there is a lot in there that might give you ideas.

-Chris

Do you have any idea how to make the rectangle be drawn outside upper
panel?

--
You received this message because you are subscribed to the Google
Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to wxpython-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

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....@noaa.gov

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

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