Пример #1
0
    def insert_image_from_file(self, imgfile, filename="image.png"):
        """Inserts an image from a file"""

        pixbuf = gdk.pixbuf_new_from_file(imgfile)
        img = RichTextImage()
        img.set_from_pixbuf(pixbuf)
        self.insert_image(img, filename)
Пример #2
0
    def _do_paste_image(self, clipboard, selection_data, data):
        """Paste image into buffer"""

        pixbuf = selection_data.get_pixbuf()
        image = RichTextImage()
        image.set_from_pixbuf(pixbuf)

        self._textbuffer.begin_user_action()
        self._textbuffer.delete_selection(False, True)
        self._textbuffer.insert_image(image)
        self._textbuffer.end_user_action()
        self.scroll_mark_onscreen(self._textbuffer.get_insert())
Пример #3
0
 def parse_starttag(self, htmltag, attrs):
     """Parse image tag"""
     
     img = RichTextImage()
     width, height = None, None
     
     for key, value in attrs:
         if key == "src":
             img.set_filename(value)
                 
         elif key == "width":
             try:
                 width = int(value)
             except ValueError, e:
                 # ignore width if we cannot parse it
                 pass
             
         elif key == "height":
             try:
                 height = int(value)
             except ValueError, e:
                 # ignore height if we cannot parse it
                 pass
Пример #4
0
    def parse_starttag(self, htmltag, attrs):
        """Parse image tag"""

        img = RichTextImage()
        width, height = None, None

        for key, value in attrs:
            if key == "src":
                img.set_filename(value)

            elif key == "width":
                try:
                    width = int(value)
                except ValueError, e:
                    # ignore width if we cannot parse it
                    pass

            elif key == "height":
                try:
                    height = int(value)
                except ValueError, e:
                    # ignore height if we cannot parse it
                    pass
Пример #5
0
    def on_drag_data_received(self, widget, drag_context, x, y, selection_data,
                              info, eventtime):
        """Callback for when drop event is received"""

        if not self._textbuffer:
            return

        img_target = self.drag_dest_find_target(drag_context,
                                                [(x, 0, 0)
                                                 for x in MIME_IMAGES])

        if img_target not in (None, "NONE"):
            # process image drop
            pixbuf = selection_data.get_pixbuf()

            if pixbuf != None:
                image = RichTextImage()
                image.set_from_pixbuf(pixbuf)

                self.insert_image(image)

                drag_context.finish(True, True, eventtime)
                self.stop_emission("drag-data-received")

        elif self.drag_dest_find_target(
                drag_context, [("text/uri-list", 0, 0)]) not in (None, "NONE"):
            # process URI drop

            uris = parse_utf(selection_data.data)

            # remove empty lines and comments
            uris = [
                x for x in (uri.strip() for uri in uris.split("\n"))
                if len(x) > 0 and x[0] != "#"
            ]

            links = ['<a href="%s">%s</a> ' % (uri, uri) for uri in uris]

            # insert links
            self.insert_html("<br />".join(links))

        #elif self.drag_dest_find_target(drag_context,
        #    [("application/pdf", 0, 0)]) not in (None, "NONE"):
        #    # process pdf drop
        #
        #    data = selection_data.data
        #    self.drop_pdf(data)
        #
        #    drag_context.finish(True, True, eventtime)
        #    self.stop_emission("drag-data-received")

        elif self.drag_dest_find_target(drag_context,
                                        [("text/html", 0, 0)]) not in (None,
                                                                       "NONE"):
            # process html drop

            html = parse_utf(selection_data.data)
            #html =
            self.insert_html(html)

        elif self.drag_dest_find_target(
                drag_context, [("text/plain", 0, 0)]) not in (None, "NONE"):
            # process text drop

            #self._textbuffer.begin_user_action()
            self._textbuffer.insert_at_cursor(selection_data.get_text())