[wxPython] OnSize called repeatedly (perhaps even recursively?)....

Hello all,

I have a annoying problem with the size handler of a scrolled window...

Firstly, the documentation is adamant that the size in the argument to one's
OnSize method is that of the ENTIRE window, not just it's "client area"
(i.e., an appropriate size to be passed to the SetSize() method of the
wxWindow, and NOT to the SetClientSize() method). However, the following
code, which I mentioned yesterday, produces output which indicates that it
is being called repeatedly, each time with a size which is smaller in both
directions by 6 pixels... {this is part of a wxScrolledWindow-derived
class...}

(Incidentally, before I forget, I'm running wxPython 2.2.2 on Windows 98SE.)

    def OnSize(self, event):
        if hasattr(self,"list") and self.list.ignore_size_events:
            return
        if __debug__:
            Errors.InformationalMessagesWindow("%s.OnSize(width=%d,
height=%d)\n"
                                               % (self,
                                                  event.GetSize().width,
                                                  event.GetSize().height))
        self.SetSize (event.GetSize ())
        if hasattr(self,"list"):
            h = self.list.GetSizeTuple() [1]
            self.list.SetSize (
                (event.GetSize().width,
                 maximum.reduce([h,
                                 event.GetSize().height])))
            self.SetScrollbars(1,1,
                               self.list.GetSizeTuple() [0],
                               h)

HOWEVER, with the
        self.SetSize (event.GetSize ())
changed to
        self.SetClientSize (event.GetSize ())
the output generated is of the form

<C wxScrolledWindow instance at
_afa360_wxScrolledWindow_p>.OnSize(width=515, height=430)

repeated about 1450 times [which I assume means until the program runs out
of memory or some other resource (e.g. stack if this is indeed a recursion
problem)].

Does anyone have any idea where this Later problem comes from? Also, this
seems to indicate an inconsistency in this control's OnSize
event-dispatching, in that the size in the event structure/class is NOT the
size of the entire window... is this a known bug, or the result of something
incorrect in the code above, or perhaps some more subtle interaction with
other parts of my code?

Thanks,
Chris

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com> Phone:(07) 3870 5639
Brisbane, Australia Mobile:(0400) 833 700
-------------------------------------------------------------------------
"Ask, and it will be given to you; seek, and you will find; knock, and
it will be opened to you. For everyone who asks receives, and he who
seeks finds, and to him who knocks it will be opened. - Matthew 7:7-8

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Hello Chris,

Friday, February 02, 2001, 10:17:56 AM, you wrote:

Hello all,

I have a annoying problem with the size handler of a scrolled window...

Firstly, the documentation is adamant that the size in the argument to one's
OnSize method is that of the ENTIRE window, not just it's "client area"
(i.e., an appropriate size to be passed to the SetSize() method of the
wxWindow, and NOT to the SetClientSize() method). However, the following
code, which I mentioned yesterday, produces output which indicates that it
is being called repeatedly, each time with a size which is smaller in both
directions by 6 pixels... {this is part of a wxScrolledWindow-derived
class...}

(Incidentally, before I forget, I'm running wxPython 2.2.2 on Windows 98SE.)

    def OnSize(self, event):
        if hasattr(self,"list") and self.list.ignore_size_events:
            return
        if __debug__:
            Errors.InformationalMessagesWindow("%s.OnSize(width=%d,
height=%d)\n"
                                               % (self,
                                                  event.GetSize().width,
                                                  event.GetSize().height))
        self.SetSize (event.GetSize ())
        if hasattr(self,"list"):
            h = self.list.GetSizeTuple() [1]
            self.list.SetSize (
                (event.GetSize().width,
                 maximum.reduce([h,
                                 event.GetSize().height])))
            self.SetScrollbars(1,1,
                               self.list.GetSizeTuple() [0],
                               h)

HOWEVER, with the
        self.SetSize (event.GetSize ())
changed to
        self.SetClientSize (event.GetSize ())
the output generated is of the form

<C wxScrolledWindow instance at
_afa360_wxScrolledWindow_p>.OnSize(width=515, height=430)

repeated about 1450 times [which I assume means until the program runs out
of memory or some other resource (e.g. stack if this is indeed a recursion
problem)].

