[xiph-commits] r15090 - in trunk/subtle: . Subtitles

jmesquita at svn.xiph.org jmesquita at svn.xiph.org
Sun Jun 29 20:26:04 PDT 2008


Author: jmesquita
Date: 2008-06-29 20:26:04 -0700 (Sun, 29 Jun 2008)
New Revision: 15090

Added:
   trunk/subtle/Subtitles/Line.py
Modified:
   trunk/subtle/Subtitles/Sub.py
   trunk/subtle/Subtitles/SubRip.py
   trunk/subtle/Subtitles/__init__.py
   trunk/subtle/Subtle.py
   trunk/subtle/subtle.glade
Log:
* New Line class to handle a single line of subtitle. Had to be written to support char counting leaving out chars that are not supposed to be counted such as endlines
* Adaptation of the codebase to use the new get/set methods for the subtitle text

Added: trunk/subtle/Subtitles/Line.py
===================================================================
--- trunk/subtle/Subtitles/Line.py	                        (rev 0)
+++ trunk/subtle/Subtitles/Line.py	2008-06-30 03:26:04 UTC (rev 15090)
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+#
+#       Line.py
+#       
+#       Copyright 2008 Joao Mesquita <jmesquita at gmail.com>
+#       
+#       This program is free software; you can redistribute it and/or modify
+#       it under the terms of the GNU General Public License as published by
+#       the Free Software Foundation; either version 3 of the License, or
+#       (at your option) any later version.
+#       
+#       This program is distributed in the hope that it will be useful,
+#       but WITHOUT ANY WARRANTY; without even the implied warranty of
+#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#       GNU General Public License for more details.
+#       
+#       You should have received a copy of the GNU General Public License
+#       along with this program; if not, write to the Free Software
+#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+#       MA 02110-1301, USA.
+
+
+class Line:
+    """
+        Each line of a subtile will have its own class to control
+        the number of characters and other features
+    """
+    def __init__(self, text):
+        """
+            Each line has its own text
+        """
+        self.text = text
+        self.length = self._count(text)
+
+    def _count(self, text):
+        """
+            We have to make our own count
+            function because of pango markups
+            and end of lines.
+        """
+        j=0
+        for i in text:
+            if i == '\n':
+                continue
+            else:
+                j += 1
+        return j

Modified: trunk/subtle/Subtitles/Sub.py
===================================================================
--- trunk/subtle/Subtitles/Sub.py	2008-06-29 16:51:17 UTC (rev 15089)
+++ trunk/subtle/Subtitles/Sub.py	2008-06-30 03:26:04 UTC (rev 15090)
@@ -18,7 +18,9 @@
 #       along with this program; if not, write to the Free Software
 #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 #       MA 02110-1301, USA.
+import string
 
+from Line import *
 
 class Sub:
     """
@@ -26,35 +28,53 @@
         individually
     """
 
-    def __init__(self):
+    def __init__(self,text):
         """
-            Lets init all the variables
-            This might work more or less like a C struct
+            Init all the variables
         """
-        self.text=""
+        self.lines = []
+        # Start with 1 cos we are only called
+        # when there is at least one line
+        self.nLines = 1
         self.start_time=None
         self.end_time=None
-        self.Attributes=None
         self.number=None
+        self._processText(text)
 
-    ## Check subtitle time.
-    # This function check if subtitle visibility in given time.
-    # \param[in] time - time to check
-    # \return 1 - if visibility in time, 0 - otherwise
     def isInTime(self, time):
+        """
+            Is it time to display a subtitle?
+        """
         if( (time>=self.start_time) and (time<=self.end_time) ):
             return 1
         else:
             return 0
 
-    ## \var text
-    # A variable to store subtitle text
+    def _processText(self,text):
+        """
+            We should parse the full text of a subtitle and divide it
+            line by line.
+            Another getSub method exists to retrieve the full text
+        """
+        lines = text.splitlines(True)
+        self.nLines = len(lines)
+        for i in xrange(0, len(lines)):
+            self.lines.append( Line(lines[i]) )
+        return
     
