Author: duncan
Date: Wed Mar  5 17:26:47 2008
New Revision: 10467

Log:
Various fixes to the tv recording interface


Modified:
   branches/rel-1/freevo/src/tv/channels.py
   branches/rel-1/freevo/src/tv/epg_types.py
   branches/rel-1/freevo/src/tv/epg_xmltv.py
   branches/rel-1/freevo/src/tv/plugins/manual_record.py
   branches/rel-1/freevo/src/tv/plugins/scheduled_recordings.py
   branches/rel-1/freevo/src/tv/plugins/view_favorites.py
   branches/rel-1/freevo/src/tv/plugins/xawtv.py
   branches/rel-1/freevo/src/tv/programitem.py
   branches/rel-1/freevo/src/tv/record_client.py
   branches/rel-1/freevo/src/tv/tvguide.py

Modified: branches/rel-1/freevo/src/tv/channels.py
==============================================================================
--- branches/rel-1/freevo/src/tv/channels.py    (original)
+++ branches/rel-1/freevo/src/tv/channels.py    Wed Mar  5 17:26:47 2008
@@ -272,7 +272,7 @@
         chan_name = config.TV_CHANNELS[self.chan_index][1]
         chan_id = config.TV_CHANNELS[self.chan_index][0]
 
-        channels = epg_xmltv.get_guide().GetPrograms(start=time.time(), 
stop=time.time(), chanids=[chan_id])
+        channels = epg_xmltv.get_guide().get_programs(start=time.time(), 
stop=time.time(), chanids=[chan_id])
 
         if channels and channels[0] and channels[0].programs:
             if showtime:
@@ -295,7 +295,7 @@
         chan_name = config.TV_CHANNELS[self.chan_index][1]
         chan_id = config.TV_CHANNELS[self.chan_index][0]
 
-        channels = epg_xmltv.get_guide().GetPrograms(start=time.time(), 
stop=time.time(), chanids=[chan_id])
+        channels = epg_xmltv.get_guide().get_programs(start=time.time(), 
stop=time.time(), chanids=[chan_id])
 
         if channels and channels[0] and channels[0].programs:
             start_t = channels[0].programs[0].start

Modified: branches/rel-1/freevo/src/tv/epg_types.py
==============================================================================
--- branches/rel-1/freevo/src/tv/epg_types.py   (original)
+++ branches/rel-1/freevo/src/tv/epg_types.py   Wed Mar  5 17:26:47 2008
@@ -39,15 +39,6 @@
 EPG_VERSION = 6
 
 
-# Cache variables for last GetPrograms()
-cache_last_start = None
-cache_last_stop = None
-cache_last_chanids = None
-cache_last_result = None
-cache_last_time = 0
-
-
-
 class TvProgram:
 
     channel_id = None
@@ -69,10 +60,10 @@
     onlyNew = None
 
 
-    def __init__(self, title='', channel_id='', start=0, stop=0):
-        self.channel_id = channel_id
+    def __init__(self, title='', channel_id='', start=0, stop=0, desc=''):
         self.title      = title
-        self.desc       = ''
+        self.channel_id = channel_id
+        self.desc       = desc
         self.sub_title  = ''
         self.start      = start
         self.pdc_start  = 0.0
@@ -108,6 +99,12 @@
         return s
 
 
+    def __repr__(self):
+        bt = time.localtime(self.start)
+        et = time.localtime(self.stop)
+        return '<TvProgram %r %s->%s>' % (self.channel_id, 
time.strftime('%H:%M', bt), time.strftime('%H:%M', et))
+
+
     def __eq__(self, other):
         """ equality method """
         if not isinstance(other, TvProgram):
@@ -177,19 +174,18 @@
 class TvChannel:
     """
     """
-    id = ''
-    displayname = ''
-    tunerid = ''
-    logo = ''   # URL or file, Not used yet
-    programs = None
-    times = None
-
-
-    def __init__(self):
-        self.programs = []
+    logo = None
+    def __init__(self, id, displayname, tunerid, logo='', times=[], 
programs=[]):
+        """ Copy the programs that are inside the indicated time bracket """
+        self.id = id
+        self.displayname = displayname
+        self.tunerid = tunerid
+        self.logo = logo
+        self.times = times
+        self.programs = programs
 
 
-    def Sort(self):
+    def sort(self):
         # Sort the programs so that the earliest is first in the list
         f = lambda a, b: cmp(a.start, b.start)
         self.programs.sort(f)