Does anyone have any idea where this Later problem comes from? Also, this
seems to indicate an inconsistency in this control's OnSize
event-dispatching, in that the size in the event structure/class is NOT the
size of the entire window... is this a known bug, or the result of something
incorrect in the code above, or perhaps some more subtle interaction with
other parts of my code?

I think that you made recursion in your code. Try using a flag
self.inside_onsize to check that.

···

--
regards,
Niki Spahiev

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

However, the following
code, which I mentioned yesterday, produces output which indicates that it
is being called repeatedly, each time with a size which is smaller in both
directions by 6 pixels...

This is the source of your repeated/recursive size events:

        self.SetSize (event.GetSize ())

There is no need to set the size of the window in the size event, as it has already happened. If you do want to change the size, then you need to guard against recursive calls, because it will happen.

Also, this
seems to indicate an inconsistency in this control's OnSize
event-dispatching, in that the size in the event structure/class is NOT the
size of the entire window... is this a known bug, or the result of something
incorrect in the code above, or perhaps some more subtle interaction with
other parts of my code?

I'm having touble duplicating this, so either it's already been fixed in the current code, or I'm not duplicating your situation correctly. If it still happens with 2.2.5 then please send me a fully functional minimal sample.

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

You're right, and as you might have seen, Robin offside pointed this out...
thanks for the reply, though... much appreciated.

Cheerio, Chris

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com> Phone:(07) 3870 5639
Brisbane, Australia Mobile:(0400) 833 700
-------------------------------------------------------------------------
"The cure for boredom is curiosity.
There is no cure for curiosity."
    - Ellen Parr

-----Original Message-----
From: wxpython-users-admin@lists.sourceforge.net
[mailto:wxpython-users-admin@lists.sourceforge.net]On Behalf Of Niki
Spahiev
Sent: Sunday, 4 February 2001 2:38 AM
To: Chris Fama
Subject: Re: [wxPython] OnSize called repeatedly (perhaps even
recursively?)....

Hello Chris,

Friday, February 02, 2001, 10:17:56 AM, you wrote:

> Hello all,

> I have a annoying problem with the size handler of a scrolled
window...

> Firstly, the documentation is adamant that the size in the
argument to one's
> OnSize method is that of the ENTIRE window, not just it's
"client area"
> (i.e., an appropriate size to be passed to the SetSize() method of the
> wxWindow, and NOT to the SetClientSize() method). However,
the following
> code, which I mentioned yesterday, produces output which
indicates that it
> is being called repeatedly, each time with a size which is
smaller in both
> directions by 6 pixels... {this is part of a wxScrolledWindow-derived
> class...}

> (Incidentally, before I forget, I'm running wxPython 2.2.2 on
Windows 98SE.)

> def OnSize(self, event):
> if hasattr(self,"list") and self.list.ignore_size_events:
> return
> if __debug__:
> Errors.InformationalMessagesWindow("%s.OnSize(width=%d,
> height=%d)\n"
> % (self,
>
event.GetSize().width,
>
event.GetSize().height))
> self.SetSize (event.GetSize ())
> if hasattr(self,"list"):
> h = self.list.GetSizeTuple() [1]
> self.list.SetSize (
> (event.GetSize().width,
> maximum.reduce([h,
> event.GetSize().height])))
> self.SetScrollbars(1,1,
> self.list.GetSizeTuple() [0],
> h)

> HOWEVER, with the
> self.SetSize (event.GetSize ())
> changed to
> self.SetClientSize (event.GetSize ())
> the output generated is of the form

> <C wxScrolledWindow instance at
> _afa360_wxScrolledWindow_p>.OnSize(width=515, height=430)

> repeated about 1450 times [which I assume means until the
program runs out
> of memory or some other resource (e.g. stack if this is
indeed a recursion
> problem)].

> Does anyone have any idea where this Later problem comes
from? Also, this
> seems to indicate an inconsistency in this control's OnSize
> event-dispatching, in that the size in the event
structure/class is NOT the
> size of the entire window... is this a known bug, or the
result of something
> incorrect in the code above, or perhaps some more subtle
interaction with
> other parts of my code?

I think that you made recursion in your code. Try using a flag
self.inside_onsize to check that.

