EventType dictionary? / Events coming from None-Objects

Hello again, dear list.

A few days ago I wondered how to access wxPythons eventqueue. With
Mikes and Robins help I did this:

class App(wx.App):
    def __init__(self):
      wx.App.__init__(self, redirect=False)
      self.SetCallFilterEvent(True)

    def FilterEvent(self, event):
      # A lot of things going on here, for example print every event's
EventType.

This works fine!

Whenever I get the event's EventType, there's an integer returned. Is
there somewhere deep within wxPython a dictionary or something where I
can look up the constant's name? (For example 10123:'wx.EVT_EXP'.)

The thing is: I want to view every event fired within (certain parts)
of my app and I want to know _when_ and _what_ event has been fired.

Another question:
As mentioned above, I want only to do something with all events fired
within a certain part of my app (events occuring within a certain
window).
In my FilterEvent I did this:

      if event.GetEventObject() not in List and event.GetEventType() !
= 10006 and event.GetEventType() != 10117 and event.GetEventObject()
is not None:
          # Do something here.

With 10006 and 10117 I excluded some events (seems to be something
like mousestuff or so .... see my question above). Also I want the
event only to be examined when it's fired by widgets who are not in
List (For example I don't want to view events coming from a "control"-
window). Sometimes I got ObjectTypes of type "None".
Now my question: Where do this None-ObjectType originate from?

I hope someone can help - thanks a lot in advance! :slight_smile:
Benjamin

PS: Here's the code shortened as far as I could:

class Frame(wx.Frame):
    def __init__(self, parent=None, id=-1, title="Frame"):
        wx.Frame.__init__(self, parent, id, title)
        self.panel = wx.Panel(self)
        self.button1 = wx.Button(self.panel, 1, "Button 1", pos =
(0,0))
        self.button2 = wx.Button(self.panel, 1, "Button 2", pos =
(0,25))

class CtrlFrame(wx.Frame):
    def __init__(self, parent=None, id=-1, title="CtrlFrame"):
      wx.Frame.__init__(self, parent, id, title)
      self.panel = wx.Panel(self)
      self.panel.button1 = wx.Button(self.panel, id=-1, label="START",
pos = (0,0))
      self.panel.button2 = wx.Button(self.panel, id=-1, label="STOP",
pos = (0,25))
      self.panel.button1.Bind(wx.EVT_BUTTON, self.btn1click)
      self.panel.button2.Bind(wx.EVT_BUTTON, self.btn2click)
      Manager.List.append(self)
      Manager.List.append(self.panel)
      Manager.List.append(self.panel.button1)
      Manager.List.append(self.panel.button2)

    def btn1click(self, event):
      Manager.evtViewActive = True
      event.StopPropagation()

    def btn2click(self, event):
      Manager.evtViewActive = False
      event.StopPropagation()

class Manager():
  evtViewActive = False
  List = []

class App(wx.App):
    def __init__(self):
      wx.App.__init__(self, redirect=False)
      Manager.List.append(self)
      self.SetCallFilterEvent(True)

    def FilterEvent(self, event):
      if Manager.evtViewActive and event.GetEventObject() not in
Manager.List and event.GetEventType() != 10006 and event.GetEventType
() != 10117 and event.GetEventObject() is not None:
        print "Eventnumber: " + str(event.GetEventType()) + "\tObject:
" + str(event.GetEventObject())

app = App()
frame1 = Frame()
frame1.Show()
frame2 = CtrlFrame()
frame2.Show()
app.MainLoop()

Hello again, dear list.

A few days ago I wondered how to access wxPythons eventqueue. With
Mikes and Robins help I did this:

class App(wx.App):
     def __init__(self):
       wx.App.__init__(self, redirect=False)
       self.SetCallFilterEvent(True)

     def FilterEvent(self, event):
       # A lot of things going on here, for example print every event's
EventType.

This works fine!

Whenever I get the event's EventType, there's an integer returned. Is
there somewhere deep within wxPython a dictionary or something where I
can look up the constant's name? (For example 10123:'wx.EVT_EXP'.)

You can build your own map with code like this:

  >>> evtmap = dict()
  >>> for name in dir(wx):
  ... if name.startswith('EVT_'):
  ... evt = getattr(wx, name)
  ... if isinstance(evt, wx.PyEventBinder):
  ... evtmap[evt.typeId] = name
  ...
  >>> evtmap[wx.EVT_BUTTON.typeId]
  'EVT_BUTTON'
  >>>

