Ejemplo n.º 1
0
    def build_widget(self):
        v=Gtk.VBox()

        tb=Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)
        v.pack_start(tb, False, True, 0)

        top_box=Gtk.HBox()
        v.pack_start(top_box, False, True, 0)

        if hasattr(self.query, 'container') and self.query.container.id == '_interactive':
            b=Gtk.Button(_("Edit query again"))
            b.connect('clicked', self.edit_query)
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, SimpleQuery):
            b=Gtk.Button(_("Edit query"))
            b.connect('clicked', lambda b: self.controller.gui.edit_element(self.query))
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, Quicksearch):
            e=Gtk.Entry()
            e.set_text(self.query.searched)
            e.set_width_chars(12)
            e.connect('activate', self.redo_quicksearch, e)
            b=get_small_stock_button(Gtk.STOCK_FIND, self.redo_quicksearch, e)
            e.set_tooltip_text(_('String to search'))
            b.set_tooltip_text(_('Search again'))
            top_box.pack_start(e, False, True, 0)
            top_box.pack_start(b, False, True, 0)

        # Present choices to display the result
        if not self.result:
            v.add(Gtk.Label(label=_("Empty result")))
        elif (isinstance(self.result, list) or isinstance(self.result, tuple)
            or isinstance(self.result, AbstractBundle)):
            # Check if there are annotations
            l=[ a for a in self.result if isinstance(a, Annotation) ]
            cr=len(self.result)
            cl=len(l)

            if cr == cl:
                t=_("Result is a list of %d annotations.") % cr
            else:
                t=_("Result is a list of  %(number)d elements with %(elements)s.") % {
                    'elements': helper.format_element_name("annotation", len(l)),
                    'number': len(self.result)}

            label=Gtk.Label(label=t)
            label.set_ellipsize(Pango.EllipsizeMode.END)
            label.set_line_wrap(True)
            top_box.add(label)

            def toggle_highlight(b, annotation_list):
                if not hasattr(b, 'highlight') or b.highlight:
                    event="AnnotationActivate"
                    label= _("Unhighlight annotations")
                    b.highlight=False
                else:
                    event="AnnotationDeactivate"
                    label=_("Highlight annotations")
                    b.highlight=True
                b.set_tooltip_text(label)
                for a in annotation_list:
                    self.controller.notify(event, annotation=a)
                return True

            if l:
                # Instanciate a table view
                table=AnnotationTable(controller=self.controller, elements=l)

                if cr == cl:
                    # Only annotations.
                    v.add(table.widget)
                else:
                    # Mixed annotations + other elements
                    notebook=Gtk.Notebook()
                    notebook.set_tab_pos(Gtk.PositionType.TOP)
                    notebook.popup_disable()
                    v.add(notebook)

                    notebook.append_page(table.widget, Gtk.Label(label=_("Annotations")))

                    gtable=GenericTable(controller=self.controller, elements=[ e
                                                                               for e in self.result
                                                                               if not isinstance(e, Annotation) ]
                                                                               )
                    notebook.append_page(gtable.widget, Gtk.Label(label=_("Other elements")))


                for (icon, tip, action) in (
                    ('timeline.png' , _("Display annotations in timeline"), lambda b: self.open_in_timeline(l)),
                    ('transcription.png', _("Display annotations as transcription"), lambda b:
                         self.controller.gui.open_adhoc_view('transcription',
                                                             label=self._label,
                                                             destination=self._destination,
                                                             elements=l)),
                    ('highlight.png', _("Highlight annotations"), lambda b: toggle_highlight(b, l)),
                    (Gtk.STOCK_CONVERT, _("Export table"), lambda b: table.csv_export()),
                    (Gtk.STOCK_NEW, _("Create annotations from the result"), self.create_annotations),
                    ('montage.png', _("Define a montage with the result"), self.create_montage),
                    ('comment.png', _("Create a comment view with the result"), self.create_comment),
                    (Gtk.STOCK_FIND_AND_REPLACE, _("Search and replace strings in the annotations content"), self.search_replace),
                    ):
                    if icon.endswith('.png'):
                        ti=get_pixmap_toolbutton(icon)
                    else:
                        ti=Gtk.ToolButton(stock_id=icon)
                    ti.connect('clicked', action)
                    ti.set_tooltip_text(tip)
                    tb.insert(ti, -1)

                self.table=table
            else:
                # Only Instanciate a generic table view
                gtable=GenericTable(controller=self.controller, elements=self.result)
                v.add(gtable.widget)

                ti=Gtk.ToolButton(Gtk.STOCK_CONVERT)
                ti.connect('clicked', lambda b: gtable.csv_export())
                ti.set_tooltip_text(_("Export table"))
                tb.insert(ti, -1)
                self.table=gtable


            ti=get_pixmap_toolbutton('editaccumulator.png',
                                     lambda b: self.open_in_edit_accumulator(self.table.get_elements()))
            ti.set_tooltip_text(_("Edit elements"))
            tb.insert(ti, -1)

            if config.data.preferences['expert-mode']:
                ti=get_pixmap_toolbutton('python.png',
                                         lambda b: self.open_in_evaluator(self.table.get_elements()))
                ti.set_tooltip_text(_("Open in python evaluator"))
                tb.insert(ti, -1)
        else:
            v.add(Gtk.Label(label=_("Result:\n%s") % str(self.result)))
        v.show_all()
        return v
Ejemplo n.º 2
0
    def build_widget(self):

        if self.vertical:
            v=gtk.VBox()
            mainbox=gtk.VBox()
        else:
            v=gtk.HBox()
            mainbox=gtk.HBox()

        mainbox.set_homogeneous(False)
        sw=gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
        sw.add_with_viewport(mainbox)
        self.mainbox=mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['annotation']:
                sources=[ self.controller.package.annotations.get(uri) for uri in unicode(selection.data, 'utf8').split('\n') ]
                for a in sources:
                    for tag in a.tags:
                        if not tag in self.tags:
                            self.tags.append(tag)
                self.refresh()
            elif targetType == config.data.target_type['tag']:
                tags=unicode(selection.data, 'utf8').split(',')
                for tag in tags:
                    if not tag in self.tags:
                        self.tags.append(tag)
                self.refresh()
            else:
                self.log("Unknown target type for mainbox drop: %d" % targetType)
            return True

        self.mainbox.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                                  gtk.DEST_DEFAULT_HIGHLIGHT |
                                  gtk.DEST_DEFAULT_ALL,
                                  config.data.drag_type['annotation']
                                  + config.data.drag_type['tag']
                                   , gtk.gdk.ACTION_LINK)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['tag']:
                tag=unicode(selection.data, 'utf8')
                if tag in self.tags:
                    self.tags.remove(tag)
                self.refresh()
            else:
                self.log("Unknown target type for remove drop: %d" % targetType)
            return True


        hb=gtk.HBox()
        hb.set_homogeneous(False)

        b=get_small_stock_button(gtk.STOCK_DELETE)

        b.set_tooltip_text(_("Drop a tag here to remove it from the list"))
        b.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                        gtk.DEST_DEFAULT_HIGHLIGHT |
                        gtk.DEST_DEFAULT_ALL,
                        config.data.drag_type['tag'], gtk.gdk.ACTION_LINK)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, expand=False)

        for (stock, tip, method) in (
            (gtk.STOCK_SAVE, _("Save as adhoc view"), self.save_view),
            (gtk.STOCK_ADD, _("Add a new tag"), self.new_tag),
            (gtk.STOCK_INDEX, _("Display all defined tags"), self.all_tags),
            ):
            b=get_small_stock_button(stock)
            b.set_tooltip_text(tip)
            b.connect('clicked', method)
            hb.pack_start(b, expand=False)

        v.buttonbox=hb

        v.pack_start(hb, expand=False)
        v.add(sw)

        return v
