Example #1
0
 def highlight_menuitem(self, clicked_menu):
     i = 0
     menu = self.menustack[-1]
     logger.debug('clicked_menu=%s, self.all_item=%s', clicked_menu, self.all_items[0])
     for menuitem in self.all_items:
         if clicked_menu == menuitem:
             sounds.play_sound(sounds.MENU_NAVIGATE)
             curr_selected = i
             menu.selected = self.all_items[curr_selected]
             self.refresh()
             return
         i += 1
Example #2
0
 def highlight_menuitem(self, clicked_menu):
     i = 0
     menu = self.menustack[-1]
     logger.debug('clicked_menu=%s, self.all_item=%s', clicked_menu, self.all_items[0])
     for menuitem in self.all_items:
         if clicked_menu == menuitem:
             sounds.play_sound(sounds.MENU_NAVIGATE)
             curr_selected = i
             menu.selected = self.all_items[curr_selected]
             self.refresh()
             return
         i += 1
Example #3
0
 def _handle_up(self, menu, event):
     curr_selected = self.all_items.index(menu.selected)
     sounds.play_sound(sounds.MENU_NAVIGATE)
     if curr_selected-self.cols < 0 and \
            menu.selected != menu.choices[0]:
         self.goto_prev_page(arg='no_refresh')
         try:
             if self.cols == 1:
                 curr_selected = self.rows - 1
             elif self.rows != 1:
                 curr_selected = self.all_items.index(menu.selected)
             else:
                 curr_selected+=self.cols
         except ValueError:
             curr_selected += self.cols
     curr_selected = max(curr_selected-self.cols, 0)
     menu.selected = self.all_items[curr_selected]
     self.refresh()
Example #4
0
 def _handle_up(self, menu, event):
     curr_selected = self.all_items.index(menu.selected)
     sounds.play_sound(sounds.MENU_NAVIGATE)
     if curr_selected-self.cols < 0 and \
            menu.selected != menu.choices[0]:
         self.goto_prev_page(arg='no_refresh')
         try:
             if self.cols == 1:
                 curr_selected = self.rows - 1
             elif self.rows != 1:
                 curr_selected = self.all_items.index(menu.selected)
             else:
                 curr_selected += self.cols
         except ValueError:
             curr_selected += self.cols
     curr_selected = max(curr_selected - self.cols, 0)
     menu.selected = self.all_items[curr_selected]
     self.refresh()
Example #5
0
    def _handle_left(self, menu, event):
        # Do nothing for an empty file list
        if not len(self.menu_items):
            return

        sounds.play_sound(sounds.MENU_NAVIGATE)
        curr_selected = self.all_items.index(menu.selected)
        if curr_selected == 0:
            self.goto_prev_page(arg='no_refresh')
            try:
                curr_selected = self.all_items.index(menu.selected)
                if self.rows == 1:
                    curr_selected = len(self.all_items)
            except ValueError:
                curr_selected += self.cols
        curr_selected = max(curr_selected-1, 0)
        menu.selected = self.all_items[curr_selected]
        self.refresh()
        return
Example #6
0
    def _handle_down(self, menu, event):
        curr_selected = self.all_items.index(menu.selected)
        sounds.play_sound(sounds.MENU_NAVIGATE)
        if curr_selected+self.cols > len(self.all_items)-1 and \
               menu.page_start + len(self.all_items) < len(menu.choices):

            self.goto_next_page(arg='no_refresh')
            try:
                if self.cols == 1:
                    curr_selected = 0
                elif self.rows != 1:
                    curr_selected = self.all_items.index(menu.selected)
                else:
                    curr_selected-=self.cols
            except ValueError:
                curr_selected -= self.cols
        curr_selected = min(curr_selected+self.cols, len(self.all_items)-1)
        menu.selected = self.all_items[curr_selected]
        self.refresh()