Note that there are some EVT_ objects in other modules besides wx, so you'll still want to be able to handle the cases where an event type is not in the map.

Now my question: Where do this None-ObjectType originate from?

I'm not sure. When you add the use of an evt map like the above then let me know what kind of binders those event types map to.

···

On 11/6/09 10:55 AM, Benjamin Herwig wrote:

--
Robin Dunn
Software Craftsman

Dear Robin!

Sorry for my late answer.
Your solution works perfectly! Thank you very much!

The events fired by None-object are always EVT_SET_CURSOR-events.
As far as I can see in the wxWidgets-reference, this event is fired
whenever a mousemotion is processed.

For this kind of event it'd be great to assign them to some object.
For example: assign EVT_SET_CURSOR to the objects the mousepointer is
moved above ... in other words: if I move the cursor across frame-1, I
want the EVT_SET_CURSOR-event to be assigned to the object frame-1,
not to None-objects.

Any idea how to do that?

Thanks again for your great help and thanks a lot in advance for any
further answers. :slight_smile:

Benjamin

···

On 6 Nov., 21:51, Robin Dunn <ro...@alldunn.com> wrote:

On 11/6/09 10:55 AM,BenjaminHerwigwrote:

> Hello again, dear list.

> A few days ago I wondered how to access wxPythons eventqueue. With
> Mikes and Robins help I did this:

> class App(wx.App):
> def __init__(self):
> wx.App.__init__(self, redirect=False)
> self.SetCallFilterEvent(True)

> def FilterEvent(self, event):
> # A lot of things going on here, for example print every event's
> EventType.

> This works fine!

> Whenever I get the event's EventType, there's an integer returned. Is
> there somewhere deep within wxPython a dictionary or something where I
> can look up the constant's name? (For example 10123:'wx.EVT_EXP'.)

You can build your own map with code like this:

>>> evtmap = dict()
>>> for name in dir(wx):
... if name.startswith('EVT_'):
... evt = getattr(wx, name)
... if isinstance(evt, wx.PyEventBinder):
... evtmap[evt.typeId] = name
...
>>> evtmap[wx.EVT_BUTTON.typeId]
'EVT_BUTTON'
>>>

Note that there are some EVT_ objects in other modules besides wx, so
you'll still want to be able to handle the cases where an event type is
not in the map.

> Now my question: Where do this None-ObjectType originate from?

I'm not sure. When you add the use of an evt map like the above then
let me know what kind of binders those event types map to.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

It will need changes in the C++ layers.

···

On 11/16/09 7:46 AM, Benjamin Herwig wrote:

Dear Robin!

Sorry for my late answer.
Your solution works perfectly! Thank you very much!

The events fired by None-object are always EVT_SET_CURSOR-events.
As far as I can see in the wxWidgets-reference, this event is fired
whenever a mousemotion is processed.

For this kind of event it'd be great to assign them to some object.
For example: assign EVT_SET_CURSOR to the objects the mousepointer is
moved above ... in other words: if I move the cursor across frame-1, I
want the EVT_SET_CURSOR-event to be assigned to the object frame-1,
not to None-objects.

Any idea how to do that?

--
Robin Dunn
Software Craftsman

Ok, maybe I'll work on that in ... well ... 25 years. :slight_smile:
Perhaps I'll find another possibility to distinguish between the
different EVT_SET_CURSOR events.

Thanks for now!

Benjamin

···

On 16 Nov., 19:32, Robin Dunn <ro...@alldunn.com> wrote:

On 11/16/09 7:46 AM, Benjamin Herwig wrote:

> Dear Robin!

> Sorry for my late answer.
> Your solution works perfectly! Thank you very much!

> The events fired by None-object are always EVT_SET_CURSOR-events.
> As far as I can see in the wxWidgets-reference, this event is fired
> whenever a mousemotion is processed.

> For this kind of event it'd be great to assign them to some object.
> For example: assign EVT_SET_CURSOR to the objects the mousepointer is
> moved above ... in other words: if I move the cursor across frame-1, I
> want the EVT_SET_CURSOR-event to be assigned to the object frame-1,
> not to None-objects.

> Any idea how to do that?

It will need changes in the C++ layers.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org