3.4. ItemPlugin

An ItemPlugin adds something to the submenu of an item. You get this menu by pressing ENTER on an item. When the submenu is generated, all global ItemPlugins and for this media type are called.

The function to be called is

def actions(self, item):
and should return a list of actions. The function can check all attributes of the item to decide what actions to return. On action can either be a MenuItem (from file menu.py) or a list. This list conatins a callback function, a text for the menu and optional a shortcut which can be put on a button for the remote.

Examples for this kind of plugin are the coversearch and the imdb plugin. They check if it makes sense to call the function and return actions.

Here is a simple example for an ItemPlugin. It checks if it's a video item and adds two actions to turn the software scaler on and off (by changing the global config variable, Ouch):

import plugin
import config

class PluginInterface(plugin.ItemPlugin):
    def actions(self, item):
        if item.type == 'video':
            return [ (self.remove_sws, 'Remove Software Scaler'),
                     (self.sws, 'Use Software Scaler') ]
        else:
            return []
        
    def remove_sws(self, menuw=None, arg=None):
        config.MPLAYER_SOFTWARE_SCALER = ''
        menuw.back_one_menu()
        
    def sws(self, menuw=None, arg=None):
        config.MPLAYER_SOFTWARE_SCALER = "-subfont-text-scale 15 -fs -sws 0 "\
                                         "-vf scale=%s:-3"\
                                         " -font /usr/share/mplayer/fonts/"\
                                         "font-arial-28-iso-8859-2/font.desc" % \
                                         config.CONF.width
        menuw.back_one_menu()