DaemonPlugin

Freevo Plugin Writing HOWTO: Writing your own plugins for Freevo
Prev | Chapter 3. The Different Types of Plugins | Next

# 3.2. DaemonPlugin

A DaemonPlugin is somthing that works in the background of Freevo. Examples for this kind of plugin are the idlebar, the usb plugin, the thread watching your rom drives and the LCD plugin. A DaemonPlugin can react on events, can be called in a specific time intervall and can draw something to the skin.

    class DaemonPlugin(Plugin):

        # Variables:
        self.poll_interval  = 1
        self.poll_menu_only = True
        self.event_listener = False

        # Functions
        def __init__(self):
            pass

        def poll(self):
            pass

        def draw(self(type, object), osd):
            pass

        def eventhandler(self, event, menuw=None):
            return False

        def shutdown(self):
            pass

The `shutdown` function will be called when Freevo shuts down to do some cleanup. Most plugins won't need that function.

## 3.2.1. Polling

A plugin can be called in a specific time intervall. To do this, it has to set the variable `poll_intervall` and define a function `poll`. After that, the `poll` will be called every `0.01 * poll_intervall` seconds. When the menu is not active (e.g. watching a movie or listening to music), the function won't be called. If you want the plugin to be called even than, you can set the variable `poll_menu_only` to True.

Example: a plugin that sends the Event `foo` every second:

    import plugin
    import rc
    from event import *

    class FooSenderPlugin(plugin.DaemonPlugin):
        """
        Sending foo events
        """
        def __init__(self):
            DaemonPlugin.__init__(self)
            self.poll_interval  = 100

        def poll(self):
            rc.post_event(Event('foo'))

## 3.2.2. Action on events

To act on specific events, the class must define the function `eventhandler`. This function will be called with the event if nothing before consumed this event. If you create your own kind of event, you can be sure you get it. If the function handles this event, it should return True, if not False.

If the plugin should see all events, the plugin should set the variable `event_listener` to True. After that, the plugin will see all events and it doesn't matter, if the function return True or not.

Example: a plugin that reacts on the Event `foo` and counts the number of the events:

    import plugin

    class FooReceiverPlugin(plugin.DaemonPlugin):
        """
        Counting foo
        """
        def __init__(self):
            DaemonPlugin.__init__(self)
            self.foo = 0

        def eventhandler(self, event, menuw=None):
            if event == 'foo':
                self.foo += 1
                return True
            return False

## 3.2.3. Drawing on the Screen

not written yet

Prev | Home | Next
The Different Types of Plugins | Up | MainMenuPlugin