Example #7
0
    def _handle_left(self, menu, event):
        # Do nothing for an empty file list
        if not len(self.menu_items):
            return

        sounds.play_sound(sounds.MENU_NAVIGATE)
        curr_selected = self.all_items.index(menu.selected)
        if curr_selected == 0:
            self.goto_prev_page(arg='no_refresh')
            try:
                curr_selected = self.all_items.index(menu.selected)
                if self.rows == 1:
                    curr_selected = len(self.all_items)
            except ValueError:
                curr_selected += self.cols
        curr_selected = max(curr_selected - 1, 0)
        menu.selected = self.all_items[curr_selected]
        self.refresh()
        return
Example #8
0
    def _handle_down(self, menu, event):
        curr_selected = self.all_items.index(menu.selected)
        sounds.play_sound(sounds.MENU_NAVIGATE)
        if curr_selected+self.cols > len(self.all_items)-1 and \
               menu.page_start + len(self.all_items) < len(menu.choices):

            self.goto_next_page(arg='no_refresh')
            try:
                if self.cols == 1:
                    curr_selected = 0
                elif self.rows != 1:
                    curr_selected = self.all_items.index(menu.selected)
                else:
                    curr_selected -= self.cols
            except ValueError:
                curr_selected -= self.cols
        curr_selected = min(curr_selected + self.cols, len(self.all_items) - 1)
        menu.selected = self.all_items[curr_selected]
        self.refresh()
Example #9
0
    def _handle_right(self, menu, event):
        # Do nothing for an empty file list
        if not len(self.menu_items):
            return

        sounds.play_sound(sounds.MENU_NAVIGATE)
        curr_selected = self.all_items.index(menu.selected)
        if curr_selected == len(self.all_items)-1:
            self.goto_next_page(arg='no_refresh')
            try:
                curr_selected = self.all_items.index(menu.selected)
                if self.rows == 1:
                    curr_selected -= 1
            except ValueError:
                curr_selected -= self.cols

        curr_selected = min(curr_selected+1, len(self.all_items)-1)
        menu.selected = self.all_items[curr_selected]
        self.refresh()
        return
Example #10
0
    def _handle_right(self, menu, event):
        # Do nothing for an empty file list
        if not len(self.menu_items):
            return

        sounds.play_sound(sounds.MENU_NAVIGATE)
        curr_selected = self.all_items.index(menu.selected)
        if curr_selected == len(self.all_items) - 1:
            self.goto_next_page(arg='no_refresh')
            try:
                curr_selected = self.all_items.index(menu.selected)
                if self.rows == 1:
                    curr_selected -= 1
            except ValueError:
                curr_selected -= self.cols

        curr_selected = min(curr_selected + 1, len(self.all_items) - 1)
        menu.selected = self.all_items[curr_selected]
        self.refresh()
        return
Example #11
0
    def _handle_play_item(self, menu, event):
        action = None
        arg    = None

        sounds.play_sound(sounds.MENU_SELECT)
        try:
            action = menu.selected.action
        except AttributeError:
            actions = menu.selected.actions() or []

            # 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 config.OSD_SOUNDS:
                if hasattr(menu.selected, 'arg'):
                    try:
                        key = "menu." + menu.selected.arg[0]
                        if config.OSD_SOUNDS[key]:
                            sounds.play_sound(sounds.load_sound(key))
                    except:
                        pass
                else:
                    try:
                        key = "menu." + menu.selected.__class__.__name__
                        if config.OSD_SOUNDS[key]:
                            sounds.play_sound(sounds.load_sound(key))
                    except:
                        pass

            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
                else:
                    action = action[0]
        if not action:
            AlertBox(text=_('No action defined for this choice!')).show()
            return
        action(arg=arg, menuw=self)