Ejemplo n.º 3
0
    def build_widget(self):
        vbox = Gtk.VBox()

        if GtkSource is not None:
            self.textview=GtkSource.View()
            self.textview.set_buffer(GtkSource.Buffer())
        else:
            self.textview = Gtk.TextView()

        # We could make it editable and modify the annotation
        self.textview.set_editable(True)
        self.textview.set_wrap_mode (Gtk.WrapMode.WORD)

        hb=Gtk.HBox()
        vbox.pack_start(hb, False, True, 0)
        if self.controller.gui:
            self.player_toolbar=self.controller.gui.get_player_control_toolbar()
            hb.add(self.player_toolbar)
        hb.add(self.get_toolbar())

        sw = Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        vbox.add (sw)


        # 0-mark at the beginning
        zero=self.create_timestamp_mark(0, self.textview.get_buffer().get_start_iter())
        self.current_mark=zero

        # Memorize the last keypress time
        self.last_keypress_time = 0

        self.textview.connect('button-press-event', self.button_press_event_cb)
        self.textview.connect('key-press-event', self.key_pressed_cb)
        self.textview.get_buffer().create_tag("past", background="#dddddd")
        self.textview.get_buffer().create_tag("ignored", strikethrough=True)

        self.textview.drag_dest_set(Gtk.DestDefaults.MOTION |
                                    Gtk.DestDefaults.HIGHLIGHT |
                                    Gtk.DestDefaults.ALL,
                                    config.data.get_target_types('timestamp'),
                                    Gdk.DragAction.COPY | Gdk.DragAction.MOVE)
        self.textview.connect('drag-data-received', self.textview_drag_received)

        # Hook the completer component
        completer=Completer(textview=self.textview,
                            controller=self.controller,
                            element=self.textview.get_buffer(),
                            indexer=self.controller.package._indexer)

        sw.add(self.textview)

        # Search box
        b=self.textview.get_buffer()

        # Create useful tags
        b.create_tag("activated", background="skyblue")
        b.create_tag("current", background="lightblue")
        b.create_tag("searched_string", background="green")

        self.searchbox=Gtk.HBox()

        def hide_searchbox(*p):
            # Clear the searched_string tags
            b=self.textview.get_buffer()
            b.remove_tag_by_name("searched_string", *b.get_bounds())
            self.searchbox.hide()
            return True

        close_button=get_pixmap_button('small_close.png', hide_searchbox)
        close_button.set_relief(Gtk.ReliefStyle.NONE)
        self.searchbox.pack_start(close_button, False, False, 0)

        def search_entry_cb(e):
            self.highlight_search_forward(e.get_text())
            return True

        def search_entry_key_press_cb(e, event):
            if event.keyval == Gdk.KEY_Escape:
                hide_searchbox()
                return True
            return False

        self.searchbox.entry=Gtk.Entry()
        self.searchbox.entry.connect('activate', search_entry_cb)
        self.searchbox.pack_start(self.searchbox.entry, False, False, 0)
        self.searchbox.entry.connect('key-press-event', search_entry_key_press_cb)

        b=get_small_stock_button(Gtk.STOCK_FIND)
        b.connect('clicked', lambda b: self.highlight_search_forward(self.searchbox.entry.get_text()))
        self.searchbox.pack_start(b, False, True, 0)

        fill=Gtk.HBox()
        self.searchbox.pack_start(fill, True, True, 0)
        self.searchbox.show_all()
        self.searchbox.hide()

        self.searchbox.set_no_show_all(True)
        vbox.pack_start(self.searchbox, False, True, 0)

        self.statusbar=Gtk.Statusbar()
        vbox.pack_start(self.statusbar, False, True, 0)
        vbox.show_all()

        return vbox
Ejemplo n.º 4
0
    def build_widget(self):

        if self.vertical:
            v = Gtk.VBox()
            mainbox = Gtk.VBox()
        else:
            v = Gtk.HBox()
            mainbox = Gtk.HBox()

        mainbox.set_homogeneous(False)
        sw = Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
        sw.add_with_viewport(mainbox)
        self.mainbox = mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType,
                                  time):
            if targetType == config.data.target_type['annotation']:
                sources = [
                    self.controller.package.annotations.get(uri)
                    for uri in str(selection.get_data(), 'utf8').split('\n')
                ]
                for a in sources:
                    for tag in a.tags:
                        if not tag in self.tags:
                            self.tags.append(tag)
                self.refresh()
            elif targetType == config.data.target_type['tag']:
                tags = str(selection.get_data(), 'utf8').split(',')
                for tag in tags:
                    if not tag in self.tags:
                        self.tags.append(tag)
                self.refresh()
            else:
                logger.warning("Unknown target type for mainbox drop: %d",
                               targetType)
            return True

        self.mainbox.drag_dest_set(
            Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT
            | Gtk.DestDefaults.ALL,
            config.data.get_target_types('annotation',
                                         'tag'), Gdk.DragAction.LINK)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        def remove_drag_received(widget, context, x, y, selection, targetType,
                                 time):
            if targetType == config.data.target_type['tag']:
                tag = str(selection.get_data(), 'utf8')
                if tag in self.tags:
                    self.tags.remove(tag)
                self.refresh()
            else:
                logger.warning("Unknown target type for remove drop: %d",
                               targetType)
            return True

        hb = Gtk.HBox()
        hb.set_homogeneous(False)

        b = get_small_stock_button(Gtk.STOCK_DELETE)

        b.set_tooltip_text(_("Drop a tag here to remove it from the list"))
        b.drag_dest_set(
            Gtk.DestDefaults.MOTION
            | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.ALL,
            config.data.get_target_types('tag'), Gdk.DragAction.LINK)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, False, True, 0)

        for (stock, tip, method) in (
            (Gtk.STOCK_SAVE, _("Save as adhoc view"), self.save_view),
            (Gtk.STOCK_ADD, _("Add a new tag"), self.new_tag),
            (Gtk.STOCK_INDEX, _("Display all defined tags"), self.all_tags),
        ):
            b = get_small_stock_button(stock)
            b.set_tooltip_text(tip)
            b.connect('clicked', method)
            hb.pack_start(b, False, True, 0)

        v.buttonbox = hb

        v.pack_start(hb, False, True, 0)
        v.add(sw)

        return v
