What are events?

Events are signals that allow communication between GUI elements without direct calls.

That allows encapsulation and recycling of components, because they don't need to know where some method resides but can just broadcast an event, that other components can receive.

How can I send events?

All objects that inherit from dabo.eventMixin.EventMixin are able to send and receive events.

You send an event using raiseEvent(eventClass, **kwargs). You can send arbitrary data with your event.

Events don't propagate up, that means they are only visible for child elements of that object that raised them. You can send events to parent elements if you raise them there, e.g. self.Form.raiseEvent or even self.Application.raiseEvent.

How can I receive an event?

You've to bind an event to a handler using bindEvent(eventClass, function). The handler function receives one event object that carries information like the sender and additional data (in event.EventData).

Which events are there?

A lot of usual events are defined in dEvent.py. Their class method appliesToClass limits the classes of objects who can receive each event.

How can I define my own events?

As you can see in dEvents.py, events are just classes that inherit from dabo.dEvents.dEvent. How you use them and how you define/document their use and parameters is up to you.

Sample code ::

        
        import dabo
        dabo.ui.loadUI('wx')
        from dabo import dEvents

        class MyEvent(dEvents.dEvent):
            def appliesToClass(eventClass, objectClass):
                return True
            appliesToClass = classmethod(appliesToClass)


        class btnPanel(dabo.ui.dPanel):
                def afterInit(self):
                        self.btn = dabo.ui.dButton(self, Caption='One')
                        self.Sizer = dabo.ui.dSizer('vertical')
                        self.Sizer.append1x(self.btn)
                        self.layout()
                        self.btn.bindEvent(dEvents.Hit, self.onBtnHit)
                def onBtnHit(self, evt):
                        print 'Button hit!', evt
                        self.Form.raiseEvent(MyEvent)



        class txtPanel(dabo.ui.dPanel):
                def afterInit(self):
                        self.txt = dabo.ui.dTextBox(self)
                        self.Sizer = dabo.ui.dSizer('vertical')
                        self.Sizer.append1x(self.txt)
                        self.layout()
                        self.Form.bindEvent(MyEvent, self.onMyEvent)
                def onMyEvent(self, evt):
                        print 'Oh my!', evt
                        self.txt.Value += 'ping '



        class mainTest(dabo.ui.dForm):
                def afterInit(self):   
                        self.Sizer = dabo.ui.dSizer('horizontal')
                        self.Sizer.append1x(btnPanel(self))
                        self.Sizer.append1x(txtPanel(self))
                        self.layout()

        app = dabo.dApp()
        app.MainFormClass = mainTest
        app.start()