On Thu, Aug 02, 2007 at 05:23:59PM +0200, Ingo Bressler wrote: > > In 1.7.2 of freevo a message box pops up and tells me that there is "no > action defined for this selection" if I _select_ an empty disc-drive. > The idea was to replace this message by something useful (eject). > Here it is the first version of my plugin. It is quite simple.
I had to modify the menu.py file because the SELECT/ENTER events did not process the actions of the plugins. Maybe Duncan or someone who understand a bit of the Freevo inners should take a look. I don't know if my code is correct but it seems to work. Another way to not modify menu.py is to make a CdromItem class with an action for ejecting the drive. Then we need to use that class instead of Item in the rom_drives plugin. This second aproach seems more clean than modify menu.py The plugin ejectromdrives.py should add an "Eject drive/Close drive" entry to the submenus of all rom_drives items. The patch is against the SVN revision 9801 but I think it will apply to 1.7.2 as I don't think that menu.py has changed very much. Hope it works
Index: src/menu.py
===================================================================
--- src/menu.py (revision 9801)
+++ src/menu.py (working copy)
@@ -665,9 +665,38 @@
try:
action = menu.selected.action
except AttributeError:
- action = menu.selected.actions()
- if action:
- action = action[0]
+ actions = menu.selected.actions()
+ if not actions:
+ actions = []
+
+ # Add the actions of the plugins to the list of actions.
+ # This is needed when a Item class has no actions but plugins
+ # provides them. This case happens with an empty disc.
+ #
+ # FIXME The event MENU_SELECT is called when selecting
+ # a submenu entry too. The item passed to the plugin is then
+ # the submenu entry instead its parent item. So if we are in
+ # a submenu we don't want to call the actions of the plugins.
+ # because we'll break some (or all) plugins behavior.
+ # Does that sound correct?
+ #
+ if not hasattr(menu, 'is_submenu'):
+ plugins = plugin.get('item') + plugin.get('item_%s' % menu.selected.type)
+
+ if hasattr(menu.selected, 'display_type'):
+ plugins += plugin.get('item_%s' % menu.selected.display_type)
+
+ plugins.sort(lambda l, o: cmp(l._level, o._level))
+
+ for p in plugins:
+ for a in p.actions(menu.selected):
+ if isinstance(a, MenuItem):
+ actions.append(a)
+ else:
+ actions.append(a[:2])
+
+ if actions:
+ action = actions[0]
if isinstance(action, MenuItem):
action = action.function
arg = action.arg
Index: src/plugins/ejectromdrives.py
===================================================================
--- src/plugins/ejectromdrives.py (revision 0)
+++ src/plugins/ejectromdrives.py (revision 0)
@@ -0,0 +1,85 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------
+# ejectromdrives.py - Adds and eject entry to the submenu of items
+# -----------------------------------------------------------------------
+# $Id
+#
+# Notes: This plugin adds an entry to the submenu for ejecting the drive
+#
+# Activate:
+# plugin.activate('ejectromdrives')
+#
+# Bugs:
+#
+# * When an audio CD is played in detached mode the drive is ejected
+# but the song is not stopped
+#
+# -----------------------------------------------------------------------
+# Freevo - A Home Theater PC framework
+# Copyright (C) 2002 Krister Lagerstrom, et al.
+# Please see the file freevo/Docs/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------
+
+
+import plugin
+import rc
+import event as em
+import menu
+
+class PluginInterface(plugin.ItemPlugin):
+ """
+ This plugin ejects/close the tray of rom drives.
+
+ plugin.activate('ejectromdrives')
+
+ """
+ def __init__(self):
+ plugin.ItemPlugin.__init__(self)
+ self.item = None
+
+ def actions(self, item):
+ self.item = item
+ myactions = []
+
+ if item.media and hasattr(item.media, 'id'):
+ if item.media.is_mounted():
+ item.media.umount()
+
+ if item.media.is_tray_open():
+ str = _('Close drive')
+ else:
+ str = _('Eject drive')
+
+ myactions.append((self.eject, str))
+
+ return myactions
+
+
+ def eject(self, arg=None, menuw=None):
+ """
+ ejects or closes tray
+ """
+ if self.item and self.item.media and hasattr(self.item.media, 'id'):
+ _debug_('Item is a CD-ROM drive')
+
+ self.item.media.move_tray(dir='toggle')
+
+ if isinstance(menuw.menustack[-1].selected, menu.MenuItem):
+ rc.post_event(em.MENU_BACK_ONE_MENU)
+ else:
+ _debug_('Item is not a CD-ROM drive')
signature.asc
Description: Digital signature
------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________ Freevo-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freevo-users
