Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function bound to resize event of wxpython widget gets called more than once while resizing

I have made a small app with a GUI in python using the wxpython toolkit. It consists of a frame as the top window and 100 StaticText child widgets. I have bind their size events (wx.EVT_SIZE) to a OnResize function which changes their font according to the size of the StaticText widgets. (This helps to increase or decrease the size of the font of the widgets when I resize my frame window accordingly at runtime.)

Now the poblem is that the OnResize function gets called 4 times every time I resize my frame. This considerably slowsdown the startup of my app (and also its resizing.) What I want is that the OnResize function must get called only once.

Is this possible in any way?

like image 757
Pushpak Dagade Avatar asked Mar 03 '26 14:03

Pushpak Dagade


1 Answers

Consider an alternative approach.

Keep a variable of the previously processed size. Then, in your size handler, only change the font size if the size of the widget actually changed since the last size event.

def OnResize(self, event):
    w, h = size = self.GetSize()
    if size != self.previous_size:
        # update font size
    self.previous_size = size
like image 105
FogleBird Avatar answered Mar 06 '26 04:03

FogleBird