Ejemplo n.º 5
0
    def build_widget(self):

        if self.vertical:
            v=Gtk.VBox()
            mainbox=Gtk.VBox()
        else:
            v=Gtk.HBox()
            mainbox=Gtk.HBox()

        mainbox.set_homogeneous(False)
        sw=Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER)
        sw.add_with_viewport(mainbox)
        self.mainbox=mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['annotation']:
                sources=[ self.controller.package.annotations.get(uri) for uri in str(selection.get_data(), 'utf8').split('\n') ]
                for a in sources:
                    for tag in a.tags:
                        if not tag in self.tags:
                            self.tags.append(tag)
                self.refresh()
            elif targetType == config.data.target_type['tag']:
                tags=str(selection.get_data(), 'utf8').split(',')
                for tag in tags:
                    if not tag in self.tags:
                        self.tags.append(tag)
                self.refresh()
            else:
                logger.warn("Unknown target type for mainbox drop: %d" % targetType)
            return True

        self.mainbox.drag_dest_set(Gtk.DestDefaults.MOTION |
                                   Gtk.DestDefaults.HIGHLIGHT |
                                   Gtk.DestDefaults.ALL,
                                   config.data.get_target_types('annotation', 'tag'),
                                   Gdk.DragAction.LINK)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['tag']:
                tag=str(selection.get_data(), 'utf8')
                if tag in self.tags:
                    self.tags.remove(tag)
                self.refresh()
            else:
                logger.warn("Unknown target type for remove drop: %d" % targetType)
            return True


        hb=Gtk.HBox()
        hb.set_homogeneous(False)

        b=get_small_stock_button(Gtk.STOCK_DELETE)

        b.set_tooltip_text(_("Drop a tag here to remove it from the list"))
        b.drag_dest_set(Gtk.DestDefaults.MOTION |
                        Gtk.DestDefaults.HIGHLIGHT |
                        Gtk.DestDefaults.ALL,
                        config.data.get_target_types('tag'),
                        Gdk.DragAction.LINK)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, False, True, 0)

        for (stock, tip, method) in (
            (Gtk.STOCK_SAVE, _("Save as adhoc view"), self.save_view),
            (Gtk.STOCK_ADD, _("Add a new tag"), self.new_tag),
            (Gtk.STOCK_INDEX, _("Display all defined tags"), self.all_tags),
            ):
            b=get_small_stock_button(stock)
            b.set_tooltip_text(tip)
            b.connect('clicked', method)
            hb.pack_start(b, False, True, 0)

        v.buttonbox=hb

        v.pack_start(hb, False, True, 0)
        v.add(sw)

        return v
Ejemplo n.º 6
0
    def build_widget(self):
        v=Gtk.VBox()

        hb=Gtk.HBox()
        hb.set_homogeneous(False)

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['timestamp']:
                data=decode_drop_parameters(selection.get_data())
                position=int(data['timestamp'])
                w=self.get_matching_bookmark(position)
                if position is not None:
                    self.bookmarks.remove(w)
                    self.refresh()
                return True
            else:
                logger.warning("Unknown target type for drop: %d", targetType)
            return False

        b=get_small_stock_button(Gtk.STOCK_DELETE)
        b.set_tooltip_text(_("Drop a position here to remove it from the list"))
        b.drag_dest_set(Gtk.DestDefaults.MOTION |
                        Gtk.DestDefaults.HIGHLIGHT |
                        Gtk.DestDefaults.ALL,
                        config.data.get_target_types('timestamp'),
                        Gdk.DragAction.LINK | Gdk.DragAction.COPY)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, False, True, 0)

        def bookmark_current_time(b):
            p=self.controller.player
            if p.is_playing():
                self.append(p.current_position_value)
            return True

        tb=Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)
        for icon, action, tip in (
                ('set-to-now.png', bookmark_current_time, _("Insert a bookmark for the current video time")),
                (Gtk.STOCK_CONVERT, self.convert_to_annotations, _("Convert bookmarks to annotations")),
                (Gtk.STOCK_SAVE, self.save_view, _("Save view")),
            ):
            if icon.endswith('.png'):
                b=get_pixmap_toolbutton(icon)
            else:
                b=Gtk.ToolButton(stock_id=icon)
            b.set_tooltip_text(tip)
            b.connect('clicked', action)
            tb.insert(b, -1)
        hb.add(tb)
        v.pack_start(hb, False, True, 0)

        if self.options['vertical']:
            mainbox=Gtk.VBox()
        else:
            mainbox=Gtk.HBox()

        sw=Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)

        sw.add_with_viewport(mainbox)
        self.scrollwindow=sw
        self.mainbox=mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['timestamp']:
                data=decode_drop_parameters(selection.get_data())
                position=int(data['timestamp'])
                comment=data.get('comment', '')
                self.append(position, comment=comment)
                return True
            else:
                logger.warning("Unknown target type for drop: %d", targetType)
            return False

        self.mainbox.drag_dest_set(Gtk.DestDefaults.MOTION |
                                   Gtk.DestDefaults.HIGHLIGHT |
                                   Gtk.DestDefaults.ALL,
                                   config.data.get_target_types('timestamp'), Gdk.DragAction.LINK | Gdk.DragAction.COPY)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        v.add(sw)

        return v
Ejemplo n.º 7
0
    def build_widget(self):
        v=Gtk.VBox()

        hb=Gtk.HBox()
        hb.set_homogeneous(False)

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['timestamp']:
                data=decode_drop_parameters(selection.get_data())
                position=int(data['timestamp'])
                w=self.get_matching_bookmark(position)
                if position is not None:
                    self.bookmarks.remove(w)
                    self.refresh()
                return True
            else:
                logger.warn("Unknown target type for drop: %d" % targetType)
            return False

        b=get_small_stock_button(Gtk.STOCK_DELETE)
        b.set_tooltip_text(_("Drop a position here to remove it from the list"))
        b.drag_dest_set(Gtk.DestDefaults.MOTION |
                        Gtk.DestDefaults.HIGHLIGHT |
                        Gtk.DestDefaults.ALL,
                        config.data.get_target_types('timestamp'),
                        Gdk.DragAction.LINK | Gdk.DragAction.COPY)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, False, True, 0)

        def bookmark_current_time(b):
            p=self.controller.player
            if p.is_playing():
                self.append(p.current_position_value)
            return True

        tb=Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)
        for icon, action, tip in (
            ('set-to-now.png', bookmark_current_time, _("Insert a bookmark for the current video time")),
            (Gtk.STOCK_CONVERT, self.convert_to_annotations, _("Convert bookmarks to annotations")),
            (Gtk.STOCK_SAVE, self.save_view, _("Save view")),
            ):
            if icon.endswith('.png'):
                b=get_pixmap_toolbutton(icon)
            else:
                b=Gtk.ToolButton(stock_id=icon)
            b.set_tooltip_text(tip)
            b.connect('clicked', action)
            tb.insert(b, -1)
        hb.add(tb)
        v.pack_start(hb, False, True, 0)

        if self.options['vertical']:
            mainbox=Gtk.VBox()
        else:
            mainbox=Gtk.HBox()

        sw=Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)

        sw.add_with_viewport(mainbox)
        self.scrollwindow=sw
        self.mainbox=mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['timestamp']:
                data=decode_drop_parameters(selection.get_data())
                position=int(data['timestamp'])
                comment=data.get('comment', '')
                self.append(position, comment=comment)
                return True
            else:
                logger.warn("Unknown target type for drop: %d" % targetType)
            return False

        self.mainbox.drag_dest_set(Gtk.DestDefaults.MOTION |
                                  Gtk.DestDefaults.HIGHLIGHT |
                                  Gtk.DestDefaults.ALL,
                                  config.data.get_target_types('timestamp'), Gdk.DragAction.LINK | Gdk.DragAction.COPY)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        v.add(sw)

        return v
