[pygtk] Searching and highlighting in pygtksourceview2

Shanjit Singh shanjitsingh at gmail.com
Wed Oct 6 02:58:39 WST 2010


Hi,

I am new to working with pygtksourceview2.

I am trying to implement searching and highlighting in a display defined
below :-

It would be really very helpful if someone could help me out. I am done with
adding the Graphical part of it, its only the searching and highlighting
part which i am not able to grasp. Could someone please provide some
pointers?

Following is the part of code written :


        self._buffer = gtksourceview2.Buffer()
        self._buffer.set_highlight_syntax(True)
        self.search_text  = ' '
        self._textview=gtk.TextView(self._buffer)

        self._source_view = gtksourceview2.View(self._buffer)
        self._source_view.set_editable(False)
        self._source_view.set_cursor_visible(True)
        self._source_view.set_show_line_numbers(True)
        self._source_view.set_show_right_margin(True)
        self._source_view.set_right_margin_position(80)
        #self._source_view.set_highlight_current_line(True) #FIXME: Ugly
color
        self._source_view.modify_font(_SOURCE_FONT)
        self.add(self._source_view)
        self._source_view.show()

.... *Some more irrelevant part of code....*

    def set_search_text(self,
text):                                                               *This
function is called when something is typed into the search box.*
        self.search_text = text

        buffer = self._buffer

        start, end = buffer.get_bounds()
    *Function
which should find bounds of the buffer.*(Not Sure, if applicable for the
current buffer)


        iter = buffer.get_start_iter()
        while True:
            next = iter.forward_search(text, 0)
            if next is None: break
            start, end = next
        *Highlighting Code comes here.
*            iter = end



I would be thankful if someone could provide me pointers on how to implement
the searching and highlighting.

Thanks


Regards
Shanjit Singh Jajmann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20101006/b3221de4/attachment.html>


More information about the pygtk mailing list