Exemplo n.º 1
0
    def _record_range(self):
        start = self.textbuffer.get_iter_at_offset(self.start_offset)
        end = self.textbuffer.get_iter_at_offset(self.end_offset)

        # TODO: I can probably discard iter's.  Maybe make argument to
        # iter_buffer_contents
        self.contents = filter(lambda (kind, it, param): 
            kind in ("begin", "end") and param == self.tag,
            buffer_contents_iter_to_offset(
                iter_buffer_contents(self.textbuffer, start, end)))
Exemplo n.º 2
0
    def _record_range(self):
        start = self.textbuffer.get_iter_at_offset(self.start_offset)
        end = self.textbuffer.get_iter_at_offset(self.end_offset)

        # TODO: I can probably discard iter's.  Maybe make argument to
        # iter_buffer_contents
        self.contents = filter(
            lambda (kind, it, param): kind in
            ("begin", "end") and param == self.tag,
            buffer_contents_iter_to_offset(
                iter_buffer_contents(self.textbuffer, start, end)))
Exemplo n.º 3
0
    def get_html(self):
        self._textview_io.save(self._textview.get_buffer())

        return
        output = StringIO.StringIO()
        self.set_output(output)
        textbuffer = textview.get_buffer()
        buffer_contents = iter_buffer_contents(textbuffer, None, None, ignore_tag)
        self.write(buffer_contents, textbuffer.tag_table, title=None)
        self._out.flush()
        return output.getvalue()
Exemplo n.º 4
0
    def get_html(self):
        self._textview_io.save(self._textview.get_buffer())

        return
        output = StringIO.StringIO()
        self.set_output(output)
        textbuffer = textview.get_buffer()
        buffer_contents = iter_buffer_contents(textbuffer, None, None,
                                               ignore_tag)
        self.write(buffer_contents, textbuffer.tag_table, title=None)
        self._out.flush()
        return output.getvalue()
Exemplo n.º 5
0
    def save(self, textbuffer):
        """Save buffer contents to file"""

        try:
            buffer_contents = iter_buffer_contents(textbuffer, None, None, ignore_tag)

            out = sys.stdout
            self._html_buffer.set_output(out)
            self._html_buffer.write(buffer_contents,
                                    textbuffer.tag_table,)
                                    ##title=title)
            out.flush()
        except IOError, e:
            raise RichTextError("Could not save '%s'." % filename, e)
Exemplo n.º 6
0
    def _load_images(self, textbuffer, path):
        """Load images present in textbuffer"""

        for kind, it, param in iter_buffer_contents(textbuffer, None, None,
                                                    ignore_tag):
            if kind == "anchor":
                child, widgets = param

                if isinstance(child, RichTextImage):
                    filename = child.get_filename()
                    if is_relative_file(filename):
                        filename = os.path.join(path, filename)

                    child.set_from_file(filename)
Exemplo n.º 7
0
    def save(self, textbuffer):
        """Save buffer contents to file"""

        try:
            buffer_contents = iter_buffer_contents(textbuffer, None, None,
                                                   ignore_tag)

            out = sys.stdout
            self._html_buffer.set_output(out)
            self._html_buffer.write(
                buffer_contents,
                textbuffer.tag_table,
            )
            ##title=title)
            out.flush()
        except IOError, e:
            raise RichTextError("Could not save '%s'." % filename, e)
Exemplo n.º 8
0
    def save(self, textbuffer, filename, title=None):
        """Save buffer contents to file"""

        path = os.path.dirname(filename)
        self._save_images(textbuffer, path)

        try:
            buffer_contents = iter_buffer_contents(textbuffer, None, None,
                                                   ignore_tag)

            out = safefile.open(filename, "wb", codec="utf-8")
            self._html_buffer.set_output(out)
            self._html_buffer.write(buffer_contents,
                                    textbuffer.tag_table,
                                    title=title)
            out.close()
        except IOError, e:
            raise RichTextError("Could not save '%s'." % filename, e)
Exemplo n.º 9
0
    def copy_contents(self, start, end):
        """Return a content stream for copying from iter start and end"""

        contents = iter(iter_buffer_contents(self, start, end, ignore_tag))

        # remove regions that can't be copied
        for item in contents:
            # NOTE: item = (kind, it, param)
            
            if item[0] == "begin" and not item[2].can_be_copied():
                end_tag = item[2]
                
                while not (item[0] == "end" and item[2] == end_tag):
                    item = contents.next()

                    if item[0] not in ("text", "anchor") and \
                       item[2] != end_tag:
                        yield item
                    
                continue

            yield item
Exemplo n.º 10
0
    def _load_images(self, textbuffer, path):
        """Load images present in textbuffer"""

        for kind, it, param in iter_buffer_contents(textbuffer, None, None,
                                                    ignore_tag):
            if kind == "anchor":
                child, widgets = param

                if isinstance(child, RichTextImage):
                    filename = child.get_filename()
                    if is_relative_file(filename):
                        filename = os.path.join(path, filename)

                    ## For absolute windows filenames
                    if filename.startswith('file://'):
                        filename = filename[7:]

                    ## Modified
                    if filename.startswith("http:") or \
                            filename.startswith("file:"):
                        child.set_from_url(filename, os.path.basename(filename))
                    else:
                        child.set_from_file(filename)
Exemplo n.º 11
0
    def _load_images(self, textbuffer, path):
        """Load images present in textbuffer"""

        for kind, it, param in iter_buffer_contents(textbuffer, None, None,
                                                    ignore_tag):
            if kind == "anchor":
                child, widgets = param

                if isinstance(child, RichTextImage):
                    filename = child.get_filename()
                    if is_relative_file(filename):
                        filename = os.path.join(path, filename)

                    ## For absolute windows filenames
                    if filename.startswith('file://'):
                        filename = filename[7:]

                    ## Modified
                    if filename.startswith("http:") or \
                            filename.startswith("file:"):
                        child.set_from_url(filename,
                                           os.path.basename(filename))
                    else:
                        child.set_from_file(filename)
Exemplo n.º 12
0
 def _record_range(self):
     start = self.textbuffer.get_iter_at_offset(self.start_offset)
     end = self.textbuffer.get_iter_at_offset(self.end_offset)
     self.contents = list(
         buffer_contents_iter_to_offset(
             iter_buffer_contents(self.textbuffer, start, end)))
Exemplo n.º 13
0
 def _record_range(self):
     start = self.textbuffer.get_iter_at_offset(self.start_offset)
     end = self.textbuffer.get_iter_at_offset(self.end_offset)
     self.contents = list(buffer_contents_iter_to_offset(
         iter_buffer_contents(self.textbuffer, start, end)))