Author: dmeyer
Date: Tue Mar 21 15:56:07 2006
New Revision: 1315
Added:
trunk/epg/src/util.py
Modified:
trunk/epg/src/__init__.py
Log:
add sort and compare function for channels
Modified: trunk/epg/src/__init__.py
==============================================================================
--- trunk/epg/src/__init__.py (original)
+++ trunk/epg/src/__init__.py Tue Mar 21 15:56:07 2006
@@ -4,6 +4,7 @@
from program import Program
from client import Client
from server import Server
+from util import cmp_channel
__all__ = [ 'connect', 'Channel', 'Program', 'Client', 'Server', 'QExpr',
'get_channels', 'search' ]
@@ -26,8 +27,13 @@
return guide
-def get_channels():
+def get_channels(sort=False):
if guide:
+ if sort:
+ channels = guide.get_channels()[:]
+ channels.sort(lambda a, b: cmp(a.name, b.name))
+ channels.sort(lambda a, b: cmp_channel(a, b))
+ return channels
return guide.get_channels()
return []
Added: trunk/epg/src/util.py
==============================================================================
--- (empty file)
+++ trunk/epg/src/util.py Tue Mar 21 15:56:07 2006
@@ -0,0 +1,48 @@
+
+def cmp_channel(c1, c2):
+
+ l1 = len(c1.tuner_id)
+ l2 = len(c2.tuner_id)
+
+ if l1 == 0:
+ if l2 == 0:
+ return 0
+ else:
+ return -1
+
+ if l2 == 0:
+ if l1 == 0:
+ return 0
+ else:
+ return 1
+
+ a = 0
+ b = 0
+
+ for t in c1.tuner_id:
+ try:
+ a = int(t)
+ break
+ except:
+ if c1.tuner_id.index(t) < l1-1:
+ # try next time
+ continue
+ else:
+ break
+
+ for t in c2.tuner_id:
+ try:
+ b = int(t)
+ break
+ except:
+ if c2.tuner_id.index(t) < l2-1:
+ # try next time
+ continue
+ else:
+ break
+
+ if a < b:
+ return -1
+ if a > b:
+ return 1
+ return 0
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog