Sascha
Sascha

Reputation: 31

Using a wx.Timer, always sends the wx.EVT_PAINT msg & not wx.EVT_TIMER

I have a wx.Dialog, that I have subclassed. In this dialog, I perform my own painting on the DC & I also have my own wx.Timer that loops every 100 clock steps.

Now what happens is when I initiate my wx.Timer by saying, self.timer.Start(100), it loops every 100 clock steps correctly BUT it sends the wx.EVT_PAINT msg to the dialog every 100 clock steps NOT the wx.EVT_TIMER msg?

Its really easy to see from my example below & if you run it you will see that the string "Got Paint" is always printed & "Got Timer" is never printed (the wx.EVT_TIMER event is never received?)

Why is it doing that? And how can I fix it?

import wx

class dlg( wx.Dialog ):

    def __init__( self, _parent ):

        wx.Dialog.__init__( self, parent=_parent, id=wx.ID_ANY )

        self.Show()

        self.w = wx.Timer( self )
        self.Bind( wx.EVT_TIMER, self.on_timer, self.w )
        self.Bind( wx.EVT_PAINT, self.on_paint )
        self.w.Start(100)


    def on_timer( self, event ):

        print "Got Timer"
        raw_input()

    def on_paint( self, event ):

        print "Got Paint"
        raw_input()



class Frame( wx.Frame ):

    def __init__( self, _parent ):

        wx.Frame.__init__( self, parent=_parent, id=wx.ID_ANY )

        self.Bind( wx.EVT_CLOSE, self.on_close )

        self.w = dlg( self )


    def on_close( self, event ):

        self.Close( True )
        self.Destroy()



if __name__ == "__main__":

    app   = wx.App(False)
    frame = Frame( None )

    frame.Show()
    app.MainLoop()

Upvotes: 0

Views: 877

Answers (1)

RobinDunn
RobinDunn

Reputation: 6306

If you are on Windows then the problem is that you do not create a wx.PaintDC in the EVT_PAINT handler. When control returns to widows after sending that event it senses that the window still has invalidated areas and so it immediately sends another paint event with a higher priority, this ends up starving out all other events and so it appears that there are no timer events being sent in your example.

If you are not on Windows then please give us more details.

Upvotes: 1

Related Questions