I am trying to filter collisions occurring in my Box2D world by reproducing this example: <https://github.com/pybox2d/pybox2d/blob/master/examples/collision_filtering.py>

I have four classes in my world, Car, Wheel, Building, and Pedestrian, I want to filter which instance collided with which and one of the possible outputs is (pseudo-code)

```py
if contact.FixtureA.isinstance(Pedestrian) and contact.FixtureB.isinstance(Car):
    print("You have caused a traffic accident")

```

I have this set of categories

```py

CAR_CATEGORY = 2
PEDESTRIAN_CATEGORY = 4
BUILDING_CATEGORY = 8
box2world = world(gravity =(0.0, 0.0), doSleep =True)

```

I also tried this: but it doesn't work (it does nothing)

```py
class myContactListener(b2ContactListener):
    def __init__(self):
        b2ContactListener.__init__(self)
    def BeginContact(self, contact):
        fixture_a = contact.fixtureA
        fixture_b = contact.fixtureB

        body_a, body_b = fixture_a.body, fixture_b.body
        ud_a, ud_b = body_a.userData, body_b.userData
        pedestrian = None
        car = None
        for ud in (body_a, body_b):
            if isinstance(ud, Pedestrian):
                pedestrian = ud
            elif isinstance(ud, Car):
                car = ud

        if car is not None and pedestrian is not None:
            if began:
                print("It does stuff")
            else:
                print("It does something")
    def EndContact(self, contact):
        pass
    def PreSolve(self, contact, oldManifold):
        pass
    def PostSolve(self, contact, impulse):
        pass

box2world = world(contactListener=myContactListener(),gravity =(0.0, 0.0), doSleep =True)

```

and I apply this in given classes (only class Pedestrian shown as example for simplicity):

```py
class Pedestrian():
    def __init__(self,box2world, ped_velocity =25, position =None,):

        if position == None:
            position = [5,5]
        self.ped_velocity = ped_velocity
        self.position = position
        self.box2world = box2world
        self.nearest_building = 0
        self.body = self.box2world.CreateDynamicBody(position = position, 
                                                       angle = 0.0,
                                                       fixtures = b2FixtureDef(
                                                            shape = b2CircleShape(radius = 1),
                                                            density = 2,
                                                            friction = 0.3,
                                                            filter = b2Filter(
                                                                categoryBits=PEDESTRIAN_CATEGORY,
                                                                maskBits=BUILDING_CATEGORY + CAR_CATEGORY,
                                                                groupIndex=0,
                                                                    )))
        self.current_position = [self.body.position]
        self.body.userData = {'obj': self}

```

And then I draw the bodies and run the world using pygame

But I am confused about how to continue, how could I use the information from the collisionfilter to be able to for example print the sentence about the accident from above?

Thank you very much
EDIT: I have found a link which solves exactly what I want to do, but it is written in C++ and I do not understand it
<http://www.iforce2d.net/b2dtut/collision-callbacks>