Пример #1
0
    def build_widget(self):
        self.image = TimestampRepresentation(
            self.value,
            None,
            self.controller,
            comment_getter=lambda: self.comment,
            width=self.width,
            precision=config.data.preferences['bookmark-snapshot-precision'])

        self.image.connect('clicked', self.image.goto_and_refresh)

        if self.display_comments:
            hbox = Gtk.HBox()
            self.comment_entry = Gtk.TextView()
            # Hook the completer component
            completer = Completer(textview=self.comment_entry,
                                  controller=self.controller,
                                  element=self.comment_entry.get_buffer(),
                                  indexer=self.controller.package._indexer)
            self.comment_entry.set_wrap_mode(Gtk.WrapMode.WORD)
            fd = Pango.FontDescription(
                'sans %d' % config.data.preferences['timeline']['font-size'])
            self.comment_entry.modify_font(fd)
            b = self.comment_entry.get_buffer()
            b.set_text(self.comment)

            def focus_in_event(wid, event):
                if b.get_text(*b.get_bounds() +
                              (False, )) == self.default_comment:
                    b.set_text('')
                return False

            self.comment_entry.connect('focus-in-event', focus_in_event)

            def focus_out_event(wid, event):
                if b.get_text(*b.get_bounds() + (False, )) == '':
                    b.set_text(self.default_comment)
                return False

            self.comment_entry.connect('focus-out-event', focus_out_event)

            def update_comment(buf):
                self.comment = buf.get_text(*buf.get_bounds() + (False, ))
                return True

            b.connect('changed', update_comment)

            #self.comment_entry.set_size_request(config.data.preferences['bookmark-snapshot-width'], -1)

            sw = Gtk.ScrolledWindow()
            sw.add(self.comment_entry)
            sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
            hbox.pack_start(self.image, False, True, 0)
            hbox.pack_start(sw, True, True, 0)
            hbox.show_all()
            return hbox
        else:
            return self.image
Пример #2
0
 def entry_editing_started(cell, editable, path):
     if isinstance(editable, Gtk.Entry):
         it = self.model.get_iter_from_string(path)
         if not it:
             return
         el = self.model.get_value(it, COLUMN_ELEMENT)
         editable._completer = Completer(
             textview=editable,
             controller=self.controller,
             element=el,
             indexer=el.rootPackage._indexer)
