Author: duncan
Date: Mon Jan 29 22:22:21 2007
New Revision: 9099

Modified:
   branches/rel-1/freevo/src/event.py
   branches/rel-1/freevo/src/tv/edit_favorite.py
   branches/rel-1/freevo/src/tv/program_display.py
   branches/rel-1/freevo/src/tv/tvguide.py

Log:
[ 1647456 ] Improvement of tvguide usage (patch)
Patch from Tanja applied


Modified: branches/rel-1/freevo/src/event.py
==============================================================================
--- branches/rel-1/freevo/src/event.py  (original)
+++ branches/rel-1/freevo/src/event.py  Mon Jan 29 22:22:21 2007
@@ -5,11 +5,11 @@
 # $Id$
 #
 # Notes:
-# Todo:        
+# Todo:
 #
 # -----------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
-# Copyright (C) 2002 Krister Lagerstrom, et al. 
+# Copyright (C) 2002 Krister Lagerstrom, et al.
 # Please see the file freevo/Docs/CREDITS for a complete list of authors.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -45,7 +45,7 @@
             self.arg     = None
             self.context = None
             self.handler = None
-        
+
         if arg or arg == 0:
             self.arg = arg
 
@@ -70,7 +70,7 @@
         """
         return int(self.name[-1])
 
-    
+
     def __cmp__(self, other):
         """
         compare function, return 0 if the objects are identical, 1 otherwise
@@ -101,9 +101,9 @@
 PLAYLIST_NEXT          = Event('PLAYLIST_NEXT')
 PLAYLIST_PREV          = Event('PLAYLIST_PREV')
 PLAYLIST_TOGGLE_REPEAT = Event('PLAYLIST_TOGGLE_REPEAT')
-                       
+
 EJECT                  = Event('EJECT')
-                       
+
 #
 # Menu
 #
@@ -115,7 +115,7 @@
 MENU_PAGEUP            = Event('MENU_PAGEUP')
 MENU_PAGEDOWN          = Event('MENU_PAGEDOWN')
 MENU_REBUILD           = Event('MENU_REBUILD')
-                       
+
 MENU_GOTO_MAINMENU     = Event('MENU_GOTO_MAINMENU')
 MENU_GOTO_TV           = Event('MENU_GOTO_TV')
 MENU_GOTO_TVGUIDE      = Event('MENU_GOTO_TVGUIDE')
@@ -126,7 +126,7 @@
 MENU_GOTO_RADIO        = Event('MENU_GOTO_RADIO')
 MENU_GOTO_SHUTDOWN     = Event('MENU_GOTO_SHUTDOWN')
 MENU_BACK_ONE_MENU     = Event('MENU_BACK_ONE_MENU')
-                       
+
 MENU_SELECT            = Event('MENU_SELECT')
 MENU_PLAY_ITEM         = Event('MENU_PLAY_ITEM')
 MENU_SUBMENU           = Event('MENU_SUBMENU')
@@ -271,7 +271,7 @@
     'ENTER'     : MENU_SUBMENU,
     'DISPLAY'   : MENU_CHANGE_STYLE,
     'EJECT'     : EJECT
-    } 
+    }
 
 TVMENU_EVENTS = {
     'LEFT'      : MENU_LEFT,
@@ -284,19 +284,10 @@
     'SHUTDOWN'  : MENU_GOTO_SHUTDOWN,
     'EXIT'      : MENU_BACK_ONE_MENU,
     'SELECT'    : MENU_SELECT,
+    'ENTER'     : MENU_SUBMENU,
     'DISPLAY'   : MENU_CHANGE_STYLE,
-    'REC'       : TV_START_RECORDING,
-    '1'         : INPUT_1,
-    '2'         : INPUT_2,
-    '3'         : INPUT_3,
-    '4'         : INPUT_4,
-    '5'         : INPUT_5,
-    '6'         : INPUT_6,
-    '7'         : INPUT_7,
-    '8'         : INPUT_8,
-    '9'         : INPUT_9,
-    '0'         : INPUT_0
-    } 
+    'REC'       : TV_START_RECORDING
+    }
 
 INPUT_EVENTS = {
     'EXIT'      : INPUT_EXIT,
@@ -435,7 +426,7 @@
     '8'         : INPUT_8,
     '9'         : INPUT_9,
     }
-    
+
 IMAGE_EVENTS = {
     'STOP'      : STOP,
     'EXIT'      : STOP,
@@ -499,7 +490,7 @@
     'VOL-'      : MIXER_VOLDOWN,
     'MUTE'      : MIXER_MUTE
     }
-    
+
 
 import pygame.locals as key
 

Modified: branches/rel-1/freevo/src/tv/edit_favorite.py
==============================================================================
--- branches/rel-1/freevo/src/tv/edit_favorite.py       (original)
+++ branches/rel-1/freevo/src/tv/edit_favorite.py       Mon Jan 29 22:22:21 2007
@@ -1,11 +1,11 @@
 # -*- coding: iso-8859-1 -*-
 # -----------------------------------------------------------------------
-# EditFavorite - 
+# EditFavorite -
 # -----------------------------------------------------------------------
 # $Id$
 #
-# Todo: 
-# Notes: 
+# Todo:
+# Notes:
 #
 # -----------------------------------------------------------------------
 #
@@ -62,7 +62,7 @@
     height    Integer
     context   Context in which the object is instanciated
     """
-    
+
     def __init__(self, parent=None, subject=None, left=None, top=None, 
width=500,
                  height=350, context=None):
 
@@ -80,14 +80,15 @@
             else:
                 self.priority = 1
 
-            self.fav = Favorite(subject.title, subject, TRUE, TRUE, TRUE, 
self.priority, TRUE, FALSE)
+            self.fav = Favorite(subject.title, subject, TRUE, TRUE, TRUE,
+                                self.priority, TRUE, FALSE)
         else:
             self.fav = subject
             self.oldname = self.fav.name
-            
 
 
-        PopupBox.__init__(self, text=_('Edit Favorite'), x=left, y=top, 
width=width, 
+
+        PopupBox.__init__(self, text=_('Edit Favorite'), x=left, y=top, 
width=width,
                           height=height)
 
         self.v_spacing = 15
@@ -114,7 +115,7 @@
         self.chan_box = OptionBox('ANY')
         self.chan_box.h_align = Align.NONE
         self.chan_box.add_item(text=_('ANY'), value='ANY')
-      
+
         i = 1
         chan_index = 0
         for ch in guide.chan_list:
@@ -160,7 +161,7 @@
 
         i = 0
         tod_index = 0
-        
+
         for h in range(0,24):
             for m in (00, 30):
                 val = i*30
@@ -189,14 +190,14 @@
         self.add_child(self.cancel)
 
     def removeFavorite(self):
-       (result, msg) = record_client.removeFavorite(self.oldname) 
+       (result, msg) = record_client.removeFavorite(self.oldname)
        if result:
            searcher = None
            if self.parent and self.context == 'favorites':
                for child in self.parent.children:
                    if isinstance(child, ViewFavorites):
                        searcher = child
-                       break 
+                       break
                if searcher:
                    searcher.refreshList()
                self.destroy()
@@ -231,7 +232,7 @@
                 self.name_input.get_selected_box().charDown()
                 self.draw()
                 return True
-            elif event in em.INPUT_ALL_NUMBERS: 
+            elif event in em.INPUT_ALL_NUMBERS:
                 self.name_input.get_selected_box().cycle_phone_char(event)
                 self.draw()
                 return True
@@ -306,11 +307,11 @@
                 if self.oldname:
                     record_client.removeFavorite(self.oldname)
                 (result, msg) = record_client.addEditedFavorite(
-                             self.name_input.get_word(), 
-                             self.fav.title, 
+                             self.name_input.get_word(),
+                             self.fav.title,
                              self.chan_box.list.get_selected_item().value,
-                             self.dow_box.list.get_selected_item().value, 
-                             self.tod_box.list.get_selected_item().value, 
+                             self.dow_box.list.get_selected_item().value,
+                             self.tod_box.list.get_selected_item().value,
                              self.fav.priority,
                              self.fav.allowDuplicates,
                              self.fav.onlyNew)
@@ -354,7 +355,7 @@
                 self.destroy()
                 return True
             return True
-        
+
         elif self.get_selected_child() == self.cancel:
             if event in (em.INPUT_LEFT, em.MENU_PAGEUP):
                 if self.remove:

Modified: branches/rel-1/freevo/src/tv/program_display.py
==============================================================================
--- branches/rel-1/freevo/src/tv/program_display.py     (original)
+++ branches/rel-1/freevo/src/tv/program_display.py     Mon Jan 29 22:22:21 2007
@@ -4,8 +4,8 @@
 # -----------------------------------------------------------------------
 # $Id$
 #
-# Todo: 
-# Notes: 
+# Todo:
+# Notes:
 #
 # -----------------------------------------------------------------------
 #
@@ -49,6 +49,9 @@
 
 
 class ProgramItem(Item):
+    """
+    Item class for program items in the tv guide
+    """
     def __init__(self, parent, prog, context='guide'):
         Item.__init__(self, parent, skin_type='video')
         self.prog = prog
@@ -86,7 +89,7 @@
                     self.categories += '%s' % cat
         except AttributeError:
             pass
-        
+
         self.ratings = ''
         try:
             for rat in prog.ratings.keys():
@@ -99,27 +102,48 @@
         return [( self.display_program , _('Display program') )]
 
 
+    ### action menu
     def display_program(self, arg=None, menuw=None):
+        """ creates the submenu for a programm
+
+        Entries of this menu:
+            1.) 'Schedule for recording' OR 'Remove from schedule'
+            2.) 'Search for more of this program'
+            3.) 'Add to favorites' OR 'Remove from favorites'
+        This function checks if the program is already scheduled or a favorite
+        and chooses the appropriate menu entries.
+        """
+
+        #list of entries for the menu
         items = []
 
+
+        ## 1.) 'Schedule for recording' OR 'Remove from schedule'
+        # check if this program is scheduled
         (got_schedule, schedule) = record_client.getScheduledRecordings()
         if got_schedule:
-            (result, message) = record_client.isProgScheduled(self.prog, 
-                                                              
schedule.getProgramList())
+            (result, message) = record_client.isProgScheduled(self.prog,
+                                               schedule.getProgramList())
             if result:
                 self.scheduled = True
+            else:
+                self.scheduled = False
 
         if self.scheduled:
-            items.append(menu.MenuItem(_('Remove from schedule'), 
+            items.append(menu.MenuItem(_('Remove from schedule'),
                                        action=self.remove_program))
         else:
-            items.append(menu.MenuItem(_('Schedule for recording'), 
+            items.append(menu.MenuItem(_('Schedule for recording'),
                                        action=self.schedule_program))
 
-        if self.context != 'search':
-            items.append(menu.MenuItem(_('Search for more of this program'), 
+
+        ## 2.) 'Seach for more of this menu
+        if not self.context == 'search':
+            items.append(menu.MenuItem(_('Search for more of this program'),
                                        action=self.find_more))
 
+        ##3.) 'Add to favorites' OR 'Remove from favorites'
+        # check if this program is a favorite
         (got_favs, favs) = record_client.getFavorites()
         if got_favs:
             (result, junk) = record_client.isProgAFavorite(self.prog, favs)
@@ -127,32 +151,44 @@
                 self.favorite = True
 
         if self.favorite:
-            items.append(menu.MenuItem(_('Remove from favorites'), 
+            items.append(menu.MenuItem(_('Remove from favorites'),
                                        action=self.rem_favorite))
         else:
-            items.append(menu.MenuItem(_('Add to favorites'), 
+            items.append(menu.MenuItem(_('Add to favorites'),
                                        action=self.add_favorite))
 
-        program_menu = menu.Menu(_('Program Menu'), items, 
+
+        ## Create the resulting menu
+        program_menu = menu.Menu(_('Program Menu'), items,
                                  item_types = 'tv program menu')
         program_menu.infoitem = self
         menuw.pushmenu(program_menu)
         menuw.refresh()
 
 
+    ### Actions:
+
     def add_favorite(self, arg=None, menuw=None):
-        fav = Favorite(self.prog.title, self.prog, True, True, True, -1, True, 
False)
+        """
+        Add a program to favorites
+        """
+        fav = Favorite(self.prog.title, self.prog,
+                       True, True, True, -1, True, False)
         fav_item = FavoriteItem(self, fav, fav_action='add')
         fav_item.display_favorite(menuw=menuw)
 
 
     def rem_favorite(self, arg=None, menuw=None):
+        """
+        Remove a program from the list of favorites
+        """
         pass
 
 
     def find_more(self, arg=None, menuw=None):
-        # XXX: The searching part of this function could probably be moved
-        #      into a util module or record_client itself.
+        """
+        Find more of this program
+        """
         _debug_(String('searching for: %s' % self.prog.title))
 
         pop = AlertBox(text=_('Searching, please wait...'))
@@ -160,7 +196,7 @@
 
         items = []
         (result, matches) = record_client.findMatches(self.prog.title)
-                             
+
         pop.destroy()
         if result:
             _debug_('search found %s matches' % len(matches))
@@ -168,21 +204,27 @@
             f = lambda a, b: cmp(a.start, b.start)
             matches.sort(f)
             for prog in matches:
-               items.append(ProgramItem(self, prog, context='search'))
+                items.append(ProgramItem(self, prog, context='search'))
         else:
             if matches == 'no matches':
-                AlertBox(text=_('No matches found for %s') % 
self.prog.title).show()
+                msgtext = _('No matches found for %s') % self.prog.title
+                AlertBox(text=msgtext).show()
                 return
             AlertBox(text=_('findMatches failed: %s') % matches).show()
             return
 
         search_menu = menu.Menu(_( 'Search Results' ), items,
                                 item_types = 'tv program menu')
+
         menuw.pushmenu(search_menu)
         menuw.refresh()
 
 
+
     def schedule_program(self, arg=None, menuw=None):
+        """
+        add a program to schedule
+        """
         (result, msg) = record_client.scheduleRecording(self.prog)
         if result:
             if menuw:
@@ -194,26 +236,30 @@
                      self.prog.title).show()
         else:
             AlertBox(text=_('Scheduling Failed')+(': %s' % msg)).show()
-        # then menu back one or refresh the menu with remove option
-        # instead of schedule
 
 
     def remove_program(self, arg=None, menuw=None):
+        """
+        remove a program from schedule
+        """
         (result, msg) = record_client.removeScheduledRecording(self.prog)
         if result:
             # then menu back one which should show an updated list if we
             # were viewing scheduled recordings or back to the guide and
             # update the colour of the program we selected.
             # or refresh the menu with remove option instead of schedule
-            if menuw:  
+            if menuw:
                 menuw.back_one_menu(arg='reload')
-
+            AlertBox(text=_('"%s" has been removed from schedule') % \
+                          self.prog.title).show()
         else:
             AlertBox(text=_('Remove Failed')+(': %s' % msg)).show()
 
 
-
 class FavoriteItem(Item):
+    """
+    Item class for favorite items
+    """
     def __init__(self, parent, fav, fav_action='edit'):
         Item.__init__(self, parent, skin_type='video')
         self.fav   = fav
@@ -229,7 +275,8 @@
         else:
            self.onlyNew = 0
 
-        self.week_days = (_('Mon'), _('Tue'), _('Wed'), _('Thu'), _('Fri'), 
_('Sat'), _('Sun'))
+        self.week_days = (_('Mon'), _('Tue'), _('Wed'), _('Thu'),
+                          _('Fri'), _('Sat'), _('Sun'))
 
         if fav.channel == 'ANY':
             self.channel = _('ANY CHANNEL')
@@ -243,7 +290,8 @@
             self.mod = _('ANY TIME')
         else:
             try:
-                self.mod = strftime(config.TV_TIMEFORMAT, 
gmtime(float(int(fav.mod) * 60)))
+                self.mod = strftime(config.TV_TIMEFORMAT,
+                                    gmtime(float(int(fav.mod) * 60)))
             except:
                 print 'Cannot add "%s" to favorites' % fav.name
 
@@ -256,35 +304,62 @@
 
 
     def display_favorite(self, arg=None, menuw=None):
+        """ Display menu for a favorite
+
+        With this menu the user can made a program a favorite.
+        All attributes of a favorite can be edited here and in the end
+        the user must select 'save changes' to finally create the favorite
+        or else choose not to remove the favorite by selecting 'Remove 
favorite'.
+        """
+
+        ### create menu items for editing the favorites attributes
         items = []
 
-        items.append(menu.MenuItem(_('Modify name'), action=self.mod_name))
-        items.append(menu.MenuItem(_('Modify channel'), 
action=self.mod_channel))
-        items.append(menu.MenuItem(_('Modify day of week'), 
action=self.mod_day))
-        items.append(menu.MenuItem(_('Modify time of day'), 
action=self.mod_time))
+        items.append(menu.MenuItem(_('Modify name'),
+                                    action=self.mod_name))
+        items.append(menu.MenuItem(_('Modify channel'),
+                                    action=self.mod_channel))
+        items.append(menu.MenuItem(_('Modify day of week'),
+                                    action=self.mod_day))
+        items.append(menu.MenuItem(_('Modify time of day'),
+                                    action=self.mod_time))
         if config.DUPLICATE_DETECTION:
-           items.append(menu.MenuItem(_('Modify duplicate flag'), 
action=self.mod_dup))
+           items.append(menu.MenuItem(_('Modify duplicate flag'),
+                                       action=self.mod_dup))
         if config.ONLY_NEW_DETECTION:
-           items.append(menu.MenuItem(_('Modify episodes flag'), 
action=self.mod_new))
+           items.append(menu.MenuItem(_('Modify episodes flag'),
+                                        action=self.mod_new))
 
         # XXX: priorities aren't quite supported yet
         if 0:
             (got_favs, favs) = record_client.getFavorites()
             if got_favs and len(favs) > 1:
-                items.append(menu.MenuItem(_('Modify priority'), 
+                items.append(menu.MenuItem(_('Modify priority'),
                                            action=self.mod_priority))
 
-        items.append(menu.MenuItem(_('Save changes'), 
action=self.save_changes))
-        items.append(menu.MenuItem(_('Remove favorite'), 
action=self.rem_favorite))
+        ### save favorite
+        items.append(menu.MenuItem(_('Save changes'),
+                                    action=self.save_changes))
+        ### cancel saving this program as favorite
+        items.append(menu.MenuItem(_('Remove favorite'),
+                                    action=self.rem_favorite))
 
-        favorite_menu = menu.Menu(_('Favorite Menu'), items, 
-                                 item_types = 'tv favorite menu')
+        ### put the whole menu together
+        favorite_menu = menu.Menu(_('Favorite Menu'), items,
+                                  item_types = 'tv favorite menu')
         favorite_menu.infoitem = self
         menuw.pushmenu(favorite_menu)
         menuw.refresh()
 
 
+    ### Actions:
+
     def mod_name(self, arg=None, menuw=None):
+        """ Modify name
+
+        This opens a input box to ask the user for a new name for this 
favorite.
+        The default name of a favorite is the name of the program.
+        """
         self.menuw = menuw
         InputBox(text=_('Alter Name'), handler=self.alter_name,
                  width = osd.get_singleton().width - config.OSD_OVERSCAN_X - 
20,
@@ -292,30 +367,51 @@
 
 
     def alter_name(self, name):
+        """ set the new name"""
         if name:
             self.name = self.fav.name = name
 
         self.menuw.refresh()
 
+
     def mod_dup(self, arg=None, menuw=None):
+        """ Modify duplication flag
+
+        This opens a submenu where the user can change the settings for the
+        duplication detection.
+        """
         items = []
-        items.append(menu.MenuItem('Allow Duplicates', 
action=self.alter_prop,arg=('dup', 'True')))
-        items.append(menu.MenuItem('Prevent Duplicates', 
action=self.alter_prop,arg=('dup', 'False')))
-        favorite_menu = menu.Menu(_('Modify Duplicate Flag'), items,item_types 
= 'tv favorite menu')
+        items.append(menu.MenuItem('Allow Duplicates', action=self.alter_prop,
+                                   arg=('dup', 'True')))
+        items.append(menu.MenuItem('Prevent Duplicates', 
action=self.alter_prop,
+                                   arg=('dup', 'False')))
+        favorite_menu = menu.Menu(_('Modify Duplicate Flag'), items,
+                                   item_types = 'tv favorite menu')
         favorite_menu.infoitem = self
         menuw.pushmenu(favorite_menu)
         menuw.refresh()
 
+
     def mod_new(self, arg=None, menuw=None):
+        """ Modify new flag
+
+        This opens a submenu where the user can choose if all episodes of
+        a program should be recorded or only new ones.
+        """
         items = []
-        items.append(menu.MenuItem('All Episodes', 
action=self.alter_prop,arg=('new', 'False')))
-        items.append(menu.MenuItem('Only New Episodes', 
action=self.alter_prop,arg=('new', 'True')))
-        favorite_menu = menu.Menu(_('Modify Only New Flag'), items,item_types 
= 'tv favorite menu')
+        items.append(menu.MenuItem('All Episodes', action=self.alter_prop,
+                                   arg=('new', 'False')))
+        items.append(menu.MenuItem('Only New Episodes', action=self.alter_prop,
+                                   arg=('new', 'True')))
+        favorite_menu = menu.Menu(_('Modify Only New Flag'), items,
+                                   item_types = 'tv favorite menu')
         favorite_menu.infoitem = self
         menuw.pushmenu(favorite_menu)
         menuw.refresh()
 
+
     def mod_channel(self, arg=None, menuw=None):
+        """Modify channel"""
         items = []
 
         items.append(menu.MenuItem('ANY CHANNEL', action=self.alter_prop,
@@ -325,7 +421,52 @@
             items.append(menu.MenuItem(chanline[1], action=self.alter_prop,
                          arg=('channel', chanline[1])))
 
-        favorite_menu = menu.Menu(_('Modify Channel'), items, 
+        favorite_menu = menu.Menu(_('Modify Channel'), items,
+                                  item_types = 'tv favorite menu')
+        favorite_menu.infoitem = self
+        menuw.pushmenu(favorite_menu)
+        menuw.refresh()
+
+
+    def mod_day(self, arg=None, menuw=None):
+        """ Modify day
+
+        Opens a submenu where the day of the week of a favorite can be 
configured.
+        """
+        items = []
+
+        items.append(menu.MenuItem('ANY DAY', action=self.alter_prop,
+                     arg=('dow', 'ANY')))
+
+        for i in range(len(self.week_days)):
+            items.append(menu.MenuItem(self.week_days[i], 
action=self.alter_prop,
+                         arg=('dow', i)))
+
+        favorite_menu = menu.Menu(_('Modify Day'), items,
+                                  item_types = 'tv favorite menu')
+        favorite_menu.infoitem = self
+        menuw.pushmenu(favorite_menu)
+        menuw.refresh()
+
+
+    def mod_time(self, arg=None, menuw=None):
+        """ Modify time
+
+        Opens a submenu where the time of a favorite can be configured.
+        """
+        items = []
+
+        items.append(menu.MenuItem('ANY TIME', action=self.alter_prop,
+                     arg=('mod', 'ANY')))
+
+        for i in range(48):
+            mod = i * 30
+            items.append(menu.MenuItem(strftime(config.TV_TIMEFORMAT,
+                                                gmtime(float(mod * 60))),
+                                       action=self.alter_prop,
+                                       arg=('mod', mod)))
+
+        favorite_menu = menu.Menu(_('Modify Time'), items,
                                   item_types = 'tv favorite menu')
         favorite_menu.infoitem = self
         menuw.pushmenu(favorite_menu)
@@ -333,6 +474,11 @@
 
 
     def alter_prop(self, arg=(None,None), menuw=None):
+        """ Alter a favorites property
+
+        This function is where the properties of a favorite really are changed.
+        """
+
         (prop, val) = arg
 
         if prop == 'channel':
@@ -357,7 +503,7 @@
                 self.fav.mod = 'ANY'
             else:
                 # self.mod = tv_util.minToTOD(val)
-                self.mod = strftime(config.TV_TIMEFORMAT, 
+                self.mod = strftime(config.TV_TIMEFORMAT,
                                     gmtime(float(val * 60)))
                 self.fav.mod = val
 
@@ -377,71 +523,42 @@
                 self.onlyNew=FALSE
                 self.fav.onlyNew=FALSE
 
-        if menuw:  
+        if menuw:
             menuw.back_one_menu(arg='reload')
 
 
-    def mod_day(self, arg=None, menuw=None):
-        items = []
-
-        items.append(menu.MenuItem('ANY DAY', action=self.alter_prop,
-                     arg=('dow', 'ANY')))
-
-        for i in range(len(self.week_days)):
-            items.append(menu.MenuItem(self.week_days[i], 
action=self.alter_prop,
-                         arg=('dow', i)))
-
-        favorite_menu = menu.Menu(_('Modify Day'), items, 
-                                  item_types = 'tv favorite menu')
-        favorite_menu.infoitem = self
-        menuw.pushmenu(favorite_menu)
-        menuw.refresh()
-
-
-    def mod_time(self, arg=None, menuw=None):
-        items = []
-
-        items.append(menu.MenuItem('ANY TIME', action=self.alter_prop,
-                     arg=('mod', 'ANY')))
-
-        for i in range(48):
-            mod = i * 30 
-            items.append(menu.MenuItem(strftime(config.TV_TIMEFORMAT, 
-                                                gmtime(float(mod * 60))), 
-                                       action=self.alter_prop,
-                                       arg=('mod', mod)))
-
-        favorite_menu = menu.Menu(_('Modify Time'), items, 
-                                  item_types = 'tv favorite menu')
-        favorite_menu.infoitem = self
-        menuw.pushmenu(favorite_menu)
-        menuw.refresh()
-
-
     def save_changes(self, arg=None, menuw=None):
+        """
+        Save favorite
+        """
+
         if self.fav_action == 'edit':
             (result, msg) = record_client.removeFavorite(self.origname)
         else:
             result = True
 
         if result:
-           if not config.DUPLICATE_DETECTION or not 
hasattr(self.fav,'allowDuplicates'):
+           if not config.DUPLICATE_DETECTION or not hasattr(self.fav,
+                                                            'allowDuplicates'):
               self.fav.allowDuplicates = 1
-           if not config.ONLY_NEW_DETECTION or not hasattr(self.fav,'onlyNew'):
+           if not config.ONLY_NEW_DETECTION or not hasattr(self.fav,
+                                                           'onlyNew'):
               self.fav.onlyNew = 0
-           (result, msg) = record_client.addEditedFavorite(self.fav.name, 
-                                                            self.fav.title, 
-                                                            self.fav.channel, 
-                                                            self.fav.dow, 
-                                                            self.fav.mod, 
-                                                            self.fav.priority,
-                                                            
self.fav.allowDuplicates,
-                                                            self.fav.onlyNew)
+
+           (result, msg) = record_client.addEditedFavorite(self.fav.name,
+                                                           self.fav.title,
+                                                           self.fav.channel,
+                                                           self.fav.dow,
+                                                           self.fav.mod,
+                                                           self.fav.priority,
+                                                           
self.fav.allowDuplicates,
+                                                           self.fav.onlyNew)
            if not result:
-                AlertBox(text=_('Save Failed, favorite was lost')+(': %s' % 
msg)).show()
+                msgtext=_('Save Failed, favorite was lost')+(': %s' % msg)
+                AlertBox(text=msgtext).show()
            else:
                 self.fav_action = 'edit'
-                if menuw:  
+                if menuw:
                     menuw.back_one_menu(arg='reload')
 
         else:
@@ -449,21 +566,20 @@
 
 
     def rem_favorite(self, arg=None, menuw=None):
+        """
+        Remove favorite
+        """
         if self.fav_action == 'add':
             AlertBox(text=_('Favorite not added yet.')).show()
             return
-       
+
         (result, msg) = record_client.removeFavorite(self.origname)
         if result:
             # then menu back one which should show an updated list if we
             # were viewing favorites or back to the program display
             # or refresh the program menu with remove option instead of add
-            if menuw:  
+            if menuw:
                 menuw.back_one_menu(arg='reload')
 
         else:
             AlertBox(text=_('Remove Failed')+(': %s' % msg)).show()
-
-
-
-

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     Mon Jan 29 22:22:21 2007
@@ -1,15 +1,15 @@
 # -*- coding: iso-8859-1 -*-
 # -----------------------------------------------------------------------
-# tvguide.py - This is the Freevo TV Guide module. 
+# tvguide.py - This is the Freevo TV Guide module.
 # -----------------------------------------------------------------------
 # $Id$
 #
 # Notes:
-# Todo:        
+# Todo:
 #
 # -----------------------------------------------------------------------
 # Freevo - A Home Theater PC framework
-# Copyright (C) 2002 Krister Lagerstrom, et al. 
+# Copyright (C) 2002 Krister Lagerstrom, et al.
 # Please see the file freevo/Docs/CREDITS for a complete list of authors.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -51,7 +51,8 @@
 import record_client as ri
 
 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')
 
@@ -62,7 +63,8 @@
         self.n_items, hours_per_page = skin.items_per_page(('tv', self))
         stop_time = start_time + hours_per_page * 60 * 60
 
-        guide = epg_xmltv.get_guide(PopupBox(text=_('Preparing the program 
guide')))
+        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()
@@ -74,7 +76,7 @@
                 selected = chan.programs[0]
                 break
 
-        self.col_time = 30 # each col represents 30 minutes 
+        self.col_time = 30 # each col represents 30 minutes
         self.n_cols  = (stop_time - start_time) / 60 / self.col_time
         self.player = player
 
@@ -86,7 +88,7 @@
 
         self.lastinput_value = None
         self.lastinput_time = None
-        
+
         self.update_schedules(force=True)
         self.fc = FreevoChannels()
 
@@ -106,8 +108,8 @@
         upsoon = '%s/upsoon' % (config.FREEVO_CACHEDIR)
         if os.path.isfile(upsoon):
             os.unlink(upsoon)
-            
-        _debug_('update schedule')
+
+        _debug_('update schedule',2)
         self.last_update = time.time()
         self.scheduled_programs = []
         self.overlap_programs = []
@@ -123,10 +125,31 @@
                 if prog.overlap:
                     self.overlap_programs.append(prog.str2utf())
 
-        
+### event handler
+
     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: Execute the first entry in the submenu
+        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, 2)
 
+        ## MENU_CHANGE_STYLE
         if event == MENU_CHANGE_STYLE:
             if skin.toggle_display_style('tv'):
                 start_time    = self.start_time
@@ -147,7 +170,7 @@
                         before = 0
                     if c.id == selected.channel_id:
                         after = 0
-                    
+
                 if self.n_items <= before:
                     start_channel = selected.channel_id
 
@@ -157,132 +180,182 @@
                         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)
-                self.menuw.refresh()
-            
+
+        ## MENU_UP: Move one channel up in the guide
         if event == MENU_UP:
             self.event_change_channel(-1)
-            self.menuw.refresh()
 
+        ## MENU_DOWN: Move one channel down in the guide
         elif event == MENU_DOWN:
             self.event_change_channel(1)
-            self.menuw.refresh()
 
+        ## MENU_LEFT: Move to the next program on this channel
         elif event == MENU_LEFT:
             self.event_change_program(-1)
-            self.menuw.refresh()
 
+        ## MENU_RIGHT: Move to previous programm on this channel
         elif event == MENU_RIGHT:
             self.event_change_program(1)
-            self.menuw.refresh()
 
+        ## MENU_PAGEUP: Moves to the first of the currently displayed channels
         elif event == MENU_PAGEUP:
             self.event_change_channel(-self.n_items)
-            self.menuw.refresh()
 
+        ## MENU_PAGEDOWN: Move to the last of the currently displayed channels
         elif event == MENU_PAGEDOWN:
             self.event_change_channel(self.n_items)
-            self.menuw.refresh()
 
+        ## MENU_SUBMENU: Open a submenu for the selected program
         elif event == MENU_SUBMENU:
-            pass
+            self.event_submenu()
+
+        ## MENU_SELECT: Open a submenu for the selected program
+        elif event == MENU_SELECT:
+            self.event_record()
 
+        ## TV_START_RECORDING: Start to record this or put it on schedule
         elif event == TV_START_RECORDING:
-            self.event_RECORD()
-            self.menuw.refresh()
+            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.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 cencel 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)
+               newinput_value = int(eventInput)
             except:
-                #Protected against INPUT_UP, INPUT_DOWN, etc
-                isNumeric=FALSE
+               #Protected against INPUT_UP, INPUT_DOWN, etc
+               isNumeric=FALSE
             if isNumeric:
                 newinput_time = int(time.time())
                 if (self.lastinput_value != None):
-                    # allow 2 seconds delay for multiple digit channels
-                    if (newinput_time - self.lastinput_time < 2):
+                    # 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 + 
newinput_value
                 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   
            
+                    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)
-                self.menuw.refresh()
- 
-        
-        elif event == MENU_SELECT or event == PLAY:
 
-            suffix = self.fc.getVideoGroup(self.selected.channel_id, 
True).vdev.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_RECORD()
-            elif os.path.exists(tvlockfile):
-                # XXX: In the future add the options to watch what we are
-                #      recording or cencel 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)
-        
-        elif event == PLAY_END:
-            self.show()
+                self.rebuild(self.start_time, self.stop_time,
+                             self.start_channel, self.selected)
 
+        ## unknown event
         else:
             return FALSE
 
         return TRUE
 
 
+    ### actions
+
     def show(self):
+        """ show the guide"""
         if not self.visible:
             self.visible = 1
             self.refresh()
 
-            
+
     def hide(self):
+        """ hide the guide"""
         if self.visible:
             self.visible = 0
             skin.clear()
-        
+
 
     def refresh(self):
-        self.update_schedules(force=True)
+        """refresh the guide
+
+        This function is called automatically by freevo whenever this menu is
+        opened or reopened.
+        """
+        _debug_('Refresh',2)
         if not self.menuw.children:
             rc.set_context(self.event_context)
             self.menuw.refresh()
+        self.update()
+
+
+    def update(self):
+        """ update the tv guide
+
+        This function updates the scheduled and overlap flags for
+        all currently displayed programs.
+        """
+        _debug_('Update',2)
+        self.update_schedules(force=True)
+        if self.table:
+            for t in self.table:
+                try:
+                    for p in t.programs:
+                        if p in self.scheduled_programs:
+                            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
+                            # Twisted includes Boolean
+                        if p in self.overlap_programs:
+                            p.overlap = TRUE
+                        else:
+                            p.overlap = FALSE
+                except:
+                    pass
+
+        self.menuw.refresh()
+
 
 
     def rebuild(self, start_time, stop_time, start_channel, selected):
+        """ rebuild the guide
 
