Source

wd_pys60 / wd_mv_display.py

Full commit
#display movie lines on symbian devices


import time
import e32
import sys


def _deal_time(d):
    d=d.strip().split(",")
    decimal=float("0."+d[1])
    hours,minutes,seconds=d[0].split(":")
    return float(hours)*3600+float(minutes)*60+float(seconds)+decimal


class TimeObj(object):
    """
    time_data:
    00:00:54,254 --> 00:00:58,247
    
    """
    def __init__(self,time_data):
        
        #print time_data
        self.start_pos,self.end_pos=time_data.strip().split("-->")
        self.start_pos=_deal_time(self.start_pos)
        self.end_pos=_deal_time(self.end_pos)
    def _deal_time(self,d):
        d=d.strip().split(",")
        decimal=float("0."+d[1])
        hours,minutes,seconds=d[0].split(":")
        return float(hours)*3600+float(minutes)*60+float(seconds)+decimal
    def time_to_display(self,_time):
        #print _time-self.start_pos
        if _time-self.start_pos>0:
            return True
        else:
            return False
    def time_to_disappear(self,_time):
        if _time-self.start_pos>0:
            return True
        else:
            return False
    def __repr__(self):
        return repr({"start":self.start_pos,"end":self.end_pos})

class Line(object):
    """
    source_data:
    1
    00:00:54,254 --> 00:00:58,247
    英国病人
    The English Patient
    """
    def __init__(self,source_data):
        _source=source_data.strip().split("\n")
        #print _source
        
        self.id=int(_source[0])
        self.time=TimeObj(_source[1])
        self.display_text=_source[2:]
    def __repr__(self):
        return repr({"id": self.id,
            "time":repr(self.time),
            "display_text":self.display_text})
class Movie(object):
    """
    """
    def __init__(self,path="E:\\Python\\1wd\\mv.txt",offset=0):
        self.running=True
        self.beginner=time.clock()-offset
        self.lines=[]
        f=file(path,"r")
        d=f.read()
        f.close()
        d=d.decode("utf8").strip().replace(u"\r\n\r\n",u"__SPLIT__TAG__")
        d=d.split(u"__SPLIT__TAG__")
        #print d
        #print len(d)
        for _d in d:
            self.lines.append(Line(_d))
    def test(self):
        for line in self.lines:
            print repr(line)
    def run(self):
        self.id=1459
        line=self.lines[self.id]
        beginner=self.beginner
        sleep=0.002
        while self.running:
            e32.ao_sleep(sleep)
            #print time.clock()-beginner
            if line.time.time_to_display(time.clock()-beginner):
                
                print self.id
                for text in line.display_text:
                    print text
                self.id+=1
                if self.id==len(self.lines):
                    break
                line=self.lines[self.id]

mv=Movie(path="E:\\Python\\1wd\\mv1.txt",offset=_deal_time("02:43:48,0"))
#print len(mv.lines)
mv.run()