Dirk Meyer schrieb:

Without looking at your code:

get category
if len(category) > 1:
   show category menu with genre submenu
else:
   show genre menu

Right, that is more or less how I did it.
But I wonder if there is a better way for "get category" than
query_data = kaa.epg.search(attrs=['category'], distinct=True)?




I'm very busy at work right now, I will look at it ina add it to svn
on Friday.

No problem!
I attached a little improved version of my patch to this mail.


Tanja
Index: ui/src/tv/plugins/genre.py
===================================================================
--- ui/src/tv/plugins/genre.py	(Revision 9327)
+++ ui/src/tv/plugins/genre.py	(Arbeitskopie)
@@ -47,14 +47,18 @@
 # get logging object
 log = logging.getLogger('tv')
 
+EXCLUDE_GENRES = ('unknown', 'none', '', None)
+ALL_GENRE = _('All Genre')
+ALL_CAT = ('All Categories')
 
 class GenreItem(Item):
     """
     Item for the TV genre
     """
-    def __init__(self, parent, name):
+    def __init__(self, parent, name, category=None):
         Item.__init__(self, parent)
         self.name = name
+        self.cat = category
 
 
     def actions(self):
@@ -68,21 +72,75 @@
         """
         items = []
         # query epg in background
-        query_data = kaa.epg.search(genre=self.name)
+        if self.cat:
+            if self.name==ALL_GENRE:
+                query_data = kaa.epg.search(category=self.cat)
+            else:
+                query_data = kaa.epg.search(genre=self.name, category=self.cat)
+        else:
+            query_data = kaa.epg.search(genre=self.name)
         yield query_data
         # fetch epg data from InProgress object
         query_data = query_data()
         for prg in query_data:
             items.append(ProgramItem(prg, self))
-        self.get_menustack().pushmenu(Menu(self.name, items, type='tv program menu'))
+        # create menu for programs    
+        self.get_menustack().pushmenu(Menu(self.name, items, 
+                                           type='tv program menu'))
 
 
+class CategoryItem(Item):
+    """
+    Item for a TV category
+    """
+    def __init__(self, parent, name):
+        Item.__init__(self, parent)
+        self.name = name
+        self.parent = parent
+
+
+    def actions(self):
+        return [ Action(_('Browse list'), self.browse)]
+        
+   
+    @kaa.notifier.yield_execution()
+    def browse(self):
+        """ 
+        Find all genres that are in this category
+        """
+        items = []
+         
+        if self.name==ALL_CAT:
+            # query epg in background for all genres
+            query_data = kaa.epg.search(attrs=['genre'], distinct=True)
+        else: 
+            # query epg in background for a specific category
+            query_data = kaa.epg.search(attrs=['genre'], category=self.name, 
+                                        distinct=True)
+        
+        yield query_data
+        # fetch epg data from InProgress object
+        query_data = query_data()
+        query_data.sort()
+        if not self.name ==ALL_CAT:
+            items.append(GenreItem(self.parent, ALL_GENRE, self.name))
+        for genre, in query_data:
+            if genre not in EXCLUDE_GENRES:
+                if self.name==ALL_CAT:
+                    items.append(GenreItem(self.parent, genre))
+                else:    
+                    items.append(GenreItem(self.parent, genre, self.name))
+       
+        # create menu      
+        self.get_menustack().pushmenu(Menu(self.name, items, 
+                                      type='tv listing'))
+    
+
+
 #
 # the plugin is defined here
 #
 
-EXCLUDE_GENRES = ('unknown', 'none', '', None)
-
 class PluginInterface(MainMenuPlugin):
     """
     Add 'Browse by Genre' to the TV menu.
@@ -94,15 +152,31 @@
         Show all category.
         """
         items = []
-        genres = []
-        # find the available category/genre in background
-        query_data = kaa.epg.search(attrs=['genre'], distinct=True)
+               
+        # look if there is category data in the epg data
+        query_data = kaa.epg.search(attrs=['category'], distinct=True)
         yield query_data
         # fetch epg data from InProgress object
         query_data = query_data()
-        for genre, in query_data:
-            if genre not in EXCLUDE_GENRES:
-                items.append(GenreItem(parent, genre))
+        query_data.sort()
+        if len(query_data)>1:
+            items.append(CategoryItem(parent, ALL_CAT))
+            # there is category data in the epg
+            for cat, in query_data:
+                if cat not in EXCLUDE_GENRES:
+                    items.append(CategoryItem(parent, cat))
+        else:
+            # maybe there is only genre data in the epg
+            query_data = kaa.epg.search(attrs=['genre'], distinct=True)
+            yield query_data
+            # fetch epg data from InProgress object
+            query_data = query_data()
+            query_data.sort()
+            for genre, in query_data:
+                if genre not in EXCLUDE_GENRES:
+                    items.append(GenreItem(parent, genre))
+        
+        # create menu
         parent.pushmenu(Menu(_('Genre'), items, type='tv listing'))
 
 
@@ -110,4 +184,4 @@
         """
         Return the main menu item.
         """
-        return [ ActionItem(_('Browse by genre'), parent, self.category) ]
+        return [ ActionItem(_('Browse by Genre'), parent, self.category) ]
-------------------------------------------------------------------------
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-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-devel

Reply via email to