Author: dmeyer
Date: Tue May 1 17:58:36 2007
New Revision: 9540
Modified:
trunk/ui/src/gui/areas/handler.py
trunk/ui/src/mainmenu.py
trunk/ui/src/menu/action.py
trunk/ui/src/menu/item.py
trunk/ui/src/menu/menu.py
trunk/ui/src/menu/stack.py
trunk/ui/src/tv/__init__.py
trunk/ui/src/video/videoitem.py
Log:
more Item cleanup
Modified: trunk/ui/src/gui/areas/handler.py
==============================================================================
--- trunk/ui/src/gui/areas/handler.py (original)
+++ trunk/ui/src/gui/areas/handler.py Tue May 1 17:58:36 2007
@@ -164,9 +164,6 @@
menu.skin_default_has_images = False
menu.skin_default_has_description = False
- if menu.submenu:
- menu.skin_default_has_images = True
-
for i in menu.choices:
if i.image:
menu.skin_default_has_images = True
Modified: trunk/ui/src/mainmenu.py
==============================================================================
--- trunk/ui/src/mainmenu.py (original)
+++ trunk/ui/src/mainmenu.py Tue May 1 17:58:36 2007
@@ -82,7 +82,16 @@
self.image = gui.theme.getimage(os.path.join(imagedir, skin_type))
-
+ def get_submenu(self):
+ """
+ Return submenu items.
+ """
+ items = Item.get_submenu(self)
+ for i in items:
+ i.image = None
+ return items
+
+
class MainMenuPlugin(plugin.Plugin):
"""
Plugin class for plugins to add something to the main menu
Modified: trunk/ui/src/menu/action.py
==============================================================================
--- trunk/ui/src/menu/action.py (original)
+++ trunk/ui/src/menu/action.py Tue May 1 17:58:36 2007
@@ -43,15 +43,15 @@
"""
Action for item.actions()
- An action has a
- name and a function to call. Optional parameter is a shortcut name to be
- placed into the config for mapping an action to a button. It also has
- an optional description.
-
- To set parameters for the function call, use the parameter function of the
- action object. The function itself has always one or two parameters. If
- the function is defined inside the item, no extra parameters are used.
- If it is outside the item, the first parameter is the item.
+ An action has a name and a function to call. Optional parameter is
+ a shortcut name to be placed into the config for mapping an action
+ to a button. It also has an optional description.
+
+ To set parameters for the function call, use the parameter
+ function of the action object. The function itself has always one
+ or two parameters. If the function is defined inside the item, no
+ extra parameters are used. If it is outside the item, the first
+ parameter is the item.
"""
def __init__(self, name, function, shortcut=None, description=None):
self.name = name
Modified: trunk/ui/src/menu/item.py
==============================================================================
--- trunk/ui/src/menu/item.py (original)
+++ trunk/ui/src/menu/item.py Tue May 1 17:58:36 2007
@@ -37,7 +37,6 @@
# python imports
import logging
-import copy
# kaa imports
from kaa.weakref import weakref
@@ -57,7 +56,7 @@
template for other info items like VideoItem, AudioItem and ImageItem
"""
type = None
-
+
def __init__(self, parent):
"""
Init the item. Sets all needed variables, if parent is given also
@@ -75,7 +74,6 @@
else:
self.parent = None
- self.iscopy = False
self.fxd_file = None
self.__initialized = False
@@ -94,32 +92,10 @@
image = property(_get_image, _set_image, None, 'image object')
- def __setitem__(self, key, value):
- """
- set the value of 'key' to 'val'
- """
- self.info[key] = value
-
-
- def copy(self):
- """
- Create a copy of the item. This item can be used in submenus of an
- item action. Items like this have self.iscopy = True and the
- original item can be accessed with self.original.
- """
- c = copy.copy(self)
- c.iscopy = True
- if hasattr(self, 'original'):
- c.original = self.original
- else:
- c.original = self
- return c
-
-
def __id__(self):
"""
Return a unique id of the item. This id should be the same when the
- item is rebuild later with the same informations
+ item is rebuild later with the same information
"""
return self.name
@@ -140,7 +116,7 @@
print 'oops', mode, self
return ''
-
+
def actions(self):
"""
Returns a list of possible actions on this item. The first
@@ -156,8 +132,8 @@
"""
raise RuntimeError("no action defined for %s", self)
-
- def get_actions(self):
+
+ def _get_actions(self):
"""
Get all actions for the item. Do not override this function,
override 'actions' instead.
@@ -189,6 +165,13 @@
return None
+ def get_submenu(self):
+ """
+ Return submenu items.
+ """
+ return [ SubMenuItem(self, a) for a in self._get_actions() ]
+
+
def pushmenu(self, menu):
"""
Append the given menu to the menu stack this item is associated with
@@ -235,11 +218,10 @@
for p in ItemPlugin.plugins(self.type):
if p.eventhandler(self, event):
return True
-
# give the event to the next eventhandler in the list
if self.parent:
return self.parent.eventhandler(event)
-
+ # nothing to do
return False
@@ -249,23 +231,26 @@
"""
if attr[:7] == 'parent(' and attr[-1] == ')' and self.parent:
return self.parent[attr[7:-1]]
-
if attr[:4] == 'len(' and attr[-1] == ')':
value = self[attr[4:-1]]
if value == None or value == '':
return 0
return len(value)
-
if attr == 'name':
return self.name
-
r = self.info.get(attr)
if r in (None, ''):
r = getattr(self, attr, None)
-
return r
+ def __setitem__(self, key, value):
+ """
+ set the value of 'key' to 'val'
+ """
+ self.info[key] = value
+
+
class ActionItem(Item, Action):
"""
@@ -273,10 +258,30 @@
passed to this action is always the parent item if not None.
"""
def __init__(self, name, parent, function, description=''):
- Action.__init__(self, name, function, description=description)
Item.__init__(self, parent)
+ Action.__init__(self, name, function, description=description)
self.item = parent
def select(self):
return self()
+
+
+
+class SubMenuItem(Item):
+ """
+ Item to show an action in a submenu (internal use)
+ """
+ def __init__(self, parent, action):
+ Item.__init__(self, parent)
+ self.action = action
+ self.name = action.name
+ self.description = action.description
+ self.image = parent.image
+
+
+ def actions(self):
+ """
+ Return the given action.
+ """
+ return [ self.action ]
Modified: trunk/ui/src/menu/menu.py
==============================================================================
--- trunk/ui/src/menu/menu.py (original)
+++ trunk/ui/src/menu/menu.py Tue May 1 17:58:36 2007
@@ -50,9 +50,9 @@
class Menu(ItemList):
"""
- A Menu page with Items for the MenuStack. It is not allowed to change
- the selected item or the internal choices directly, use 'select',
- 'set_items' or 'change_item' to do this.
+ A Menu page with Items for the MenuStack. It is not allowed to
+ change the selected item or the internal choices directly, use
+ 'select', 'set_items' or 'change_item' to do this.
"""
next_id = 0
@@ -79,7 +79,7 @@
self.type = type
# Menu type
- self.submenu = False
+ self._is_submenu = False
# Reference to the item that created this menu
self.item = None
@@ -182,7 +182,7 @@
return True
if event == MENU_SELECT or event == MENU_PLAY_ITEM:
- actions = self.selected.get_actions()
+ actions = self.selected._get_actions()
if not actions:
OSD_MESSAGE.post(_('No action defined for this choice!'))
else:
@@ -195,30 +195,22 @@
return True
if event == MENU_SUBMENU:
- if self.submenu or not self.stack:
+ if self._is_submenu or not self.stack:
return False
- actions = self.selected.get_actions()
- if not actions or len(actions) <= 1:
+ items = self.selected.get_submenu()
+ if len(items) < 2:
+ # no submenu
return False
- items = []
- for action in actions:
- items.append(Item(self.selected, action))
-
- # FIXME: remove this for loop
- for i in items:
- if not self.selected.type == 'main':
- i.image = self.selected.image
-
s = Menu(self.selected.name, items)
- s.submenu = True
+ s._is_submenu = True
s.item = self.selected
self.stack.pushmenu(s)
return True
if event == MENU_CALL_ITEM_ACTION:
log.info('calling action %s' % event.arg)
- for action in self.selected.get_actions():
+ for action in self.selected._get_actions():
if action.shortcut == event.arg:
return action() or True
log.info('action %s not found' % event.arg)
Modified: trunk/ui/src/menu/stack.py
==============================================================================
--- trunk/ui/src/menu/stack.py (original)
+++ trunk/ui/src/menu/stack.py Tue May 1 17:58:36 2007
@@ -88,7 +88,7 @@
new menu if the attributes are set to True. If osd_message is set,
this message will be send if the current menu is no submenu
"""
- if len(self.menustack) > 1 and self.menustack[-1].submenu:
+ if len(self.menustack) > 1 and self.menustack[-1]._is_submenu:
self.back_one_menu(refresh)
elif len(self.menustack) > 1 and osd_message:
OSD_MESSAGE.post(osd_message)
@@ -113,7 +113,7 @@
if menu.autoselect and len(menu.choices) == 1:
log.info('autoselect action')
# autoselect only item in the menu
- menu.choices[0].get_actions()[0]()
+ menu.choices[0]._get_actions()[0]()
return
# refresh will do the update
Modified: trunk/ui/src/tv/__init__.py
==============================================================================
--- trunk/ui/src/tv/__init__.py (original)
+++ trunk/ui/src/tv/__init__.py Tue May 1 17:58:36 2007
@@ -64,7 +64,7 @@
items += p.items(self)
m = Menu(_('TV Main Menu'), items, type = 'tv main menu')
- m.infoitem = Info()
+ m.infoitem = Info(self)
self.pushmenu(m)
Modified: trunk/ui/src/video/videoitem.py
==============================================================================
--- trunk/ui/src/video/videoitem.py (original)
+++ trunk/ui/src/video/videoitem.py Tue May 1 17:58:36 2007
@@ -152,15 +152,6 @@
self.set_name(self.name)
- def copy(self):
- """
- Create a copy of the VideoItem.
- """
- c = MediaItem.copy(self)
- c.tv_show = False
- return c
-
-
def __getitem__(self, key):
"""
return the specific attribute
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog