[Cvs-annodex] commit (annodex): keystroke/trunk/clip.py keystroke/trunk/cliplist.py keystroke/trunk/keystroke.py keystroke/trunk/scriptview.py keystroke/trunk/textsrc.py keystroke/trunk/time_converter.py +keystroke/trunk/cliplistiter.py

scott nobody at lists.annodex.net
Tue Oct 24 08:04:30 UTC 2006


Update of /var/local/lib/svn/annodex (new revision 2536)

Added files:
   keystroke/trunk/cliplistiter.py

Modified files:
   keystroke/trunk/clip.py
   keystroke/trunk/cliplist.py
   keystroke/trunk/keystroke.py
   keystroke/trunk/scriptview.py
   keystroke/trunk/textsrc.py
   keystroke/trunk/time_converter.py

Log Message:
Broke clip list iter into own class to avoid two things try to iterate at the same time.  Made to_ms more robust.  Fixed review mode.

Modified: keystroke/trunk/clip.py
===================================================================
--- keystroke/trunk/clip.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/clip.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -20,7 +20,7 @@
 This program will allow annotating without taking your fingers off of the keyboard.
 It will automatically store start and stop times along with the text.
 """
-
+from time_converter import *
 class clip:
   __start = 0 #an int in milliseconds
   __end = 0 #an int in milliseconds
@@ -107,3 +107,6 @@
   def get_duration(self):
     """Returns the duration in milliseconds."""
     return self.__end - self.__start
+  
+  def __str__(self):
+    return format_time(self.get_start()) + "-" + format_time(self.get_end()) + " : " + self.get_text()

Modified: keystroke/trunk/cliplist.py
===================================================================
--- keystroke/trunk/cliplist.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/cliplist.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -17,7 +17,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 """
-
+from cliplistiter import cliplistiter
 class cliplist:
   
   def __init__(self):
@@ -59,22 +59,18 @@
     return -(low+1)
    
   def __iter__(self):
-    self.__iter_index = 0
-    return self
+    return cliplistiter(self)
   
   def next(self,clip=None):
-    if clip:
-      index = self.__find(clip)
-      if index>0 and index < len(self.__data)-1:
-        return self.__data[index+1]
-    else:
-      if self.__iter_index < len(self.__data)-1:
-        self.__iter_index += 1
-        return self.__data[self.__iter_index]
-      else:
-        raise StopIteration
+    if clip == -2:
+      return self.__data[0]
+    index = self.__find(clip)
+    if index>0 and index < len(self.__data)-1:
+      return self.__data[index+1]
   
   def previous(self,clip=None):
+    if clip == -1:
+      return None
     if clip:
       index = self.__find(clip)
       if index>0:
@@ -82,14 +78,11 @@
       else:
         return None
   
-  def reset_iter(self):
-    self.__iter_index = 0
-  
   def get_last_clip(self):
     return self.__data[-1]
   
+  def get_at_index(self, index):
+    return self.__data[index]
+  
   def length(self):
     return len(self.__data)
-  
-  def has_next(self):
-    return self.__iter_index+1<len(self.__data)

Added: keystroke/trunk/cliplistiter.py
===================================================================
--- keystroke/trunk/cliplistiter.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/cliplistiter.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -0,0 +1,20 @@
+class cliplistiter:
+  def __init__(self, cliplist):
+    self.__data = cliplist
+    self.__iter = -1
+
+  def next(self):
+    if self.__iter < self.__data.length()-1:
+      self.__iter += 1
+      return self.__data.get_at_index(self.__iter)
+    else:
+      raise StopIteration
+  
+  def has_next(self):
+    return self.__iter+1<self.__data.length()
+  
+  def reset_iter(self):
+    self.__iter = -1
+  
+  def length(self):
+    return self.__cliplist.length()
\ No newline at end of file

Modified: keystroke/trunk/keystroke.py
===================================================================
--- keystroke/trunk/keystroke.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/keystroke.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -201,7 +201,7 @@
       self.end_time.set_text(format_time(next.get_end()))
       self.clip_text.set_text(next.get_text())
     elif self.end_time.get_text()!="xx:xx:xx.xxx":
