def build_widget(self): if not self.annotations: return Gtk.Label(label=(_("No annotations to adjust"))) vbox = Gtk.VBox() self.title_widget = Gtk.Label() vbox.pack_start(self.title_widget, True, True, 0) self.selector = FrameSelector( self.controller, self.annotations[0].fragment.begin, label= _("Click on the frame just after the cut to adjust the cut time.\nControl-click on a frame to indicate a missing cut." )) self.selector.callback = self.validate_and_next def handle_index_change(adj): i = int(adj.get_value()) - 1 if i >= 0 and i <= len(self.annotations) - 1: a = self.annotations[i] self.selector.set_timestamp(a.fragment.begin) self.set_title( _("Begin of #%(index)d (title: %(content)s)") % { 'index': i + 1, 'content': self.controller.get_title(a, max_size=60).replace( '&', '&').replace('<', '<') }) self.prev_button.set_sensitive(i > 0) self.next_button.set_sensitive(i < len(self.annotations) - 1) else: # End: display a message ? pass self.current_index.connect('value-changed', handle_index_change) vbox.add(self.selector.widget) # Button bar hb = Gtk.HBox() self.prev_button = Gtk.Button(_("< Previous cut")) self.prev_button.set_tooltip_text(_("Display previous cut")) self.prev_button.connect("clicked", lambda b: self.set_index(self.index - 1)) hb.add(self.prev_button) l = Gtk.Label(label="#") hb.pack_start(l, False, True, 0) self.next_button = Gtk.Button(_("Next cut >")) self.next_button.set_tooltip_text(_("Display next cut")) self.next_button.connect("clicked", lambda b: self.set_index(self.index + 1)) s = Gtk.SpinButton.new(self.current_index, 1, 0) s.set_increments(1, 10) #s.set_update_policy(Gtk.UPDATE_IF_VALID) s.set_numeric(True) hb.add(s) hb.add(self.next_button) vbox.pack_start(hb, False, True, 0) hb = Gtk.HButtonBox() b = Gtk.Button(_("Current time")) b.set_tooltip_text( _("Go to annotation containing current player time.")) b.connect("clicked", self.goto_current) hb.add(b) b = Gtk.Button(_("Refresh")) b.set_tooltip_text(_("Refresh missing snapshots")) b.connect("clicked", lambda b: self.selector.refresh_snapshots()) hb.add(b) b = Gtk.Button(_("Undo")) b.set_tooltip_text(_("Undo last modification")) b.connect("clicked", self.undo) hb.add(b) b.set_sensitive(False) self.undo_button = b b = Gtk.Button(_("Merge")) b.set_tooltip_text( _("Merge with previous annotation, i.e. remove this bound.")) b.connect("clicked", self.merge) hb.add(b) b = Gtk.Button(stock=Gtk.STOCK_CLOSE) b.set_tooltip_text(_("Close view.")) b.connect("clicked", self.close) hb.add(b) vbox.pack_start(hb, False, True, 0) self.statusbar = Gtk.Statusbar() vbox.pack_start(self.statusbar, False, True, 0) self.set_index(0) vbox.connect('key-press-event', self.handle_keypress) vbox.connect('scroll-event', self.handle_scroll_event) vbox.show_all() # Hack: since the view if often launched from the timeline # view, moving the mouse in timeline steals the focus from the # window. Let's only grab focus after a small timeout, so that # the user has time to get the mouse out of the timeline # window GObject.timeout_add(2000, lambda: self.next_button.grab_focus()) return vbox
def build_widget(self): if not self.annotations: return gtk.Label((_("No annotations to adjust"))) vbox = gtk.VBox() self.title_widget = gtk.Label() vbox.pack_start(self.title_widget) self.selector = FrameSelector(self.controller, self.annotations[0].fragment.begin, label=_("Click on the frame just after the cut to adjust the cut time.\nControl-click on a frame to indicate a missing cut.")) self.selector.callback = self.validate_and_next def handle_index_change(adj): i = int(adj.get_value()) - 1 if i >= 0 and i <= len(self.annotations) - 1: a=self.annotations[i] self.selector.set_timestamp(a.fragment.begin) self.set_title(_("Begin of #%(index)d (title: %(content)s)") % { 'index': i + 1, 'content': self.controller.get_title(a, max_size=60).replace('&', '&').replace('<', '<') }) self.prev_button.set_sensitive(i > 0) self.next_button.set_sensitive(i < len(self.annotations) - 1) else: # End: display a message ? pass self.current_index.connect('value-changed', handle_index_change) vbox.add(self.selector.widget) # Button bar hb=gtk.HBox() self.prev_button = gtk.Button(_("< Previous cut")) self.prev_button.set_tooltip_text(_("Display previous cut")) self.prev_button.connect("clicked", lambda b: self.set_index(self.index - 1)) hb.add(self.prev_button) l = gtk.Label("#") hb.pack_start(l, expand=False) self.next_button = gtk.Button(_("Next cut >")) self.next_button.set_tooltip_text(_("Display next cut")) self.next_button.connect("clicked", lambda b: self.set_index(self.index + 1)) s=gtk.SpinButton(self.current_index, 1, 0) s.set_increments(1, 10) s.set_update_policy(gtk.UPDATE_IF_VALID) s.set_numeric(True) # For an unknown reason, the default behaviour of updating # SpinButton through scroll does not work. Emulate it. def handle_spin_scroll(widget, event): if event.direction == gtk.gdk.SCROLL_UP: offset=+1 elif event.direction == gtk.gdk.SCROLL_DOWN: offset=-1 self.set_index(self.index + offset) return True s.connect('scroll-event', handle_spin_scroll) hb.add(s) hb.add(self.next_button) vbox.pack_start(hb, expand=False) hb = gtk.HButtonBox() b=gtk.Button(_("Current time")) b.set_tooltip_text(_("Go to annotation containing current player time.")) b.connect("clicked", self.goto_current) hb.add(b) b=gtk.Button(_("Refresh snapshots")) b.set_tooltip_text(_("Refresh missing snapshots")) b.connect("clicked", lambda b: self.selector.refresh_snapshots()) hb.add(b) b=gtk.Button(_("Undo")) b.set_tooltip_text(_("Undo last modification")) b.connect("clicked", self.undo) hb.add(b) b.set_sensitive(False) self.undo_button = b b=gtk.Button(_("Merge with previous")) b.set_tooltip_text(_("Merge with previous annotation, i.e. remove this bound.")) b.connect("clicked", self.merge) hb.add(b) b=gtk.Button(stock=gtk.STOCK_CLOSE) b.set_tooltip_text(_("Close view.")) b.connect("clicked", self.close) hb.add(b) vbox.pack_start(hb, expand=False) self.statusbar = gtk.Statusbar() vbox.pack_start(self.statusbar, expand=False) self.set_index(0) vbox.show_all() vbox.connect('key-press-event', self.handle_keypress) return vbox