Ejemplo n.º 8
0
    def build_widget(self):
        self.zoom_adjustment = Gtk.Adjustment.new(value=1.0,
                                                  lower=0.01,
                                                  upper=2.0,
                                                  step_increment=.01,
                                                  page_increment=.1,
                                                  page_size=.1)

        def zoom_adj_change(adj):
            # Update the value of self.scale accordingly
            # Get the window size
            if not self.mainbox.get_window():
                # The widget is not yet realized
                return True
            display_size = self.mainbox.get_parent().get_window().get_width()
            # Dropzones are approximately 10 pixels wide, and should
            # be taken into account, but it enforces handling the corner cases
            self.scale.set_value(1.0 * self.duration /
                                 (display_size / adj.get_value()))

            # Update the zoom combobox value
            self.zoom_combobox.get_child().set_text('%d%%' %
                                                    int(100 * adj.get_value()))
            return True

        def remove_drag_received(widget, context, x, y, selection, targetType,
                                 time):
            if targetType == config.data.target_type['uri-list']:
                m = re.match('advene:/adhoc/%d/(.+)' % hash(self),
                             selection.get_data().decode('utf-8'))
                if m:
                    h = int(m.group(1))
                    l = [w for w in self.contents if hash(w) == h]
                    if l:
                        # Found the element. Remove it.
                        self.contents.remove(l[0])
                        self.refresh()
                return True
            else:
                logger.warning("Unknown target type for drop: %d", targetType)
            return False

        self.zoom_adjustment.connect('value-changed', zoom_adj_change)

        v = Gtk.VBox()

        # Toolbar
        tb = Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)

        b = get_small_stock_button(Gtk.STOCK_DELETE)
        b.set_tooltip_text(
            _("Drop an annotation here to remove it from the list"))
        b.drag_dest_set(
            Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT
            | Gtk.DestDefaults.ALL, config.data.get_target_types('uri-list'),
            Gdk.DragAction.COPY | Gdk.DragAction.LINK)
        b.connect('drag-data-received', remove_drag_received)
        ti = Gtk.ToolItem()
        ti.add(b)
        tb.insert(ti, -1)

        b = Gtk.ToolButton(Gtk.STOCK_MEDIA_PLAY)
        b.set_tooltip_text(_("Play the montage"))
        b.connect('clicked', self.play)
        tb.insert(b, -1)

        b = Gtk.ToolButton(Gtk.STOCK_SAVE)
        b.set_tooltip_text(_("Save the view in the package"))
        b.connect('clicked', self.save_view)
        tb.insert(b, -1)

        def zoom_entry(entry):
            f = entry.get_text()

            i = re.findall(r'\d+', f)
            if i:
                f = int(i[0]) / 100.0
            else:
                return True
            self.zoom_adjustment.set_value(f)
            return True

        def zoom_change(combo):
            v = combo.get_current_element()
            if isinstance(v, float):
                self.zoom_adjustment.set_value(v)
            return True

        def zoom(i, factor):
            self.zoom_adjustment.set_value(self.zoom_adjustment.get_value() *
                                           factor)
            return True

        b = Gtk.ToolButton(Gtk.STOCK_ZOOM_OUT)
        b.connect('clicked', zoom, 1.3)
        b.set_tooltip_text(_("Zoom out"))
        tb.insert(b, -1)

        b = Gtk.ToolButton(Gtk.STOCK_ZOOM_IN)
        b.connect('clicked', zoom, .7)
        b.set_tooltip_text(_("Zoom in"))
        tb.insert(b, -1)

        self.zoom_combobox = dialog.list_selector_widget(members=[
            (f, "%d%%" % int(100 * f))
            for f in [(1.0 / pow(1.5, n)) for n in range(0, 10)]
        ],
                                                         entry=True,
                                                         callback=zoom_change)
        self.zoom_combobox.get_child().connect('activate', zoom_entry)
        self.zoom_combobox.get_child().set_width_chars(4)

        ti = Gtk.ToolItem()
        ti.add(self.zoom_combobox)
        ti.set_tooltip_text(_("Set zoom level"))
        tb.insert(ti, -1)

        b = Gtk.ToolButton(Gtk.STOCK_ZOOM_100)
        b.connect('clicked', lambda i: self.zoom_adjustment.set_value(1.0))
        b.set_tooltip_text(_("Set 100% zoom"))
        tb.insert(b, -1)

        def toggle_highlight(b):
            if b.highlight:
                event = "AnnotationActivate"
                label = _("Unhighlight annotations")
                b.highlight = False
            else:
                event = "AnnotationDeactivate"
                label = _("Highlight annotations")
                b.highlight = True
            b.set_tooltip_text(label)
            for a in set(w.annotation for w in self.contents):
                self.controller.notify(event, annotation=a)
            return True

        i = Gtk.Image()
        i.set_from_file(config.data.advenefile(('pixmaps', 'highlight.png')))
        b = Gtk.ToggleToolButton()
        b.set_tooltip_text(_("Highlight annotations"))
        b.set_icon_widget(i)
        b.highlight = True
        b.connect('clicked', toggle_highlight)
        tb.insert(b, -1)

        v.pack_start(tb, False, True, 0)

        self.mainbox = Gtk.HBox()

        def mainbox_drag_received(widget, context, x, y, selection, targetType,
                                  time):
            if targetType == config.data.target_type['annotation']:
                sources = [
                    self.controller.package.annotations.get(uri)
                    for uri in str(selection.get_data(), 'utf8').split('\n')
                ]
                for ann in sources:
                    if ann is None:
                        self.log("Problem when getting annotation from DND")
                        pass
                    self.insert(ann)
                    # If the origin is from the same montage, then
                    # consider it is a move and remove the origin
                    # annotation
                    w = Gtk.drag_get_source_widget(context)
                    if w in self.contents:
                        self.contents.remove(w)
                self.refresh()
                return True
            elif targetType == config.data.target_type['annotation-type']:
                at = self.controller.package.annotationTypes.get(
                    str(selection.get_data(), 'utf8'))
                for a in at.annotations:
                    self.insert(a)
                self.refresh()
                return True
            else:
                logger.warning("Unknown target type for drag: %d", targetType)
            return False

        v.drag_dest_set(
            Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT
            | Gtk.DestDefaults.ALL,
            config.data.get_target_types('annotation', 'annotation-type'),
            Gdk.DragAction.COPY | Gdk.DragAction.LINK | Gdk.DragAction.MOVE)
        v.connect('drag-data-received', mainbox_drag_received)

        sw = Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
        sw.add_with_viewport(self.mainbox)
        self.scrollwindow = sw

        v.pack_start(sw, False, True, 0)

        a = AnnotationDisplay(controller=self.controller)
        f = Gtk.Frame.new(_("Inspector"))
        f.add(a.widget)
        v.add(f)
        self.controller.gui.register_view(a)
        a.set_master_view(self)
        a.widget.show_all()

        v.pack_start(Gtk.VBox(), True, True, 0)

        hb = Gtk.HBox()
        l = Gtk.Label(label=_("Total duration:"))
        hb.pack_start(l, False, True, 0)
        self.duration_label = Gtk.Label(label='??')
        hb.pack_start(self.duration_label, False, True, 0)
        v.pack_start(hb, False, True, 0)

        return v
