Changeset 2491
- Timestamp:
- 2006-09-14 00:13:37 (2 years ago)
- Files:
-
- scripts/trunk/annotool.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
scripts/trunk/annotool.py
r2451 r2491 89 89 90 90 def open_file(self, accel_group, window, keyval, modifier): 91 print "Ctrl - O" 91 92 dialog = gtk.FileChooserDialog("Open",self.window,gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) 92 93 dialog.set_default_response(gtk.RESPONSE_OK) … … 113 114 114 115 def import_file(self, accel_group, window, keyval, modifier): 116 print "Ctrl - I" 115 117 dialog = gtk.FileChooserDialog("Import",self.window,gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) 116 118 dialog.set_default_response(gtk.RESPONSE_OK) … … 145 147 146 148 def save_file(self, accel_group, window, keyval, modifier): 149 print "Ctrl - S" 147 150 dialog = gtk.FileChooserDialog("Save",self.window,gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK)) 148 151 dialog.set_default_response(gtk.RESPONSE_OK) … … 181 184 # Text overlay functions. 182 185 def toggle_track(self, accel_group, window, keyval, modifier): 186 print "Ctrl - T" 183 187 keys = self.times.keys() 184 188 new_track = keys.index(self.current_track)+1 … … 188 192 # Navigation functions. 189 193 def restart_clip(self, accel_group, window, keyval, modifier): 190 self.pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(self.start_time.get_text()), gst.SEEK_TYPE_NONE, 0) 194 print "Ctrl - R" 195 self.seek(self.start_time.get_text()) 196 197 def current_clip(self,current_time): 198 x = 0 199 while (x)<len(self.times[self.current_track]['start']) and current_time>=to_ms(self.times[self.current_track]['start'][x]): 200 x += 1 201 return x-1 191 202 192 203 def previous_clip(self, accel_group, window, keyval, modifier): 193 if len(self.times[self.current_track]['start'])>1 and self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND>to_ms(self.times[self.current_track]['start'][1]): 194 x = 2 195 while x<len(self.times[self.current_track]['start']) and self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND>to_ms(self.times[self.current_track]['start'][x]): 196 x += 1 197 self.pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(self.times[self.current_track]['start'][x-2]), gst.SEEK_TYPE_NONE, 0) 198 self.start_time.set_text(self.times[self.current_track]['start'][x-2]) 204 print "Ctrl - B" 205 clip_now = self.current_clip(self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND) 206 if clip_now > 0: 207 self.seek(self.times[self.current_track]['start'][clip_now-1],self.times[self.current_track]['start'][clip_now]) 208 209 #Highlight chapter entry. 210 self.text.remove_tag(self.tag_current, self.text.get_start_iter(),self.text.get_end_iter()) 211 mark = self.text.get_mark(self.times[self.current_track]['start'][clip_now-1]) 212 start_iter = self.text.get_iter_at_mark(mark) 213 if not start_iter.begins_tag(self.tag_clip): 214 start_iter.forward_to_tag_toggle(self.tag_clip) 215 end_iter = start_iter.copy() 216 end_iter.forward_to_tag_toggle(self.tag_clip) 217 self.text.apply_tag(self.tag_current, start_iter, end_iter) 218 219 #Scroll to mark 220 self.textView.scroll_to_mark(mark,0.1) 221 222 self.mode = 'review' 223 224 self.start_time.set_text(self.times[self.current_track]['start'][clip_now-1]) 225 self.end_time.set_text(self.times[self.current_track]['start'][clip_now]) 199 226 if self.pipeline_duration==10: 200 227 self.pipeline_duration = self.pipeline.query_duration(gst.FORMAT_TIME)[0]/gst.MSECOND 201 self.progress.props.fraction = float(to_ms(self.times[self.current_track]['start'][ x-2]))/self.pipeline_duration228 self.progress.props.fraction = float(to_ms(self.times[self.current_track]['start'][clip_now-1]))/self.pipeline_duration 202 229 else: 203 self.pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*0, gst.SEEK_TYPE_NONE, 0) 204 self.start_time.set_text('00:00:00.000') 205 self.progress.props.fraction = 0 230 print self.current_track + " has no previous clips." 206 231 207 232 def next_clip(self, accel_group, window, keyval, modifier): 233 print "Ctrl - N" 208 234 #Only seek forward clips if more clips exist. 209 if self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND<to_ms(self.times[self.current_track]['start'][-1]):235 if len(self.times[self.current_track]['start'])>1 and self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND<to_ms(self.times[self.current_track]['start'][-1]): 210 236 x = 2 211 237 while x<len(self.times[self.current_track]['start']) and self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND<to_ms(self.times[self.current_track]['start'][-x]): 212 238 x += 1 213 self.pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(self.times[self.current_track]['start'][-(x-1)]), gst.SEEK_TYPE_NONE, 0) 239 if x > 3: 240 self.seek(self.times[self.current_track]['start'][-(x-1)], self.times[self.current_track]['start'][-(x-2)]) 241 else: 242 self.seek(self.times[self.current_track]['start'][-(x-1)]) 243 self.mode = 'transcribe' 244 245 #Highlight chapter entry. 246 self.text.remove_tag(self.tag_current, self.text.get_start_iter(),self.text.get_end_iter()) 247 mark = self.text.get_mark(self.times[self.current_track]['start'][-(x-1)]) 248 start_iter = self.text.get_iter_at_mark(mark) 249 if not start_iter.begins_tag(self.tag_clip): 250 start_iter.forward_to_tag_toggle(self.tag_clip) 251 end_iter = start_iter.copy() 252 end_iter.forward_to_tag_toggle(self.tag_clip) 253 self.text.apply_tag(self.tag_current, start_iter, end_iter) 254 255 #Scroll to mark 256 self.textView.scroll_to_mark(mark,0.1) 257 258 self.mode = 'review' 259 214 260 self.start_time.set_text(self.times[self.current_track]['start'][-(x-1)]) 261 self.end_time.set_text(self.times[self.current_track]['start'][-(x-2)]) 215 262 if self.pipeline_duration==10: 216 263 self.pipeline_duration = self.pipeline.query_duration(gst.FORMAT_TIME)[0]/gst.MSECOND 217 264 self.progress.props.fraction = float(to_ms(self.times[self.current_track]['start'][-(x-1)]))/self.pipeline_duration 265 else: 266 print self.current_track + " has no more clips." 218 267 219 268 def just_play(self, accel_group, window, keyval, modifier): 269 print "Ctrl - P" 220 270 if (self.pipeline.get_state()[1] != gst.STATE_PLAYING): 221 271 self.pipeline.set_state(gst.STATE_PLAYING); 222 272 273 def seek(self,start,end=None): 274 if end==None: 275 return self.pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(start), gst.SEEK_TYPE_NONE, 0) 276 else: 277 return self.pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(start), gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(end)) 278 223 279 def enter_activated(self, widget, data=None): 224 280 #Handles clip to text buffer, formatting and pipeline control. 281 print "Enter" 225 282 if (self.pipeline.get_state()[1] == gst.STATE_PLAYING): 226 283 self.pipeline.set_state(gst.STATE_PAUSED); … … 232 289 self.pipeline_duration = self.pipeline.query_duration(gst.FORMAT_TIME)[0]/gst.MSECOND 233 290 self.progress.props.fraction = float(current_time)/self.pipeline_duration 234 elif (self.pipeline.get_state()[1] == gst.STATE_PAUSED):291 elif self.pipeline.get_state()[1] == gst.STATE_PAUSED and not self.mode=='review': 235 292 text = self.clip_text.get_text() 236 if text[:1] == ")" or (text.find(":")==-1 and self.last_type_def==")") :293 if text[:1] == ")" or (text.find(":")==-1 and self.last_type_def==")") and self.start_time.get_text() != 'xx:xx:xx.xxx': 237 294 #Chapter deocration. 238 295 self.text.insert(self.text.get_end_iter(),"\n\nChapter " + str(len(self.times["chapter"])+1) + ": ") 239 296 #Mark handling. 240 297 self.times["chapter"]['start'].append(self.start_time.get_text()) 241 self.times["chapter"]['all'].append(self.start_time.get_text())242 298 mark = self.text.create_mark(self.start_time.get_text(),self.text.get_end_iter(),True) 243 299 mark.set_visible(self.visible_marks) … … 245 301 self.text.insert(self.text.get_end_iter(),text.strip().strip(")")) 246 302 self.last_type_def = ")" 247 elif text.find(":")!=-1 or self.last_type_def.endswith(":") :303 elif text.find(":")!=-1 or self.last_type_def.endswith(":") and self.start_time.get_text() != 'xx:xx:xx.xxx': 248 304 # If using the last type def make sure doesn't have ';' instead of intended ':' 249 305 if text.find(":")==-1 and text.find(";")!=-1: … … 261 317 self.last_type_def = text[:text.find(":")+1].lower() 262 318 elif text!='': 263 #Handles spaces between clips. FIXME319 #Handles spaces between clips. 264 320 self.text.insert(self.text.get_end_iter()," ") 265 321 #Mark handling. 266 322 self.times["subtitle"]['start'].append(self.start_time.get_text()) 267 self.times["subtitle"]['all'].append(self.start_time.get_text())268 323 mark = self.text.create_mark(self.start_time.get_text(),self.text.get_end_iter(),True) 269 324 mark.set_visible(self.visible_marks) … … 272 327 #Insert text. 273 328 self.text.insert(self.text.get_end_iter(),text[text.find(":")+1:].strip()) 274 if text != "" :329 if text != "" and self.start_time.get_text() != 'xx:xx:xx.xxx': 275 330 try: 276 #Change mark gravity.277 ##Cannot change mark gravity? Whats with that? FIXME278 331 #Underline contents. 279 332 clip_iter = self.text.get_iter_at_mark(mark) … … 288 341 self.end_time.set_text("xx:xx:xx.xxx") 289 342 self.textView.props.can_focus = False 343 self.scroll_to_bottom() 344 self.pipeline.set_state(gst.STATE_PLAYING); 345 self.progress.props.text = self.current_file + ": Playing." 346 elif self.pipeline.get_state()[1] == gst.STATE_PAUSED: 347 self.start_time.set_text(format_time(self.pipeline.query_position(gst.FORMAT_TIME)[0]/gst.MSECOND)) 348 self.end_time.set_text("xx:xx:xx.xxx") 349 self.textView.props.can_focus = False 290 350 self.pipeline.set_state(gst.STATE_PLAYING); 291 351 self.progress.props.text = self.current_file + ": Playing." 292 352 return 293 353 294 def scroll_to_bottom(self, widget): 295 self.textView.scroll_to_mark(self.text.get_mark("insert"),0.1) 354 def scroll_to_bottom(self): 355 if self.mode=='transcribe': 356 self.textView.scroll_to_iter(self.text.get_end_iter(),0.1) 296 357 297 358 def export_buffer(self): … … 478 539 last_speaker = title 479 540 elif track.startswith('subtitle'): 480 #Handles spaces between clips. FIXME541 #Handles spaces between clips. 481 542 self.text.insert(self.text.get_end_iter()," ") 482 543 else: 483 self.text.insert(self.text.get_end_iter(),"\n\nChapter " + str(len(self.times["chapter"] )+1) + ": ")544 self.text.insert(self.text.get_end_iter(),"\n\nChapter " + str(len(self.times["chapter"]["start"])+1) + ": ") 484 545 485 546 #Create start mark. … … 508 569 x += 1 509 570 self.progress.props.fraction = x/total_clips 510 self.pipeline.get_state() # Hack but stalls script until state change. FIXME571 self.pipeline.get_state() # Let pipeline catch up to script. 511 572 if end_time!="": 512 self. pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(end_time), gst.SEEK_TYPE_NONE, 0)573 self.seek(end_time) 513 574 self.start_time.set_text(end_time) 514 575 else: 515 self. pipeline.seek(1.0, gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, gst.SEEK_TYPE_SET, gst.MSECOND*to_ms(start_time), gst.SEEK_TYPE_NONE, 0)576 self.seek(start_time) 516 577 self.start_time.set_text(start_time) 517 578 f.close() … … 590 651 self.tag_clip = self.text.create_tag("clip",underline=pango.UNDERLINE_SINGLE) 591 652 self.tag_speaker = self.text.create_tag("speaker",invisible=True) 592 self.t ext.connect("changed", self.scroll_to_bottom)653 self.tag_current = self.text.create_tag("current",foreground="red") 593 654 self.textView = gtk.TextView(self.text) 594 655 self.textView.set_editable(True) … … 651 712 self.playbin.props.video_sink = self.video_process 652 713 else: 653 self.playbin.props.video_sink = gst.element_factory_make ("x vimagesink")714 self.playbin.props.video_sink = gst.element_factory_make ("ximagesink") 654 715 self.playbin.props.vis_plugin = gst.element_factory_make ("libvisual_corona") 655 716 … … 662 723 self.last_type_def = "$" 663 724 self.current_track = "subtitle" 664 self.visible_marks = True725 self.visible_marks = False 665 726 self.pipeline_duration = 1000 #Something non-zero to avoid non-zero errors. 727 self.mode = 'transcribe' 666 728 667 729 self.window.show_all()