IdlebarPlugin

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

# 3.5. IdlebarPlugin

Idlebar plugins are deceptively simple. Only two methods are reccomedded to be implemented. There is the init method which most often calls the parent init and sets any class variables based on arguments to it. The other method is draw. Draw as its name suggests draws in the idlebar area assigned to the plugin.

Draw is where most of the action happens. Basically you get a reference to the plugin, the X coordinate to start drawing at, an osd object to use to call all the drawing methods, and a tuple containing a type and object (what do they do? have never seen them used).

The most complicated part is probably the drawing methods. Basically we can write text and, draw images. The osd variable actually is the Plugin_Area class which is a skin_area subclass and not the real osd class you would expect. You can look in freevo/src/skins/main/area.py and freevo/src/skins/main/main.py for class definitions and possible methods. The osd variable is also how we get and set the font we wish to use.

Here is a full out example:

    import random
    from plugins.idlebar import IdleBarPlugin

    # for a simple example put in a file called YeaNay.py in
    # /usr/local/freevo/src/plugins/idlebar/
    class PluginInterface(IdleBarPlugin):
        """
        Shows Yea or Nay randomly as text in the idlebar

        Activate with:
        plugin.activate('idlebar.YeaNay',   level=45)
        """
        def __init__(self):
            IdleBarPlugin.__init__(self)
            if ( random.randrange(2) ):
                self.yeanay = 'yea'
            else:
                self.yeanay = 'nay'

        def draw(self, (type, object), x, osd):
            font  = osd.get_font('clock')
            idlebar_height = 60
            w = font.font.stringsize( self.yeanay )
            h = font.font.height
            if h > idlebar_height:
                h = idlebar_height
            osd.write_text( self.yeanay, font, None,
                            ( x + 5 ),
                            ( osd.y + ( idlebar_height - h ) / 2 ),
                            ( w + 1 ), h , 'right', 'center')
            return 0

Prev | Home | Next
ItemPlugin | Up | MimetypePlugin