Package Subtitles :: Module Sub
[hide private]
[frames] | no frames]

Source Code for Module Subtitles.Sub

 1  #!/usr/bin/env python 
 2  # 
 3  #       Sub.py 
 4  #        
 5  #       Copyright 2008 Joao Mesquita <jmesquita@gmail.com> 
 6  #        
 7  #       This program is free software; you can redistribute it and/or modify 
 8  #       it under the terms of the GNU General Public License as published by 
 9  #       the Free Software Foundation; either version 3 of the License, or 
10  #       (at your option) any later version. 
11  #        
12  #       This program is distributed in the hope that it will be useful, 
13  #       but WITHOUT ANY WARRANTY; without even the implied warranty of 
14  #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
15  #       GNU General Public License for more details. 
16  #        
17  #       You should have received a copy of the GNU General Public License 
18  #       along with this program; if not, write to the Free Software 
19  #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
20  #       MA 02110-1301, USA. 
21  import string 
22   
23  from Line import * 
24   
25 -class Sub:
26 """ 27 The Sub class, is the class that handles each subtitle 28 individually 29 """ 30
31 - def __init__(self,text):
32 """ 33 Init all the variables 34 """ 35 self.lines = [] 36 # Start with 1 cos we are only called 37 # when there is at least one line 38 self.nLines = 1 39 self.start_time=None 40 self.start_frame=0 41 self.end_time=None 42 self.end_frame=0 43 self.number=None 44 self._processText(text)
45
46 - def isInTime(self, time):
47 """ 48 Is it time to display a subtitle? 49 """ 50 if( (time>=self.start_time) and (time<=self.end_time) ): 51 return 1 52 else: 53 return 0
54
55 - def _processText(self,text):
56 """ 57 We should parse the full text of a subtitle and divide it 58 line by line. 59 Another getSub method exists to retrieve the full text 60 """ 61 lines = text.splitlines(True) 62 self.nLines = len(lines) 63 for i in xrange(0, len(lines)): 64 self.lines.append( Line(lines[i]) ) 65 return
66
67 - def getSubText(self):
68 """ 69 Retrieve the full subtitle text. 70 The data model is yet to be defined. 71 """ 72 fullText = '' 73 for i in range(0, self.nLines): 74 fullText += self.lines[i].text 75 return fullText
76
77 - def setSubText(self, text):
78 """ 79 Set the subtitle text and this method will rearrange the 80 structure of lines as well as all other attributes. 81 """ 82 pass
83