+        This is neccessary we change the set of programs that have to be
+        displayed, this is the case when the user moves around in the menu.
+        """
         self.guide = epg_xmltv.get_guide()
         channels = self.guide.GetPrograms(start=start_time+1, stop=stop_time-1)
 
         table = [ ]
-        self.update_schedules()
 
         self.start_time    = start_time
         self.stop_time     = stop_time
@@ -302,7 +375,7 @@
         found_1stchannel = 0
         if stop_time == None:
             found_1stchannel = 1
-            
+
         flag_selected = 0
 
         n = 0
@@ -310,13 +383,13 @@
             if n >= self.n_items:
                 self.display_down_arrow = TRUE
                 break
-            
+
             if start_channel != None and chan.id == start_channel:
-                found_1stchannel = 1            
+                found_1stchannel = 1
 
             if not found_1stchannel:
                 self.display_up_arrow = TRUE
-                
+
             if found_1stchannel:
                 if not chan.programs:
                     prg = epg_types.TvProgram()
@@ -327,12 +400,12 @@
                     prg.desc = ''
                     chan.programs = [ prg ]
 
-                    
+
                 for i in range(len(chan.programs)):
                     if selected:
                         if chan.programs[i] == selected:
                             flag_selected = 1
-                                
+
                 table += [  chan  ]
                 n += 1
 
@@ -350,33 +423,42 @@
                                 break
 
         self.table = table
-        for t in table:
-            try:
-                for p in t.programs:
-                    if p in self.scheduled_programs:
-                        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
-                                            # Twisted includes Boolean
-                    if p in self.overlap_programs:
-                        p.overlap = TRUE
-                    else:
-                        p.overlap = FALSE
-            except:
-                pass
+        # then we can refresh the display with this programs
+        self.update()
+
 
+    def event_record(self):
+        """ Add to schedule or remove from schedule
 