--
regards,
Niki Spahiev

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Inside my class MyFrame(wxFrame) definition, I have
EVT_CHAR(self, self.OnChar)
and
def OnChar (self, event):
      print "OnChar called"

I have this just to see if the EVT_CHAR and OnChar are working. It works
find in windows, but in Linux, I don't get anything. It just never gets
called in Linux.

What can I do to capture key presses in Linux?

···

--------------------------------------------------------------------------
C. Porter Bassett porter@et.byu.edu http://www.et.byu.edu/~porter
--------------------------------------------------------------------------
"Pretend like this is a really witty saying." - Anonymous
--------------------------------------------------------------------------

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

That does indeed seem strange... according to the docs, one would expect
this problem from OnCharHook/EVT_CHAR_HOOK, not OnChar/EVT_CHAR... are you
certain you're using the latter [well, EVT_CHAR] and not the former?

Please excuse me if you've already RTFM'd [the docs for wxWindow]...

Cheerio, Chris

[Caveat emptor: I'm waiting for the TrollTech/IBM coalition to properly
voice-enable KDE before I really use Linux, so don't speak with any real
experience!]

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com> Phone:(07) 3870 5639
Brisbane, Australia Mobile:(0400) 833 700
-------------------------------------------------------------------------
Treat people as if they were what they ought to be, and you help them
to become what they are capable of being. - Goethe: 1749-1832

-----Original Message-----
From: wxpython-users-admin@lists.sourceforge.net
[mailto:wxpython-users-admin@lists.sourceforge.net]On Behalf Of C.
Porter Bassett
Sent: Friday, 9 February 2001 9:27 AM
To: wxpython-users@lists.sourceforge.net
Subject: [wxPython] EVT_CHAR works on windows, but not linux

Inside my class MyFrame(wxFrame) definition, I have
EVT_CHAR(self, self.OnChar)
and
def OnChar (self, event):
      print "OnChar called"

I have this just to see if the EVT_CHAR and OnChar are working. It works
find in windows, but in Linux, I don't get anything. It just never gets
called in Linux.

What can I do to capture key presses in Linux?

--------------------------------------------------------------------------
C. Porter Bassett porter@et.byu.edu http://www.et.byu.edu/~porter
--------------------------------------------------------------------------
"Pretend like this is a really witty saying." - Anonymous
--------------------------------------------------------------------------

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

>
> Inside my class MyFrame(wxFrame) definition, I have
> EVT_CHAR(self, self.OnChar)
> and
> def OnChar (self, event):
> print "OnChar called"
>
> I have this just to see if the EVT_CHAR and OnChar are working. It

works

> find in windows, but in Linux, I don't get anything. It just never gets
> called in Linux.
>
> What can I do to capture key presses in Linux?
>

I'm a little surprised that you gt the event on Windows. Whichever window
has the keyboard focus is the one that gets the EVT_CHAR. I didn't think
frames could have the focus, at least if they had any other eindoes in them.

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Yes, I am using EVT_CHAR. Go ahead and look at my sample program. It can
be found at http://www.et.byu.edu/~porter/temp/t1.py

It is just one of the examples from the tutorial with the EVT_CHAR and
OnKey thrown in there. On windows, it prints something out each time you
type a key. On linux, it, well, doesn't.

···

--------------------------------------------------------------------------
C. Porter Bassett porter@et.byu.edu http://www.cporterbassett.com
--------------------------------------------------------------------------
"Pretend like this is a really witty saying." - Anonymous
--------------------------------------------------------------------------

On Sat, 10 Feb 2001, Chris Fama wrote:

That does indeed seem strange... according to the docs, one would expect
this problem from OnCharHook/EVT_CHAR_HOOK, not OnChar/EVT_CHAR... are you
certain you're using the latter [well, EVT_CHAR] and not the former?

Please excuse me if you've already RTFM'd [the docs for wxWindow]...

Cheerio, Chris

[Caveat emptor: I'm waiting for the TrollTech/IBM coalition to properly
voice-enable KDE before I really use Linux, so don't speak with any real
experience!]

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@whollysnakes.com> Phone:(07) 3870 5639
Brisbane, Australia Mobile:(0400) 833 700
-------------------------------------------------------------------------
Treat people as if they were what they ought to be, and you help them
to become what they are capable of being. - Goethe: 1749-1832

