Пример #1
0
    def eventhandler(self, event, menuw=None):
        """
        Handles events in the tv guide
        """
        logger.log(9, 'eventhandler(event=%r, menuw=%r)', event.name, menuw)

        ## MENU_CHANGE_STYLE
        if event == MENU_CHANGE_STYLE:
            if skin.toggle_display_style('tv'):
                start_time = self.start_time
                stop_time = self.stop_time
                selected = self.selected

                self.n_items, hours_per_page = skin.items_per_page(
                    ('tv', self))

                stop_time = start_time + hours_per_page * 60 * 60

                self.n_cols = (stop_time - start_time) / 60 / self.col_time
                self.rebuild(start_time, stop_time, lambda p: p == selected)
            return True

        ## MENU_UP: Move one channel up in the guide
        elif event == MENU_UP:
            self.change_channel(-1)
            return True

        ## MENU_DOWN: Move one channel down in the guide
        elif event == MENU_DOWN:
            self.change_channel(1)
            return True

        ## MENU_LEFT: Move to the next program on this channel
        elif event == MENU_LEFT:
            self.change_program(-1)
            return True

        ## MENU_RIGHT: Move to previous program on this channel
        elif event == MENU_RIGHT:
            self.change_program(1)
            return True

        ## MENU_PAGEUP: Moves to the first of the currently displayed channels
        elif event == MENU_PAGEUP:
            self.change_channel(-self.n_items)
            return True

        ## MENU_PAGEDOWN: Move to the last of the currently displayed channels
        elif event == MENU_PAGEDOWN:
            self.change_channel(self.n_items)
            return True

        ## MENU_SUBMENU: Open a submenu for the selected program
        elif event == MENU_SUBMENU:
            # create a ProgramItem for the selected program
            pi = ProgramItem(self, prog=self.selected, context='guide')
            #and show its submenu
            pi.display_submenu(menuw=self.menuw)
            return True

        ## MENU_SELECT: Show the description
        elif event == MENU_SELECT:
            # create a ProgramItem for the selected program
            pi = ProgramItem(self, prog=self.selected, context='guide')
            #and show selecte the first action in the actions list
            pi.actions()[0][0](menuw=self.menuw)
            return True

        ## TV_START_RECORDING: add or remove this program from schedule
        elif event == TV_START_RECORDING:
            pi = ProgramItem(self, prog=self.selected, context='guide')
            pi.toggle_rec(menuw=self.menuw)
            return True

        ## PLAY: Start to watch the selected channel (if it is possible)
        elif event == PLAY:
            # create a ProgramItem for the selected program
            pi = ProgramItem(self, prog=self.selected, context='guide')
            #and show its submenu
            pi.play(menuw=self.menuw)
            return True

        ## PLAY_END: Show the guide again
        elif event == PLAY_END:
            self.show()
            self.jump_to_now(self.selected)
            return True

        # FIX or REMOVE:
        # the numerical INPUT events are not available in the tvmenu context
        ## numerical INPUT: Jump to a specific channel number
        elif event in INPUT_ALL_NUMBERS:
            newinput_time = time.time()
            if self.lastinput_value is not None:
                # allow 1.2 seconds delay for multiple digit channels
                if newinput_time - self.lastinput_time < 1.2:
                    # this enables multiple (max 3) digit channel selection
                    if self.lastinput_value >= 100:
                        self.lastinput_value = (self.lastinput_value % 100)
                    newinput_value = self.lastinput_value * 10 + int(event)
            self.lastinput_value = newinput_value
            self.lastinput_time = newinput_time

            channel_no = int(newinput_value) - 1
            if channel_no < len(config.TV_CHANNELS):
                self.start_channel = config.TV_CHANNELS[channel_no][0]
            else:
                self.lastinput_value = None
            s = self.selected
            self.rebuild(self.start_time, self.stop_time, lambda p: p == s)
            return True

        return False