-    ## \var start_time
-    # A variable to store a start time of visibility of subtitle (in ns).
-    
-    ## \var end_time
-    # A variable to store a end time of visibility of subtitle (in ns).
-    
-    ## \var Attributes
-    # A array of attributes of subtitle. (NOT USED YET)
+    def getSubText(self):
+        """
+            Retrieve the full subtitle text.
+            The data model is yet to be defined.
+        """
+        fullText = ''
+        for i in range(0, self.nLines):
+            fullText += self.lines[i].text
+        return fullText
+        
+    def setSubText(self, text):
+        """
+            Set the subtitle text and this method will rearrange the
+            structure of lines as well as all other attributes.
+        """
+        pass

Modified: trunk/subtle/Subtitles/SubRip.py
===================================================================
--- trunk/subtle/Subtitles/SubRip.py	2008-06-29 16:51:17 UTC (rev 15089)
+++ trunk/subtle/Subtitles/SubRip.py	2008-06-30 03:26:04 UTC (rev 15090)
@@ -111,9 +111,9 @@
             ST=int(Timing[0:2])*3600000+int(Timing[3:5])*60000+int(Timing[6:8])*1000+int(Timing[9:12])
             ET=int(Timing[17:19])*3600000+int(Timing[20:22])*60000+int(Timing[23:25])*1000+int(Timing[26:29])
             
-            TS=Sub()
+            TS=Sub(Text)
             num_sub += 1
-            TS.text=Text
+            #TS.text=Text
             TS.start_time=ST
             TS.end_time=ET
             TS.number = num_sub

Modified: trunk/subtle/Subtitles/__init__.py
===================================================================
--- trunk/subtle/Subtitles/__init__.py	2008-06-29 16:51:17 UTC (rev 15089)
+++ trunk/subtle/Subtitles/__init__.py	2008-06-30 03:26:04 UTC (rev 15090)
@@ -18,5 +18,5 @@
 #       along with this program; if not, write to the Free Software
 #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 #       MA 02110-1301, USA.
-__all__=["Subtitles", "SubRip","Discoverer"]
+__all__=["Subtitles", "SubRip","Discoverer","Line"]
 