> -----Original Message-----
> From: wxpython-users-admin@lists.sourceforge.net
> [mailto:wxpython-users-admin@lists.sourceforge.net]On Behalf Of C.
> Porter Bassett
> Sent: Friday, 9 February 2001 9:27 AM
> To: wxpython-users@lists.sourceforge.net
> Subject: [wxPython] EVT_CHAR works on windows, but not linux
>
>
> Inside my class MyFrame(wxFrame) definition, I have
> EVT_CHAR(self, self.OnChar)
> and
> def OnChar (self, event):
> print "OnChar called"
>
> I have this just to see if the EVT_CHAR and OnChar are working. It works
> find in windows, but in Linux, I don't get anything. It just never gets
> called in Linux.
>
> What can I do to capture key presses in Linux?
>
> --------------------------------------------------------------------------
> C. Porter Bassett porter@et.byu.edu http://www.et.byu.edu/~porter
> --------------------------------------------------------------------------
> "Pretend like this is a really witty saying." - Anonymous
> --------------------------------------------------------------------------
>
>
>
> _______________________________________________
> wxPython-users mailing list
> wxPython-users@lists.sourceforge.net
> http://lists.sourceforge.net/lists/listinfo/wxpython-users
>

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Well, like I said, I am very new at this. I have done almost no GUI
programming before, and I am trying to wrap my mind around all this
stuff. For reference, the code I am talking about can be seen at
http://www.et.byu.edu/~porter/temp/t2.py

I went and moved my EVT_CHAR and OnChar from the wxFrame to the
wxPanel. This did two things. On linux, it now works! It picks up my
key presses and prints them out. On Windows, however, it no longer
works. ARRGGHH!! What am I to do?

Should I just put EVT_CHAR on both the Frame and the Panel, and have both
of them point to the same external function, or should I duplicate the
function on both my Frame and my Panel?

···

--------------------------------------------------------------------------
C. Porter Bassett porter@et.byu.edu http://www.cporterbassett.com
--------------------------------------------------------------------------
"Pretend like this is a really witty saying." - Anonymous
--------------------------------------------------------------------------

On Sat, 10 Feb 2001, Robin Dunn wrote:

> >
> > Inside my class MyFrame(wxFrame) definition, I have
> > EVT_CHAR(self, self.OnChar)
> > and
> > def OnChar (self, event):
> > print "OnChar called"
> >
> > I have this just to see if the EVT_CHAR and OnChar are working. It
works
> > find in windows, but in Linux, I don't get anything. It just never gets
> > called in Linux.
> >
> > What can I do to capture key presses in Linux?
> >

I'm a little surprised that you gt the event on Windows. Whichever window
has the keyboard focus is the one that gets the EVT_CHAR. I didn't think
frames could have the focus, at least if they had any other eindoes in them.

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Never duplicate functions you don't absolutely have to. If it comes
to it, make a separate stand-alone function that handles the event,
and make a proxy type of function that calls the real function.

If you duplicate the event handler function, and later you want to
change what happens, or need to fix a bug you will have 2 places to
make the same change. Maintenance nightmare.

Here's an example:

class C1 :
    def ProxyHandler( self, event ) :
        RealHandler( self , event )

class C2 :
    def ProxyHandler( self , event ) :
        RealHandler( self , event )

def RealHandler( C1_or_C2_instance , event ) :
    print "Got an event"
    print event

If you need to access instance variables in the event handler (quite
likely!) then you will probably want to have the proxy functions put
the instance variables into a dict to pass to the real handler
function instead of passing 'self'. That way the real handler will
have access, and can be uniform for both cases.

Sorry I can't help you solve your problem the right way, I've only
just begun to learn how wxPython works.

-D

···

On Tue, Feb 13, 2001 at 02:21:17PM -0700, C. Porter Bassett wrote:

Should I just put EVT_CHAR on both the Frame and the Panel, and have both
of them point to the same external function, or should I duplicate the
function on both my Frame and my Panel?

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Well, like I said, I am very new at this. I have done almost no GUI
programming before, and I am trying to wrap my mind around all this
stuff. For reference, the code I am talking about can be seen at
http://www.et.byu.edu/~porter/temp/t2.py