Пример #2
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:
            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)
            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)
            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

            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

            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

            try:
                action = menu.selected.action
            except AttributeError:
                action = menu.selected.actions()
                if action:
                    action = action[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 and (len(actions) > 1 or force):
                self.make_submenu(menu.selected.name, actions, menu.selected)
            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
Пример #3
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
Пример #4
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
Пример #5
0
    def eventhandler(self, event, menuw=None):
        """
        Handles events in the tv guide
        """
        logger.log( 9, 'eventhandler(event=%r, menuw=%r)', event.name, menuw)

        ## MENU_CHANGE_STYLE
        if event == MENU_CHANGE_STYLE:
            if skin.toggle_display_style('tv'):
                start_time    = self.start_time
                stop_time     = self.stop_time
                selected      = self.selected

                self.n_items, hours_per_page = skin.items_per_page(('tv', self))

                stop_time = start_time + hours_per_page * 60 * 60

                self.n_cols  = (stop_time - start_time) / 60 / self.col_time
                self.rebuild(start_time, stop_time, lambda p: p == selected)
            return True

        ## MENU_UP: Move one channel up in the guide
        elif event == MENU_UP:
            self.change_channel(-1)
            return True

        ## MENU_DOWN: Move one channel down in the guide
        elif event == MENU_DOWN:
            self.change_channel(1)
            return True

        ## MENU_LEFT: Move to the next program on this channel
        elif event == MENU_LEFT:
            self.change_program(-1)
            return True

        ## MENU_RIGHT: Move to previous program on this channel
        elif event == MENU_RIGHT:
            self.change_program(1)
            return True

        ## MENU_PAGEUP: Moves to the first of the currently displayed channels
        elif event == MENU_PAGEUP:
            self.change_channel(-self.n_items)
            return True

        ## MENU_PAGEDOWN: Move to the last of the currently displayed channels
        elif event == MENU_PAGEDOWN:
            self.change_channel(self.n_items)
            return True


        ## MENU_SUBMENU: Open a submenu for the selected program
        elif event == MENU_SUBMENU:
            # create a ProgramItem for the selected program
            pi = ProgramItem(self, prog=self.selected, context='guide')
            #and show its submenu
            pi.display_submenu(menuw=self.menuw)
            return True

        ## MENU_SELECT: Show the description
        elif event == MENU_SELECT:
            # create a ProgramItem for the selected program
            pi = ProgramItem(self, prog=self.selected, context='guide')
            #and show selecte the first action in the actions list
            pi.actions()[0][0](menuw=self.menuw)
            return True

        ## TV_START_RECORDING: add or remove this program from schedule
        elif event == TV_START_RECORDING:
            pi = ProgramItem(self, prog=self.selected, context='guide')
            pi.toggle_rec(menuw=self.menuw)
            return True

        ## PLAY: Start to watch the selected channel (if it is possible)
        elif event == PLAY:
            # create a ProgramItem for the selected program
            pi = ProgramItem(self, prog=self.selected, context='guide')
            #and show its submenu
            pi.play(menuw=self.menuw)
            return True

        ## PLAY_END: Show the guide again
        elif event == PLAY_END:
            self.show()
            self.jump_to_now(self.selected)
            return True

        # FIX or REMOVE:
        # the numerical INPUT events are not available in the tvmenu context
        ## numerical INPUT: Jump to a specific channel number
        elif event in INPUT_ALL_NUMBERS:
            newinput_time = time.time()
            if self.lastinput_value is not None:
                # allow 1.2 seconds delay for multiple digit channels
                if newinput_time - self.lastinput_time < 1.2:
                    # this enables multiple (max 3) digit channel selection
                    if self.lastinput_value >= 100:
                        self.lastinput_value = (self.lastinput_value % 100)
                    newinput_value = self.lastinput_value * 10 + int(event)
            self.lastinput_value = newinput_value
            self.lastinput_time = newinput_time

            channel_no = int(newinput_value)-1
            if channel_no < len(config.TV_CHANNELS):
                self.start_channel = config.TV_CHANNELS[channel_no][0]
            else:
                self.lastinput_value = None
            s = self.selected
            self.rebuild(self.start_time, self.stop_time, lambda p : p == s)
            return True

        return False
Пример #6
0
    def eventhandler(self, event, menuw=None):
        """ Handles events in the tv guide

        Events handled by this are:
        MENU_CHANGE_STYLE: ?
        MENU_UP: Move one channel up in the guide
        MENU_DOWN: Move one channel down in the guide
        MENU_LEFT: Move to the next program on this channel
        MENU_RIGHT: Move to previous programm on this channel
        MENU_PAGEUP: Moves to the first of the currently displayed channels
        MENU_PAGEDOWN: Move to the last of the currently displayed channels
        MENU_SUBMENU: Open a submenu for the selected program
        MENU_SELECT: Open a submenu for the selected program
        TV_START_RECORDING: Start to record this or put it on schedule
        PLAY: Start to watch the selected channel (if it is possible)
        PLAY_END: Show the guide again
        numerical INPUTs: Jump to a specific channel number
        """

        _debug_('TVGUIDE EVENT is %s' % event, 0)

        ## MENU_CHANGE_STYLE
        if event == MENU_CHANGE_STYLE:
            if skin.toggle_display_style('tv'):
                start_time = self.start_time
                stop_time = self.stop_time
                start_channel = self.start_channel
                selected = self.selected

                self.n_items, hours_per_page = skin.items_per_page(
                    ('tv', self))

                before = -1
                after = -1
                for c in self.guide.chan_list:
                    if before >= 0 and after == -1:
                        before += 1
                    if after >= 0:
                        after += 1
                    if c.id == start_channel:
                        before = 0
                    if c.id == selected.channel_id:
                        after = 0

                if self.n_items <= before:
                    start_channel = selected.channel_id

                if after < self.n_items:
                    up = min(self.n_items - after, len(
                        self.guide.chan_list)) - 1
                    for i in range(len(self.guide.chan_list) - up):
                        if self.guide.chan_list[i + up].id == start_channel:
                            start_channel = self.guide.chan_list[i].id
                            break

                stop_time = start_time + hours_per_page * 60 * 60

                self.n_cols = (stop_time - start_time) / 60 / self.col_time
                self.rebuild(start_time, stop_time, start_channel, selected)

        ## MENU_UP: Move one channel up in the guide
        if event == MENU_UP:
            self.event_change_channel(-1)

        ## MENU_DOWN: Move one channel down in the guide
        elif event == MENU_DOWN:
            self.event_change_channel(1)

        ## MENU_LEFT: Move to the next program on this channel
        elif event == MENU_LEFT:
            self.event_change_program(-1)

        ## MENU_RIGHT: Move to previous programm on this channel
        elif event == MENU_RIGHT:
            self.event_change_program(1)

        ## MENU_PAGEUP: Moves to the first of the currently displayed channels
        elif event == MENU_PAGEUP:
            self.event_change_channel(-self.n_items)

        ## MENU_PAGEDOWN: Move to the last of the currently displayed channels
        elif event == MENU_PAGEDOWN:
            self.event_change_channel(self.n_items)

        ## MENU_SUBMENU: Open a submenu for the selected program
        elif event == MENU_SUBMENU:
            self.event_submenu()

        ## MENU_SELECT: Open a submenu for the selected program
        elif event == MENU_SELECT:
            self.event_submenu()

        ## TV_START_RECORDING: Start to record this or put it on schedule
        elif event == TV_START_RECORDING:
            self.event_record()

        ## PLAY: Start to watch the selected channel (if it is possible)
        elif event == PLAY:
            suffix = self.fc.getVideoGroup(self.selected.channel_id, True).vdev
            suffix = suffix.split('/')[-1]
            tvlockfile = config.FREEVO_CACHEDIR + '/record.' + suffix

            # Check if the selected program is >7 min in the future
            # if so, bring up the record dialog
            now = time.time() + (7 * 60)
            if self.selected.start > now:
                self.event_submenu()
            elif os.path.exists(tvlockfile):
                # XXX: In the future add the options to watch what we are
                #      recording or cancel it and watch TV.
                AlertBox(text=_('Sorry, you cannot watch TV while recording. ')+ \
                              _('If this is not true then remove ') + \
                              tvlockfile + '.', height=200).show()
                return TRUE
            else:
                self.hide()
                self.player('tv', self.selected.channel_id)

        ## PLAY_END: Show the guide again
        elif event == PLAY_END:
            self.show()

        ## numerical INPUT: Jump to a specific channel number
        if str(event).startswith("INPUT_"):
            # tune explicit channel
            eventInput = str(event)[6]
            isNumeric = TRUE
            try:
                newinput_value = int(eventInput)
            except:
                #Protected against INPUT_UP, INPUT_DOWN, etc
                isNumeric = FALSE
            if isNumeric:
                newinput_time = int(time.time())
                if (self.lastinput_value != None):
                    # allow 1 seconds delay for multiple digit channels
                    if (newinput_time - self.lastinput_time < 1):
                        # this enables multiple (max 3) digit channel selection
                        if (self.lastinput_value >= 100):
                            self.lastinput_value = (self.lastinput_value % 100)
                        newinput_value += self.lastinput_value * 10
                self.lastinput_value = newinput_value
                self.lastinput_time = newinput_time

                channel_no = int(newinput_value) - 1
                if channel_no < len(self.guide.chan_list):
                    self.start_channel = self.guide.chan_list[channel_no].id
                else:
                    self.lastinput_value = None

                self.rebuild(self.start_time, self.stop_time,
                             self.start_channel, self.selected)

        ## unknown event
        else:
            return FALSE

        return TRUE