-    def event_RECORD(self):
+        This function adds or removes the selected program to schedule,
+        if the user presses REC inside of TVGuide.
+        This is a kind of a short cut, which directly manipulates the schedule
+        without opening the submenu for ProgramItems.
+        """
         if self.selected.scheduled:
-            pi = ProgramItem(self, prog=self.selected, context='schedule')
+            # remove this program from schedule it it is already scheduled
+            pi = ProgramItem(self, prog=self.selected).remove_program()
         else:
-            pi = ProgramItem(self, prog=self.selected, context='guide')
+            # otherwise add it to schedule without more questions
+            pi = ProgramItem(self, prog=self.selected).schedule_program()
+        self.refresh()
+
+
+    def event_submenu(self):
+        """ Opens the submenu for ProgramItems
+
+        The user can choose from this submenu what to do with the selected
+        program, e.g. schedule a program for recording or search for more of
+        that program.
+        """
+        # create a ProgramItem for the selected program
+        pi = ProgramItem(self, prog=self.selected)
+        # and show its submenu
         pi.display_program(menuw=self.menuw)
 
 
     def event_change_program(self, value, full_scan=False):
+
         start_time    = self.start_time
         stop_time     = self.stop_time
         start_channel = self.start_channel
@@ -384,10 +466,13 @@
 
         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,
+            all_programs = self.guide.GetPrograms(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.GetPrograms(start_time+1,
+                                                  stop_time-1,
+                                                  [ channel.id ])
 
         # Current channel programs
         programs = all_programs[0].programs
@@ -439,7 +524,7 @@
 
         else:
             prg = epg_types.TvProgram()
-            prg.channel_id = channel.id            
+            prg.channel_id = channel.id
             prg.start = 0
             prg.stop = 2147483647   # Year 2038
             prg.title = CHAN_NO_DATA
@@ -448,7 +533,7 @@
 
         self.rebuild(start_time, stop_time, start_channel, prg)
 
-        
+
     def event_change_channel(self, value):
         start_time    = self.start_time
         stop_time     = self.stop_time
@@ -457,7 +542,7 @@
 
         for i in range(len(self.guide.chan_list)):
             if self.guide.chan_list[i].id == start_channel:
-                start_pos = i                                        
+                start_pos = i
                 end_pos   = i + self.n_items
             if self.guide.chan_list[i].id == last_prg.channel_id:
                 break
@@ -466,7 +551,7 @@
 
         # calc real changed value
         value = channel_pos - i
-        
+
         if value < 0 and channel_pos and channel_pos <= start_pos:
             # move start channel up
             start_channel = self.guide.chan_list[start_pos + value].id
@@ -475,10 +560,11 @@
                channel_pos + 1 >= end_pos:
             # move start channel down
             start_channel = self.guide.chan_list[start_pos + value].id
-            
+
         channel = self.guide.chan_list[channel_pos]
 
-        programs = self.guide.GetPrograms(start_time+1, stop_time-1, [ 
channel.id ])
+        programs = self.guide.GetPrograms(start_time+1, stop_time-1,
+                                         [ channel.id ])
         programs = programs[0].programs
 
 
@@ -488,17 +574,17 @@
                 if programs[i].stop > self.select_time and programs[i].stop > 
start_time:
                     break
 
-                
+
             prg = programs[i]
             if prg.sub_title:
                 procdesc = '"' + prg.sub_title + '"\n' + prg.desc
             else:
                 procdesc = prg.desc
-            
+
             to_info = (prg.title, procdesc)
         else:
             prg = epg_types.TvProgram()
-            prg.channel_id = channel.id            
+            prg.channel_id = channel.id
             prg.start = 0
             prg.stop = 2147483647   # Year 2038
             prg.title = CHAN_NO_DATA

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to