Пример #3
0
    def build_widget(self):
        v = gtk.VBox()

        self.label = {}
        self.sw = {}

        h = gtk.HBox()
        self.label['title'] = gtk.Label()
        h.pack_start(self.label['title'], expand=False)
        v.pack_start(h, expand=False)

        h = gtk.HBox()
        self.label['begin'] = gtk.Label()
        h.pack_start(self.label['begin'], expand=False)
        l = gtk.Label(' - ')
        h.pack_start(l, expand=False)
        self.label['end'] = gtk.Label()
        h.pack_start(self.label['end'], expand=False)
        v.pack_start(h, expand=False)

        def handle_motion(widget, event):
            if isinstance(self.annotation, Annotation):
                i = self.label['image']
                i.epsilon = self.annotation.fragment.duration / widget.allocation.width
                v = self.annotation.fragment.begin + i.epsilon * 20 * int(
                    event.x / 20)
                i.set_value(v)
            return True

        def handle_leave(widget, event):
            if isinstance(self.annotation, Annotation):
                i = self.label['image']
                i.epsilon = config.data.preferences[
                    'bookmark-snapshot-precision']
                i.set_value(self.annotation.fragment.begin)
            return True

        fr = gtk.Expander()
        fr.set_label(_("Screenshot"))
        self.label['image'] = TimestampRepresentation(
            -1,
            self.controller,
            width=config.data.preferences['drag-snapshot-width'],
            epsilon=config.data.preferences['bookmark-snapshot-precision'],
            visible_label=False)
        self.label['image'].add_events(gtk.gdk.POINTER_MOTION_MASK
                                       | gtk.gdk.LEAVE_NOTIFY_MASK)
        self.label['image'].connect('motion-notify-event', handle_motion)
        self.label['image'].connect('leave-notify-event', handle_leave)

        fr.add(self.label['image'])
        fr.set_expanded(True)
        v.pack_start(fr, expand=False)

        # Contents frame
        def handle_ok(b):
            b.hide()
            if isinstance(self.annotation, Annotation):
                self.controller.notify('EditSessionStart',
                                       element=self.annotation,
                                       immediate=True)
                self.annotation.content.data = self.label['contents'].get_text(
                )
                self.controller.notify("AnnotationEditEnd",
                                       annotation=self.annotation)
                self.controller.notify('EditSessionEnd',
                                       element=self.annotation)
            return True

        hbox = gtk.HBox()
        hbox.pack_start(gtk.Label(_("Contents")), expand=False)
        ok_button = get_pixmap_button('small_ok.png', handle_ok)
        ok_button.set_relief(gtk.RELIEF_NONE)
        ok_button.set_tooltip_text(_("Validate"))
        ok_button.set_no_show_all(True)
        hbox.pack_start(ok_button, expand=False)

        f = gtk.Frame()
        f.set_label_widget(hbox)

        def contents_modified(buf):
            if buf.get_modified():
                if not buf.ignore_modified:
                    ok_button.show()
            else:
                ok_button.hide()
            return True

        c = self.label['contents'] = gtk.TextView()
        c.set_wrap_mode(gtk.WRAP_WORD_CHAR)
        c.get_buffer().ignore_modified = False
        c.get_buffer().connect('modified-changed', contents_modified)
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(c)

        def set_text(widget, t):
            b = widget.get_buffer()
            b.ignore_modified = True
            b.delete(*b.get_bounds())
            b.set_text(t)
            b.set_modified(False)
            b.ignore_modified = False
            return True

        c.set_text = set_text.__get__(c)

        def get_text(widget):
            b = widget.get_buffer()
            return b.get_text(*b.get_bounds())

        c.get_text = get_text.__get__(c)
        self.sw['contents'] = sw

        def handle_keypress(widget, event):
            if (event.keyval == gtk.keysyms.Return
                    and event.state & gtk.gdk.CONTROL_MASK
                    and widget.get_buffer().get_modified()):
                handle_ok(ok_button)
                return True
            return False

        c.connect('key-press-event', handle_keypress)

        # Hook the completer component
        if hasattr(self.controller.package, '_indexer'):
            self.completer = Completer(
                textview=c,
                controller=self.controller,
                element=self.annotation,
                indexer=self.controller.package._indexer)

        image = self.label['imagecontents'] = gtk.Image()

        swi = gtk.ScrolledWindow()
        swi.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        swi.add_with_viewport(image)
        self.sw['imagecontents'] = swi

        vb = gtk.VBox()
        vb.add(sw)
        vb.add(swi)

        f.add(vb)
        v.add(f)

        v.show_all()
        image.hide()
        v.set_no_show_all(True)

        def annotation_drag_received_cb(widget, context, x, y, selection,
                                        targetType, time):
            """Handle the drop of an annotation.
            """
            if targetType == config.data.target_type['annotation']:
                sources = [
                    self.controller.package.annotations.get(uri)
                    for uri in unicode(selection.data, 'utf8').split('\n')
                ]
                if sources:
                    self.set_annotation(sources[0])
                return True
            return False

        # The button can receive drops (to display annotations)
        v.connect('drag-data-received', annotation_drag_received_cb)
        v.drag_dest_set(
            gtk.DEST_DEFAULT_MOTION | gtk.DEST_DEFAULT_HIGHLIGHT
            | gtk.DEST_DEFAULT_ALL, config.data.drag_type['annotation'],
            gtk.gdk.ACTION_COPY | gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE)

        return v
Пример #4
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