Ejemplo n.º 9
0
    def build_widget(self):
        v=gtk.VBox()

        hb=gtk.HBox()
        hb.set_homogeneous(False)

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['timestamp']:
                data=decode_drop_parameters(selection.data)
                position=long(data['timestamp'])
                w=self.get_matching_bookmark(position)
                if position is not None:
                    self.bookmarks.remove(w)
                    self.refresh()
                return True
            else:
                print "Unknown target type for drop: %d" % targetType
            return False

        b=get_small_stock_button(gtk.STOCK_DELETE)
        b.set_tooltip_text(_("Drop a position here to remove it from the list"))
        b.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                        gtk.DEST_DEFAULT_HIGHLIGHT |
                        gtk.DEST_DEFAULT_ALL,
                        config.data.drag_type['timestamp'], gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_COPY)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, expand=False)

        def bookmark_current_time(b):
            p=self.controller.player
            if p.status in (p.PlayingStatus, p.PauseStatus):
                v=p.current_position_value
                # Make a snapshot
                self.controller.update_snapshot(v)
                self.append(v)
            return True

        tb=gtk.Toolbar()
        tb.set_style(gtk.TOOLBAR_ICONS)
        for icon, action, tip in (
            ('set-to-now.png', bookmark_current_time, _("Insert a bookmark for the current video time")),
            (gtk.STOCK_CONVERT, self.convert_to_annotations, _("Convert bookmarks to annotations")),
            (gtk.STOCK_SAVE, self.save_view, _("Save view")),
            ):
            if icon.endswith('.png'):
                b=get_pixmap_toolbutton(icon)
            else:
                b=gtk.ToolButton(stock_id=icon)
            b.set_tooltip_text(tip)
            b.connect('clicked', action)
            tb.insert(b, -1)
        hb.add(tb)
        v.pack_start(hb, expand=False)

        if self.options['vertical']:
            mainbox=gtk.VBox()
        else:
            mainbox=gtk.HBox()

        sw=gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        sw.add_with_viewport(mainbox)
        self.scrollwindow=sw
        self.mainbox=mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['timestamp']:
                data=decode_drop_parameters(selection.data)
                position=long(data['timestamp'])
                comment=data.get('comment', '')
                self.append(position, comment=comment)
                return True
            else:
                print "Unknown target type for drop: %d" % targetType
            return False

        self.mainbox.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                                  gtk.DEST_DEFAULT_HIGHLIGHT |
                                  gtk.DEST_DEFAULT_ALL,
                                  config.data.drag_type['timestamp'], gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_COPY)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        v.add(sw)

        return v
Ejemplo n.º 10
0
    def build_widget(self):
        v=Gtk.VBox()

        tb=Gtk.Toolbar()
        tb.set_style(Gtk.ToolbarStyle.ICONS)
        v.pack_start(tb, False, True, 0)

        top_box=Gtk.HBox()
        v.pack_start(top_box, False, True, 0)

        if hasattr(self.query, 'container') and self.query.container.id == '_interactive':
            b=Gtk.Button(_("Edit query again"))
            b.connect('clicked', self.edit_query)
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, SimpleQuery):
            b=Gtk.Button(_("Edit query"))
            b.connect('clicked', lambda b: self.controller.gui.edit_element(self.query))
            top_box.pack_start(b, False, True, 0)
        elif isinstance(self.query, Quicksearch):
            e=Gtk.Entry()
            e.set_text(self.query.searched)
            e.set_width_chars(12)
            e.connect('activate', self.redo_quicksearch, e)
            b=get_small_stock_button(Gtk.STOCK_FIND, self.redo_quicksearch, e)
            e.set_tooltip_text(_('String to search'))
            b.set_tooltip_text(_('Search again'))
            top_box.pack_start(e, False, True, 0)
            top_box.pack_start(b, False, True, 0)

        # Present choices to display the result
        if not self.result:
            v.add(Gtk.Label(label=_("Empty result")))
        elif isinstance(self.result, (list, tuple, AbstractBundle)):
            # Check if there are annotations
            l=[ a for a in self.result if isinstance(a, Annotation) ]
            cr=len(self.result)
            cl=len(l)

            if cr == cl:
                t=_("Result is a list of %d annotations.") % cr
            else:
                t=_("Result is a list of  %(number)d elements with %(elements)s.") % {
                    'elements': helper.format_element_name("annotation", len(l)),
                    'number': len(self.result)}

            label=Gtk.Label(label=t)
            label.set_ellipsize(Pango.EllipsizeMode.END)
            label.set_line_wrap(True)
            top_box.add(label)

            def toggle_highlight(b, annotation_list):
                if not hasattr(b, 'highlight') or b.highlight:
                    event="AnnotationActivate"
                    label= _("Unhighlight annotations")
                    b.highlight=False
                else:
                    event="AnnotationDeactivate"
                    label=_("Highlight annotations")
                    b.highlight=True
                b.set_tooltip_text(label)
                for a in annotation_list:
                    self.controller.notify(event, annotation=a)
                return True

            if l:
                # Instanciate a table view
                table=AnnotationTable(controller=self.controller, elements=l)

                if cr == cl:
                    # Only annotations.
                    v.add(table.widget)
                else:
                    # Mixed annotations + other elements
                    notebook=Gtk.Notebook()
                    notebook.set_tab_pos(Gtk.PositionType.TOP)
                    notebook.popup_disable()
                    v.add(notebook)

                    notebook.append_page(table.widget, Gtk.Label(label=_("Annotations")))

                    gtable=GenericTable(controller=self.controller, elements=[ e
                                                                               for e in self.result
                                                                               if not isinstance(e, Annotation) ])
                    notebook.append_page(gtable.widget, Gtk.Label(label=_("Other elements")))


                for (icon, tip, action) in (
                        ('timeline.png' , _("Display annotations in timeline"), lambda b: self.open_in_timeline(l)),
                        ('transcription.png', _("Display annotations as transcription"), lambda b:
                         self.controller.gui.open_adhoc_view('transcription',
                                                             label=self._label,
                                                             destination=self._destination,
                                                             elements=l)),
                        ('highlight.png', _("Highlight annotations"), lambda b: toggle_highlight(b, l)),
                        (Gtk.STOCK_CONVERT, _("Export table"), lambda b: table.csv_export()),
                        (Gtk.STOCK_NEW, _("Create annotations from the result"), self.create_annotations),
                        ('montage.png', _("Define a montage with the result"), self.create_montage),
                        ('comment.png', _("Create a comment view with the result"), self.create_comment),
                        (Gtk.STOCK_FIND_AND_REPLACE, _("Search and replace strings in the annotations content"), self.search_replace),
                ):
                    if icon.endswith('.png'):
                        ti=get_pixmap_toolbutton(icon)
                    else:
                        ti=Gtk.ToolButton(stock_id=icon)
                    ti.connect('clicked', action)
                    ti.set_tooltip_text(tip)
                    tb.insert(ti, -1)

                self.table=table
            else:
                # Only Instanciate a generic table view
                gtable=GenericTable(controller=self.controller, elements=self.result)
                v.add(gtable.widget)

                ti=Gtk.ToolButton(Gtk.STOCK_CONVERT)
                ti.connect('clicked', lambda b: gtable.csv_export())
                ti.set_tooltip_text(_("Export table"))
                tb.insert(ti, -1)
                self.table=gtable


            ti=get_pixmap_toolbutton('editaccumulator.png',
                                     lambda b: self.open_in_edit_accumulator(self.table.get_elements()))
            ti.set_tooltip_text(_("Edit elements"))
            tb.insert(ti, -1)

            if config.data.preferences['expert-mode']:
                ti=get_pixmap_toolbutton('python.png',
                                         lambda b: self.open_in_evaluator(self.table.get_elements()))
                ti.set_tooltip_text(_("Open in python evaluator"))
                tb.insert(ti, -1)
        else:
            v.add(Gtk.Label(label=_("Result:\n%s") % str(self.result)))
        v.show_all()
        return v