@@ -207,7 +203,7 @@
 
 
     def __repr__(self):
-        return '<TvChannel %(id)r>' % (self.__dict__)
+        return '<TvChannel %r>' % (self.id)
 
 
 
@@ -225,7 +221,7 @@
         self.EPG_VERSION = EPG_VERSION
 
 
-    def AddChannel(self, channel):
+    def add_channel(self, channel):
         if not self.chan_dict.has_key(channel.id):
             # Add the channel to both the dictionary and the list. This works
             # well in Python since they will both point to the same object!
@@ -233,7 +229,7 @@
             self.chan_list += [channel]
 
 
-    def AddProgram(self, program):
+    def add_program(self, program):
         # The channel must be present, or the program is
         # silently dropped
         if self.chan_dict.has_key(program.channel_id):
@@ -251,66 +247,39 @@
             self.chan_dict[program.channel_id].programs += [program]
 
 
-    # Get all programs that occur at least partially between
-    # the start and stop timeframe.
-    # If start is None, get all programs from the start.
-    # If stop is None, get all programs until the end.
-    # The chanids can be used to select only certain channel id's,
-    # all channels are returned otherwise
-    #
-    # The return value is a list of channels (TvChannel)
-    def GetPrograms(self, start=None, stop=None, chanids=None):
-        if start == None:
-            start = 0
-        if stop == None:
-            stop = 2147483647   # Year 2038
-        _debug_('GetPrograms(start=%r, stop=%r, chanids=%r)' % 
(time.strftime('%H:%M', time.localtime(start)),
+    def get_programs(self, start=0, stop=2147483647, chanids=None):
+        """
+        Get all programs that occur at least partially between the start and 
stop
+        timeframe.
+        
+        @param start: is 0, get all programs from the start.
+        @param stop: is 2147483647, get all programs until the end.
+        @param chanids: can be used to select only certain channel id's, all 
channels are returned otherwise.
+        @returns: a list of channels (TvChannel)
+        """
+        _debug_('get_programs(start=%r, stop=%r, chanids=%r)' % 
(time.strftime('%H:%M', time.localtime(start)),
             time.strftime('%H:%M', time.localtime(stop)), chanids))
 
-        # Return a cached version?
-        global cache_last_start, cache_last_stop, cache_last_chanids, 
cache_last_time, cache_last_result
-
-        if (cache_last_start == start and cache_last_stop == stop and
-            cache_last_chanids == chanids and time.time() < cache_last_time):
-            _debug_('GetPrograms: return cached results, valid for %1.1f 
secs.' % cache_last_time - time.time())
-            return cache_last_result[:]  # Return a copy
-
         channels = []
         for chan in self.chan_list:
             if chanids and (not chan.id in chanids):
                 continue
 
-            # Copy the channel info
-            c = TvChannel()
-            c.id = chan.id
-            c.displayname = chan.displayname
-            c.tunerid = chan.tunerid
-            c.logo = chan.logo
-            c.times = chan.times
+            c = TvChannel(chan.id, chan.displayname, chan.tunerid, chan.logo, 
chan.times)
             # Copy the programs that are inside the indicated time bracket
             f = lambda p, a=start, b=stop: not (p.start > b or p.stop < a)
             c.programs = filter(f, chan.programs)
 
             channels.append(c)
 
-        # Update cache variables
-        cache_last_start = start
-        cache_last_stop = stop
-        if chanids:
-            cache_last_chanids = chanids[:]
-        else:
-            cache_last_chanids = None
-        cache_last_timeout = time.time() + 20
-        cache_last_result = channels[:] # Make a copy in case the caller 
modifies it
-
-        _debug_('GetPrograms: channels=%r' % (channels,))
+        _debug_('get_programs: channels=%r' % (channels,))
         return channels
 
 
-    def Sort(self):
-        # Sort all channel programs in time order
+    def sort(self):
+        """ Sort all channel programs in time order """
         for chan in self.chan_list:
-            chan.Sort()
+            chan.sort()
 
 
     def __str__(self):
@@ -318,3 +287,7 @@
         for chan in self.chan_list:
             s += String(chan)
         return s
+
+
+    def __repr__(self):
+        return '<TvGuide %r>' % (self.EPG_VERSION)

Modified: branches/rel-1/freevo/src/tv/epg_xmltv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/epg_xmltv.py   (original)
+++ branches/rel-1/freevo/src/tv/epg_xmltv.py   Wed Mar  5 17:26:47 2008
@@ -45,7 +45,7 @@
 
 # The EPG data types. They need to be in an external module in order for 
pickling
 # to work properly when run from inside this module and from the tv.py module.
-import tv.epg_types as epg_types
+from tv.epg_types import EPG_VERSION, TvGuide, TvChannel, TvProgram
 
 class EpgException(Exception):
     """
@@ -101,7 +101,7 @@
                     _debug_('EPG does not have a version number, must be 
reloaded')
                     print dir(cached_guide)
 
-            if epg_ver != epg_types.EPG_VERSION:
+            if epg_ver != EPG_VERSION:
                 if verbose:
                     _debug_('EPG version missmatch, must be reloaded')
 
@@ -147,7 +147,7 @@
 
     if not cached_guide:
         # An error occurred, return an empty guide
-        cached_guide = epg_types.TvGuide()
+        cached_guide = TvGuide()
 
     if popup:
         popup.destroy()
@@ -164,7 +164,7 @@
         XMLTV_FILE = config.XMLTV_FILE
 
     # Create a new guide
-    guide = epg_types.TvGuide()
+    guide = TvGuide()
 
     # Is there a file to read from?
     if os.path.isfile(XMLTV_FILE):
@@ -181,18 +181,15 @@
             _debug_('epg_xmltv.py: Only adding channels in list')
 
         for data in config.TV_CHANNELS:
-            (id, disp, tunerid) = data[:3]
-            c = epg_types.TvChannel()
-            c.id = id
-            c.displayname = disp
-            c.tunerid = tunerid
+            (id, displayname, tunerid) = data[:3]
+            c = TvChannel(id, displayname, tunerid)
 
             # Handle the optional time-dependent station info
             c.times = []
             if len(data) > 3 and len(data[3:4]) == 3:
                 for (days, start_time, stop_time) in data[3:4]:
                     c.times.append((days, int(start_time), int(stop_time)))
-            guide.AddChannel(c)
+            guide.add_channel(c)
 
 
     else: # Add all channels in the XMLTV file
@@ -209,22 +206,21 @@
 
         for chan in xmltv_channels:
             id = chan['id'].encode(config.LOCALE, 'ignore')
-            c = epg_types.TvChannel()
-            c.id = id
             if ' ' in id:
                 # Assume the format is "TUNERID CHANNELNAME"
-                c.displayname = id.split()[1]   # XXX Educated guess
-                c.tunerid = id.split()[0]       # XXX Educated guess
+                displayname = id.split()[1]   # XXX Educated guess
+                tunerid = id.split()[0]       # XXX Educated guess
             else:
                 displayname = chan['display-name'][0][0]
                 if ' ' in displayname:
-                    c.displayname = displayname.split()[1]
-                    c.tunerid = displayname.split()[0]
+                    displayname = displayname.split()[1]
+                    tunerid = displayname.split()[0]
                 else:
-                    c.displayname = displayname
-                    c.tunerid = _('REPLACE WITH TUNERID FOR %s') % displayname
+                    displayname = displayname
+                    tunerid = _('REPLACE WITH TUNERID FOR %s') % displayname
+            c = TvChannel(id, displayname, tunerid)
 
-            guide.AddChannel(c)
+            guide.add_channel(c)
 
     xmltv_programs = None
     if gotfile:
@@ -250,7 +246,7 @@
         if not p['channel'] in needed_ids:
             continue
         try:
-            prog = epg_types.TvProgram()
+            prog = TvProgram()
             prog.channel_id = p['channel']
             prog.title = Unicode(p['title'][0][0])
             if p.has_key('date'):
@@ -296,12 +292,12 @@
                     except Exception, e:
                         print 'Teil:', e
 
-            guide.AddProgram(prog)
+            guide.add_program(prog)
         except:
             traceback.print_exc()
             print 'Error in tv guide, skipping'
 
-    guide.Sort()
+    guide.sort()
     return guide
 
 

Modified: branches/rel-1/freevo/src/tv/plugins/manual_record.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/manual_record.py       (original)
+++ branches/rel-1/freevo/src/tv/plugins/manual_record.py       Wed Mar  5 
17:26:47 2008
@@ -122,6 +122,10 @@
 
     def display_recitem(self, arg=None, menuw=None):
         _debug_('display_recitem(self, arg=None, menuw=None)', 2)
+        if not self.recordclient.pingNow():
+            AlertBox(self.recordclient.recordserverdown).show()
+            return
+
         self.make_newprog()
 
         items = []

Modified: branches/rel-1/freevo/src/tv/plugins/scheduled_recordings.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/scheduled_recordings.py        
(original)
+++ branches/rel-1/freevo/src/tv/plugins/scheduled_recordings.py        Wed Mar 
 5 17:26:47 2008
@@ -51,14 +51,17 @@
 
 
     def display_schedule(self, arg=None, menuw=None):
+        if not self.recordclient.pingNow():
+            AlertBox(self.recordclient.recordserverdown).show()
+            return
+
         items = self.get_items()
         if not len(items):
             AlertBox(_('Nothing scheduled.')).show()
             return
 
-        schedule_menu = menu.Menu(_( 'Scheduled Recordings'), items,
-                                  reload_func = self.reload,
-                                  item_types = 'tv program menu')
+        schedule_menu = menu.Menu(_('Scheduled Recordings'), items,
+            reload_func=self.reload, item_types='tv program menu')
         self.menuw = menuw
         rc.app(None)
         menuw.pushmenu(schedule_menu)
@@ -86,13 +89,12 @@
     def get_items(self):
         items = []
 
-        #(server_available, msg) = self.recordclient.connectionTest()
-        #if not server_available:
-        #    AlertBox(_('Recording server is not available')+(':\n%s' % 
msg)).show()
-        #    return []
+        if not self.recordclient.pingNow():
+            AlertBox(self.recordclient.recordserverdown).show()
+            return []
 
         (status, schedule) = self.recordclient.getScheduledRecordingsNow()
-        if schedule is not None:
+        if status:
             progs = schedule.getProgramList()
 
             f = lambda a, b: cmp(a.start, b.start)

Modified: branches/rel-1/freevo/src/tv/plugins/view_favorites.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/view_favorites.py      (original)
+++ branches/rel-1/freevo/src/tv/plugins/view_favorites.py      Wed Mar  5 
17:26:47 2008
@@ -54,6 +54,10 @@
 
     def view_favorites(self, arg=None, menuw=None):
         _debug_('view_favorites(arg=%r, menuw=%r)' % (arg, menuw), 2)
+        if not self.recordclient.pingNow():
+            AlertBox(self.recordclient.recordserverdown).show()
+            return
+
         items = self.get_items()
         if not len(items):
             AlertBox(_('No favorites.')).show()
@@ -89,11 +93,6 @@
         _debug_('get_items()', 2)
         items = []
 
-        server_available = self.recordclient.pingNow()
-        if not server_available:
-            AlertBox(_('Recording server is not available')).show()
-            return []
-
         favorites = self.recordclient.getFavoritesNow()
         if favorites:
             f = lambda a, b: cmp(a.priority, b.priority)

Modified: branches/rel-1/freevo/src/tv/plugins/xawtv.py
==============================================================================
--- branches/rel-1/freevo/src/tv/plugins/xawtv.py       (original)
+++ branches/rel-1/freevo/src/tv/plugins/xawtv.py       Wed Mar  5 17:26:47 2008
@@ -99,8 +99,7 @@
         chan_name = config.TV_CHANNELS[self.tuner_chidx][1]
         chan_id = config.TV_CHANNELS[self.tuner_chidx][0]
 
-        channels = epg.get_guide().GetPrograms(start=time.time(),
-                                               stop=time.time(), 
chanids=[chan_id])
+        channels = epg.get_guide().get_programs(start=time.time(), 
stop=time.time(), chanids=[chan_id])
 
         if channels and channels[0] and channels[0].programs:
             start_s = time.strftime(config.TV_TIME_FORMAT, 
time.localtime(channels[0].programs[0].start))

Modified: branches/rel-1/freevo/src/tv/programitem.py
==============================================================================
--- branches/rel-1/freevo/src/tv/programitem.py (original)
+++ branches/rel-1/freevo/src/tv/programitem.py Wed Mar  5 17:26:47 2008
@@ -93,33 +93,33 @@
         items = []
 
         #'Play', if this programm is currently running or starts soon
-        if self.context=='guide':
-            now = time.time()
-            if self.prog.start <= now+(7*60) and self.prog.stop > now:
-                items.append((self.play, _('Play')))
+        if self.context == 'guide':
+            items.append((self.play, _('Play')))
+            #now = time.time()
+            #if self.prog.start <= now+(7*60) and self.prog.stop > now:
+            #    items.append((self.play, _('Play')))
 
         # 'Show full description'
         items.append((self.show_description, _('Full Description')))
 
-        # 'Schedule for recording' OR 'Remove from schedule'
-        (status, schedule) = self.recordclient.getScheduledRecordingsNow()
-        if schedule:
-            (self.scheduled, reason) = 
self.recordclient.isProgScheduledNow(self.prog, schedule.getProgramList())
+        if self.recordclient.pingNow():
 
-        if status:
-            items.append((self.remove_program, _('Remove from schedule')))
-        else:
-            items.append((self.schedule_program, _('Schedule for recording')))
-
-        # 'Add to favorites' OR 'Remove from favorites'
-        (result, message) = self.recordclient.isProgAFavoriteNow(self.prog)
-        if result:
-            self.favorite = True
+            # 'Schedule for recording' OR 'Remove from schedule'
+            (status, schedule) = self.recordclient.getScheduledRecordingsNow()
+            (status, reason) = self.recordclient.isProgScheduledNow(self.prog, 
schedule.getProgramList())
+            self.scheduled = status
+            if self.scheduled:
+                items.append((self.remove_program, _('Remove from schedule')))
+            else:
+                items.append((self.schedule_program, _('Schedule for 
recording')))
 
-        if self.favorite:
-            items.append((self.edit_favorite, _('Edit favorite')))
-        else:
-            items.append((self.add_favorite, _('Add to favorites')))
+            # 'Add to favorites' OR 'Remove from favorites'
+            (status, reason) = self.recordclient.isProgAFavoriteNow(self.prog)
+            self.favorite = status
+            if self.favorite:
+                items.append((self.edit_favorite, _('Edit favorite')))
+            else:
+                items.append((self.add_favorite, _('Add to favorites')))
 
         # 'Seach for more of this'
         if not self.context == 'search':
@@ -134,7 +134,7 @@
         """ Start watching TV """
         _debug_('play(arg=%r, menuw=%r)' % (arg, menuw), 1)
         # watching TV should only be possible from the guide
-        if not self.context=='guide':
+        if not self.context == 'guide':
             rc.post_event(MENU_SELECT)
             return
         now = time.time()
@@ -194,8 +194,8 @@
         """ Add a program to schedule """
         _debug_('schedule_program(arg=%r, menuw=%r)' % (arg, menuw), 1)
         # schedule the program
-        (result, reason) = self.recordclient.scheduleRecordingNow(self.prog)
-        if result:
+        (status, reason) = self.recordclient.scheduleRecordingNow(self.prog)
+        if status:
             menuw.delete_submenu(refresh=False)
             if hasattr(self.parent, 'update'):
                 self.parent.update(force=True)
@@ -213,8 +213,8 @@
         """ Remove a program from schedule """
         _debug_('remove_program(arg=%r, menuw=%r)' % (arg, menuw), 1)
         # remove the program
-        (result, reason) = 
self.recordclient.removeScheduledRecordingNow(self.prog)
-        if result:
+        (status, reason) = 
self.recordclient.removeScheduledRecordingNow(self.prog)
+        if status:
             menuw.delete_submenu(refresh=False)
             if hasattr(self.parent, 'update'):
                 self.parent.update(force=True)
@@ -273,10 +273,10 @@
         pop = PopupBox(text=_('Searching, please wait...'))
         pop.show()
         # do the search
-        (result, matches) = self.recordclient.findMatchesNow(self.title)
+        (status, matches) = self.recordclient.findMatchesNow(self.title)
         # we are ready -> kill the popup message
         pop.destroy()
-        if result:
+        if status:
             # we have been successful!
             items = []
             _debug_('search found %s matches' % len(matches), 1)

Modified: branches/rel-1/freevo/src/tv/record_client.py
==============================================================================
--- branches/rel-1/freevo/src/tv/record_client.py       (original)
+++ branches/rel-1/freevo/src/tv/record_client.py       Wed Mar  5 17:26:47 2008
@@ -97,11 +97,12 @@
                     return None
                 except Exception, why:
                     _debug_('%s' % (why,), DERROR)
-            try:
-                return self.server.rpc(cmd, *args, **kwargs)
-            except Exception, why:
-                _debug_('%s' % (why,), DERROR)
-                return None
+            return self.server.rpc(cmd, *args, **kwargs)
+            #try:
+            #    return self.server.rpc(cmd, *args, **kwargs)
+            #except Exception, why:
+            #    _debug_('%s' % (why,), DERROR)
+            #    return None
         except kaa.rpc.ConnectError, e:
             _debug_('%r is down' % (self.socket,), DINFO)
             self.server = None
@@ -462,16 +463,11 @@
                     self.server = kaa.rpc.Client(self.socket, self.secret)
                     self.server.signals['closed'].connect(closed_handler)
                     _debug_('%r is up' % (self.socket,), DINFO)
-                    return True
                 except kaa.rpc.ConnectError:
                     _debug_('%r is down' % (self.socket,), DINFO)
                     self.server = None
                     return False
-            try:
-                return self.server.rpc(cmd, *args, **kwargs).connect(callback)
-            except Exception, why:
-                _debug_('%s' % (why,), DERROR)
-                return False
+            self.server.rpc(cmd, *args, **kwargs).connect(callback)
             return True
         except kaa.rpc.ConnectError, e:
             _debug_('%r is down' % (self.socket,), DINFO)
@@ -587,6 +583,10 @@
         result = rc.pingNow()
         print 'result: %r\n"%s"' % (result, result)
 
+    elif function == "ping":
+        result = rc.ping(handler)
+        print 'result: %r\n"%s"' % (result, result)
+
     elif function == "findnextprogramnow":
         result = rc.findNextProgramNow(True)
         print 'recording:%r\n"%s"' % (result, result)

Modified: branches/rel-1/freevo/src/tv/tvguide.py
==============================================================================
--- branches/rel-1/freevo/src/tv/tvguide.py     (original)
+++ branches/rel-1/freevo/src/tv/tvguide.py     Wed Mar  5 17:26:47 2008
@@ -37,16 +37,16 @@
 from gui.PopupBox import PopupBox
 from gui.AlertBox import AlertBox
 
+from event import *
 from item import Item
 from programitem import ProgramItem
-from event import *
 
-import epg_xmltv, epg_types
+import tv.epg_xmltv
+from tv.epg_types import TvProgram
 from tv.record_client import RecordClient
 
 skin = skin.get_singleton()
-skin.register('tv', ('screen', 'title', 'subtitle', 'view',
-                     'tvlisting', 'info', 'plugin'))
+skin.register('tv', ('screen', 'title', 'subtitle', 'view', 'tvlisting', 
'info', 'plugin'))
 
 CHAN_NO_DATA = _('This channel has no data loaded')
 
@@ -65,9 +65,9 @@
 
         # constructing the guide takes some time
         msgtext = _('Preparing the program guide')
-        guide = epg_xmltv.get_guide(PopupBox(text=msgtext))
+        guide = tv.epg_xmltv.get_guide(PopupBox(text=msgtext))
         # getting channels
-        channels = guide.GetPrograms(start=start_time+1, stop=stop_time-1)
+        channels = guide.get_programs(start=start_time+1, stop=stop_time-1)
         if not channels:
             AlertBox(text=_('TV Guide is corrupt!')).show()
             return
@@ -147,7 +147,6 @@
         Handles events in the tv guide
         """
         _debug_('eventhandler(event=%r, menuw=%r)' % (event.name, menuw), 2)
-        event_consumed = False
 
         ## MENU_CHANGE_STYLE
         if event == MENU_CHANGE_STYLE:
@@ -185,37 +184,37 @@
 
                 self.n_cols  = (stop_time - start_time) / 60 / self.col_time
                 self.rebuild(start_time, stop_time, start_channel, selected)
-            event_consumed = True
+            return True
 
         ## MENU_UP: Move one channel up in the guide
-        if event == MENU_UP:
+        elif event == MENU_UP:
             self.change_channel(-1)
-            event_consumed = True
+            return True
 
         ## MENU_DOWN: Move one channel down in the guide
         elif event == MENU_DOWN:
             self.change_channel(1)
-            event_consumed = True
+            return True
 
         ## MENU_LEFT: Move to the next program on this channel
         elif event == MENU_LEFT:
             self.change_program(-1)
-            event_consumed = True
+            return True
 
         ## MENU_RIGHT: Move to previous programm on this channel
         elif event == MENU_RIGHT:
             self.change_program(1)
-            event_consumed = True
+            return True
 
         ## MENU_PAGEUP: Moves to the first of the currently displayed channels
         elif event == MENU_PAGEUP:
             self.change_channel(-self.n_items)
-            event_consumed = True
+            return True
 
         ## MENU_PAGEDOWN: Move to the last of the currently displayed channels
         elif event == MENU_PAGEDOWN:
             self.change_channel(self.n_items)
-            event_consumed = True
+            return True
 
 
         ## MENU_SUBMENU: Open a submenu for the selected program
@@ -224,7 +223,7 @@
             pi = ProgramItem(self, prog=self.selected, context='guide')
             #and show its submenu
             pi.display_submenu(menuw=self.menuw)
-            event_consumed = True
+            return True
 
         ## MENU_SELECT: Show the description
         elif event == MENU_SELECT:
@@ -232,13 +231,13 @@
             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)
-            event_consumed = True
+            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)
-            event_consumed = True
+            return True
 
         ## PLAY: Start to watch the selected channel (if it is possible)
         elif event == PLAY:
@@ -246,48 +245,38 @@
             pi = ProgramItem(self, prog=self.selected, context='guide')
             #and show its submenu
             pi.play(menuw=self.menuw)
-            event_consumed = True
+            return True
 
         ## PLAY_END: Show the guide again
         elif event == PLAY_END:
             self.show()
-            event_consumed = True
+            return True
 
         # FIX or REMOVE:
         # the numerical INPUT events are not available in the tvmenu context
         ## 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
+        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(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)
-                event_consumed = True
+            self.rebuild(self.start_time, self.stop_time, self.start_channel, 
self.selected)
+            return True
 
-        return event_consumed
+        return False
 
 
     ### gui functions
@@ -336,23 +325,23 @@
                 try:
                     for p in t.programs:
                         if p in self.scheduled_programs:
-                            p.scheduled = TRUE
+                            p.scheduled = True
                             # DO NOT change this to 'True' Twisted
                             # does not support boolean objects and
                             # it will break under Python 2.3
                         else:
-                            p.scheduled = FALSE
-                            # Same as above; leave as 'FALSE' until
+                            p.scheduled = False
+                            # Same as above; leave as 'False' until
                             # Twisted includes Boolean
                         if p in self.overlap_programs:
-                            p.overlap = TRUE
+                            p.overlap = True
                         else:
-                            p.overlap = FALSE
+                            p.overlap = False
 
                         if p in self.favorite_programs:
-                            p.favorite = TRUE
+                            p.favorite = True
                         else:
-                            p.favorite = FALSE
+                            p.favorite = False
                 except:
                     pass
 
@@ -370,9 +359,9 @@
 
         # we need to determine the program,
         # that is running now at the selected channel
-        programs = self.guide.GetPrograms(start=start_time+1, 
stop=stop_time-1, chanids=old_selected.channel_id)
+        programs = self.guide.get_programs(start=start_time+1, 
stop=stop_time-1, chanids=old_selected.channel_id)
 
-        if (len(programs) > 0) and (len(programs[0].programs) > 0):
+        if len(programs) > 0 and len(programs[0].programs) > 0:
             selected = programs[0].programs[0]
         else:
             selected = None
@@ -390,9 +379,9 @@
         start_channel = self.start_channel
 
         # we need to determine the new selected program
-        programs = self.guide.GetPrograms(start=new_start_time+1, 
stop=new_end_time-1, chanids=self.start_channel)
+        programs = self.guide.get_programs(start=new_start_time+1, 
stop=new_end_time-1, chanids=self.start_channel)
 
-        if (len(programs) > 0) and (len(programs[0].programs) > 0):
+        if len(programs) > 0 and len(programs[0].programs) > 0:
             selected = programs[0].programs[0]
         else:
             selected = None
@@ -407,8 +396,9 @@
         displayed, this is the case when the user moves around in the menu.
         """
         _debug_('rebuild(start_time=%r, stop_time=%r, start_channel=%r, 
selected=%r)' % (start_time, stop_time, start_channel, selected), 1)
-        self.guide = epg_xmltv.get_guide()
-        channels = self.guide.GetPrograms(start=start_time+1, stop=stop_time-1)
+        self.guide = tv.epg_xmltv.get_guide()
+        #channels = self.guide.get_programs(start=start_time+1, 
stop=stop_time-1, chanids=[start_channel])
+        channels = self.guide.get_programs(start=start_time+1, 
stop=stop_time-1, chanids=None)
 
         table = [ ]
 
@@ -417,8 +407,8 @@
         self.start_channel = start_channel
         self.selected      = selected
 
-        self.display_up_arrow   = FALSE
-        self.display_down_arrow = FALSE
+        self.display_up_arrow   = False
+        self.display_down_arrow = False
 
         # table header
         table += [ ['Chan'] ]
@@ -436,26 +426,20 @@
         n = 0
         for chan in channels:
             if n >= self.n_items:
-                self.display_down_arrow = TRUE
+                self.display_down_arrow = True
                 break
 
             if start_channel != None and chan.id == start_channel:
                 found_1stchannel = 1
 
             if not found_1stchannel:
-                self.display_up_arrow = TRUE
+                self.display_up_arrow = True
 
             if found_1stchannel:
                 if not chan.programs:
-                    prg = epg_types.TvProgram()
-                    prg.channel_id = chan.id
-                    prg.start = 0
-                    prg.stop = 2147483647   # Year 2038
-                    prg.title = CHAN_NO_DATA
-                    prg.desc = ''
+                    prg = TvProgram(CHAN_NO_DATA, chan.id, 0, 2147483647, 
desc='')
                     chan.programs = [ prg ]
 
-
                 for i in range(len(chan.programs)):
                     if selected:
                         if chan.programs[i] == selected:
@@ -495,9 +479,9 @@
 
         channel = self.guide.chan_dict[last_prg.channel_id]
         if full_scan:
-            all_programs = self.guide.GetPrograms(start_time-24*60*60, 
stop_time+24*60*60, [ channel.id ])
+            all_programs = self.guide.get_programs(start_time-24*60*60, 
stop_time+24*60*60, [ channel.id ])
         else:
-            all_programs = self.guide.GetPrograms(start_time+1, stop_time-1, [ 
channel.id ])
+            all_programs = self.guide.get_programs(start_time+1, stop_time-1, 
[ channel.id ])
 
         # Current channel programs
         programs = all_programs[0].programs
@@ -546,12 +530,7 @@
                 start_time -= (self.col_time * 60)
                 stop_time -= (self.col_time * 60)
         else:
-            prg = epg_types.TvProgram()
-            prg.channel_id = channel.id
-            prg.start = 0
-            prg.stop = 2147483647   # Year 2038
-            prg.title = CHAN_NO_DATA
-            prg.desc = ''
+            prg = TvProgram(CHAN_NO_DATA, channel.id, 0, 2147483647, '')
             to_info = CHAN_NO_DATA
 
         self.rebuild(start_time, stop_time, start_channel, prg)
@@ -585,7 +564,7 @@
         channel = self.guide.chan_list[channel_pos]
 
 
-        programs = self.guide.GetPrograms(start_time+1, stop_time-1, [ 
channel.id ])
+        programs = self.guide.get_programs(start_time+1, stop_time-1, [ 
channel.id ])
         programs = programs[0].programs
 
         prg = None
@@ -602,12 +581,7 @@
 
             to_info = (prg.title, procdesc)
         else:
-            prg = epg_types.TvProgram()
-            prg.channel_id = channel.id
-            prg.start = 0
-            prg.stop = 2147483647   # Year 2038
-            prg.title = CHAN_NO_DATA
-            prg.desc = ''
+            prg = TvProgram(CHAN_NO_DATA, channel.id, 0, 2147483647, '')
             to_info = CHAN_NO_DATA
 
         self.rebuild(start_time, stop_time, start_channel, prg)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to