[wxPython] OnSize-ing

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] OnSize-ing

Gary Strangman

Hi all,

I appear to have uncovered a conceptual confusion on my part with regard
to handling SizeEvents in wxPython (Python1.5.2, wxPython2.1b2, WinNT4).
I'm trying to create a frame (containing multiple sub-frames) that, when
resized by the user, retains the original aspect ratio of this main
(outermost) frame.  My inital attempts to do this, using an EVT_SIZE
macro, have all resulted in infinite callbacks until the program seizes.
My attempt to handle the event was essentially the following:

class myframe(wxFrame):
    ...
    def __init__(self,...):
        ...
        self.aspectratio = 1.2
        self.winwidth = 400
        self.winheight = int(self.winsize*self.aspectratio)
        self.SetSize(wxSize(self.winwidth,self.winheight))
        EVT_SIZE(self, self.OnSize)

    def OnSize(self,event):
        size = event.GetSize()
        if ((size.x > self.winwidth and size.y > self.winheight) or (size.x < self.winwidth and size.y < self.winheight)):
            self.winwidth = size.x
            self.winheight = size.x*self.aspectratio
        self.SetSize(wxSize(self.winwidth,self.winheight*1.25))
        event.Skip()

I'm guessing the self.SetSize() in my OnSize method creates my infinite
loop of callbacks.  Either that, or the existence of other
subframes/panels that need to be sized cause the problem.  Regardless, I
think my question should be, how do I _change_ a resize event instead of
generating a new one?  I essentially want to change a user's
probably-not-aspect-ratio-preserving SizeEvent into a SetSize command that
is aspect-ratio preserving.  Or maybe there's a better (read:  easier) way
of "tidying up" an "imperfect" SizeEvent.  I'm afraid my problem lies in
my weak understanding of which element(s) generate callbacks to/from whom
during a SizeEvent.

Anyone able to help me out?

Cheers,
Gary


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] OnSize-ing

Robin Dunn
> Hi all,
>
> I appear to have uncovered a conceptual confusion on my part with regard
> to handling SizeEvents in wxPython (Python1.5.2, wxPython2.1b2, WinNT4).
> I'm trying to create a frame (containing multiple sub-frames) that, when
> resized by the user, retains the original aspect ratio of this main
> (outermost) frame.  My inital attempts to do this, using an EVT_SIZE
> macro, have all resulted in infinite callbacks until the program seizes.
> My attempt to handle the event was essentially the following:
>

Probably the easiest thing in this case is to just prevent the contents of
your OnSize from executing recursivly.  Something like:

def OnSize(self, event):
    if self.doingOnSize:
        return
    self.doingOnSize = true

    # do your resizing stuff here

    self.doingOnSize = false


A more elegant solution might be possible with Layout Constraints, and then
you won't need to have an OnSize at all.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

[wxPython] Focus?

Gary Strangman

Hi again,

I'm encountering odd (in my opinion) behaviors from my wxPython app.  I
have a frame containing (1) a window (filled with a glcanvas) and (2) a
panel (containing a scrollbar, textctrl and 2 buttons--play-movie, and
stop-movie).  I've set the focus on the window and am capturing keyboard
events there.  About half of the time, everything works fine ... pressing
the play button animates my movie (via a wxTimer) and pressing stop stops
the animation (timer.Stop()).  However, the other half of the time, one of
two situations occur ...

1)  Sometimes, pressing stop _doesn't_ stop my movie (it apparently
doesn't even generate a button-event; or at least it never reaches the
destination of my EVT_BUTTON constructor).  Pressing the stop button
repeatedly (esp. quickly) eventually generates a stop-event and stops the
movie.  Sometimes it takes 2 clicks, sometimes 10-ish.

2)  The other situation is that the play/stop buttons continue to work,
but keyboard events cease being captured.  Usually, hiding the window
(i.e., selecting another program) and then re-selecting the wxPython app
restores the keyboard capturing.

The problem is an interaction ... the buttons work without key-capturing
key, and key-capturing works without the buttons.  Any guesses anyone?
E.g., does SetFocus() affect more than key events?

Gary


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Focus?

Harri Pasanen


Gary Strangman wrote:

>
> Hi again,
>
> I'm encountering odd (in my opinion) behaviors from my wxPython app.  I
> have a frame containing (1) a window (filled with a glcanvas) and (2) a
> panel (containing a scrollbar, textctrl and 2 buttons--play-movie, and
> stop-movie).  I've set the focus on the window and am capturing keyboard
> events there.  About half of the time, everything works fine ... pressing
> the play button animates my movie (via a wxTimer) and pressing stop stops
> the animation (timer.Stop()).  However, the other half of the time, one of
> two situations occur ...
>
> 1)  Sometimes, pressing stop _doesn't_ stop my movie (it apparently
> doesn't even generate a button-event; or at least it never reaches the
> destination of my EVT_BUTTON constructor).  Pressing the stop button
> repeatedly (esp. quickly) eventually generates a stop-event and stops the
> movie.  Sometimes it takes 2 clicks, sometimes 10-ish.
>

My guess it that you are running on MW-Windows?

Windows is free to toss out UI event messages if it thinks it is too
busy doing other things. I would venture a guess that this is what is
happening in your case.

Can you try this on faster/slower machine to see if this is the case?

Just guessing here,

Harri

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users