Пример #1
0
    def __init__(self, start_time, player, menuw):
        _debug_(
            'TVGuide.__init__(start_time=%r, player=%r, menuw=%r)' %
            (start_time, player, menuw), 2)
        Item.__init__(self)

        # get skin definitions of the TVGuide
        self.n_items, self.hours_per_page = skin.items_per_page(('tv', self))
        # end of visible guide
        stop_time = start_time + self.hours_per_page * 60 * 60

        # constructing the guide takes some time
        msgtext = _('Preparing the program guide')
        guide = tv.epg_xmltv.get_guide(PopupBox(text=msgtext))
        # getting channels
        channels = guide.get_programs(start_time + 1, stop_time - 1)
        if not channels:
            AlertBox(text=_('TV Guide is corrupt!')).show()
            return

        # select the first available program
        selected = None
        for chan in channels:
            if chan.programs:
                self.selected = chan.programs[0]
                break

        self.recordclient = RecordClient()
        self.col_time = 30  # each col represents 30 minutes
        self.n_cols = (stop_time - start_time) / 60 / self.col_time
        self.player = player

        self.type = 'tv'
        self.menuw = menuw
        self.visible = True
        self.select_time = start_time
        self.last_update = 0

        self.lastinput_value = None
        self.lastinput_time = None

        self.update_schedules(force=True)

        self.event_context = 'tvmenu'
        self.rebuild(start_time, stop_time, guide.chan_list[0].id, selected)
        menuw.pushmenu(self)
Пример #2
0
    def __init__(self, channels, start_time, player, menuw):
        logger.log(9, 'TVGuide.__init__(start_time=%r, player=%r, menuw=%r)',
                   start_time, player, menuw)
        Item.__init__(self)

        self.channels = channels
        self.start_channel_idx = 0
        self.selected_channel_idx = 0

        # get skin definitions of the TVGuide
        self.n_items, self.hours_per_page = skin.items_per_page(('tv', self))
        # end of visible guide
        stop_time = start_time + self.hours_per_page * 60 * 60

        self.selected = None
        self.col_time = 30  # each col represents 30 minutes
        self.n_cols = (stop_time - start_time) / 60 / self.col_time
        self.player = player

        self.type = 'tv'
        self.menuw = menuw
        self.visible = True
        self.select_time = start_time
        self.last_update = 0

        self.lastinput_value = None
        self.lastinput_time = None

        self.event_context = 'tvmenu'
        self.transition = skin.TRANSITION_IN
        self.start_time = 0
        self.stop_time = 0

        # We select the first channel/program available an relie on
        # the rebuild method not calling the select function again
        # after a program has been selected.
        self.rebuild(start_time, stop_time, lambda p: True)

        menuw.pushmenu(self)
Пример #3
0
    def __init__(self, channels, start_time, player, menuw):
        logger.log( 9, 'TVGuide.__init__(start_time=%r, player=%r, menuw=%r)', start_time, player, menuw)
        Item.__init__(self)

        self.channels = channels
        self.start_channel_idx = 0
        self.selected_channel_idx = 0

        # get skin definitions of the TVGuide
        self.n_items, self.hours_per_page = skin.items_per_page(('tv', self))
        # end of visible guide
        stop_time = start_time + self.hours_per_page * 60 * 60

        self.selected = None
        self.col_time = 30      # each col represents 30 minutes
        self.n_cols  = (stop_time - start_time) / 60 / self.col_time
        self.player = player

        self.type = 'tv'
        self.menuw = menuw
        self.visible = True
        self.select_time = start_time
        self.last_update = 0

        self.lastinput_value = None
        self.lastinput_time = None

        self.event_context = 'tvmenu'
        self.transition = skin.TRANSITION_IN
        self.start_time = 0
        self.stop_time = 0

        # We select the first channel/program available an relie on
        # the rebuild method not calling the select function again
        # after a program has been selected.
        self.rebuild(start_time, stop_time, lambda  p: True)
        
        menuw.pushmenu(self)
Пример #4
0
    def __init__(self, start_time, player, menuw):
        Item.__init__(self)

        self.n_items, hours_per_page = skin.items_per_page(('tv', self))
        stop_time = start_time + hours_per_page * 60 * 60

        msgtext = _('Preparing the program guide')
        guide = epg_xmltv.get_guide(PopupBox(text=msgtext))
        channels = guide.GetPrograms(start=start_time + 1, stop=stop_time - 1)
        if not channels:
            AlertBox(text=_('TV Guide is corrupt!')).show()
            return

        selected = None
        for chan in channels:
            if chan.programs:
                selected = chan.programs[0]
                break

        self.col_time = 30  # each col represents 30 minutes
        self.n_cols = (stop_time - start_time) / 60 / self.col_time
        self.player = player

        self.type = 'tv'
        self.menuw = menuw
        self.visible = True
        self.select_time = start_time
        self.last_update = 0

        self.lastinput_value = None
        self.lastinput_time = None

        self.update_schedules(force=True)
        self.fc = FreevoChannels()

        self.rebuild(start_time, stop_time, guide.chan_list[0].id, selected)
        self.event_context = 'tvmenu'
        menuw.pushmenu(self)
Пример #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 items_per_page(self):
     """
     return the number of items per page for this skin
     """
     return skin.items_per_page(('menu', self))
Пример #7
0
 def items_per_page(self):
     """
     return the number of items per page for this skin
     """
     return skin.items_per_page(('menu', self))
Пример #8
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
Пример #9
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