Ejemplo n.º 11
0
    def build_widget(self):
        vbox = Gtk.VBox()

        if GtkSource is not None:
            self.textview=GtkSource.View()
            self.textview.set_buffer(GtkSource.Buffer())
        else:
            self.textview = Gtk.TextView()

        # We could make it editable and modify the annotation
        self.textview.set_editable(True)
        self.textview.set_wrap_mode (Gtk.WrapMode.WORD)

        hb=Gtk.HBox()
        vbox.pack_start(hb, False, True, 0)
        if self.controller.gui:
            self.player_toolbar=self.controller.gui.get_player_control_toolbar()
            hb.add(self.player_toolbar)
        hb.add(self.get_toolbar())

        sw = Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        vbox.add (sw)


        # 0-mark at the beginning
        zero=self.create_timestamp_mark(0, self.textview.get_buffer().get_start_iter())
        self.current_mark=zero

        # Memorize the last keypress time
        self.last_keypress_time = 0

        self.textview.connect('button-press-event', self.button_press_event_cb)
        self.textview.connect('key-press-event', self.key_pressed_cb)
        self.textview.get_buffer().create_tag("past", background="#dddddd")
        self.textview.get_buffer().create_tag("ignored", strikethrough=True)

        self.textview.drag_dest_set(Gtk.DestDefaults.MOTION |
                                    Gtk.DestDefaults.HIGHLIGHT |
                                    Gtk.DestDefaults.ALL,
                                    config.data.get_target_types('timestamp'),
                                    Gdk.DragAction.COPY | Gdk.DragAction.MOVE)
        self.textview.connect('drag-data-received', self.textview_drag_received)

        # Hook the completer component
        self.completer=Completer(textview=self.textview,
                                 controller=self.controller,
                                 element=self.textview.get_buffer(),
                                 indexer=self.controller.package._indexer)
        sw.add(self.textview)

        # Search box
        b=self.textview.get_buffer()

        # Create useful tags
        b.create_tag("activated", background="skyblue")
        b.create_tag("current", background="lightblue")
        b.create_tag("searched_string", background="green")

        self.searchbox=Gtk.HBox()

        def hide_searchbox(*p):
            # Clear the searched_string tags
            b=self.textview.get_buffer()
            b.remove_tag_by_name("searched_string", *b.get_bounds())
            self.searchbox.hide()
            return True

        close_button=get_pixmap_button('small_close.png', hide_searchbox)
        close_button.set_relief(Gtk.ReliefStyle.NONE)
        self.searchbox.pack_start(close_button, False, False, 0)

        def search_entry_cb(e):
            self.highlight_search_forward(e.get_text())
            return True

        def search_entry_key_press_cb(e, event):
            if event.keyval == Gdk.KEY_Escape:
                hide_searchbox()
                return True
            return False

        self.searchbox.entry=Gtk.Entry()
        self.searchbox.entry.connect('activate', search_entry_cb)
        self.searchbox.pack_start(self.searchbox.entry, False, False, 0)
        self.searchbox.entry.connect('key-press-event', search_entry_key_press_cb)

        b=get_small_stock_button(Gtk.STOCK_FIND)
        b.connect('clicked', lambda b: self.highlight_search_forward(self.searchbox.entry.get_text()))
        self.searchbox.pack_start(b, False, True, 0)

        fill=Gtk.HBox()
        self.searchbox.pack_start(fill, True, True, 0)
        self.searchbox.show_all()
        self.searchbox.hide()

        self.searchbox.set_no_show_all(True)
        vbox.pack_start(self.searchbox, False, True, 0)

        self.statusbar=Gtk.Statusbar()
        vbox.pack_start(self.statusbar, False, True, 0)
        vbox.show_all()

        return vbox
