Get your text editor ready because this time I'm showing you the basics of plugin development for MediaBox.
Last time, I have explained the component system of MediaBox. If you haven't read this article yet, please do so as it will help you understand what's going on.
Now we're going to write a simple plugin that displays a short notification when the application has started.
As I have told you before, a plugin is a directory with some components in it. MediaBox looks for the plugin directories in its components directory. So we put a new directory in there with two empty files __init__.py and StartupNotifier.py in it:
Every plugin needs the __init__.py file. This is the place where components are loaded and messages are defined. In this example, we will only load our StartupNotifier component, though.
Put the following code into __init__.py:
from StartupNotifier import StartupNotifier
The function get_classes is called by MediaBox to load the components. This function must return a list of the classes (not instantiated objects) of your components.
Now we are going to fill StartupNotifier.py with life. It is a simple component, so we derive StartupNotifier from the Component baseclass:
from com import Component, msgs
def handle_message(self, msg, *args):
if (msg == msgs.CORE_EV_APP_STARTED):
"Application Startup Complete")
That's all. This simple form of a component is called a mediator component, because it just listens for and emits messages. When a component wants to listen to the message bus, it simply overrides the method handle_message and checks for the message types it's interested in. The call_service method on the other hand sends a service call to the message bus.
When you now start MediaBox, you will be greeted by your new plugin.
Next time will be a bit more theoretical again. Then I'll talk about the different types of components and what they do in MediaBox.