Modified: trunk/subtle/Subtle.py
===================================================================
--- trunk/subtle/Subtle.py	2008-06-29 16:51:17 UTC (rev 15089)
+++ trunk/subtle/Subtle.py	2008-06-30 03:26:04 UTC (rev 15090)
@@ -364,13 +364,6 @@
         """
         self.subtitle_pane.show()
 
-
-    def cb_onStreamsWindow(self, menu):
-        if self.windowStreams:
-            WND=self.windowStreams.get_widget("STREAM_WINDOW")
-            WND.show()
-
-
     def getSubtitle(self, source):
         for i in self.Subtitles:
             if i.subSource==source:
@@ -379,10 +372,11 @@
 
 
     def cb_saveStream(self, widget):
-        if not self.windowStreams:
-            return
-        if not self.streamsTreeStore:
-            return
+        """
+            Save a stream. This will be renamed to cb_saveSub
+            since we don't offer video editting (yet)
+        """
+        #TODO: This is broken. How about implementing it correctly?
         TView = self.windowStreams.get_widget("LIST_STREAMS")
         TSelec = TView.get_selection()
         TModel, TIter = TSelec.get_selected()
@@ -618,7 +612,7 @@
                     self.play_toggled()
         if event.type == gtk.gdk.BUTTON_RELEASE:
             model, self.cur_edit_sub_iter =  Selection.get_selected() 
-            self.setSubtitleEdit(Sub.text)
+            self.setSubtitleEdit( Sub.getSubText() )
 
 
     def cb_onSubTextEdited(self, cell, path, new_text):
@@ -671,7 +665,7 @@
             self.subsListStore.set(iter,0, j, 
                                         1, int(S.start_time),
                                         2, int(S.end_time),
-                                        3, str(S.text))
+                                        3, str(S.getSubText()))
             j +=1
 
 

Modified: trunk/subtle/subtle.glade
===================================================================
--- trunk/subtle/subtle.glade	2008-06-29 16:51:17 UTC (rev 15089)
+++ trunk/subtle/subtle.glade	2008-06-30 03:26:04 UTC (rev 15090)
@@ -261,8 +261,8 @@
                                 <property name="use_underline">True</property>
                                 <property name="stock_id">gtk-go-down</property>
                                 <signal name="clicked" handler="on_TOOL_IN_SUB_clicked"/>
+                                <accelerator key="c" modifiers="GDK_MOD1_MASK" signal="clicked"/>
                                 <accelerator key="C" modifiers="GDK_MOD1_MASK" signal="clicked"/>
-                                <accelerator key="c" modifiers="GDK_MOD1_MASK" signal="clicked"/>
                               </widget>
                               <packing>
                                 <property name="expand">False</property>
@@ -275,8 +275,8 @@
                                 <property name="use_underline">True</property>
                                 <property name="stock_id">gtk-go-up</property>
                                 <signal name="clicked" handler="on_TOOL_OUT_SUB_clicked"/>
+                                <accelerator key="V" modifiers="GDK_MOD1_MASK" signal="clicked"/>
                                 <accelerator key="v" modifiers="GDK_MOD1_MASK" signal="clicked"/>
-                                <accelerator key="V" modifiers="GDK_MOD1_MASK" signal="clicked"/>
                               </widget>
                               <packing>
                                 <property name="expand">False</property>
@@ -473,9 +473,14 @@
                               <widget class="GtkVBox" id="vbox7">
                                 <property name="visible">True</property>
                                 <child>
-                                  <widget class="GtkLabel" id="lbl_seek_format">
+                                  <widget class="GtkComboBox" id="COMBO_SEEK_TYPE">
                                     <property name="visible">True</property>
-                                    <property name="label" translatable="yes">Seconds</property>
+                                    <property name="tooltip" translatable="yes">What unit to use when seeking</property>
+                                    <property name="items" translatable="yes">Frames
+Seconds
+Nanoseconds
+Minutes</property>
+                                    <signal name="changed" handler="on_COMBO_SEEK_TYPE_changed"/>
                                   </widget>
                                   <packing>
                                     <property name="expand">False</property>
@@ -1095,8 +1100,8 @@
                 <property name="use_underline">True</property>
                 <property name="stock_id">gtk-go-down</property>
                 <signal name="clicked" handler="on_TOOL_IN_SUB_clicked"/>
+                <accelerator key="c" modifiers="GDK_MOD1_MASK" signal="clicked"/>
                 <accelerator key="C" modifiers="GDK_MOD1_MASK" signal="clicked"/>
-                <accelerator key="c" modifiers="GDK_MOD1_MASK" signal="clicked"/>
               </widget>
               <packing>
                 <property name="expand">False</property>
@@ -1109,8 +1114,8 @@
                 <property name="use_underline">True</property>
                 <property name="stock_id">gtk-go-up</property>
                 <signal name="clicked" handler="on_TOOL_OUT_SUB_clicked"/>
+                <accelerator key="V" modifiers="GDK_MOD1_MASK" signal="clicked"/>
                 <accelerator key="v" modifiers="GDK_MOD1_MASK" signal="clicked"/>
-                <accelerator key="V" modifiers="GDK_MOD1_MASK" signal="clicked"/>
               </widget>
               <packing>
                 <property name="expand">False</property>
@@ -1206,8 +1211,8 @@
     <property name="window_position">GTK_WIN_POS_CENTER</property>
     <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
     <property name="gravity">GDK_GRAVITY_CENTER</property>
+    <property name="show_hidden">True</property>
     <property name="do_overwrite_confirmation">True</property>
-    <property name="show_hidden">True</property>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialog-vbox2">
         <property name="visible">True</property>



More information about the commits mailing list