Skip to content

Commit

Permalink
Add ItemConfigurePlugin to configure an Item
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirk Meyer committed Feb 10, 2013
1 parent 6af7fd0 commit 71669b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/core/menu/__init__.py
Expand Up @@ -30,7 +30,7 @@
# -----------------------------------------------------------------------------

__all__ = [ 'Item', 'ActionItem', 'ItemList', 'MediaItem', 'Action',
'Menu', 'MenuStack', 'ItemPlugin', 'MediaPlugin']
'Menu', 'MenuStack', 'ItemPlugin', 'ItemConfigurePlugin', 'MediaPlugin']

# import the submodules
from item import Item, ActionItem
Expand All @@ -39,4 +39,4 @@
from action import Action
from menu import Menu
from stack import MenuStack
from plugin import ItemPlugin, MediaPlugin
from plugin import ItemPlugin, ItemConfigurePlugin, MediaPlugin
14 changes: 12 additions & 2 deletions src/core/menu/item.py
Expand Up @@ -41,7 +41,7 @@
from kaa.utils import property

# menu imports
from plugin import ItemPlugin
from plugin import ItemPlugin, ItemConfigurePlugin
from action import Action

# get logging object
Expand Down Expand Up @@ -146,7 +146,7 @@ def uid(self):
def get_thumbnail_attribute(self, attribute):
"""
Return a thumbnail object for the given attribute (e.g. movie
poster). The attribute mist be an image filename.
poster). The attribute must be an image filename.
"""
if hasattr(self.info, 'get_thumbnail_attribute'):
return self.info.get_thumbnail_attribute(attribute)
Expand Down Expand Up @@ -219,6 +219,16 @@ def subitems(self):
"""
return [ SubMenuItem(self, a) for a in self._get_actions() ]

@property
def cfgitems(self):
"""
Return configure items.
"""
configure = []
for p in ItemConfigurePlugin.plugins(self.type):
configure += p.actions(self)
return [ SubMenuItem(self, a) for a in configure ]

@property
def playlist(self):
"""
Expand Down
14 changes: 14 additions & 0 deletions src/core/menu/menu.py
Expand Up @@ -42,10 +42,22 @@

# menu imports
from listing import ItemList
from item import ActionItem

# get logging object
log = logging.getLogger()

def show_config_menu(item):
"""
Show the item configure submenu
"""
items = item.cfgitems
if not len(items):
# no submenu
return False
item.menustack.pushmenu(Menu(_('Configure'), items, type='submenu'))


class Menu(ItemList):
"""
A Menu page with Items for the MenuStack. It is not allowed to
Expand Down Expand Up @@ -162,6 +174,8 @@ def eventhandler(self, event):
if self.type == 'submenu' or not self.stack:
return False
items = self.selected.subitems
if self.selected.cfgitems:
items.append(ActionItem(_('Configure'), self.selected, show_config_menu))
if len(items) < 2:
# no submenu
return False
Expand Down
21 changes: 20 additions & 1 deletion src/core/menu/plugin.py
Expand Up @@ -29,7 +29,7 @@
#
# -----------------------------------------------------------------------------

__all__ = [ 'ItemPlugin', 'MediaPlugin' ]
__all__ = [ 'ItemPlugin', 'ItemConfigurePlugin', 'MediaPlugin' ]

# freevo imports
from .. import api as freevo
Expand Down Expand Up @@ -64,6 +64,24 @@ def plugins(subtype=''):
return [ x for x in ItemPlugin.plugin_list if x.plugin_media in (None, subtype) ]


class ItemConfigurePlugin(freevo.Plugin):
"""
Plugin class to add something to the item configure list
"""
def actions(self, item):
"""
return a list of actions to that item. Each action is type Action
"""
return []

@staticmethod
def plugins(subtype=''):
"""
Static function to return all ItemConfigurePlugin.
"""
return [ x for x in ItemConfigurePlugin.plugin_list if x.plugin_media in (None, subtype) ]


class MediaPlugin(freevo.Plugin):
"""
Plugin class for medias handled in a directory/playlist.
Expand Down Expand Up @@ -111,3 +129,4 @@ def plugins(media_type=None):
# register base class
freevo.register_plugin(MediaPlugin)
freevo.register_plugin(ItemPlugin)
freevo.register_plugin(ItemConfigurePlugin)

0 comments on commit 71669b9

Please sign in to comment.