-      self.seek(self.end_time.get_text())
+      self.seek(to_ms(self.end_time.get_text()))
       self.mode = self.MODE_TRANSCRIBE
   
   def just_play(self, accel_group, window, keyval, modifier):
@@ -239,7 +239,8 @@
         self.end_time.set_text(format_time(current_time))
       elif self.mode==self.MODE_REVIEW:
         current = self.scriptview.current_clip(current_time)
-        self.scriptview.highlight(current)
+        if current:
+          self.scriptview.highlight(current)
         self.start_time.set_text(format_time(current.get_start()))
         self.end_time.set_text(format_time(current.get_end()))
         self.clip_text.set_text(current.get_text())
@@ -274,7 +275,7 @@
         self.clip_text.set_text("")
         self.start_time.set_text(format_time(self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND))
         self.end_time.set_text("xx:xx:xx.xxx")
-        self.scriptview.scroll_to_bottom(self.mode)
+        self.scriptview.scroll_to_bottom()
       elif self.mode==self.MODE_REVIEW:
         pass
         #FIXME this is where to put clip update code.

Modified: keystroke/trunk/scriptview.py
===================================================================
--- keystroke/trunk/scriptview.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/scriptview.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -78,8 +78,7 @@
     #Avoid duplicate mark if same mark time ended last clip.
     if self.__tracks[clip.get_track()].length()!=0:
       last_clip = self.__tracks[clip.get_track()].get_last_clip()
-      if last_clip.get_end() != clip.get_start():
-        if last_clip.get_end()==None:
+      if last_clip.get_end()==None:
           last_clip.set_end(clip.get_start())
 
     if self.__tracks[clip.get_track()].length()==0 or last_clip.get_end() != clip.get_start():
@@ -106,12 +105,12 @@
         last_clip = current_clip
       else:
         break
-    if last_clip and self.__tracks[self.__current_track].has_next():
+    if last_clip != None:
       return last_clip
-    elif self.__tracks[self.__current_track].has_next():
+    elif self.__tracks[self.__current_track].get_last_clip()!=last_clip and time>=current_clip.get_start():
       return current_clip
     else:
-      return None
+      return -2
   
   def next(self,time):
     """This returns the beginning timestamp of the next clip after the current

Modified: keystroke/trunk/textsrc.py
===================================================================
--- keystroke/trunk/textsrc.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/textsrc.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -21,6 +21,7 @@
 import pygst
 pygst.require("0.10")
 import gst
+from cliplistiter import cliplistiter
 
 class TextSource (gst.PushSrc):
   """This gstreamer element pushes buffers out of the cliplist given.
@@ -71,4 +72,4 @@
     return self.__cliplist
   
   def set_cliplist(self,cliplist):
-    self.__cliplist = cliplist
+    self.__cliplist = cliplistiter(cliplist)

Modified: keystroke/trunk/time_converter.py
===================================================================
--- keystroke/trunk/time_converter.py	2006-10-22 19:57:56 UTC (rev 2535)
+++ keystroke/trunk/time_converter.py	2006-10-24 08:04:25 UTC (rev 2536)
@@ -47,5 +47,19 @@
   return hour + ":" + minute + ":" + seconds + "." + mseconds
   
 def to_ms(string):
-  h,m,ms = string.replace(".","").split(":")
+  # If the string is empty return empty.
+  if string=="":
+    return ""
+  time = string.split(":")
+  if len(time)==3:
+    h,m,s = time
+    if s.find(".")!=-1:
+      s,ms = s.split(".")
+      ms = s + ms + "0"*(3-len(ms))
+    else:
+      ms = s + "000"
+  elif len(time)==2:
+      m,s = time
+      h = "0"
+      ms = str(1000*int(s))
   return int(h)*3600*1000 + int(m)*60*1000 + int(ms)


-- 
scott



More information about the cvs-annodex mailing list