I went and moved my EVT_CHAR and OnChar from the wxFrame to the
wxPanel. This did two things. On linux, it now works! It picks up my
key presses and prints them out. On Windows, however, it no longer
works.

Figures...

ARRGGHH!! What am I to do?

Should I just put EVT_CHAR on both the Frame and the Panel, and have both
of them point to the same external function, or should I duplicate the
function on both my Frame and my Panel?

Maybe it would be better to find out what you want to use EVT_CHAR for?
Maybe there is a way to do what you want already in the library.

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Well, for starters, whenever I am writing and debugging anything that pops
up another window, I like to be able to hit Esc to kill it and go make
modifications. Being a vi user, I hate having to take my hands off the
keyboard and then *waaaaay* over to that darn mouse.

In the future, I know that I am going to want things like spacebar=pause.

···

--------------------------------------------------------------------------
C. Porter Bassett porter@et.byu.edu http://www.cporterbassett.com
--------------------------------------------------------------------------
"Pretend like this is a really witty saying." - Anonymous
--------------------------------------------------------------------------

On Tue, 13 Feb 2001, Robin Dunn wrote:

> Well, like I said, I am very new at this. I have done almost no GUI
> programming before, and I am trying to wrap my mind around all this
> stuff. For reference, the code I am talking about can be seen at
> http://www.et.byu.edu/~porter/temp/t2.py
>
> I went and moved my EVT_CHAR and OnChar from the wxFrame to the
> wxPanel. This did two things. On linux, it now works! It picks up my
> key presses and prints them out. On Windows, however, it no longer
> works.

Figures...

> ARRGGHH!! What am I to do?
>
> Should I just put EVT_CHAR on both the Frame and the Panel, and have both
> of them point to the same external function, or should I duplicate the
> function on both my Frame and my Panel?
>

Maybe it would be better to find out what you want to use EVT_CHAR for?
Maybe there is a way to do what you want already in the library.

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Well, for starters, whenever I am writing and debugging anything that pops
up another window, I like to be able to hit Esc to kill it and go make
modifications. Being a vi user, I hate having to take my hands off the
keyboard and then *waaaaay* over to that darn mouse.

In the future, I know that I am going to want things like spacebar=pause.

That's what I thought you were trying to do. As I said before only the
window (right down to the sub-window or control) that has the keyboard focus
gets the EVT_CHAR, EVT_KEY_UP and EVT_KEY_DOWN events, so as you've
discovered they are not very appropriate for catching keystroke events on a
more global basis.

Instead you should use accelerators. You've probably seen apps with some
text in the menus that describe a key and when you hit the key it is as if
you clicked on the menu item. Those are accelerators and in wxPython you
can do them with or without a menubar. When an accelerator is defined and
the key is pressed then an EVT_MENU is generated and sent to the frame.

If you do have a menubar then there is a shortcut for making accelerators,
you can put it in the text of the menu item using a tab character like this:

        menu.Append(ID_EXIT, 'E&xit\tAlt-X', 'Get the heck outta here!')

but I think that only works for Alt or Ctrl keys. The more general approach
which also works if you don't have a menu is to make a wxAcceleratorTable
object. For example I have a frame without a menu that contains a panel
with a Cancel button. I want ESC to be the same as clicking Cancel (a
wxDialog does this automatically if the ID is wxID_CANCEL, but I needed a
wxFrame) so I did this:

        aTable = wxAcceleratorTable([ (wxACCEL_NORMAL, WXK_ESCAPE,
ID_CANCELBTN) ])
        self.SetAcceleratorTable(aTable)
        EVT_MENU(self, ID_CANCELBTN, self.OnCancelBtn)
        EVT_BUTTON(self, ID_CANCELBTN, self.OnCancelBtn)

One warning is that if you have an accelerator for a particular key that is
significant to some sub-window (even in a frame or dialog that has the main
frame as a parent) then the sub-window will most likely *not* get the key.

--------------------------------------------------------------------------
C. Porter Bassett porter@et.byu.edu http://www.cporterbassett.com

BTW, I once had a cs.byu.edu email address, (way back in the dark ages
before most people knew what email or the 'Net was,) and more recently 2 of
my brothers have had et.byu.edu addresses. Small world, eh?

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users