Ejemplo n.º 12
0
    def build_widget(self):
        vbox = gtk.VBox()

        if gtksourceview2 is not None:
            self.textview=gtksourceview2.View()
            self.textview.set_buffer(gtksourceview2.Buffer())
        else:
            self.textview = gtk.TextView()

        # We could make it editable and modify the annotation
        self.textview.set_editable(True)
        self.textview.set_wrap_mode (gtk.WRAP_WORD)

        hb=gtk.HBox()
        vbox.pack_start(hb, expand=False)
        if self.controller.gui:
            self.player_toolbar=self.controller.gui.get_player_control_toolbar()
            hb.add(self.player_toolbar)
        hb.add(self.get_toolbar())

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        vbox.add (sw)


        # 0-mark at the beginning
        zero=self.create_timestamp_mark(0, self.textview.get_buffer().get_start_iter())
        self.current_mark=zero

        # Memorize the last keypress time
        self.last_keypress_time = 0

        self.textview.connect('button-press-event', self.button_press_event_cb)
        self.textview.connect('key-press-event', self.key_pressed_cb)
        self.textview.get_buffer().create_tag("past", background="#dddddd")
        self.textview.get_buffer().create_tag("ignored", strikethrough=True)

        self.textview.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                                    gtk.DEST_DEFAULT_HIGHLIGHT |
                                    gtk.DEST_DEFAULT_ALL,
                                    config.data.drag_type['timestamp']
                                    ,
                                    gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_MOVE)
        self.textview.connect('drag-data-received', self.textview_drag_received)

        # Hook the completer component
        completer=Completer(textview=self.textview,
                            controller=self.controller,
                            element=self.textview.get_buffer(),
                            indexer=self.controller.package._indexer)

        sw.add(self.textview)

        # Search box
        b=self.textview.get_buffer()

        # Create useful tags
        b.create_tag("activated", background="skyblue")
        b.create_tag("current", background="lightblue")
        b.create_tag("searched_string", background="green")

        self.searchbox=gtk.HBox()

        def hide_searchbox(*p):
            # Clear the searched_string tags
            b=self.textview.get_buffer()
            b.remove_tag_by_name("searched_string", *b.get_bounds())
            self.searchbox.hide()
            return True

        close_button=get_pixmap_button('small_close.png', hide_searchbox)
        close_button.set_relief(gtk.RELIEF_NONE)
        self.searchbox.pack_start(close_button, expand=False, fill=False)

        def search_entry_cb(e):
            self.highlight_search_forward(e.get_text())
            return True

        def search_entry_key_press_cb(e, event):
            if event.keyval == gtk.keysyms.Escape:
                hide_searchbox()
                return True
            return False

        self.searchbox.entry=gtk.Entry()
        self.searchbox.entry.connect('activate', search_entry_cb)
        self.searchbox.pack_start(self.searchbox.entry, expand=False, fill=False)
        self.searchbox.entry.connect('key-press-event', search_entry_key_press_cb)

        b=get_small_stock_button(gtk.STOCK_FIND)
        b.connect('clicked', lambda b: self.highlight_search_forward(self.searchbox.entry.get_text()))
        self.searchbox.pack_start(b, expand=False)

        fill=gtk.HBox()
        self.searchbox.pack_start(fill, expand=True, fill=True)
        self.searchbox.show_all()
        self.searchbox.hide()

        self.searchbox.set_no_show_all(True)
        vbox.pack_start(self.searchbox, expand=False)

        self.statusbar=gtk.Statusbar()
        self.statusbar.set_has_resize_grip(False)
        vbox.pack_start(self.statusbar, expand=False)
        vbox.show_all()

        return vbox
Ejemplo n.º 13
0
    def build_widget(self):
        self.zoom_adjustment=gtk.Adjustment(value=1.0, lower=0.01, upper=2.0)

        def zoom_adj_change(adj):
            # Update the value of self.scale accordingly
            # Get the window size
            if not self.mainbox.window:
                # The widget is not yet realized
                return True
            display_size=self.mainbox.parent.window.get_size()[0]
            # Dropzones are approximately 10 pixels wide, and should
            # be taken into account, but it enforces handling the corner cases
            self.scale.value = 1.0 * self.duration / (display_size / adj.value )

            # Update the zoom combobox value
            self.zoom_combobox.child.set_text('%d%%' % long(100 * adj.value))
            return True

        def remove_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['uri-list']:
                m=re.match('advene:/adhoc/%d/(.+)' % hash(self),
                           selection.data)
                if m:
                    h=long(m.group(1))
                    l=[ w for w in self.contents if hash(w) == h ]
                    if l:
                        # Found the element. Remove it.
                        self.contents.remove(l[0])
                        self.refresh()
                return True
            else:
                print "Unknown target type for drop: %d" % targetType
            return False

        self.zoom_adjustment.connect('value-changed', zoom_adj_change)

        v=gtk.VBox()

        # Toolbar
        tb=gtk.Toolbar()
        tb.set_style(gtk.TOOLBAR_ICONS)

        b=get_small_stock_button(gtk.STOCK_DELETE)
        b.set_tooltip_text(_("Drop an annotation here to remove it from the list"))
        b.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                        gtk.DEST_DEFAULT_HIGHLIGHT |
                        gtk.DEST_DEFAULT_ALL,
                        config.data.drag_type['uri-list'], gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_LINK)
        b.connect('drag-data-received', remove_drag_received)
        ti=gtk.ToolItem()
        ti.add(b)
        tb.insert(ti, -1)

        b=gtk.ToolButton(gtk.STOCK_MEDIA_PLAY)
        b.set_tooltip_text(_("Play the montage"))
        b.connect('clicked', self.play)
        tb.insert(b, -1)

        b = gtk.ToolButton(gtk.STOCK_SAVE)
        b.set_tooltip_text(_("Save the view in the package"))
        b.connect('clicked', self.save_view)
        tb.insert(b, -1)

        def zoom_entry(entry):
            f=unicode(entry.get_text())

            i=re.findall(r'\d+', f)
            if i:
                f=int(i[0])/100.0
            else:
                return True
            self.zoom_adjustment.value=f
            return True

        def zoom_change(combo):
            v=combo.get_current_element()
            if isinstance(v, float):
                self.zoom_adjustment.value=v
            return True

        def zoom(i, factor):
            self.zoom_adjustment.value=self.zoom_adjustment.value * factor
            return True

        b=gtk.ToolButton(gtk.STOCK_ZOOM_OUT)
        b.connect('clicked', zoom, 1.3)
        b.set_tooltip_text(_("Zoom out"))
        tb.insert(b, -1)

        b=gtk.ToolButton(gtk.STOCK_ZOOM_IN)
        b.connect('clicked', zoom, .7)
        b.set_tooltip_text(_("Zoom in"))
        tb.insert(b, -1)

        self.zoom_combobox=dialog.list_selector_widget(members=[
                ( f, "%d%%" % long(100*f) )
                for f in [
                    (1.0 / pow(1.5, n)) for n in range(0, 10)
                    ]
                ],
                                                       entry=True,
                                                       callback=zoom_change)
        self.zoom_combobox.child.connect('activate', zoom_entry)
        self.zoom_combobox.child.set_width_chars(4)

        ti=gtk.ToolItem()
        ti.add(self.zoom_combobox)
        ti.set_tooltip_text(_("Set zoom level"))
        tb.insert(ti, -1)

        b=gtk.ToolButton(gtk.STOCK_ZOOM_100)
        b.connect('clicked', lambda i: self.zoom_adjustment.set_value(1.0))
        b.set_tooltip_text(_("Set 100% zoom"))
        tb.insert(b, -1)

        def toggle_highlight(b):
            if b.highlight:
                event="AnnotationActivate"
                label= _("Unhighlight annotations")
                b.highlight=False
            else:
                event="AnnotationDeactivate"
                label=_("Highlight annotations")
                b.highlight=True
            b.set_tooltip_text(label)
            for a in set( [ w.annotation for w in self.contents ] ):
                self.controller.notify(event, annotation=a)
            return True
        i=gtk.Image()
        i.set_from_file(config.data.advenefile( ( 'pixmaps', 'highlight.png') ))
        b=gtk.ToggleToolButton()
        b.set_tooltip_text(_("Highlight annotations"))
        b.set_icon_widget(i)
        b.highlight=True
        b.connect('clicked', toggle_highlight)
        tb.insert(b, -1)

        v.pack_start(tb, expand=False)

        self.mainbox=gtk.HBox()

        def mainbox_drag_received(widget, context, x, y, selection, targetType, time):
            if targetType == config.data.target_type['annotation']:
                sources=[ self.controller.package.annotations.get(uri) for uri in unicode(selection.data, 'utf8').split('\n') ]
                for ann in sources:
                    if ann is None:
                        self.log("Problem when getting annotation from DND")
                        pass
                    self.insert(ann)
                    # If the origin is from the same montage, then
                    # consider it is a move and remove the origin
                    # annotation
                    w=context.get_source_widget()
                    if w in self.contents:
                        self.contents.remove(w)
                self.refresh()
                return True
            elif targetType == config.data.target_type['annotation-type']:
                at=self.controller.package.annotationTypes.get(unicode(selection.data, 'utf8'))
                for a in at.annotations:
                    self.insert(a)
                self.refresh()
                return True
            else:
                print "Unknown target type for drag: %d" % targetType
            return False
        v.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
                                   gtk.DEST_DEFAULT_HIGHLIGHT |
                                   gtk.DEST_DEFAULT_ALL,
                                   config.data.drag_type['annotation']
                                   + config.data.drag_type['annotation-type'],
                                   gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE)
        v.connect('drag-data-received', mainbox_drag_received)

        sw=gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER)
        sw.add_with_viewport(self.mainbox)
        self.scrollwindow=sw

        v.pack_start(sw, expand=False)

        a=AnnotationDisplay(controller=self.controller)
        f=gtk.Frame(_("Inspector"))
        f.add(a.widget)
        v.add(f)
        self.controller.gui.register_view (a)
        a.set_master_view(self)
        a.widget.show_all()

        v.pack_start(gtk.VBox(), expand=True)

        hb=gtk.HBox()
        l=gtk.Label(_("Total duration:"))
        hb.pack_start(l, expand=False)
        self.duration_label=gtk.Label('??')
        hb.pack_start(self.duration_label, expand=False)
        v.pack_start(hb, expand=False)

        return v