Example #12
0
    def goto_media_menu(self, media='audio'):
        """
        Go to a main menu item media = 'tv' or 'audio' or 'video' or 'image' or 'games'
        used for events:
            - MENU_GOTO_TVMENU
            - MENU_GOTO_TVGUIDEMENU #doesn't yet work
            - MENU_GOTO_VIDEOMENU
            - MENU_GOTO_AUDIOMENU
            - MENU_GOTO_IMAGEMENU
            - MENU_GOTO_GAMESMENU
            - MENU_GOTO_RADIOMENU
            - MENU_GOTO_SHUTDOWN
        """
        self.menustack = [self.menustack[0]]
        menu = self.menustack[0]
        self.set_event_context()
        self.init_page()

        if media == 'shutdown':
            for menuitem in self.menustack[0].choices:
                if self.all_items.index(menuitem) >= self.rows - 1:
                    self.goto_next_page()
                if string.find(str(menuitem), 'shutdown.') > 0:
                    menu.selected = menuitem
                    self.eventhandler(MENU_SELECT)
                    return

        elif media == 'tv.guide':
            menu.selected = self.all_items[len(self.menustack[0].choices)-1]
            for menuitem in self.menustack[0].choices:
                try:
                    if menuitem.arg == ('tv', 0):
                        menu.selected = menuitem
                        self.refresh()
                        self.eventhandler(MENU_SELECT)
                        self.refresh()
                        self.eventhandler(MENU_SELECT)
                        return
                except:
                    return
        level = 0
        for mediaitem in media.split('.'):
            for menuitem in self.menustack[level].choices:
                try:
                    if menuitem.arg[0] == mediaitem:
                        if config.OSD_SOUNDS:
                            try:
                                key = "menu." + media
                                if config.OSD_SOUNDS[key]:
                                    sounds.play_sound(sounds.load_sound(key))
                            except KeyError:
                                pass
                        osd.busyicon.wait(config.OSD_BUSYICON_TIMER[0])
                        menuitem.select(menuw=self)
                        osd.busyicon.stop()
                        break
                except AttributeError: # may have no .arg (no media menu)
                    pass
                except TypeError: # .arg may be not indexable
                    pass
            level += 1
Example #13
0
    def _handle_play_item(self, menu, event):
        action = None
        arg = None

        sounds.play_sound(sounds.MENU_SELECT)
        try:
            action = menu.selected.action
        except AttributeError:
            actions = menu.selected.actions() or []

            # 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 config.OSD_SOUNDS:
                if hasattr(menu.selected, 'arg'):
                    try:
                        key = "menu." + menu.selected.arg[0]
                        if config.OSD_SOUNDS[key]:
                            sounds.play_sound(sounds.load_sound(key))
                    except:
                        pass
                else:
                    try:
                        key = "menu." + menu.selected.__class__.__name__
                        if config.OSD_SOUNDS[key]:
                            sounds.play_sound(sounds.load_sound(key))
                    except:
                        pass

            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
                else:
                    action = action[0]
        if not action:
            AlertBox(text=_('No action defined for this choice!')).show()
            return
        action(arg=arg, menuw=self)
Example #14
0
    def goto_media_menu(self, media='audio'):
        """
        Go to a main menu item media = 'tv' or 'audio' or 'video' or 'image' or 'games'
        used for events:
            - MENU_GOTO_TVMENU
            - MENU_GOTO_TVGUIDEMENU #doesn't yet work
            - MENU_GOTO_VIDEOMENU
            - MENU_GOTO_AUDIOMENU
            - MENU_GOTO_IMAGEMENU
            - MENU_GOTO_GAMESMENU
            - MENU_GOTO_RADIOMENU
            - MENU_GOTO_SHUTDOWN
        """
        self.menustack = [self.menustack[0]]
        menu = self.menustack[0]
        self.set_event_context()
        self.init_page()

        if media == 'shutdown':
            for menuitem in self.menustack[0].choices:
                if self.all_items.index(menuitem) >= self.rows - 1:
                    self.goto_next_page()
                if string.find(str(menuitem), 'shutdown.') > 0:
                    menu.selected = menuitem
                    self.eventhandler(MENU_SELECT)
                    return

        elif media == 'tv.guide':
            menu.selected = self.all_items[len(self.menustack[0].choices) - 1]
            for menuitem in self.menustack[0].choices:
                try:
                    if menuitem.arg == ('tv', 0):
                        menu.selected = menuitem
                        self.refresh()
                        self.eventhandler(MENU_SELECT)
                        self.refresh()
                        self.eventhandler(MENU_SELECT)
                        return
                except:
                    return
        level = 0
        for mediaitem in media.split('.'):
            for menuitem in self.menustack[level].choices:
                try:
                    if menuitem.arg[0] == mediaitem:
                        if config.OSD_SOUNDS:
                            try:
                                key = "menu." + media
                                if config.OSD_SOUNDS[key]:
                                    sounds.play_sound(sounds.load_sound(key))
                            except KeyError:
                                pass
                        osd.busyicon.wait(config.OSD_BUSYICON_TIMER[0])
                        menuitem.select(menuw=self)
                        osd.busyicon.stop()
                        break
                except AttributeError:  # may have no .arg (no media menu)
                    pass
                except TypeError:  # .arg may be not indexable
                    pass
            level += 1
