matt_t
matt_t

Reputation: 89

Getting the event name rather than integer ID in wxPython

I have the following code:

self.sliderR.Bind(wx.EVT_SCROLL,self.OnSlide)

In the function OnSlide I have the inserted the code pdb.set_trace() to help me debug.

In the pdb prompt if I type event.GetEventType() it returns a number (10136) but I have no idea which event that corresponds to.

Does the 10136 refer to the wx.EVT_SCROLL or another event that also triggers the wx.EVT_SCROLL event? If the latter is true, how do I find the specific event?

Thanks.

Upvotes: 3

Views: 1409

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33071

There isn't a built-in way. You will need to build an event dictionary. Robin Dunn has some code here that will help: http://osdir.com/ml/wxpython-users/2009-11/msg00138.html

Or you can check out my simple example:

import wx

class MyForm(wx.Frame):

    def __init__(self):
        wx.Frame.__init__(self, None, title="Tutorial")

        self.eventDict = {}
        for name in dir(wx):
            if name.startswith('EVT_'):
                evt = getattr(wx, name)
                if isinstance(evt, wx.PyEventBinder):
                    self.eventDict[evt.typeId] = name

        # Add a panel so it looks the correct on all platforms
        panel = wx.Panel(self, wx.ID_ANY)
        btn = wx.Button(panel, wx.ID_ANY, "Get POS")

        btn.Bind(wx.EVT_BUTTON, self.onEvent)
        panel.Bind(wx.EVT_LEFT_DCLICK, self.onEvent)
        panel.Bind(wx.EVT_RIGHT_DOWN, self.onEvent)


    def onEvent(self, event):
        """
        Print out what event was fired
        """
        evt_id = event.GetEventType()
        print self.eventDict[evt_id]


# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

Upvotes: 4

Related Questions