Differentiate between code-driven and user-driven window resize?

23 views
Skip to first unread message

bht

unread,
May 16, 2013, 11:41:37 AM5/16/13
to wxpytho...@googlegroups.com
I would like to have my wx code detect when a user has resized a Frame (for example, by dragging the Frame border, etc), as opposed to when the window is resized via a call to Sizer.Fit(Frame) or Frame.SetSize(), etc. Is there any way to tell the difference?

David Woods

unread,
May 16, 2013, 11:54:50 AM5/16/13
to wxpytho...@googlegroups.com
The event object has a Dragging() method which should do the trick.

David

bht

unread,
May 16, 2013, 12:09:23 PM5/16/13
to wxpytho...@googlegroups.com

The event object has a Dragging() method which should do the trick.


The EVT_SIZE event does not have that method. I presume the various mouse events do, but how do I correlate a mouse event with a frame event or determine which mouse events are doing a Frame resize?

nepix32

unread,
May 17, 2013, 3:44:59 AM5/17/13
to wxPython-users
On May 16, 6:09 pm, bht <brian.t...@anl.gov> wrote:
> The EVT_SIZE event does not have that method. I presume the various mouse
> events do, but how do I correlate a mouse event with a frame event or
> determine which mouse events are doing a Frame resize?

Try this:

in the method bound to EVT_SIZE:

query for left mouse button down with:

mousevt = wx.GetMouseState()
# print dir(mousevt)
leftdown = mousevt.LeftDown()

leftdown will be True if the border had been dragged or the header had
been double clicked. In other cases like clicking minimize/maximize/
using wx.Frame.SetSize((w, h)) leftdown will be false. This works at
least at Windows.

bht

unread,
May 17, 2013, 11:00:53 AM5/17/13
to wxpytho...@googlegroups.com
Try this:

in the method bound to EVT_SIZE:

query for left mouse button down with:

        mousevt = wx.GetMouseState()
#        print dir(mousevt)
        leftdown = mousevt.LeftDown()

leftdown will be True if the border had been dragged or the header had
been double clicked. In other cases like clicking minimize/maximize/
using wx.Frame.SetSize((w, h)) leftdown will be false. This works at
least at Windows.

I though about this too, but my resize events were generated by a button click and this sometimes captured that button was down from that.

For the benefit of anyone else struggling with this, my eventual solution was to change the button event handler (fortunately there was only one) to Unbind EVT_SIZE before doing any sizing and re-Bind EVT_SIZE again at the end.
Reply all
Reply to author
Forward
0 new messages