Example #15
0
    def eventhandler(self, event):
        menu = self.menustack[-1]

        if self.cols == 1 and isinstance(menu, Menu):
            if config.MENU_ARROW_NAVIGATION:
                if event == MENU_LEFT:
                    event = MENU_BACK_ONE_MENU
                elif event == MENU_RIGHT:
                    event = MENU_SELECT

            else:
                if event == MENU_LEFT:
                    event = MENU_PAGEUP
                elif event == MENU_RIGHT:
                    event = MENU_PAGEDOWN

        if self.eventhandler_plugins == None:
            self.eventhandler_plugins = plugin.get('daemon_eventhandler')

        if event == MENU_GOTO_MAINMENU:
            self.goto_main_menu()
            return True

        if event == MENU_GOTO_TV:
            self.goto_media_menu("tv")
            return True

        if event == MENU_GOTO_TVGUIDE:
            self.goto_media_menu("tv.guide")
            return True

        if event == MENU_GOTO_VIDEOS:
            self.goto_media_menu("video")
            return True

        if event == MENU_GOTO_MUSIC:
            self.goto_media_menu("audio")
            return True

        if event == MENU_GOTO_IMAGES:
            self.goto_media_menu("image")
            return True

        if event == MENU_GOTO_GAMES:
            self.goto_media_menu("games")
            return True

        if event == MENU_GOTO_RADIO:
            self.goto_media_menu("audio.radio")
            return True

        if event == MENU_GOTO_SHUTDOWN:
            self.goto_media_menu("shutdown")
            return True

        if event == MENU_BACK_ONE_MENU or \
            (event == MOUSE_BTN_PRESS and event.button == 3):
            sounds.play_sound(sounds.MENU_BACK_ONE)
            self.back_one_menu()
            return True

        if not isinstance(menu, Menu) and menu.eventhandler(event):
            return True

        if event == 'MENU_RELOAD':
            self.refresh(True)
            return True

        if event == 'MENU_REFRESH':
            self.refresh()
            return True

        if event == 'MENU_REBUILD':
            self.init_page()
            self.refresh()
            return True

        if not self.menu_items:
            if event in (MENU_SELECT, MENU_SUBMENU, MENU_PLAY_ITEM):
                self.back_one_menu()
                return True
            menu = self.menustack[-2]
            if hasattr(menu, 'selected') and hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler:
                if menu.selected.eventhandler(event=event, menuw=self):
                    return True
            for p in self.eventhandler_plugins:
                if p.eventhandler(event=event, menuw=self):
                    return True
            return False

        if not isinstance(menu, Menu):
            if self.eventhandler_plugins == None:
                self.eventhandler_plugins = plugin.get('daemon_eventhandler')

            for p in self.eventhandler_plugins:
                if p.eventhandler(event=event, menuw=self):
                    return True

            logger.log( 9, 'no eventhandler for event %s', event)
            return False

        if event == MENU_UP:
            self._handle_up(menu, event)
            return True

        if event == MENU_DOWN:
            self._handle_down(menu, event)
            return True

        if event == MENU_PAGEUP:
            self._handle_pageup(menu, event)
            return True

        if event == MENU_PAGEDOWN:
            self._handle_pagedown(menu, event)
            return True

        if event == MENU_LEFT:
            self._handle_left(menu, event)
            return True

        if event == MENU_RIGHT:
            self._handle_right(menu, event)
            return True

        if event == MENU_PLAY_ITEM and hasattr(menu.selected, 'play'):
            menu.selected.play(menuw=self)
            return True

        if event == MENU_PLAY_ITEM or event == MENU_SELECT:
            self._handle_play_item(menu, event)
            return True

        if event == MENU_SUBMENU:
            self._handle_submenu(menu, event)
            return True

        if event == MENU_CALL_ITEM_ACTION:
            self._handle_call_item_action(menu, event)
            return True

        if event == MENU_CHANGE_STYLE and len(self.menustack) > 1:
            # did the menu change?
            if skin.toggle_display_style(menu):
                self.rebuild_page()
                self.refresh()
            return True

        if event == MOUSE_MOTION:
            for menuitem in menu.choices:
                if menuitem.rect.collidepoint(event.pos):
                    self.highlight_menuitem(menuitem)
            return True

        if event == MOUSE_BTN_PRESS:
            # Left click
            if event.button == 1:
                for menuitem in menu.choices:
                    if menuitem.rect.collidepoint(event.pos):
                        self.highlight_menuitem(menuitem)
                        self.select_menuitem(menuitem)
            # Middle click
            elif event.button == 2:
                self.submenu_menuitem()
            # Wheel up
            elif event.button == 4:
                self.up_menuitem()
            # Wheel down
            elif event.button == 5:
                self.down_menuitem()
            return True
        
        if hasattr(menu.selected, 'eventhandler') and menu.selected.eventhandler:
            if menu.selected.eventhandler(event=event, menuw=self):
                return True

        for p in self.eventhandler_plugins:
            if p.eventhandler(event=event, menuw=self):
                return True

        logger.log( 9, 'no eventhandler for event %s', str(event))
        return False