Ejemplo n.º 14
0
    def build_widget(self):

        if self.vertical:
            v = gtk.VBox()
            mainbox = gtk.VBox()
        else:
            v = gtk.HBox()
            mainbox = gtk.HBox()

        mainbox.set_homogeneous(False)
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
        sw.add_with_viewport(mainbox)
        self.mainbox = mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType,
                                  time):
            if targetType == config.data.target_type['annotation']:
                sources = [
                    self.controller.package.annotations.get(uri)
                    for uri in unicode(selection.data, 'utf8').split('\n')
                ]
                for a in sources:
                    for tag in a.tags:
                        if not tag in self.tags:
                            self.tags.append(tag)
                self.refresh()
            elif targetType == config.data.target_type['tag']:
                tags = unicode(selection.data, 'utf8').split(',')
                for tag in tags:
                    if not tag in self.tags:
                        self.tags.append(tag)
                self.refresh()
            else:
                self.log("Unknown target type for mainbox drop: %d" %
                         targetType)
            return True

        self.mainbox.drag_dest_set(
            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT
            | gtk.DEST_DEFAULT_ALL,
            config.data.drag_type['annotation'] + config.data.drag_type['tag'],
            gtk.gdk.ACTION_LINK)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        def remove_drag_received(widget, context, x, y, selection, targetType,
                                 time):
            if targetType == config.data.target_type['tag']:
                tag = unicode(selection.data, 'utf8')
                if tag in self.tags:
                    self.tags.remove(tag)
                self.refresh()
            else:
                self.log("Unknown target type for remove drop: %d" %
                         targetType)
            return True

        hb = gtk.HBox()
        hb.set_homogeneous(False)

        b = get_small_stock_button(gtk.STOCK_DELETE)

        b.set_tooltip_text(_("Drop a tag here to remove it from the list"))
        b.drag_dest_set(
            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT
            | gtk.DEST_DEFAULT_ALL, config.data.drag_type['tag'],
            gtk.gdk.ACTION_LINK)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, expand=False)

        for (stock, tip, method) in (
            (gtk.STOCK_SAVE, _("Save as adhoc view"), self.save_view),
            (gtk.STOCK_ADD, _("Add a new tag"), self.new_tag),
            (gtk.STOCK_INDEX, _("Display all defined tags"), self.all_tags),
        ):
            b = get_small_stock_button(stock)
            b.set_tooltip_text(tip)
            b.connect('clicked', method)
            hb.pack_start(b, expand=False)

        v.buttonbox = hb

        v.pack_start(hb, expand=False)
        v.add(sw)

        return v
Ejemplo n.º 15
0
    def build_widget(self):
        v = gtk.VBox()

        hb = gtk.HBox()
        hb.set_homogeneous(False)

        def remove_drag_received(widget, context, x, y, selection, targetType,
                                 time):
            if targetType == config.data.target_type['timestamp']:
                data = decode_drop_parameters(selection.data)
                position = long(data['timestamp'])
                w = self.get_matching_bookmark(position)
                if position is not None:
                    self.bookmarks.remove(w)
                    self.refresh()
                return True
            else:
                print "Unknown target type for drop: %d" % targetType
            return False

        b = get_small_stock_button(gtk.STOCK_DELETE)
        b.set_tooltip_text(
            _("Drop a position here to remove it from the list"))
        b.drag_dest_set(
            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT
            | gtk.DEST_DEFAULT_ALL, config.data.drag_type['timestamp'],
            gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_COPY)
        b.connect('drag-data-received', remove_drag_received)
        hb.pack_start(b, expand=False)

        def bookmark_current_time(b):
            p = self.controller.player
            if p.status in (p.PlayingStatus, p.PauseStatus):
                v = p.current_position_value
                # Make a snapshot
                self.controller.update_snapshot(v)
                self.append(v)
            return True

        tb = gtk.Toolbar()
        tb.set_style(gtk.TOOLBAR_ICONS)
        for icon, action, tip in (
            ('set-to-now.png', bookmark_current_time,
             _("Insert a bookmark for the current video time")),
            (gtk.STOCK_CONVERT, self.convert_to_annotations,
             _("Convert bookmarks to annotations")),
            (gtk.STOCK_SAVE, self.save_view, _("Save view")),
        ):
            if icon.endswith('.png'):
                b = get_pixmap_toolbutton(icon)
            else:
                b = gtk.ToolButton(stock_id=icon)
            b.set_tooltip_text(tip)
            b.connect('clicked', action)
            tb.insert(b, -1)
        hb.add(tb)
        v.pack_start(hb, expand=False)

        if self.options['vertical']:
            mainbox = gtk.VBox()
        else:
            mainbox = gtk.HBox()

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        sw.add_with_viewport(mainbox)
        self.scrollwindow = sw
        self.mainbox = mainbox

        def mainbox_drag_received(widget, context, x, y, selection, targetType,
                                  time):
            if targetType == config.data.target_type['timestamp']:
                data = decode_drop_parameters(selection.data)
                position = long(data['timestamp'])
                comment = data.get('comment', '')
                self.append(position, comment=comment)
                return True
            else:
                print "Unknown target type for drop: %d" % targetType
            return False

        self.mainbox.drag_dest_set(
            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT
            | gtk.DEST_DEFAULT_ALL, config.data.drag_type['timestamp'],
            gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_COPY)
        self.mainbox.connect('drag-data-received', mainbox_drag_received)

        v.add(sw)

        return v