Example #16
0
    def eventhandler(self, event):
        menu = self.menustack[-1]

        if self.cols == 1 and isinstance(menu, Menu):
            if config.MENU_ARROW_NAVIGATION:
                if event == MENU_LEFT:
                    event = MENU_BACK_ONE_MENU
                elif event == MENU_RIGHT:
                    event = MENU_SELECT

            else:
                if event == MENU_LEFT:
                    event = MENU_PAGEUP
                elif event == MENU_RIGHT:
                    event = MENU_PAGEDOWN

        if self.eventhandler_plugins == None:
            self.eventhandler_plugins = plugin.get('daemon_eventhandler')

        if event == MENU_GOTO_MAINMENU:
            self.goto_main_menu()
            return True

        if event == MENU_GOTO_TV:
            self.goto_media_menu("tv")
            return True

        if event == MENU_GOTO_TVGUIDE:
            self.goto_media_menu("tv.guide")
            return True

        if event == MENU_GOTO_VIDEOS:
            self.goto_media_menu("video")
            return True

        if event == MENU_GOTO_MUSIC:
            self.goto_media_menu("audio")
            return True

        if event == MENU_GOTO_IMAGES:
            self.goto_media_menu("image")
            return True

        if event == MENU_GOTO_GAMES:
            self.goto_media_menu("games")
            return True

        if event == MENU_GOTO_RADIO:
            self.goto_media_menu("audio.radio")
            return True

        if event == MENU_GOTO_SHUTDOWN:
            self.goto_media_menu("shutdown")
            return True

        if event == MENU_BACK_ONE_MENU or \
            (event == MOUSE_BTN_PRESS and event.button == 3):
            sounds.play_sound(sounds.MENU_BACK_ONE)
            self.back_one_menu()
            return True

        if not isinstance(menu, Menu) and menu.eventhandler(event):
            return True

        if event == 'MENU_RELOAD':
            self.refresh(True)
            return True

        if event == 'MENU_REFRESH':
            self.refresh()
            return True

        if event == 'MENU_REBUILD':
            self.init_page()
            self.refresh()
            return True

        if not self.menu_items:
            if event in (MENU_SELECT, MENU_SUBMENU, MENU_PLAY_ITEM):
                self.back_one_menu()
                return True
            menu = self.menustack[-2]
            if hasattr(menu, 'selected') and hasattr(
                    menu.selected,
                    'eventhandler') and menu.selected.eventhandler:
                if menu.selected.eventhandler(event=event, menuw=self):
                    return True
            for p in self.eventhandler_plugins:
                if p.eventhandler(event=event, menuw=self):
                    return True
            return False

        if not isinstance(menu, Menu):
            if self.eventhandler_plugins == None:
                self.eventhandler_plugins = plugin.get('daemon_eventhandler')

            for p in self.eventhandler_plugins:
                if p.eventhandler(event=event, menuw=self):
                    return True

            logger.log(9, 'no eventhandler for event %s', event)
            return False

        if event == MENU_UP:
            self._handle_up(menu, event)
            return True

        if event == MENU_DOWN:
            self._handle_down(menu, event)
            return True

        if event == MENU_PAGEUP:
            self._handle_pageup(menu, event)
            return True

        if event == MENU_PAGEDOWN:
            self._handle_pagedown(menu, event)
            return True

        if event == MENU_LEFT:
            self._handle_left(menu, event)
            return True

        if event == MENU_RIGHT:
            self._handle_right(menu, event)
            return True

        if event == MENU_PLAY_ITEM and hasattr(menu.selected, 'play'):
            menu.selected.play(menuw=self)
            return True

        if event == MENU_PLAY_ITEM or event == MENU_SELECT:
            self._handle_play_item(menu, event)
            return True

        if event == MENU_SUBMENU:
            self._handle_submenu(menu, event)
            return True

        if event == MENU_CALL_ITEM_ACTION:
            self._handle_call_item_action(menu, event)
            return True

        if event == MENU_CHANGE_STYLE and len(self.menustack) > 1:
            # did the menu change?
            if skin.toggle_display_style(menu):
                self.rebuild_page()
                self.refresh()
            return True

        if event == MOUSE_MOTION:
            for menuitem in menu.choices:
                if menuitem.rect.collidepoint(event.pos):
                    self.highlight_menuitem(menuitem)
            return True

        if event == MOUSE_BTN_PRESS:
            # Left click
            if event.button == 1:
                for menuitem in menu.choices:
                    if menuitem.rect.collidepoint(event.pos):
                        self.highlight_menuitem(menuitem)
                        self.select_menuitem(menuitem)
            # Middle click
            elif event.button == 2:
                self.submenu_menuitem()
            # Wheel up
            elif event.button == 4:
                self.up_menuitem()
            # Wheel down
            elif event.button == 5:
                self.down_menuitem()
            return True

        if hasattr(menu.selected,
                   'eventhandler') and menu.selected.eventhandler:
            if menu.selected.eventhandler(event=event, menuw=self):
                return True

        for p in self.eventhandler_plugins:
            if p.eventhandler(event=event, menuw=self):
                return True

        logger.log(9, 'no eventhandler for event %s', str(event))
        return False
Example #17
0
    def eventhandler(self, event):
        menu = self.menustack[-1]

        if self.cols == 1 and isinstance(menu, Menu):
            if config.MENU_ARROW_NAVIGATION:
                if event == MENU_LEFT:
                    event = MENU_BACK_ONE_MENU
                elif event == MENU_RIGHT:
                    event = MENU_SELECT

            else:
                if event == MENU_LEFT:
                    event = MENU_PAGEUP
                elif event == MENU_RIGHT:
                    event = MENU_PAGEDOWN

        if self.eventhandler_plugins == None:
            self.eventhandler_plugins = plugin.get('daemon_eventhandler')

        if event == MENU_GOTO_MAINMENU:
            self.goto_main_menu()
            return

        if event == MENU_GOTO_TV:
            self.goto_media_menu("tv")
            return

        if event == MENU_GOTO_TVGUIDE:
            self.goto_media_menu("tv.guide")
            return

        if event == MENU_GOTO_VIDEOS:
            self.goto_media_menu("video")
            return

        if event == MENU_GOTO_MUSIC:
            self.goto_media_menu("audio")
            return

        if event == MENU_GOTO_IMAGES:
            self.goto_media_menu("image")
            return

        if event == MENU_GOTO_GAMES:
            self.goto_media_menu("games")
            return

        if event == MENU_GOTO_RADIO:
            self.goto_media_menu("audio.radio")
            return

        if event == MENU_GOTO_SHUTDOWN:
            self.goto_media_menu("shutdown")
            return

        if event == MENU_BACK_ONE_MENU:
            sounds.play_sound(sounds.MENU_BACK_ONE)
            self.back_one_menu()
            return

        if not isinstance(menu, Menu) and menu.eventhandler(event):
            return

        if event == 'MENU_REFRESH':
            self.refresh()
            return

        if event == 'MENU_REBUILD':
            self.init_page()
            self.refresh()
            return

        if not self.menu_items:
            if event in (MENU_SELECT, MENU_SUBMENU, MENU_PLAY_ITEM):
                self.back_one_menu()
                return
            menu = self.menustack[-2]
            if hasattr(menu.selected,
                       'eventhandler') and menu.selected.eventhandler:
                if menu.selected.eventhandler(event=event, menuw=self):
                    return
            for p in self.eventhandler_plugins:
                if p.eventhandler(event=event, menuw=self):
                    return
            return

        if not isinstance(menu, Menu):
            if self.eventhandler_plugins == None:
                self.eventhandler_plugins = plugin.get('daemon_eventhandler')

            for p in self.eventhandler_plugins:
                if p.eventhandler(event=event, menuw=self):
                    return

            _debug_('no eventhandler for event %s' % event, 2)
            return

        if event == MENU_UP:
            curr_selected = self.all_items.index(menu.selected)
            sounds.play_sound(sounds.MENU_NAVIGATE)
            if curr_selected-self.cols < 0 and \
                   menu.selected != menu.choices[0]:
                self.goto_prev_page(arg='no_refresh')
                try:
                    if self.cols == 1:
                        curr_selected = self.rows - 1
                    elif self.rows != 1:
                        curr_selected = self.all_items.index(menu.selected)
                    else:
                        curr_selected += self.cols
                except ValueError:
                    curr_selected += self.cols
            curr_selected = max(curr_selected - self.cols, 0)
            menu.selected = self.all_items[curr_selected]
            self.refresh()
            return

        elif event == MENU_DOWN:
            curr_selected = self.all_items.index(menu.selected)
            sounds.play_sound(sounds.MENU_NAVIGATE)
            if curr_selected+self.cols > len(self.all_items)-1 and \
                   menu.page_start + len(self.all_items) < len(menu.choices):

                self.goto_next_page(arg='no_refresh')
                try:
                    if self.cols == 1:
                        curr_selected = 0
                    elif self.rows != 1:
                        curr_selected = self.all_items.index(menu.selected)
                    else:
                        curr_selected -= self.cols
                except ValueError:
                    curr_selected -= self.cols
            curr_selected = min(curr_selected + self.cols,
                                len(self.all_items) - 1)
            menu.selected = self.all_items[curr_selected]
            self.refresh()
            return

        elif event == MENU_PAGEUP:
            # Do nothing for an empty file list
            if not len(self.menu_items):
                return

            curr_selected = self.all_items.index(menu.selected)

            # Move to the previous page if the current position is at the
            # top of the list, otherwise move to the top of the list.
            if curr_selected == 0:
                self.goto_prev_page()
            else:
                curr_selected = 0
                menu.selected = self.all_items[curr_selected]
                self.refresh()
            return

        elif event == MENU_PAGEDOWN:
            # Do nothing for an empty file list
            if not len(self.menu_items):
                return

            if menu.selected == menu.choices[-1]:
                return

            curr_selected = self.all_items.index(menu.selected)
            bottom_index = self.menu_items.index(self.menu_items[-1])

            # Move to the next page if the current position is at the
            # bottom of the list, otherwise move to the bottom of the list.
            if curr_selected >= bottom_index:
                self.goto_next_page()
            else:
                curr_selected = bottom_index
                menu.selected = self.all_items[curr_selected]
                self.refresh()
            return

        elif event == MENU_LEFT:
            # Do nothing for an empty file list
            if not len(self.menu_items):
                return

            sounds.play_sound(sounds.MENU_NAVIGATE)
            curr_selected = self.all_items.index(menu.selected)
            if curr_selected == 0:
                self.goto_prev_page(arg='no_refresh')
                try:
                    curr_selected = self.all_items.index(menu.selected)
                    if self.rows == 1:
                        curr_selected = len(self.all_items)
                except ValueError:
                    curr_selected += self.cols
            curr_selected = max(curr_selected - 1, 0)
            menu.selected = self.all_items[curr_selected]
            self.refresh()
            return

        elif event == MENU_RIGHT:
            # Do nothing for an empty file list
            if not len(self.menu_items):
                return

            sounds.play_sound(sounds.MENU_NAVIGATE)
            curr_selected = self.all_items.index(menu.selected)
            if curr_selected == len(self.all_items) - 1:
                self.goto_next_page(arg='no_refresh')
                try:
                    curr_selected = self.all_items.index(menu.selected)
                    if self.rows == 1:
                        curr_selected -= 1
                except ValueError:
                    curr_selected -= self.cols

            curr_selected = min(curr_selected + 1, len(self.all_items) - 1)
            menu.selected = self.all_items[curr_selected]
            self.refresh()
            return

        elif event == MENU_PLAY_ITEM and hasattr(menu.selected, 'play'):
            menu.selected.play(menuw=self)

        elif event == MENU_SELECT or event == MENU_PLAY_ITEM:
            action = None
            arg = None

            sounds.play_sound(sounds.MENU_SELECT)
            try:
                action = menu.selected.action
            except AttributeError:
                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 config.OSD_SOUNDS:
                    if hasattr(menu.selected, 'arg'):
                        try:
                            key = "menu." + menu.selected.arg[0]
                            if config.OSD_SOUNDS[key]:
                                sounds.play_sound(sounds.load_sound(key))
                        except:
                            pass
                    else:
                        try:
                            key = "menu." + menu.selected.__class__.__name__
                            if config.OSD_SOUNDS[key]:
                                sounds.play_sound(sounds.load_sound(key))
                        except:
                            pass

                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
                    else:
                        action = action[0]
            if not action:
                print 'No action.. '
                AlertBox(text=_('No action defined for this choice!')).show()
            else:
                action(arg=arg, menuw=self)
            return

        elif event == MENU_SUBMENU:
            if hasattr(menu, 'is_submenu'):
                return

            actions = menu.selected.actions()
            force = False
            if not actions:
                actions = []
                force = True

            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 len(a) == 3 and a[2] == 'MENU_SUBMENU':
                            a[0](menuw=self)
                            return

            if actions:
                if len(actions) > 1 or force:
                    self.make_submenu(menu.selected.name, actions,
                                      menu.selected)
                elif len(actions) == 1:
                    # if there is only one action, call it!
                    action = actions[0]
                    arg = None
                    if isinstance(action, MenuItem):
                        action = action.function
                        arg = action.arg
                    else:
                        action = action[0]
                    action(arg=arg, menuw=self)
            return

        elif event == MENU_CALL_ITEM_ACTION:
            _debug_('calling action %s' % event.arg)

            for a in menu.selected.actions():
                if not isinstance(a,
                                  Item) and len(a) > 2 and a[2] == event.arg:
                    a[0](arg=None, menuw=self)
                    return

            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)

            for p in plugins:
                for a in p.actions(menu.selected):
                    if not isinstance(
                            a, MenuItem) and len(a) > 2 and a[2] == event.arg:
                        a[0](arg=None, menuw=self)
                        return
            _debug_('action %s not found' % event.arg)

        elif event == MENU_CHANGE_STYLE and len(self.menustack) > 1:
            # did the menu change?
            if skin.toggle_display_style(menu):
                self.rebuild_page()
                self.refresh()
                return

        elif hasattr(menu.selected,
                     'eventhandler') and menu.selected.eventhandler:
            if menu.selected.eventhandler(event=event, menuw=self):
                return

        for p in self.eventhandler_plugins:
            if p.eventhandler(event=event, menuw=self):
                return

        _debug_('no eventhandler for event %s' % str(event), 2)
        return 0